[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:
@@ -857,10 +857,12 @@ export default class ExpressionParser extends LValParser {
|
||||
): N.Expression {
|
||||
if (node.callee.type === "Import") {
|
||||
if (node.arguments.length === 2) {
|
||||
// todo(Babel 8): remove the if condition,
|
||||
// moduleAttributes is renamed to importAssertions
|
||||
if (!this.hasPlugin("moduleAttributes")) {
|
||||
if (process.env.BABEL_8_BREAKING) {
|
||||
this.expectPlugin("importAssertions");
|
||||
} else {
|
||||
if (!this.hasPlugin("moduleAttributes")) {
|
||||
this.expectPlugin("importAssertions");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.arguments.length === 0 || node.arguments.length > 2) {
|
||||
|
||||
@@ -2197,9 +2197,7 @@ export default class StatementParser extends ExpressionParser {
|
||||
const assertions = this.maybeParseImportAssertions();
|
||||
if (assertions) {
|
||||
node.assertions = assertions;
|
||||
}
|
||||
// todo(Babel 8): remove module attributes support
|
||||
else {
|
||||
} else if (!process.env.BABEL_8_BREAKING) {
|
||||
const attributes = this.maybeParseModuleAttributes();
|
||||
if (attributes) {
|
||||
node.attributes = attributes;
|
||||
|
||||
@@ -87,22 +87,28 @@ export function validatePlugins(plugins: PluginList) {
|
||||
}
|
||||
|
||||
if (hasPlugin(plugins, "moduleAttributes")) {
|
||||
if (hasPlugin(plugins, "importAssertions")) {
|
||||
if (process.env.BABEL_8_BREAKING) {
|
||||
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`.",
|
||||
);
|
||||
}
|
||||
const moduleAttributesVerionPluginOption = getPluginOption(
|
||||
plugins,
|
||||
"moduleAttributes",
|
||||
"version",
|
||||
);
|
||||
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'.",
|
||||
} else {
|
||||
if (hasPlugin(plugins, "importAssertions")) {
|
||||
throw new Error(
|
||||
"Cannot combine importAssertions and moduleAttributes plugins.",
|
||||
);
|
||||
}
|
||||
const moduleAttributesVerionPluginOption = getPluginOption(
|
||||
plugins,
|
||||
"moduleAttributes",
|
||||
"version",
|
||||
);
|
||||
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'.",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user