Skip to content

Commit

Permalink
fix: identify ESM in empty export file (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Dec 2, 2023
1 parent c80cc50 commit 01592a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/utils/esm-pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const esmPattern = /\b(?:import|export)\b/;
export const isESM = (code: string) => {
if (code.includes('import') || code.includes('export')) {
try {
const [imports, exports] = parseEsm(code);
return imports.length > 0 || exports.length > 0;
const hasModuleSyntax = parseEsm(code)[3];
return hasModuleSyntax;
} catch {
/**
* If it fails to parse, there's a syntax error
Expand Down
3 changes: 2 additions & 1 deletion tests/specs/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ const files = {
type: 'module',
exports: './index.js',
}),
'index.js': syntaxLowering,
'index.js': `${syntaxLowering}\nexport * from "./empty-export.js"`,
'empty-export.js': 'export {}',
},
},

Expand Down

0 comments on commit 01592a7

Please sign in to comment.