Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions config_2010.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"indent_size": 4,
"indent_char": " ",
"max_preserve_newlines": 1,
"preserve_newlines": true,
"keep_array_indentation": true,
"break_chained_methods": false,
"indent_scripts": "normal",
"brace_style": "collapse",
"space_before_conditional": true,
"unescape_strings": false,
"jslint_happy": false,
"end_with_newline": false,
"wrap_line_length": 0,
"indent_inner_html": false,
"comma_first": true,
"e4x": true,
"indent_empty_lines": true,
"space_in_paren": true,
"indent_with_tabs": true
}
5 changes: 5 additions & 0 deletions input_2010.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = [
1,
2,
3
]
12 changes: 8 additions & 4 deletions js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,13 @@ Beautifier.prototype._handle_tag_close = function(printer, raw_token, last_tag_t
printer.add_raw_token(raw_token);
} else {
if (last_tag_token.tag_start_char === '<') {
printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
if ((this._is_wrap_attributes_preserve || this._is_wrap_attributes_preserve_aligned) &&
printer.traverse_whitespace(raw_token)) {
// preserved newline or space
} else if (this._is_wrap_attributes_force_expand_multiline && last_tag_token.has_wrapped_attrs) {
printer.print_newline(false);
} else {
printer.set_space_before_token(raw_token.text[0] === '/', true); // space before />, no space before >
}
}
printer.print_token(raw_token);
Expand Down Expand Up @@ -750,7 +754,7 @@ Beautifier.prototype._set_tag_position = function(printer, raw_token, parser_tok
}

// Don't add a newline before elements that should remain where they are.
if (parser_token.tag_name === '!--' && last_token.type === TOKEN.TAG_CLOSE &&
if (parser_token.tag_name.indexOf('!--') === 0 && last_token.type === TOKEN.TAG_CLOSE &&
last_tag_token.is_end_tag && parser_token.text.indexOf('\n') === -1) {
//Do nothing. Leave comments on same line.
} else {
Expand Down Expand Up @@ -816,7 +820,7 @@ Beautifier.prototype._do_optional_end_element = function(parser_token) {
// are handled automatically by the beautifier.
// It assumes parent or ancestor close tag closes all children.
// https://www.w3.org/TR/html5/syntax.html#optional-tags
if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent) {
if (parser_token.is_empty_element || !parser_token.is_start_tag || !parser_token.parent || parser_token.tag_start_char !== '<') {
return;

}
Expand Down
4 changes: 2 additions & 2 deletions js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ Beautifier.prototype.handle_comma = function(current_token) {
if (this._flags.declaration_assignment) {
this._flags.declaration_assignment = false;
this.print_newline(false, true);
} else if (this._options.comma_first) {
} else if (this._options.comma_first && !(this._options.keep_array_indentation && is_array(this._flags.mode) && current_token.newlines)) {
// for comma-first, we want to allow a newline before the comma
// to turn into a newline after the comma, which we will fixup later
this.allow_wrap_or_preserved_newline(current_token);
Expand All @@ -1136,7 +1136,7 @@ Beautifier.prototype.handle_comma = function(current_token) {
if (!this._flags.inline_frame) {
this.print_newline();
}
} else if (this._options.comma_first) {
} else if (this._options.comma_first && !(this._options.keep_array_indentation && is_array(this._flags.mode) && current_token.newlines)) {
// EXPR or DO_BLOCK
// for comma-first, we want to allow a newline before the comma
// to turn into a newline after the comma, which we will fixup later
Expand Down
5 changes: 5 additions & 0 deletions output_1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = [
1
, 2
, 3
]
5 changes: 5 additions & 0 deletions output_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = [
1
, 2
, 3
]
5 changes: 5 additions & 0 deletions output_3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = [
1
, 2
, 3
]
32 changes: 31 additions & 1 deletion test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4402,6 +4402,36 @@ exports.test_data = {
]
}]
}, {
name: "New Test Suite"
name: "Issue #1823",
description: "HTML comments without leading spaces should remain on the same line as the preceding closing tag.",
matrix: [{
options: [
{ name: "inline_custom_elements", value: "false" }
]
}],
tests: [{
fragment: true,
unchanged: '<button>Click here</button><!--comment-->'
}, {
fragment: true,
unchanged: '<button>Click here</button><!-- comment -->'
}]
}, {
name: "Issue #1707",
description: "wrap_attributes: 'preserve' should preserve newline before closing bracket",
matrix: [{
options: [
{ name: "wrap_attributes", value: "'preserve'" }
]
}],
tests: [{
fragment: true,
unchanged: [
'<div',
' attr="val"',
'>',
'</div>'
]
}]
}]
};