mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix async explicit resource management in browser builds (#19896)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -4157,7 +4157,7 @@ pub const ParseTask = struct {
|
||||
// The definitions of __dispose and __asyncDispose match what esbuild's __wellKnownSymbol() helper does
|
||||
else =>
|
||||
\\var __dispose = Symbol.dispose || /* @__PURE__ */ Symbol.for('Symbol.dispose');
|
||||
\\var __asyncDispose = Symbol.dispose || /* @__PURE__ */ Symbol.for('Symbol.dispose');
|
||||
\\var __asyncDispose = Symbol.asyncDispose || /* @__PURE__ */ Symbol.for('Symbol.asyncDispose');
|
||||
\\
|
||||
\\export var __using = (stack, value, async) => {
|
||||
\\ if (value != null) {
|
||||
|
||||
@@ -320,4 +320,46 @@ describe("bundler", () => {
|
||||
expect(contents).toBe("");
|
||||
},
|
||||
});
|
||||
|
||||
itBundled("browser/AwaitUsingStatement", {
|
||||
files: {
|
||||
"/entry.js": `
|
||||
async function test() {
|
||||
await using resource = {
|
||||
async [Symbol.asyncDispose]() {
|
||||
console.log("The function was called");
|
||||
await 42;
|
||||
console.log("and the await finished");
|
||||
}
|
||||
};
|
||||
console.log("Before!");
|
||||
}
|
||||
test();
|
||||
`,
|
||||
},
|
||||
target: "browser",
|
||||
run: {
|
||||
stdout: "Before!\nThe function was called\nand the await finished\n",
|
||||
},
|
||||
});
|
||||
|
||||
itBundled("browser/UsingStatement", {
|
||||
files: {
|
||||
"/entry.js": `
|
||||
function test() {
|
||||
using resource = {
|
||||
[Symbol.dispose]() {
|
||||
console.log("The dispose function was called");
|
||||
}
|
||||
};
|
||||
console.log("Before!");
|
||||
}
|
||||
test();
|
||||
`,
|
||||
},
|
||||
target: "browser",
|
||||
run: {
|
||||
stdout: "Before!\nThe dispose function was called\n",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -57,9 +57,9 @@ describe("bundler", () => {
|
||||
"../entry.tsx",
|
||||
],
|
||||
mappings: [
|
||||
["react.development.js:524:'getContextName'", "1:5426:Y1"],
|
||||
["react.development.js:524:'getContextName'", "1:5436:Y1"],
|
||||
["react.development.js:2495:'actScopeDepth'", "23:4092:GJ++"],
|
||||
["react.development.js:696:''Component'", '1:7488:\'Component "%s"'],
|
||||
["react.development.js:696:''Component'", '1:7498:\'Component "%s"'],
|
||||
["entry.tsx:6:'\"Content-Type\"'", '100:18849:"Content-Type"'],
|
||||
["entry.tsx:11:'<html>'", "100:19103:void"],
|
||||
["entry.tsx:23:'await'", "100:19203:await"],
|
||||
@@ -67,7 +67,7 @@ describe("bundler", () => {
|
||||
},
|
||||
},
|
||||
expectExactFilesize: {
|
||||
"out/entry.js": 222164,
|
||||
"out/entry.js": 222174,
|
||||
},
|
||||
run: {
|
||||
stdout: "<!DOCTYPE html><html><body><h1>Hello World</h1><p>This is an example.</p></body></html>",
|
||||
|
||||
Reference in New Issue
Block a user