From 896c8a7dd087d041ffb29a00065a4f71d62ed249 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 29 Jun 2022 10:26:27 +0200 Subject: [PATCH] fix(detectSyntax): detect `export class` as esm syntax --- src/syntax.ts | 2 +- test/syntax.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/syntax.ts b/src/syntax.ts index d823a01..05ecc17 100644 --- a/src/syntax.ts +++ b/src/syntax.ts @@ -4,7 +4,7 @@ import { readPackageJSON } from 'pkg-types' import { ResolveOptions, resolvePath } from './resolve' import { isNodeBuiltin, getProtocol } from './utils' -const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|type|function|const|var|let|async function)|import\.meta\b)/m +const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|class|type|function|const|var|let|async function)|import\.meta\b)/m const BUILTIN_EXTENSIONS = new Set(['.mjs', '.cjs', '.node', '.wasm']) diff --git a/test/syntax.test.ts b/test/syntax.test.ts index fd2f6a4..a7da182 100644 --- a/test/syntax.test.ts +++ b/test/syntax.test.ts @@ -20,6 +20,7 @@ const staticTests = { 'export const a = 1': { hasESM: true, hasCJS: false, isMixed: false }, 'export function hi() {}': { hasESM: true, hasCJS: false, isMixed: false }, 'export async function foo() {}': { hasESM: true, hasCJS: false, isMixed: false }, + 'export class': { hasESM: true, hasCJS: false, isMixed: false }, // CJS 'exports.c={}': { hasESM: false, hasCJS: true, isMixed: false }, 'const b=true;module.exports={b};': { hasESM: false, hasCJS: true, isMixed: false },