Use strict namespace behavior for mjs files. (#7545)
This commit is contained in:
@@ -15,6 +15,14 @@ export default declare((api, options) => {
|
||||
|
||||
const {
|
||||
loose,
|
||||
|
||||
// 'true' for non-mjs files to strictly have .default, instead of having
|
||||
// destructuring-like behavior for their properties.
|
||||
strictNamespace = false,
|
||||
|
||||
// 'true' for mjs files to strictly have .default, instead of having
|
||||
// destructuring-like behavior for their properties.
|
||||
mjsStrictNamespace = true,
|
||||
allowTopLevelThis,
|
||||
strict,
|
||||
strictMode,
|
||||
@@ -32,6 +40,13 @@ export default declare((api, options) => {
|
||||
throw new Error(`.lazy must be a boolean, array of strings, or a function`);
|
||||
}
|
||||
|
||||
if (typeof strictNamespace !== "boolean") {
|
||||
throw new Error(`.strictNamespace must be a boolean, or undefined`);
|
||||
}
|
||||
if (typeof mjsStrictNamespace !== "boolean") {
|
||||
throw new Error(`.mjsStrictNamespace must be a boolean, or undefined`);
|
||||
}
|
||||
|
||||
const getAssertion = localName => template.expression.ast`
|
||||
(function(){
|
||||
throw new Error(
|
||||
@@ -103,7 +118,7 @@ export default declare((api, options) => {
|
||||
return {
|
||||
visitor: {
|
||||
Program: {
|
||||
exit(path) {
|
||||
exit(path, state) {
|
||||
if (!isModule(path)) return;
|
||||
|
||||
// Rename the bindings auto-injected into the scope so there is no
|
||||
@@ -137,6 +152,11 @@ export default declare((api, options) => {
|
||||
allowTopLevelThis,
|
||||
noInterop,
|
||||
lazy,
|
||||
esNamespaceOnly:
|
||||
typeof state.filename === "string" &&
|
||||
/\.mjs$/.test(state.filename)
|
||||
? mjsStrictNamespace
|
||||
: strictNamespace,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user