[autofix.ci] apply automated fixes

This commit is contained in:
autofix-ci[bot]
2025-07-28 03:17:38 +00:00
committed by GitHub
parent dbc06d6aed
commit b7059f88dd
2 changed files with 16 additions and 14 deletions

View File

@@ -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", () => {
}
},
});
});
});

View File

@@ -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", () => {
}
},
});
});
});