From b7059f88dd71fa12840580fbbc842c72aef7ebf7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 28 Jul 2025 03:17:38 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- .../top-level-await-async-keyword.test.ts | 20 ++++++++++--------- .../bundler-top-level-await-async.test.ts | 10 +++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/test/bundler/top-level-await-async-keyword.test.ts b/test/bundler/top-level-await-async-keyword.test.ts index c2a56df37d..af21f790f4 100644 --- a/test/bundler/top-level-await-async-keyword.test.ts +++ b/test/bundler/top-level-await-async-keyword.test.ts @@ -19,17 +19,17 @@ describe("bundler", () => { onAfterBundle(api) { // Check if the bundled code contains __esm wrappers const bundledContent = api.readFile("/out.js"); - + // If there are __esm wrappers with await, they should have async keyword const esmWithAwaitPattern = /__esm\(\(\) => \{[\s\S]*?await/; const esmAsyncPattern = /__esm\(async \(\) => \{[\s\S]*?await/; - + if (bundledContent.includes("__esm(") && bundledContent.includes("await")) { // Should NOT have non-async __esm functions that contain await if (esmWithAwaitPattern.test(bundledContent)) { throw new Error("Found __esm() function without async keyword that contains await"); } - + // Should have async __esm functions if they contain await if (!esmAsyncPattern.test(bundledContent)) { throw new Error("Expected to find __esm(async () => { ... await ... }) pattern"); @@ -64,11 +64,11 @@ describe("bundler", () => { onAfterBundle(api) { // Check typical splitting output files const potentialFiles = ["entry.js", "chunk.js", "module-a.js", "module-b.js"]; - + for (const file of potentialFiles) { try { const content = api.readFile(`/out/${file}`); - + // If there are __esm wrappers with await, they should have async keyword if (content.includes("__esm(") && content.includes("await")) { const badPattern = /__esm\(\(\) => \{[\s\S]*?await/; @@ -115,17 +115,19 @@ describe("bundler", () => { onAfterBundle(api) { // Check typical splitting output files const potentialFiles = ["entry.js", "log.js", "env.js", "statsigStorage.js", "chunk.js"]; - + for (const file of potentialFiles) { try { const content = api.readFile(`/out/${file}`); - + // The bug was: var init_statsigStorage = __esm(() => { await init_log(); ... }); // Should be: var init_statsigStorage = __esm(async () => { await init_log(); ... }); if (content.includes("__esm(") && content.includes("await")) { const badPattern = /__esm\(\(\) => \{[\s\S]*?await/; if (badPattern.test(content)) { - throw new Error(`Found __esm(() => { await ... }) - missing async keyword in ${file}! Content: ${content}`); + throw new Error( + `Found __esm(() => { await ... }) - missing async keyword in ${file}! Content: ${content}`, + ); } } } catch (e) { @@ -134,4 +136,4 @@ describe("bundler", () => { } }, }); -}); \ No newline at end of file +}); diff --git a/test/regression/issue/bundler-top-level-await-async.test.ts b/test/regression/issue/bundler-top-level-await-async.test.ts index a8508ac448..5db2c4fa9c 100644 --- a/test/regression/issue/bundler-top-level-await-async.test.ts +++ b/test/regression/issue/bundler-top-level-await-async.test.ts @@ -1,7 +1,7 @@ import { describe } from "bun:test"; import { itBundled } from "../../bundler/expectBundled"; -// Regression test for bundler bug where top-level await modules +// Regression test for bundler bug where top-level await modules // generated __esm(() => { await ... }) instead of __esm(async () => { await ... }) // This caused SyntaxError: Unexpected reserved word when the bundled code was executed describe("bundler regression: top-level await async keyword", () => { @@ -37,13 +37,13 @@ describe("bundler regression: top-level await async keyword", () => { onAfterBundle(api) { // The original bug: var init_X = __esm(() => { await ... }); (missing async) // Should be: var init_X = __esm(async () => { await ... }); - + const potentialFiles = ["log.js", "env.js", "statsigStorage.js", "chunk.js"]; - + for (const file of potentialFiles) { try { const content = api.readFile(`/out/${file}`); - + if (content.includes("__esm(") && content.includes("await")) { // This should never happen - __esm functions with await must be async const badPattern = /__esm\(\(\) => \{[\s\S]*?await/; @@ -57,4 +57,4 @@ describe("bundler regression: top-level await async keyword", () => { } }, }); -}); \ No newline at end of file +});