Skip to content

Commit bf09398

Browse files
authored
Merge pull request microsoft#288 from microsoft/aeschli/update-jsbeautify
update jsbeautify
2 parents d3a439c + cd180ae commit bf09398

File tree

5 files changed

+72
-21
lines changed

5 files changed

+72
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@typescript-eslint/parser": "^5.25.0",
2222
"@vscode/web-custom-data": "^0.3.10",
2323
"eslint": "^8.15.0",
24-
"js-beautify": "^1.14.3",
24+
"js-beautify": "^1.14.6",
2525
"mocha": "^10.0.0",
2626
"rimraf": "^3.0.2",
2727
"typescript": "^4.5.5"

src/beautify/beautify-css.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// copied from js-beautify/js/lib/beautify-css.js
2-
// version: 1.14.3
2+
// version: 1.14.6
33
/* AUTO-GENERATED. DO NOT MODIFY. */
44
/*
55
@@ -1093,6 +1093,7 @@ function Beautifier(source_text, options) {
10931093
"@document": true
10941094
};
10951095
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
1096+
"grid-template-areas",
10961097
"grid-template"
10971098
];
10981099

@@ -1424,7 +1425,8 @@ Beautifier.prototype.beautify = function() {
14241425
}
14251426
}
14261427
} else if (this._ch === '"' || this._ch === '\'') {
1427-
this.preserveSingleSpace(isAfterSpace);
1428+
var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
1429+
this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
14281430
this.print_string(this._ch + this.eatString(this._ch));
14291431
this.eatWhitespace(true);
14301432
} else if (this._ch === ';') {
@@ -1468,7 +1470,12 @@ Beautifier.prototype.beautify = function() {
14681470
}
14691471
}
14701472
} else {
1471-
this.preserveSingleSpace(isAfterSpace);
1473+
var space_needed = false;
1474+
if (this._input.lookBack("with")) {
1475+
// look back is not an accurate solution, we need tokens to confirm without whitespaces
1476+
space_needed = true;
1477+
}
1478+
this.preserveSingleSpace(isAfterSpace || space_needed);
14721479
this.print_string(this._ch);
14731480

14741481
// handle scss/sass map
@@ -1526,7 +1533,7 @@ Beautifier.prototype.beautify = function() {
15261533
this._ch = '';
15271534
}
15281535
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
1529-
this.print_string(' ');
1536+
this._output.space_before_token = true;
15301537
this.print_string(this._ch);
15311538
} else {
15321539
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';

src/beautify/esm/beautify-css.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// copied from js-beautify/js/lib/beautify-css.js
2-
// version: 1.14.3
2+
// version: 1.14.6
33
/* AUTO-GENERATED. DO NOT MODIFY. */
44
/*
55
@@ -1090,6 +1090,7 @@ function Beautifier(source_text, options) {
10901090
"@document": true
10911091
};
10921092
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
1093+
"grid-template-areas",
10931094
"grid-template"
10941095
];
10951096

@@ -1421,7 +1422,8 @@ Beautifier.prototype.beautify = function() {
14211422
}
14221423
}
14231424
} else if (this._ch === '"' || this._ch === '\'') {
1424-
this.preserveSingleSpace(isAfterSpace);
1425+
var preserveQuoteSpace = previous_ch === '"' || previous_ch === '\'';
1426+
this.preserveSingleSpace(preserveQuoteSpace || isAfterSpace);
14251427
this.print_string(this._ch + this.eatString(this._ch));
14261428
this.eatWhitespace(true);
14271429
} else if (this._ch === ';') {
@@ -1465,7 +1467,12 @@ Beautifier.prototype.beautify = function() {
14651467
}
14661468
}
14671469
} else {
1468-
this.preserveSingleSpace(isAfterSpace);
1470+
var space_needed = false;
1471+
if (this._input.lookBack("with")) {
1472+
// look back is not an accurate solution, we need tokens to confirm without whitespaces
1473+
space_needed = true;
1474+
}
1475+
this.preserveSingleSpace(isAfterSpace || space_needed);
14691476
this.print_string(this._ch);
14701477

14711478
// handle scss/sass map
@@ -1523,7 +1530,7 @@ Beautifier.prototype.beautify = function() {
15231530
this._ch = '';
15241531
}
15251532
} else if (this._ch === '!' && !this._input.lookBack("\\")) { // !important
1526-
this.print_string(' ');
1533+
this._output.space_before_token = true;
15271534
this.print_string(this._ch);
15281535
} else {
15291536
var preserveAfterSpace = previous_ch === '"' || previous_ch === '\'';

src/test/css/formatter.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,24 @@ suite('CSS - Formatter', () => {
201201

202202
});
203203

204+
test('spaces', () => {
205+
// https://github.com/microsoft/vscode/issues/159295
206+
const content = [
207+
'.body {',
208+
' font-size: @fs !important; // 2 space -> BUG',
209+
'}'
210+
].join('\n');
211+
212+
const expected = [
213+
'.body {',
214+
' font-size: @fs !important; // 2 space -> BUG',
215+
'}'
216+
].join('\n');
217+
218+
assertFormat(content, expected, { insertSpaces: true, tabSize: 2, preserveNewLines: true, maxPreserveNewLines: 3 });
219+
220+
});
221+
222+
204223

205224
});

yarn.lock

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
resolved "https://registry.yarnpkg.com/@vscode/web-custom-data/-/web-custom-data-0.3.10.tgz#7d6ad4bf0a44fffa3f662723cc755b604e505118"
163163
integrity sha512-xLUV5IZGVWQDzTerNXlWVnCsrv6VPi01zOehRNSoR/l2lXojY/zYBwR56cNz9hRgZ3l68HL057R8xolheiga5Q==
164164

165-
abbrev@1:
165+
abbrev@^1.0.0:
166166
version "1.1.1"
167167
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
168168
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==
@@ -679,6 +679,17 @@ glob@^7.1.3:
679679
once "^1.3.0"
680680
path-is-absolute "^1.0.0"
681681

682+
glob@^8.0.3:
683+
version "8.0.3"
684+
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
685+
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
686+
dependencies:
687+
fs.realpath "^1.0.0"
688+
inflight "^1.0.4"
689+
inherits "2"
690+
minimatch "^5.0.1"
691+
once "^1.3.0"
692+
682693
globals@^13.6.0:
683694
version "13.9.0"
684695
resolved "https://registry.yarnpkg.com/globals/-/globals-13.9.0.tgz#4bf2bf635b334a173fb1daf7c5e6b218ecdc06cb"
@@ -802,15 +813,15 @@ isexe@^2.0.0:
802813
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
803814
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
804815

805-
js-beautify@^1.14.3:
806-
version "1.14.3"
807-
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.3.tgz#3dd11c949178de7f3bdf3f6f752778d3bed95150"
808-
integrity sha512-f1ra8PHtOEu/70EBnmiUlV8nJePS58y9qKjl4JHfYWlFH6bo7ogZBz//FAZp7jDuXtYnGYKymZPlrg2I/9Zo4g==
816+
js-beautify@^1.14.6:
817+
version "1.14.6"
818+
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.6.tgz#b23ca5d74a462c282c7711bb51150bcc97f2b507"
819+
integrity sha512-GfofQY5zDp+cuHc+gsEXKPpNw2KbPddreEo35O6jT6i0RVK6LhsoYBhq5TvK4/n74wnA0QbK8gGd+jUZwTMKJw==
809820
dependencies:
810821
config-chain "^1.1.13"
811822
editorconfig "^0.15.3"
812-
glob "^7.1.3"
813-
nopt "^5.0.0"
823+
glob "^8.0.3"
824+
nopt "^6.0.0"
814825

815826
js-yaml@4.1.0, js-yaml@^4.1.0:
816827
version "4.1.0"
@@ -906,6 +917,13 @@ minimatch@^3.1.2:
906917
dependencies:
907918
brace-expansion "^1.1.7"
908919

920+
minimatch@^5.0.1:
921+
version "5.1.0"
922+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
923+
integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
924+
dependencies:
925+
brace-expansion "^2.0.1"
926+
909927
mocha@^10.0.0:
910928
version "10.0.0"
911929
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9"
@@ -959,12 +977,12 @@ natural-compare@^1.4.0:
959977
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
960978
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
961979

962-
nopt@^5.0.0:
963-
version "5.0.0"
964-
resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88"
965-
integrity sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==
980+
nopt@^6.0.0:
981+
version "6.0.0"
982+
resolved "https://registry.yarnpkg.com/nopt/-/nopt-6.0.0.tgz#245801d8ebf409c6df22ab9d95b65e1309cdb16d"
983+
integrity sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==
966984
dependencies:
967-
abbrev "1"
985+
abbrev "^1.0.0"
968986

969987
normalize-path@^3.0.0, normalize-path@~3.0.0:
970988
version "3.0.0"

0 commit comments

Comments
 (0)