Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions lib/esm-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,7 @@ function detectESMFeatures(
let isTopLevel = true;

while (parent) {
if (
parent.isFunctionDeclaration() ||
parent.isFunctionExpression() ||
parent.isArrowFunctionExpression() ||
parent.isObjectMethod() ||
parent.isClassMethod()
) {
if (parent.isFunction()) {
isTopLevel = false;
break;
}
Expand All @@ -132,13 +126,7 @@ function detectESMFeatures(
let isTopLevel = true;

while (parent) {
if (
parent.isFunctionDeclaration() ||
parent.isFunctionExpression() ||
parent.isArrowFunctionExpression() ||
parent.isObjectMethod() ||
parent.isClassMethod()
) {
if (parent.isFunction()) {
isTopLevel = false;
break;
}
Expand Down
15 changes: 15 additions & 0 deletions test/unit/esm-transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ describe('transformESMtoCJS', () => {
assert.doesNotMatch(res.code, /async\s*\(\s*\)\s*=>/);
});

it('await inside a private class method does NOT trigger IIFE wrap', () => {
// `async #m()` is a ClassPrivateMethod, not a ClassMethod — the climber
// must treat it as a function boundary too, otherwise any module using
// private async methods is reported as TLA + exports and left untransformed.
const src = [
'export class C {',
' async #m() { await 1; }',
' async #n() { for await (const x of []) {} }',
'}',
].join('\n');
const res = transformESMtoCJS(src, 'private-method.mjs');
assert.equal(res.isTransformed, true);
assert.doesNotMatch(res.code, /async\s*\(\s*\)\s*=>/);
});

it('import.meta: esbuild emits shim, we inject the real implementation', () => {
const res = transformESMtoCJS(
'export const here = import.meta.url;\n',
Expand Down
Loading