Skip to content

Commit ab9d7c3

Browse files
authored
Merge pull request #2026 from beautify-web/staging/release
Pulling staging/release into release
2 parents 8e29f8a + 21bf240 commit ab9d7c3

File tree

26 files changed

+1475
-463
lines changed

26 files changed

+1475
-463
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ depends: $(BUILD_DIR)/node $(BUILD_DIR)/python
119119

120120
# update dependencies information
121121
update: depends
122-
npm update
122+
@rm package-lock.json
123+
$(NPM) update --save
123124

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

132133
$(BUILD_DIR)/python: $(BUILD_DIR)/generate python/setup-js.py python/setup-css.py | $(BUILD_DIR) $(BUILD_DIR)/virtualenv
@@ -143,6 +144,8 @@ $(BUILD_DIR)/virtualenv: | $(BUILD_DIR)
143144
virtualenv --version || pip install virtualenv
144145
virtualenv build/python-dev
145146
virtualenv build/python-rel
147+
$(SCRIPT_DIR)/python-dev pip install pip --upgrade
148+
$(SCRIPT_DIR)/python-rel pip install pip --upgrade
146149
$(SCRIPT_DIR)/python-dev3 pip install black
147150
@touch $(BUILD_DIR)/virtualenv
148151

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries
5858

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

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

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

7474
Older versions are available by changing the version number.
@@ -401,4 +401,4 @@ Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, D
401401
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
402402
Mathias Bynens, Vittorio Gambaletta and others.
403403
404-
(README.md: js-beautify@1.14.2)
404+
(README.md: js-beautify@1.14.3)

js/lib/beautifier.js

Lines changed: 55 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lib/beautifier.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lib/beautifier.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lib/beautifier.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lib/beautify-css.js

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,9 @@ function Beautifier(source_text, options) {
10901090
"@supports": true,
10911091
"@document": true
10921092
};
1093+
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
1094+
"grid-template"
1095+
];
10931096

10941097
}
10951098

@@ -1214,7 +1217,9 @@ Beautifier.prototype.beautify = function() {
12141217
var enteringConditionalGroup = false;
12151218
var insideAtExtend = false;
12161219
var insideAtImport = false;
1220+
var insideScssMap = false;
12171221
var topCharacter = this._ch;
1222+
var insideNonSemiColonValues = false;
12181223
var whitespace;
12191224
var isAfterSpace;
12201225
var previous_ch;
@@ -1266,7 +1271,7 @@ Beautifier.prototype.beautify = function() {
12661271

12671272
// Ensures any new lines following the comment are preserved
12681273
this.eatWhitespace(true);
1269-
} else if (this._ch === '@') {
1274+
} else if (this._ch === '@' || this._ch === '$') {
12701275
this.preserveSingleSpace(isAfterSpace);
12711276

12721277
// deal with less propery mixins @{...}
@@ -1337,7 +1342,12 @@ Beautifier.prototype.beautify = function() {
13371342
this.indent();
13381343
this._output.set_indent(this._indentLevel);
13391344
} else {
1340-
this.indent();
1345+
// inside mixin and first param is object
1346+
if (previous_ch === '(') {
1347+
this._output.space_before_token = false;
1348+
} else if (previous_ch !== ',') {
1349+
this.indent();
1350+
}
13411351
this.print_string(this._ch);
13421352
}
13431353

@@ -1369,7 +1379,21 @@ Beautifier.prototype.beautify = function() {
13691379
this._output.add_new_line(true);
13701380
}
13711381
}
1382+
if (this._input.peek() === ')') {
1383+
this._output.trim(true);
1384+
if (this._options.brace_style === "expand") {
1385+
this._output.add_new_line(true);
1386+
}
1387+
}
13721388
} else if (this._ch === ":") {
1389+
1390+
for (var i = 0; i < this.NON_SEMICOLON_NEWLINE_PROPERTY.length; i++) {
1391+
if (this._input.lookBack(this.NON_SEMICOLON_NEWLINE_PROPERTY[i])) {
1392+
insideNonSemiColonValues = true;
1393+
break;
1394+
}
1395+
}
1396+
13731397
if ((insideRule || enteringConditionalGroup) && !(this._input.lookBack("&") || this.foundNestedPseudoClass()) && !this._input.lookBack("(") && !insideAtExtend && parenLevel === 0) {
13741398
// 'property: value' delimiter
13751399
// which could be in a conditional group query
@@ -1402,6 +1426,7 @@ Beautifier.prototype.beautify = function() {
14021426
this.print_string(this._ch + this.eatString(this._ch));
14031427
this.eatWhitespace(true);
14041428
} else if (this._ch === ';') {
1429+
insideNonSemiColonValues = false;
14051430
if (parenLevel === 0) {
14061431
if (insidePropertyValue) {
14071432
this.outdent();
@@ -1443,20 +1468,32 @@ Beautifier.prototype.beautify = function() {
14431468
} else {
14441469
this.preserveSingleSpace(isAfterSpace);
14451470
this.print_string(this._ch);
1446-
this.eatWhitespace();
1447-
parenLevel++;
1448-
this.indent();
1471+
1472+
// handle scss/sass map
1473+
if (insidePropertyValue && previous_ch === "$" && this._options.selector_separator_newline) {
1474+
this._output.add_new_line();
1475+
insideScssMap = true;
1476+
} else {
1477+
this.eatWhitespace();
1478+
parenLevel++;
1479+
this.indent();
1480+
}
14491481
}
14501482
} else if (this._ch === ')') {
14511483
if (parenLevel) {
14521484
parenLevel--;
14531485
this.outdent();
14541486
}
1487+
if (insideScssMap && this._input.peek() === ";" && this._options.selector_separator_newline) {
1488+
insideScssMap = false;
1489+
this.outdent();
1490+
this._output.add_new_line();
1491+
}
14551492
this.print_string(this._ch);
14561493
} else if (this._ch === ',') {
14571494
this.print_string(this._ch);
14581495
this.eatWhitespace(true);
1459-
if (this._options.selector_separator_newline && !insidePropertyValue && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
1496+
if (this._options.selector_separator_newline && (!insidePropertyValue || insideScssMap) && parenLevel === 0 && !insideAtImport && !insideAtExtend) {
14601497
this._output.add_new_line();
14611498
} else {
14621499
this._output.space_before_token = true;
@@ -1490,8 +1527,13 @@ Beautifier.prototype.beautify = function() {
14901527
this.print_string(' ');
14911528
this.print_string(this._ch);
14921529
} else {
1493-
this.preserveSingleSpace(isAfterSpace);
1530+
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';
1531+
this.preserveSingleSpace(preserveAfterSpace || isAfterSpace);
14941532
this.print_string(this._ch);
1533+
1534+
if (!this._output.just_added_newline() && this._input.peek() === '\n' && insideNonSemiColonValues) {
1535+
this._output.add_new_line();
1536+
}
14951537
}
14961538
}
14971539

js/lib/beautify.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,10 @@ Beautifier.prototype.handle_start_block = function(current_token) {
836836
)) {
837837
// We don't support TypeScript,but we didn't break it for a very long time.
838838
// We'll try to keep not breaking it.
839-
if (!in_array(this._last_last_text, ['class', 'interface'])) {
840-
this.set_mode(MODE.ObjectLiteral);
841-
} else {
839+
if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) {
842840
this.set_mode(MODE.BlockStatement);
841+
} else {
842+
this.set_mode(MODE.ObjectLiteral);
843843
}
844844
} else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') {
845845
// arrow function: (param1, paramN) => { statements }
@@ -955,7 +955,7 @@ Beautifier.prototype.handle_word = function(current_token) {
955955
if (current_token.type === TOKEN.RESERVED) {
956956
if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) {
957957
current_token.type = TOKEN.WORD;
958-
} else if (current_token.text === 'import' && this._tokens.peek().text === '(') {
958+
} else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) {
959959
current_token.type = TOKEN.WORD;
960960
} else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) {
961961
current_token.type = TOKEN.WORD;
@@ -2533,15 +2533,15 @@ var digit = /[0-9]/;
25332533
var dot_pattern = /[^\d\.]/;
25342534

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

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

0 commit comments

Comments
 (0)