Skip to content

Commit

Permalink
Release: 1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed Jun 20, 2022
1 parent 3fb3f02 commit 2689316
Show file tree
Hide file tree
Showing 12 changed files with 1,133 additions and 42 deletions.
67 changes: 49 additions & 18 deletions js/lib/beautifier.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/lib/beautifier.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/lib/beautifier.min.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions js/lib/beautify-css.js
Expand Up @@ -1091,6 +1091,7 @@ function Beautifier(source_text, options) {
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
"grid-template"
];

Expand Down Expand Up @@ -1422,7 +1423,8 @@ Beautifier.prototype.beautify = function() {
}
}
} else if (this._ch === '"' || this._ch === '\'') {
this.preserveSingleSpace(isAfterSpace);
var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
this.print_string(this._ch + this.eatString(this._ch));
this.eatWhitespace(true);
} else if (this._ch === ';') {
Expand Down Expand Up @@ -1466,7 +1468,12 @@ Beautifier.prototype.beautify = function() {
}
}
} else {
this.preserveSingleSpace(isAfterSpace);
var space_needed = false;
if (this._input.lookBack("with")) {
// look back is not an accurate solution, we need tokens to confirm without whitespaces
space_needed = true;
}
this.preserveSingleSpace(isAfterSpace || space_needed);
this.print_string(this._ch);

// handle scss/sass map
Expand Down Expand Up @@ -1524,7 +1531,7 @@ Beautifier.prototype.beautify = function() {
this._ch = '';
}
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
this.print_string(' ');
this._output.space_before_token = true;
this.print_string(this._ch);
} else {
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
Expand Down
23 changes: 18 additions & 5 deletions js/lib/beautify-html.js
Expand Up @@ -2355,14 +2355,19 @@ var TagOpenParserToken = function(parent, raw_token) {
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';
} else {
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
tag_check_match = raw_token.text.match(/^{{~?(?:[\^]|#\*?)?([^\s}]+)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text.split(' ')[0];
// handle "{{#> myPartial}}" or "{{~#> myPartial}}"
if ((raw_token.text.startsWith('{{#>') || raw_token.text.startsWith('{{~#>')) && this.tag_check[0] === '>') {
if (this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text.split(' ')[0];
} else {
this.tag_check = raw_token.text.split('>')[1];
}
}
}

this.tag_check = this.tag_check.toLowerCase();

if (raw_token.type === TOKEN.COMMENT) {
Expand All @@ -2374,9 +2379,17 @@ var TagOpenParserToken = function(parent, raw_token) {
this.is_end_tag = !this.is_start_tag ||
(raw_token.closed && raw_token.closed.text === '/>');

// if whitespace handler ~ included (i.e. {{~#if true}}), handlebars tags start at pos 3 not pos 2
var handlebar_starts = 2;
if (this.tag_start_char === '{' && this.text.length >= 3) {
if (this.text.charAt(2) === '~') {
handlebar_starts = 3;
}
}

// handlebars tags that don't start with # or ^ are single_tags, and so also start and end.
this.is_end_tag = this.is_end_tag ||
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(2)))));
(this.tag_start_char === '{' && (this.text.length < 3 || (/[^#\^]/.test(this.text.charAt(handlebar_starts)))));
}
};

Expand Down
31 changes: 21 additions & 10 deletions js/lib/beautify.js
Expand Up @@ -330,6 +330,7 @@ Beautifier.prototype.create_flags = function(flags_base, mode) {
inline_frame: false,
if_block: false,
else_block: false,
class_start_block: false, // class A { INSIDE HERE } or class B extends C { INSIDE HERE }
do_block: false,
do_while: false,
import_block: false,
Expand Down Expand Up @@ -742,6 +743,8 @@ Beautifier.prototype.handle_start_expr = function(current_token) {
(peek_back_two.text === '*' && (peek_back_three.text === '{' || peek_back_three.text === ','))) {
this._output.space_before_token = true;
}
} else if (this._flags.parent && this._flags.parent.class_start_block) {
this._output.space_before_token = true;
}
}
} else {
Expand Down Expand Up @@ -856,6 +859,12 @@ Beautifier.prototype.handle_start_block = function(current_token) {
this.set_mode(MODE.BlockStatement);
}

if (this._flags.last_token) {
if (reserved_array(this._flags.last_token.previous, ['class', 'extends'])) {
this._flags.class_start_block = true;
}
}

var empty_braces = !next_token.comments_before && next_token.text === '}';
var empty_anonymous_function = empty_braces && this._flags.last_word === 'function' &&
this._flags.last_token.type === TOKEN.END_EXPR;
Expand Down Expand Up @@ -1296,13 +1305,6 @@ Beautifier.prototype.handle_operator = function(current_token) {
this.handle_whitespace_and_comments(current_token, preserve_statement_flags);
}

if (reserved_array(this._flags.last_token, special_words)) {
// "return" had a special handling in TK_WORD. Now we need to return the favor
this._output.space_before_token = true;
this.print_token(current_token);
return;
}

// hack for actionscript's import .*;
if (current_token.text === '*' && this._flags.last_token.type === TOKEN.DOT) {
this.print_token(current_token);
Expand Down Expand Up @@ -1430,7 +1432,11 @@ Beautifier.prototype.handle_operator = function(current_token) {
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
// if there is a newline between -- or ++ and anything else we should preserve it.
if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) {
this.print_newline(false, true);
var new_line_needed = reserved_array(this._flags.last_token, special_words) && current_token.newlines;
if (new_line_needed && (this._previous_flags.if_block || this._previous_flags.else_block)) {
this.restore_mode();
}
this.print_newline(new_line_needed, true);
}

if (this._flags.last_token.text === ';' && is_expression(this._flags.mode)) {
Expand Down Expand Up @@ -1570,6 +1576,10 @@ Beautifier.prototype.handle_dot = function(current_token) {
this.handle_whitespace_and_comments(current_token, true);
}

if (this._flags.last_token.text.match('^[0-9]+$')) {
this._output.space_before_token = true;
}

if (reserved_array(this._flags.last_token, special_words)) {
this._output.space_before_token = false;
} else {
Expand Down Expand Up @@ -2554,7 +2564,7 @@ var punct_pattern = new RegExp(punct);

// words which should always start on new line.
var line_starters = 'continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,import,export'.split(',');
var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as']);
var reserved_words = line_starters.concat(['do', 'in', 'of', 'else', 'get', 'set', 'new', 'catch', 'finally', 'typeof', 'yield', 'async', 'await', 'from', 'as', 'class', 'extends']);
var reserved_word_pattern = new RegExp('^(?:' + reserved_words.join('|') + ')$');

// var template_pattern = /(?:(?:<\?php|<\?=)[\s\S]*?\?>)|(?:<%[\s\S]*?%>)/g;
Expand Down Expand Up @@ -2645,7 +2655,8 @@ Tokenizer.prototype._read_word = function(previous_token) {
if (!(previous_token.type === TOKEN.DOT ||
(previous_token.type === TOKEN.RESERVED && (previous_token.text === 'set' || previous_token.text === 'get'))) &&
reserved_word_pattern.test(resulting_string)) {
if (resulting_string === 'in' || resulting_string === 'of') { // hack for 'in' and 'of' operators
if ((resulting_string === 'in' || resulting_string === 'of') &&
(previous_token.type === TOKEN.WORD || previous_token.type === TOKEN.STRING)) { // hack for 'in' and 'of' operators
return this._create_token(TOKEN.OPERATOR, resulting_string);
}
return this._create_token(TOKEN.RESERVED, resulting_string);
Expand Down

0 comments on commit 2689316

Please sign in to comment.