[Babel 8]: remove module attributes parser/generator support (#13308)
* breaking: remove support of moduleAttributes * Update packages/babel-parser/src/plugin-utils.js Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com> * chore: remove todo comments * make prettier happy Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
b670c11070
commit
b3d35cd412
@ -204,15 +204,15 @@ export function ImportDeclaration(this: Printer, node: t.ImportDeclaration) {
|
|||||||
this.print(node.source, node);
|
this.print(node.source, node);
|
||||||
|
|
||||||
this.printAssertions(node);
|
this.printAssertions(node);
|
||||||
// todo(Babel 8): remove this if branch
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
// `module-attributes` support is discontinued, use `import-assertions` instead.
|
|
||||||
// @ts-expect-error
|
|
||||||
if (node.attributes?.length) {
|
|
||||||
this.space();
|
|
||||||
this.word("with");
|
|
||||||
this.space();
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
this.printList(node.attributes, node);
|
if (node.attributes?.length) {
|
||||||
|
this.space();
|
||||||
|
this.word("with");
|
||||||
|
this.space();
|
||||||
|
// @ts-expect-error
|
||||||
|
this.printList(node.attributes, node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
|
|||||||
@ -7,5 +7,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"sourceType": "module"
|
"sourceType": "module",
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -857,10 +857,12 @@ export default class ExpressionParser extends LValParser {
|
|||||||
): N.Expression {
|
): N.Expression {
|
||||||
if (node.callee.type === "Import") {
|
if (node.callee.type === "Import") {
|
||||||
if (node.arguments.length === 2) {
|
if (node.arguments.length === 2) {
|
||||||
// todo(Babel 8): remove the if condition,
|
if (process.env.BABEL_8_BREAKING) {
|
||||||
// moduleAttributes is renamed to importAssertions
|
|
||||||
if (!this.hasPlugin("moduleAttributes")) {
|
|
||||||
this.expectPlugin("importAssertions");
|
this.expectPlugin("importAssertions");
|
||||||
|
} else {
|
||||||
|
if (!this.hasPlugin("moduleAttributes")) {
|
||||||
|
this.expectPlugin("importAssertions");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.arguments.length === 0 || node.arguments.length > 2) {
|
if (node.arguments.length === 0 || node.arguments.length > 2) {
|
||||||
|
|||||||
@ -2197,9 +2197,7 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
const assertions = this.maybeParseImportAssertions();
|
const assertions = this.maybeParseImportAssertions();
|
||||||
if (assertions) {
|
if (assertions) {
|
||||||
node.assertions = assertions;
|
node.assertions = assertions;
|
||||||
}
|
} else if (!process.env.BABEL_8_BREAKING) {
|
||||||
// todo(Babel 8): remove module attributes support
|
|
||||||
else {
|
|
||||||
const attributes = this.maybeParseModuleAttributes();
|
const attributes = this.maybeParseModuleAttributes();
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
node.attributes = attributes;
|
node.attributes = attributes;
|
||||||
|
|||||||
@ -87,22 +87,28 @@ export function validatePlugins(plugins: PluginList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hasPlugin(plugins, "moduleAttributes")) {
|
if (hasPlugin(plugins, "moduleAttributes")) {
|
||||||
if (hasPlugin(plugins, "importAssertions")) {
|
if (process.env.BABEL_8_BREAKING) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Cannot combine importAssertions and moduleAttributes plugins.",
|
"`moduleAttributes` has been removed in Babel 8, please use `importAssertions` parser plugin, or `@babel/plugin-syntax-import-assertions`.",
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
const moduleAttributesVerionPluginOption = getPluginOption(
|
if (hasPlugin(plugins, "importAssertions")) {
|
||||||
plugins,
|
throw new Error(
|
||||||
"moduleAttributes",
|
"Cannot combine importAssertions and moduleAttributes plugins.",
|
||||||
"version",
|
);
|
||||||
);
|
}
|
||||||
if (moduleAttributesVerionPluginOption !== "may-2020") {
|
const moduleAttributesVerionPluginOption = getPluginOption(
|
||||||
throw new Error(
|
plugins,
|
||||||
"The 'moduleAttributes' plugin requires a 'version' option," +
|
"moduleAttributes",
|
||||||
" representing the last proposal update. Currently, the" +
|
"version",
|
||||||
" only supported value is 'may-2020'.",
|
|
||||||
);
|
);
|
||||||
|
if (moduleAttributesVerionPluginOption !== "may-2020") {
|
||||||
|
throw new Error(
|
||||||
|
"The 'moduleAttributes' plugin requires a 'version' option," +
|
||||||
|
" representing the last proposal update. Currently, the" +
|
||||||
|
" only supported value is 'may-2020'.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)"
|
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)",
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/babel-parser/test/fixtures/experimental/module-attributes/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/experimental/module-attributes/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"BABEL_8_BREAKING": false
|
||||||
|
}
|
||||||
@ -65,4 +65,13 @@ describe("plugin options", function () {
|
|||||||
expect(getParser(SYNTAX_2, [OPT_1, OPT_2])).toThrow();
|
expect(getParser(SYNTAX_2, [OPT_1, OPT_2])).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("'moduleAttributes' plugin", () => {
|
||||||
|
(process.env.BABEL_8_BREAKING ? it : it.skip)("removed in Babel 8", () => {
|
||||||
|
expect(
|
||||||
|
getParser("", ["moduleAttributes"]),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(
|
||||||
|
`"\`moduleAttributes\` has been removed in Babel 8, please use \`importAssertions\` parser plugin, or \`@babel/plugin-syntax-import-assertions\`."`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user