From b57f51fda2b8255ff986887c9b975db96277400a Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Sun, 11 Dec 2022 14:18:09 -0800 Subject: [PATCH] Add a test for some scopes --- test/bun.js/transpiler.test.js | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js index aef88780e9..02d4f11e2c 100644 --- a/test/bun.js/transpiler.test.js +++ b/test/bun.js/transpiler.test.js @@ -1764,6 +1764,54 @@ console.log(foo, array); ); }); + it("constant folding scopes", () => { + var transpiler = new Bun.Transpiler({ + inline: true, + platform: "bun", + allowBunRuntime: false, + }); + + // Check that pushing/popping scopes doesn't cause a crash + // We panic at runtime if the scopes are unbalanced, so this test just checks we don't have any crashes + function check(input) { + transpiler.transformSync(input); + } + + check("var x; 1 ? 0 : ()=>{}; (()=>{})()"); + check("var x; 0 ? ()=>{} : 1; (()=>{})()"); + check("var x; 0 && (()=>{}); (()=>{})()"); + check("var x; 1 || (()=>{}); (()=>{})()"); + check("if (1) 0; else ()=>{}; (()=>{})()"); + check("if (0) ()=>{}; else 1; (()=>{})()"); + check(` + var func = () => {}; + var x; + 1 ? 0 : func; + (() => {})(); + switch (1) { + case 0: { + class Foo { + static { + function hey() { + return class { + static { + var foo = class { + hey(arg) { + return 1; + } + }; + new foo(); + } + }; + } + } + } + new Foo(); + } + } + `); + }); + it("substitution", () => { var transpiler = new Bun.Transpiler({ inline: true,