@@ -66,8 +66,54 @@ const CLASS_DECLARATION = 'ClassDeclaration'
6666const DEFAULT = 'default'
6767const TYPE_ALIAS = 'TypeAlias'
6868
69+ /**
70+ * List of imports per file.
71+ *
72+ * Represented by a two-level Map to a Set of identifiers. The upper-level Map
73+ * keys are the paths to the modules containing the imports, while the
74+ * lower-level Map keys are the paths to the files which are being imported
75+ * from. Lastly, the Set of identifiers contains either names being imported
76+ * or a special AST node name listed above (e.g ImportDefaultSpecifier).
77+ *
78+ * For example, if we have a file named foo.js containing:
79+ *
80+ * import { o2 } from './bar.js';
81+ *
82+ * Then we will have a structure that looks like:
83+ *
84+ * Map { 'foo.js' => Map { 'bar.js' => Set { 'o2' } } }
85+ *
86+ * @type {Map<string, Map<string, Set<string>>> }
87+ */
6988const importList = new Map ( )
89+
90+ /**
91+ * List of exports per file.
92+ *
93+ * Represented by a two-level Map to an object of metadata. The upper-level Map
94+ * keys are the paths to the modules containing the exports, while the
95+ * lower-level Map keys are the specific identifiers or special AST node names
96+ * being exported. The leaf-level metadata object at the moment only contains a
97+ * `whereUsed` propoerty, which contains a Set of paths to modules that import
98+ * the name.
99+ *
100+ * For example, if we have a file named bar.js containing the following exports:
101+ *
102+ * const o2 = 'bar';
103+ * export { o2 };
104+ *
105+ * And a file named foo.js containing the following import:
106+ *
107+ * import { o2 } from './bar.js';
108+ *
109+ * Then we will have a structure that looks like:
110+ *
111+ * Map { 'bar.js' => Map { 'o2' => { whereUsed: Set { 'foo.js' } } } }
112+ *
113+ * @type {Map<string, Map<string, object>> }
114+ */
70115const exportList = new Map ( )
116+
71117const ignoredFiles = new Set ( )
72118const filesOutsideSrc = new Set ( )
73119
@@ -453,9 +499,12 @@ module.exports = {
453499 }
454500 }
455501
456- const exportStatement = exports . get ( exportedValue )
502+ // exportsList will always map any imported value of 'default' to 'ImportDefaultSpecifier'
503+ const exportsKey = exportedValue === DEFAULT ? IMPORT_DEFAULT_SPECIFIER : exportedValue
504+
505+ const exportStatement = exports . get ( exportsKey )
457506
458- const value = exportedValue === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportedValue
507+ const value = exportsKey === IMPORT_DEFAULT_SPECIFIER ? DEFAULT : exportsKey
459508
460509 if ( typeof exportStatement !== 'undefined' ) {
461510 if ( exportStatement . whereUsed . size < 1 ) {
0 commit comments