Skip to content

Commit

Permalink
Release: 1.14.3
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed Apr 9, 2022
1 parent bb39fc8 commit 21bf240
Show file tree
Hide file tree
Showing 10 changed files with 667 additions and 35 deletions.
68 changes: 55 additions & 13 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.

56 changes: 49 additions & 7 deletions js/lib/beautify-css.js
Expand Up @@ -1090,6 +1090,9 @@ function Beautifier(source_text, options) {
"@supports": true,
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template"
];

}

Expand Down Expand Up @@ -1214,7 +1217,9 @@ Beautifier.prototype.beautify = function() {
var enteringConditionalGroup = false;
var insideAtExtend = false;
var insideAtImport = false;
var insideScssMap = false;
var topCharacter = this._ch;
var insideNonSemiColonValues = false;
var whitespace;
var isAfterSpace;
var previous_ch;
Expand Down Expand Up @@ -1266,7 +1271,7 @@ Beautifier.prototype.beautify = function() {

// Ensures any new lines following the comment are preserved
this.eatWhitespace(true);
} else if (this._ch === '@') {
} else if (this._ch === '@' || this._ch === '$') {
this.preserveSingleSpace(isAfterSpace);

// deal with less propery mixins @{...}
Expand Down Expand Up @@ -1337,7 +1342,12 @@ Beautifier.prototype.beautify = function() {
this.indent();
this._output.set_indent(this._indentLevel);
} else {
this.indent();
// inside mixin and first param is object
if (previous_ch === '(') {
this._output.space_before_token = false;
} else if (previous_ch !== ',') {
this.indent();
}
this.print_string(this._ch);
}

Expand Down Expand Up @@ -1369,7 +1379,21 @@ Beautifier.prototype.beautify = function() {
this._output.add_new_line(true);
}
}
if (this._input.peek() === ')') {
this._output.trim(true);
if (this._options.brace_style === "expand") {
this._output.add_new_line(true);
}
}
} else if (this._ch === ":") {

for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
insideNonSemiColonValues = true;
break;
}
}

if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
// 'property: value' delimiter
// which could be in a conditional group query
Expand Down Expand Up @@ -1402,6 +1426,7 @@ Beautifier.prototype.beautify = function() {
this.print_string(this._ch + this.eatString(this._ch));
this.eatWhitespace(true);
} else if (this._ch === ';') {
insideNonSemiColonValues = false;
if (parenLevel === 0) {
if (insidePropertyValue) {
this.outdent();
Expand Down Expand Up @@ -1443,20 +1468,32 @@ Beautifier.prototype.beautify = function() {
} else {
this.preserveSingleSpace(isAfterSpace);
this.print_string(this._ch);
this.eatWhitespace();
parenLevel++;
this.indent();

// handle scss/sass map
if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
this._output.add_new_line();
insideScssMap = true;
} else {
this.eatWhitespace();
parenLevel++;
this.indent();
}
}
} else if (this._ch === ')') {
if (parenLevel) {
parenLevel--;
this.outdent();
}
if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
insideScssMap = false;
this.outdent();
this._output.add_new_line();
}
this.print_string(this._ch);
} else if (this._ch === ',') {
this.print_string(this._ch);
this.eatWhitespace(true);
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
this._output.add_new_line();
} else {
this._output.space_before_token = true;
Expand Down Expand Up @@ -1490,8 +1527,13 @@ Beautifier.prototype.beautify = function() {
this.print_string(' ');
this.print_string(this._ch);
} else {
this.preserveSingleSpace(isAfterSpace);
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
this.print_string(this._ch);

if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
this._output.add_new_line();
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions js/lib/beautify.js
Expand Up @@ -836,10 +836,10 @@ Beautifier.prototype.handle_start_block = function(current_token) {
)) {
// We don't support TypeScript,but we didn't break it for a very long time.
// We'll try to keep not breaking it.
if (!in_array(this._last_last_text, ['class', 'interface'])) {
this.set_mode(MODE.ObjectLiteral);
} else {
if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
this.set_mode(MODE.BlockStatement);
} else {
this.set_mode(MODE.ObjectLiteral);
}
} else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
// arrow function: (param1, paramN) => { statements }
Expand Down Expand Up @@ -955,7 +955,7 @@ Beautifier.prototype.handle_word = function(current_token) {
if (current_token.type === TOKEN.RESERVED) {
if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
current_token.type = TOKEN.WORD;
} else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
} else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
current_token.type = TOKEN.WORD;
} else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
current_token.type = TOKEN.WORD;
Expand Down Expand Up @@ -2533,15 +2533,15 @@ var digit = /[0-9]/;
var dot_pattern = /[^\d\.]/;

var positionable_operators = (
">>> === !== " +
">>> === !== &&= ??= ||= " +
"<< && >= ** != == <= >> || ?? |> " +
"< / - + > : & % ? ^ | *").split(' ');

// IMPORTANT: this must be sorted longest to shortest or tokenizing many not work.
// Also, you must update possitionable operators separately from punct
var punct =
">>>= " +
"... >>= <<= === >>> !== **= " +
"... >>= <<= === >>> !== **= &&= ??= ||= " +
"=> ^= :: /= << <= == && -= >= >> != -- += ** || ?? ++ %= &= *= |= |> " +
"= ! ? > < : / ^ - + * & % ~ |";

Expand Down

0 comments on commit 21bf240

Please sign in to comment.