From 9fcc5551bfbc188781b7d59dcd8383921fbd4ae9 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 29 Nov 2021 15:13:35 +0100 Subject: [PATCH] fix(findExports): detect `async function` --- src/analyze.ts | 2 +- test/exports.test.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/analyze.ts b/src/analyze.ts index 46af87c..e331612 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -53,7 +53,7 @@ export interface DefaultExport extends ESMExport { export const ESM_STATIC_IMPORT_RE = /^(?<=\s*)import\s*(["'\s]*(?[\w*${}\n\r\t, /]+)from\s*)?["']\s*(?.*[@\w_-]+)\s*["'][^\n]*$/gm export const DYNAMIC_IMPORT_RE = /import\s*\((?(?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*)\)/gm -export const EXPORT_DECAL_RE = /\bexport\s+(?(function|let|const|var|class))\s+(?[\w$_]+)/g +export const EXPORT_DECAL_RE = /\bexport\s+(?(async function|function|let|const|var|class))\s+(?[\w$_]+)/g const EXPORT_NAMED_RE = /\bexport\s+{(?[^}]+)}/g const EXPORT_DEFAULT_RE = /\bexport\s+default\s+/g diff --git a/test/exports.test.mjs b/test/exports.test.mjs index 71c73c3..053d509 100644 --- a/test/exports.test.mjs +++ b/test/exports.test.mjs @@ -7,7 +7,7 @@ describe('findExports', () => { 'export const useD = () => { return \'d\' }': { name: 'useD', type: 'declaration' }, 'export { useB, _useC as useC }': { names: ['useB', 'useC'], type: 'named' }, 'export default foo': { type: 'default', name: 'default', names: ['default'] }, - 'export async function foo ()': { type: 'named', names: ['foo'] }, + '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'] } }