Skip to content

Commit 64fa466

Browse files
Enable import attributes parsing by default (#16850)
* Enable import attributes parsing by default * Remove plugin from tests * Update fixtures * Fix failures * `make build` * Fix TS errors * Fix * Update .d.ts * Move in core * [babel 8] Remove syntax plugins from preset-env * Update fixtures * Fix ESM build of Babel 7 and standalone * Update flow allowlist * Update parser fixtures for Babel 8 * Update generator tests * Update parser test * Update standalone * Do not run import attribtues plugin test in Babel 8 * Make tests pass in babel 8 * Fix Babel 8 build * [babel 8] Stop printing legacy "with" attributes * fix prettier integration test * Fix Babel 8 compat in syntax-import-attributes * Try fix * Do not error for the removed `importAttributes` plugin * Skip a test in babel7/8 compat e2e * Throw an error when using removed option from the parser * Fixes after rebase * Raise `ImportCallArity` also when `createImportExpressions` * Fix linting
1 parent c369676 commit 64fa466

File tree

309 files changed

+1271
-624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

309 files changed

+1271
-624
lines changed

Gulpfile.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ function buildRollup(packages, buildStandalone) {
410410
bool(process.env.BABEL_8_BREAKING)
411411
? [
412412
// These require()s are all in babel-preset-env/src/polyfills/babel-7-plugins.cjs
413+
// and packages/babel-preset-env/src/babel-7-available-plugins.cjs.
413414
// They are gated by a !process.env.BABEL_8_BREAKING check, but
414415
// @rollup/plugin-commonjs extracts them to import statements outside of the
415416
// check and thus they end up in the final bundle.
@@ -418,6 +419,8 @@ function buildRollup(packages, buildStandalone) {
418419
"./babel-polyfill.cjs",
419420
"./regenerator.cjs",
420421
"@babel/compat-data/corejs2-built-ins",
422+
"@babel/plugin-syntax-import-assertions",
423+
"@babel/plugin-syntax-import-attributes",
421424
]
422425
: [],
423426
dynamicRequireTargets: [

eslint/babel-eslint-parser/test/index.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,31 @@ const BABEL_OPTIONS = {
3232
),
3333
};
3434
const PROPS_TO_REMOVE = [
35-
"importKind",
36-
"exportKind",
37-
"variance",
38-
"typeArguments",
39-
"filename",
40-
"identifierName",
35+
{ key: "importKind", type: null },
36+
{ key: "exportKind", type: null },
37+
{ key: "variance", type: null },
38+
{ key: "typeArguments", type: null },
39+
{ key: "filename", type: null },
40+
{ key: "identifierName", type: null },
41+
// espree doesn't support these yet
42+
{ key: "attributes", type: "ImportDeclaration" },
43+
{ key: "attributes", type: "ExportNamedDeclaration" },
44+
{ key: "attributes", type: "ExportAllDeclaration" },
45+
{ key: "attributes", type: "ImportExpression" },
46+
{ key: "options", type: "ImportExpression" },
4147
];
4248

4349
function deeplyRemoveProperties(obj, props) {
4450
for (const [k, v] of Object.entries(obj)) {
51+
if (
52+
props.some(
53+
({ key, type }) => key === k && (type == null || type === obj.type),
54+
)
55+
) {
56+
delete obj[k];
57+
continue;
58+
}
59+
4560
if (typeof v === "object") {
4661
if (Array.isArray(v)) {
4762
for (const el of v) {
@@ -51,16 +66,9 @@ function deeplyRemoveProperties(obj, props) {
5166
}
5267
}
5368

54-
if (props.includes(k)) {
55-
delete obj[k];
56-
} else if (v != null) {
69+
if (v != null) {
5770
deeplyRemoveProperties(v, props);
5871
}
59-
continue;
60-
}
61-
62-
if (props.includes(k)) {
63-
delete obj[k];
6472
}
6573
}
6674
}
@@ -101,6 +109,7 @@ describe("Babel and Espree", () => {
101109
}).ast;
102110

103111
deeplyRemoveProperties(babelAST, PROPS_TO_REMOVE);
112+
deeplyRemoveProperties(espreeAST, ["offset"]);
104113
expect(babelAST).toEqual(espreeAST);
105114
} else {
106115
// ESLint 8
@@ -117,6 +126,7 @@ describe("Babel and Espree", () => {
117126
}).ast;
118127

119128
deeplyRemoveProperties(babelAST, PROPS_TO_REMOVE);
129+
deeplyRemoveProperties(espreeAST, ["offset"]);
120130
expect(babelAST).toEqual(espreeAST);
121131
}
122132
}

packages/babel-core/src/parser/util/missing-plugin-helper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ const pluginNameMap: Record<
8484
url: "https://github.com/babel/babel/tree/main/packages/babel-preset-react",
8585
},
8686
},
87-
importAttributes: {
88-
syntax: {
89-
name: "@babel/plugin-syntax-import-attributes",
90-
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes",
91-
},
92-
},
9387
pipelineOperator: {
9488
syntax: {
9589
name: "@babel/plugin-syntax-pipeline-operator",
@@ -204,6 +198,12 @@ if (!process.env.BABEL_8_BREAKING) {
204198
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-assertions",
205199
},
206200
},
201+
importAttributes: {
202+
syntax: {
203+
name: "@babel/plugin-syntax-import-attributes",
204+
url: "https://github.com/babel/babel/tree/main/packages/babel-plugin-syntax-import-attributes",
205+
},
206+
},
207207
importMeta: {
208208
syntax: {
209209
name: "@babel/plugin-syntax-import-meta",

packages/babel-generator/src/generators/modules.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export function _printAttributes(
7878
const { attributes, assertions } = node;
7979

8080
if (
81+
!process.env.BABEL_8_BREAKING &&
8182
attributes &&
8283
!importAttributesKeyword &&
8384
// In the production build only show the warning once.
@@ -101,7 +102,11 @@ Please specify the "importAttributesKeyword" generator option, whose value can b
101102
this.word(useAssertKeyword ? "assert" : "with");
102103
this.space();
103104

104-
if (!useAssertKeyword && importAttributesKeyword !== "with") {
105+
if (
106+
!process.env.BABEL_8_BREAKING &&
107+
!useAssertKeyword &&
108+
importAttributesKeyword !== "with"
109+
) {
105110
// with-legacy
106111
this.printList(attributes || assertions);
107112
return;
@@ -132,11 +137,9 @@ export function ExportAllDeclaration(
132137
this.space();
133138
this.word("from");
134139
this.space();
135-
// @ts-expect-error Fixme: attributes is not defined in DeclareExportAllDeclaration
136140
if (node.attributes?.length || node.assertions?.length) {
137141
this.print(node.source, true);
138142
this.space();
139-
// @ts-expect-error Fixme: attributes is not defined in DeclareExportAllDeclaration
140143
this._printAttributes(node, false);
141144
} else {
142145
this.print(node.source);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"plugins": [["importAttributes", { "deprecatedAssertSyntax": true }]],
2+
"plugins": ["deprecatedImportAssert"],
33
"importAttributesKeyword": "assert"
44
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
22
"BABEL_8_BREAKING": true,
3-
"plugins": [["importAttributes", { "deprecatedAssertSyntax": true }]],
4-
"warns": "You are using import attributes, without specifying the desired output syntax.",
5-
"expectedReParseError": true
3+
"plugins": ["deprecatedImportAssert"]
64
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import "a" with type: "json";
1+
import "a" with { type: "json" };
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"plugins": [["importAttributes", { "deprecatedAssertSyntax": true }]],
2+
"BABEL_8_BREAKING": false,
3+
"plugins": ["deprecatedImportAssert"],
34
"importAttributesKeyword": "with-legacy",
45
"expectedReParseError": true
56
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"plugins": [["importAttributes", { "deprecatedAssertSyntax": true }]],
2+
"plugins": ["deprecatedImportAssert"],
33
"importAttributesKeyword": "with"
44
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "a" with { type: "json" };

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy