From af777cbe3ce09d23c6a994334e658f1b21e71ea6 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Thu, 16 Jun 2022 13:27:13 +0300 Subject: [PATCH] feat: support named star export (#45) --- src/analyze.ts | 2 +- test/exports.test.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/analyze.ts b/src/analyze.ts index 51bf365..742e342 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -57,7 +57,7 @@ export const DYNAMIC_IMPORT_RE = /import\s*\((?(?:[^)(]+|\((?:[^)(]+ export const EXPORT_DECAL_RE = /\bexport\s+(?(async function|function|let|const|var|class))\s+(?[\w$_]+)/g const EXPORT_NAMED_RE = /\bexport\s+{(?[^}]+)}(\s*from\s*["']\s*(?(?<="\s*)[^"]*[^"\s](?=\s*")|(?<='\s*)[^']*[^'\s](?=\s*'))\s*["'][^\n]*)?/g -const EXPORT_STAR_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 export function findStaticImports (code: string): StaticImport[] { diff --git a/test/exports.test.ts b/test/exports.test.ts index 116cd7f..02b0f88 100644 --- a/test/exports.test.ts +++ b/test/exports.test.ts @@ -11,7 +11,8 @@ describe('findExports', () => { 'export async function foo ()': { type: 'declaration', names: ['foo'] }, 'export const $foo = () => {}': { type: 'declaration', names: ['$foo'] }, 'export { foo as default }': { type: 'default', name: 'default', names: ['default'] }, - 'export * from "./other"': { type: 'star', specifier: './other' } + 'export * from "./other"': { type: 'star', specifier: './other' }, + 'export * as foo from "./other"': { type: 'star', specifier: './other', name: 'foo' } } describe('findExports', () => {