Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix lookbefore in front of import #43

Merged
merged 1 commit into from Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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