diff --git a/src/analyze.ts b/src/analyze.ts index 404f684..51bf365 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -52,7 +52,7 @@ export interface DefaultExport extends ESMExport { type: 'default' } -export const ESM_STATIC_IMPORT_RE = /(?<=\s*|^|;)import\s*(["'\s]*(?[\w*${}\n\r\t, /]+)from\s*)?["']\s*(?(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][\s;]*/gm +export const ESM_STATIC_IMPORT_RE = /(?<=\s|^|;)import\s*(["'\s]*(?[\w*${}\n\r\t, /]+)from\s*)?["']\s*(?(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][\s;]*/gm export const DYNAMIC_IMPORT_RE = /import\s*\((?(?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gm export const EXPORT_DECAL_RE = /\bexport\s+(?(async function|function|let|const|var|class))\s+(?[\w$_]+)/g diff --git a/test/imports.test.ts b/test/imports.test.ts index 66a8beb..a3c082f 100644 --- a/test/imports.test.ts +++ b/test/imports.test.ts @@ -46,10 +46,16 @@ const staticTests = { 'import "module-name";': { specifier: 'module-name' }, - 'import { thing } from "module-name";import { other } from "other-module"': [{ - specifier: 'module-name', - namedImports: { thing: 'thing' } - }] + 'import { thing } from "module-name";import { other } from "other-module"': [ + { + specifier: 'module-name', + namedImports: { thing: 'thing' } + }, { + specifier: 'other-module', + namedImports: { other: 'other' } + } + ], + '"import"===node.object.meta.name&&"': [] } staticTests[`import { @@ -102,6 +108,7 @@ describe('findStaticImports', () => { it(input.replace(/\n/g, '\\n'), () => { const matches = findStaticImports(input) const results = Array.isArray(_results) ? _results : [_results] + expect(results.length).toEqual(matches.length) for (let i = 0; i < results.length; i++) { const test = results[i] const match = matches[i]