aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/transpiler.test.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-11 14:18:09 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-11 14:18:09 -0800
commitb57f51fda2b8255ff986887c9b975db96277400a (patch)
tree54ea27f7ce7d2055b1cf7bb7f0037e668445d057 /test/bun.js/transpiler.test.js
parentfad1742410062c1d321e3e816802d6a6fde969b7 (diff)
downloadbun-b57f51fda2b8255ff986887c9b975db96277400a.tar.gz
bun-b57f51fda2b8255ff986887c9b975db96277400a.tar.zst
bun-b57f51fda2b8255ff986887c9b975db96277400a.zip
Add a test for some scopes
Diffstat (limited to 'test/bun.js/transpiler.test.js')
-rw-r--r--test/bun.js/transpiler.test.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js
index aef88780e..02d4f11e2 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,