Skip to content
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

Update babel to v7.20.0 #13733

Merged
merged 8 commits into from Oct 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -31,8 +31,8 @@
"dependencies": {
"@angular/compiler": "14.2.7",
"@babel/code-frame": "7.18.6",
"@babel/parser": "7.19.6",
"@babel/types": "7.19.4",
"@babel/parser": "7.20.0",
"@babel/types": "7.20.0",
"@glimmer/syntax": "0.84.2",
"@iarna/toml": "2.2.5",
"@prettier/is-es5-identifier-name": "0.0.2",
Expand Down Expand Up @@ -104,7 +104,7 @@
"yaml-unist-parser": "2.0.1"
},
"devDependencies": {
"@babel/generator": "7.19.6",
"@babel/generator": "7.20.0",
"@esbuild-plugins/node-modules-polyfill": "0.1.4",
"@glimmer/reference": "0.84.2",
"@types/estree": "1.0.0",
Expand Down
16 changes: 6 additions & 10 deletions src/language-js/loc.js
Expand Up @@ -4,20 +4,16 @@ import isNonEmptyArray from "../utils/is-non-empty-array.js";
* @typedef {import("./types/estree.js").Node} Node
*/

function locStart(node, opts) {
const { ignoreDecorators } = opts || {};
function locStart(node) {
const start = node.range ? node.range[0] : node.start;

// Handle nodes with decorators. They should start at the first decorator
if (!ignoreDecorators) {
const decorators =
(node.declaration && node.declaration.decorators) || node.decorators;

if (isNonEmptyArray(decorators)) {
return locStart(decorators[0]);
}
const decorators = node.declaration?.decorators ?? node.decorators;
if (isNonEmptyArray(decorators)) {
return Math.min(locStart(decorators[0]), start);
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the old one is not right, if decorators after export, it will still use range of decorators[0]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case is locStart(decorators[0]) less then start? The change in Babel that broke prettier was that now the start of the outer node should always be ≤ than the start of the inner nodes, so startlocStart(decorators[0]).

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case is locStart(decorators[0]) less then start?

Other parsers, flow/typescript I think they followed old behavior of babel.

}

return node.range ? node.range[0] : node.start;
return start;
}

function locEnd(node) {
Expand Down
3 changes: 1 addition & 2 deletions src/language-js/print/decorators.js
Expand Up @@ -74,8 +74,7 @@ function hasDecoratorsBeforeExport(node) {
const decorators = node.declaration && node.declaration.decorators;

return (
isNonEmptyArray(decorators) &&
locStart(node, { ignoreDecorators: true }) > locStart(decorators[0])
isNonEmptyArray(decorators) && locStart(node) === locStart(decorators[0])
);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/__snapshots__/visitor-keys.js.snap
Expand Up @@ -868,6 +868,10 @@ exports[`visitor keys estree 1`] = `
"TSRestType": [
"typeAnnotation",
],
"TSSatisfiesExpression": [
"expression",
"typeAnnotation",
],
"TSStaticKeyword": [],
"TSStringKeyword": [],
"TSSymbolKeyword": [],
Expand Down
32 changes: 16 additions & 16 deletions yarn.lock
Expand Up @@ -84,14 +84,14 @@ __metadata:
languageName: node
linkType: hard

"@babel/generator@npm:7.19.6, @babel/generator@npm:^7.18.10, @babel/generator@npm:^7.7.2":
version: 7.19.6
resolution: "@babel/generator@npm:7.19.6"
"@babel/generator@npm:7.20.0, @babel/generator@npm:^7.18.10, @babel/generator@npm:^7.7.2":
version: 7.20.0
resolution: "@babel/generator@npm:7.20.0"
dependencies:
"@babel/types": ^7.19.4
"@babel/types": ^7.20.0
"@jridgewell/gen-mapping": ^0.3.2
jsesc: ^2.5.1
checksum: 734fcb1fbef182e7b8967459cb39b81edd2701dd13170c154b368d4e086842f72ef214798c5a37e67e0a695dfb34b13143277bedcd9795b3b1b83da8e1d236c6
checksum: df2fef0ac305cf031013e311d4582b15b5c297fd538bec71e6cae3b689189ac4be6055482487b06da1be2f007b8985d5162a84e14e43a20435b8c89551910509
languageName: node
linkType: hard

Expand Down Expand Up @@ -228,12 +228,12 @@ __metadata:
languageName: node
linkType: hard

"@babel/parser@npm:7.19.6, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11":
version: 7.19.6
resolution: "@babel/parser@npm:7.19.6"
"@babel/parser@npm:7.20.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11":
version: 7.20.0
resolution: "@babel/parser@npm:7.20.0"
bin:
parser: ./bin/babel-parser.js
checksum: 9a3dca4ee3acd7e4fc3b58e1e1526a11fa334acbfe437f8ebf91dfaf48e943c147ef64b1733ba0a55af57d1eccafbf4e4a4afc46a15becd921971fe2ddf309bf
checksum: d54d68e45ff1b9a0c50a3f79d9031f482eb58f18928525949dc20da5b1658ee79167e756129371fd75d3e8fc7e218ab707727145a68958636be9672c7b71768e
languageName: node
linkType: hard

Expand Down Expand Up @@ -420,14 +420,14 @@ __metadata:
languageName: node
linkType: hard

"@babel/types@npm:7.19.4, @babel/types@npm:^7.0.0, @babel/types@npm:^7.18.10, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.19.4, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.8.3":
version: 7.19.4
resolution: "@babel/types@npm:7.19.4"
"@babel/types@npm:7.20.0, @babel/types@npm:^7.0.0, @babel/types@npm:^7.18.10, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.20.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.8.3":
version: 7.20.0
resolution: "@babel/types@npm:7.20.0"
dependencies:
"@babel/helper-string-parser": ^7.19.4
"@babel/helper-validator-identifier": ^7.19.1
to-fast-properties: ^2.0.0
checksum: 4032f6407093f80dd4f4764be676f7527d2a5c0381586967cd79683cf8af01cdc16745a381b9cef045f702f0c9b0dffd880d84ee55dad59ba01bd23d5d52a8e0
checksum: 8729b1114c707a03625cd79e3ae3a28d69b36ddcf804cb0a4599af226e5e9fad71665bdc0e56c43527ecfcabc545d9c797231f5ce718ae1ab52d31a57b6c2024
languageName: node
linkType: hard

Expand Down Expand Up @@ -6611,9 +6611,9 @@ __metadata:
dependencies:
"@angular/compiler": 14.2.7
"@babel/code-frame": 7.18.6
"@babel/generator": 7.19.6
"@babel/parser": 7.19.6
"@babel/types": 7.19.4
"@babel/generator": 7.20.0
"@babel/parser": 7.20.0
"@babel/types": 7.20.0
"@esbuild-plugins/node-modules-polyfill": 0.1.4
"@glimmer/reference": 0.84.2
"@glimmer/syntax": 0.84.2
Expand Down