diff --git a/src/ExportMap.js b/src/ExportMap.js index 9374c4f656..081e32262b 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -44,12 +44,9 @@ export default class ExportMap { this.imports = new Map(); this.errors = []; /** - * true when we are still unsure if - * the module is ESM, happens when the module - * contains dynamic `import()` but no other - * ESM import/export + * type {'ambiguous' | 'Module' | 'Script'} */ - this.maybeNotEsm = false; + this.parseGoal = 'ambiguous'; } get hasDefault() { return this.get('default') != null; } // stronger than this.has @@ -413,8 +410,8 @@ ExportMap.parse = function (path, content, context) { }, }); - const maybeNotEsm = !unambiguous.isModule(ast); - if (maybeNotEsm && !hasDynamicImports) return null; + const unambiguouslyEsm = unambiguous.isModule(ast); + if (!unambiguouslyEsm && !hasDynamicImports) return null; const docstyle = (context.settings && context.settings['import/docstyle']) || ['jsdoc']; const docStyleParsers = {}; @@ -718,7 +715,9 @@ ExportMap.parse = function (path, content, context) { m.namespace.set('default', {}); // add default export } - m.maybeNotEsm = maybeNotEsm; + if (unambiguouslyEsm) { + m.parseGoal = 'Module'; + } return m; }; diff --git a/src/rules/named.js b/src/rules/named.js index ffc787001e..a529c295b7 100644 --- a/src/rules/named.js +++ b/src/rules/named.js @@ -40,7 +40,7 @@ module.exports = { } const imports = Exports.get(node.source.value, context); - if (imports == null || imports.maybeNotEsm) { + if (imports == null || imports.parseGoal === 'ambiguous') { return; } @@ -97,7 +97,7 @@ module.exports = { // return if it's not a string source || source.type !== 'Literal' || variableExports == null - || variableExports.maybeNotEsm + || variableExports.parseGoal === 'ambiguous' ) { return; }