Skip to content

Commit 56b6838

Browse files
committed
refactor: replace boolean maybeNotEsm with parseGoal
1 parent 0dba1cf commit 56b6838

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/ExportMap.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ export default class ExportMap {
4444
this.imports = new Map();
4545
this.errors = [];
4646
/**
47-
* true when we are still unsure if
48-
* the module is ESM, happens when the module
49-
* contains dynamic `import()` but no other
50-
* ESM import/export
47+
* type {'ambiguous' | 'Module' | 'Script'}
5148
*/
52-
this.maybeNotEsm = false;
49+
this.parseGoal = 'ambiguous';
5350
}
5451

5552
get hasDefault() { return this.get('default') != null; } // stronger than this.has
@@ -413,8 +410,8 @@ ExportMap.parse = function (path, content, context) {
413410
},
414411
});
415412

416-
const maybeNotEsm = !unambiguous.isModule(ast);
417-
if (maybeNotEsm && !hasDynamicImports) return null;
413+
const unambiguouslyEsm = unambiguous.isModule(ast);
414+
if (!unambiguouslyEsm && !hasDynamicImports) return null;
418415

419416
const docstyle = (context.settings && context.settings['import/docstyle']) || ['jsdoc'];
420417
const docStyleParsers = {};
@@ -718,7 +715,9 @@ ExportMap.parse = function (path, content, context) {
718715
m.namespace.set('default', {}); // add default export
719716
}
720717

721-
m.maybeNotEsm = maybeNotEsm;
718+
if (unambiguouslyEsm) {
719+
m.parseGoal = 'Module';
720+
}
722721
return m;
723722
};
724723

src/rules/named.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = {
4040
}
4141

4242
const imports = Exports.get(node.source.value, context);
43-
if (imports == null || imports.maybeNotEsm) {
43+
if (imports == null || imports.parseGoal === 'ambiguous') {
4444
return;
4545
}
4646

@@ -97,7 +97,7 @@ module.exports = {
9797
// return if it's not a string source
9898
|| source.type !== 'Literal'
9999
|| variableExports == null
100-
|| variableExports.maybeNotEsm
100+
|| variableExports.parseGoal === 'ambiguous'
101101
) {
102102
return;
103103
}

0 commit comments

Comments
 (0)