Skip to content

Commit

Permalink
refactor: replace boolean maybeNotEsm with parseGoal
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Dec 30, 2021
1 parent 0dba1cf commit 56b6838
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/ExportMap.js
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
};

Expand Down
4 changes: 2 additions & 2 deletions src/rules/named.js
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 56b6838

Please sign in to comment.