Skip to content

Commit

Permalink
fix: fix lookbefore in front of import (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Apr 13, 2022
1 parent de60f32 commit fbc9b5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/analyze.ts
Expand Up @@ -52,7 +52,7 @@ export interface DefaultExport extends ESMExport {
type: 'default'
}

export const ESM_STATIC_IMPORT_RE = /(?<=\s*|^|;)import\s*(["'\s]*(?<imports>[\w*${}\n\r\t, /]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][\s;]*/gm
export const ESM_STATIC_IMPORT_RE = /(?<=\s|^|;)import\s*(["'\s]*(?<imports>[\w*${}\n\r\t, /]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][\s;]*/gm
export const DYNAMIC_IMPORT_RE = /import\s*\((?<expression>(?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gm

export const EXPORT_DECAL_RE = /\bexport\s+(?<declaration>(async function|function|let|const|var|class))\s+(?<name>[\w$_]+)/g
Expand Down
15 changes: 11 additions & 4 deletions test/imports.test.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit fbc9b5a

Please sign in to comment.