Skip to content

update jsbeautify #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@typescript-eslint/parser": "^5.25.0",
"@vscode/web-custom-data": "^0.3.10",
"eslint": "^8.15.0",
"js-beautify": "^1.14.3",
"js-beautify": "^1.14.6",
"mocha": "^10.0.0",
"rimraf": "^3.0.2",
"typescript": "^4.5.5"
Expand Down
15 changes: 11 additions & 4 deletions src/beautify/beautify-css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-css.js
// version: 1.14.3
// version: 1.14.6
/* AUTO-GENERATED. DO NOT MODIFY. */
/*

Expand Down Expand Up @@ -1093,6 +1093,7 @@ function Beautifier(source_text, options) {
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
"grid-template"
];

Expand Down Expand Up @@ -1424,7 +1425,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 @@ -1468,7 +1470,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 @@ -1526,7 +1533,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
15 changes: 11 additions & 4 deletions src/beautify/esm/beautify-css.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// copied from js-beautify/js/lib/beautify-css.js
// version: 1.14.3
// version: 1.14.6
/* AUTO-GENERATED. DO NOT MODIFY. */
/*

Expand Down Expand Up @@ -1090,6 +1090,7 @@ function Beautifier(source_text, options) {
"@document": true
};
this.NON_SEMICOLON_NEWLINE_PROPERTY = [
"grid-template-areas",
"grid-template"
];

Expand Down Expand Up @@ -1421,7 +1422,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 @@ -1465,7 +1467,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 @@ -1523,7 +1530,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
19 changes: 19 additions & 0 deletions src/test/css/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,24 @@ suite('CSS - Formatter', () => {

});

test('spaces', () => {
// https://github.com/microsoft/vscode/issues/159295
const content = [
'.body {',
' font-size: @fs !important; // 2 space -> BUG',
'}'
].join('\n');

const expected = [
'.body {',
' font-size: @fs !important; // 2 space -> BUG',
'}'
].join('\n');

assertFormat(content, expected, { insertSpaces: true, tabSize: 2, preserveNewLines: true, maxPreserveNewLines: 3 });

});



});
42 changes: 30 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
resolved "https://registry.yarnpkg.com/@vscode/web-custom-data/-/web-custom-data-0.3.10.tgz#7d6ad4bf0a44fffa3f662723cc755b604e505118"
integrity sha512-xLUV5IZGVWQDzTerNXlWVnCsrv6VPi01zOehRNSoR/l2lXojY/zYBwR56cNz9hRgZ3l68HL057R8xolheiga5Q==

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

glob@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e"
integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^5.0.1"
once "^1.3.0"

globals@^13.6.0:
version "13.9.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-13.9.0.tgz#4bf2bf635b334a173fb1daf7c5e6b218ecdc06cb"
Expand Down Expand Up @@ -802,15 +813,15 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=

js-beautify@^1.14.3:
version "1.14.3"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.3.tgz#3dd11c949178de7f3bdf3f6f752778d3bed95150"
integrity sha512-f1ra8PHtOEu/70EBnmiUlV8nJePS58y9qKjl4JHfYWlFH6bo7ogZBz//FAZp7jDuXtYnGYKymZPlrg2I/9Zo4g==
js-beautify@^1.14.6:
version "1.14.6"
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.14.6.tgz#b23ca5d74a462c282c7711bb51150bcc97f2b507"
integrity sha512-GfofQY5zDp+cuHc+gsEXKPpNw2KbPddreEo35O6jT6i0RVK6LhsoYBhq5TvK4/n74wnA0QbK8gGd+jUZwTMKJw==
dependencies:
config-chain "^1.1.13"
editorconfig "^0.15.3"
glob "^7.1.3"
nopt "^5.0.0"
glob "^8.0.3"
nopt "^6.0.0"

js-yaml@4.1.0, js-yaml@^4.1.0:
version "4.1.0"
Expand Down Expand Up @@ -906,6 +917,13 @@ minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimatch@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.1.0.tgz#1717b464f4971b144f6aabe8f2d0b8e4511e09c7"
integrity sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==
dependencies:
brace-expansion "^2.0.1"

mocha@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.0.0.tgz#205447d8993ec755335c4b13deba3d3a13c4def9"
Expand Down Expand Up @@ -959,12 +977,12 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

nopt@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88"
integrity sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==
nopt@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-6.0.0.tgz#245801d8ebf409c6df22ab9d95b65e1309cdb16d"
integrity sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==
dependencies:
abbrev "1"
abbrev "^1.0.0"

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
Expand Down