From ac7c37c079cdfa602d9e0d908292f51cd0472406 Mon Sep 17 00:00:00 2001 From: azaleta <24407500@qq.com> Date: Thu, 18 Aug 2022 16:40:43 +0800 Subject: [PATCH] feat(findExports): support typescript enum exports (#69) --- src/analyze.ts | 2 +- test/exports.test.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/analyze.ts b/src/analyze.ts index 980692c..bf8728f 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -58,7 +58,7 @@ export interface DefaultExport extends ESMExport { 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 +export const EXPORT_DECAL_RE = /\bexport\s+(?(async function|function|let|const enum|const|enum|var|class))\s+(?[\w$_]+)/g const EXPORT_NAMED_RE = /\bexport\s+{(?[^}]+?)(?:[,\s]*)}(\s*from\s*["']\s*(?(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g const EXPORT_STAR_RE = /\bexport\s*(\*)(\s*as\s+(?[\w$_]+)\s+)?\s*(\s*from\s*["']\s*(?(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g const EXPORT_DEFAULT_RE = /\bexport\s+default\s+/g diff --git a/test/exports.test.ts b/test/exports.test.ts index ef1a864..d638867 100644 --- a/test/exports.test.ts +++ b/test/exports.test.ts @@ -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 = ``;\nexport default true;': { type: 'default', name: 'default', names: ['default'] } + 'const a = ``;\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)) {