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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(findExports): support typescript enum exports #69

Merged
merged 1 commit into from Aug 18, 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 @@ -58,7 +58,7 @@ export interface DefaultExport extends ESMExport {
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
export const EXPORT_DECAL_RE = /\bexport\s+(?<declaration>(async function|function|let|const enum|const|enum|var|class))\s+(?<name>[\w$_]+)/g
const EXPORT_NAMED_RE = /\bexport\s+{(?<exports>[^}]+?)(?:[,\s]*)}(\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g
const EXPORT_STAR_RE = /\bexport\s*(\*)(\s*as\s+(?<name>[\w$_]+)\s+)?\s*(\s*from\s*["']\s*(?<specifier>(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g
const EXPORT_DEFAULT_RE = /\bexport\s+default\s+/g
Expand Down
4 changes: 3 additions & 1 deletion test/exports.test.ts
Expand Up @@ -18,7 +18,9 @@ describe('findExports', () => {
'export * from "./other"': { type: 'star', specifier: './other' },
'export * as foo from "./other"': { type: 'star', specifier: './other', name: 'foo' },
// eslint-disable-next-line no-template-curly-in-string
'const a = `<div${JSON.stringify({ class: 42 })}>`;\nexport default true;': { type: 'default', name: 'default', names: ['default'] }
'const a = `<div${JSON.stringify({ class: 42 })}>`;\nexport default true;': { type: 'default', name: 'default', names: ['default'] },
'export const enum foo { a = \'xx\' }': { type: 'declaration', names: ['foo'] },
'export enum bar { a = \'xx\' }': { type: 'declaration', names: ['bar'] }
}

for (const [input, test] of Object.entries(tests)) {
Expand Down