Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging/main' into staging/release
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Action committed Apr 9, 2022
2 parents 8e29f8a + ecd5278 commit bb39fc8
Show file tree
Hide file tree
Showing 16 changed files with 808 additions and 428 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ depends: $(BUILD_DIR)/node $(BUILD_DIR)/python

# update dependencies information
update: depends
npm update
@rm package-lock.json
$(NPM) update --save

# when we pull dependencies also pull docker image
# without this images can get stale and out of sync from CI system
$(BUILD_DIR)/node: package.json package-lock.json | $(BUILD_DIR)
@$(NODE) --version
$(NPM) install
$(NPM) --version
$(NPM) install
@touch $(BUILD_DIR)/node

$(BUILD_DIR)/python: $(BUILD_DIR)/generate python/setup-js.py python/setup-css.py | $(BUILD_DIR) $(BUILD_DIR)/virtualenv
Expand All @@ -143,6 +144,8 @@ $(BUILD_DIR)/virtualenv: | $(BUILD_DIR)
virtualenv --version || pip install virtualenv
virtualenv build/python-dev
virtualenv build/python-rel
$(SCRIPT_DIR)/python-dev pip install pip --upgrade
$(SCRIPT_DIR)/python-rel pip install pip --upgrade
$(SCRIPT_DIR)/python-dev3 pip install black
@touch $(BUILD_DIR)/virtualenv

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries

To pull the latest version from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify-html.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.2/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.3/beautify-html.min.js"></script>

<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.2/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.2/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.2/js/lib/beautify-html.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.3/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.3/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.14.3/js/lib/beautify-html.js"></script>
```

Older versions are available by changing the version number.
Expand Down Expand Up @@ -401,4 +401,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
(README.md: js-beautify@1.14.2)
(README.md: js-beautify@1.14.3)
56 changes: 49 additions & 7 deletions js/src/css/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ function Beautifier(source_text, options) {
"@supports": true,
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template"
];

}

Expand Down Expand Up @@ -191,7 +194,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 @@ -243,7 +248,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 @@ -314,7 +319,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 @@ -346,7 +356,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 @@ -379,6 +403,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 @@ -420,20 +445,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 @@ -467,8 +504,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
8 changes: 4 additions & 4 deletions js/src/javascript/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,10 +691,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 @@ -810,7 +810,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
4 changes: 2 additions & 2 deletions js/src/javascript/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,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 bb39fc8

Please sign in to comment.