diff --git a/config_2010.json b/config_2010.json new file mode 100644 index 000000000..3c0ed524a --- /dev/null +++ b/config_2010.json @@ -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 +} diff --git a/input_2010.js b/input_2010.js new file mode 100644 index 000000000..5b50fc4a2 --- /dev/null +++ b/input_2010.js @@ -0,0 +1,5 @@ +a = [ + 1, + 2, + 3 +] diff --git a/js/src/html/beautifier.js b/js/src/html/beautifier.js index e32940fb7..b0840ac34 100644 --- a/js/src/html/beautifier.js +++ b/js/src/html/beautifier.js @@ -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); @@ -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 { @@ -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; } diff --git a/js/src/javascript/beautifier.js b/js/src/javascript/beautifier.js index 37350c225..2b7b96c05 100644 --- a/js/src/javascript/beautifier.js +++ b/js/src/javascript/beautifier.js @@ -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); @@ -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 diff --git a/output_1.js b/output_1.js new file mode 100644 index 000000000..109f92ac9 --- /dev/null +++ b/output_1.js @@ -0,0 +1,5 @@ +a = [ + 1 + , 2 + , 3 +] diff --git a/output_2.js b/output_2.js new file mode 100644 index 000000000..109f92ac9 --- /dev/null +++ b/output_2.js @@ -0,0 +1,5 @@ +a = [ + 1 + , 2 + , 3 +] diff --git a/output_3.js b/output_3.js new file mode 100644 index 000000000..109f92ac9 --- /dev/null +++ b/output_3.js @@ -0,0 +1,5 @@ +a = [ + 1 + , 2 + , 3 +] diff --git a/test/data/html/tests.js b/test/data/html/tests.js index 5595636e3..2f1c4de8f 100644 --- a/test/data/html/tests.js +++ b/test/data/html/tests.js @@ -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: '' + }, { + fragment: true, + unchanged: '' + }] + }, { + name: "Issue #1707", + description: "wrap_attributes: 'preserve' should preserve newline before closing bracket", + matrix: [{ + options: [ + { name: "wrap_attributes", value: "'preserve'" } + ] + }], + tests: [{ + fragment: true, + unchanged: [ + '