From 96dba7943a83deab3c705227e49fb99aa10d1580 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Tue, 21 Jan 2025 11:13:24 +0100 Subject: [PATCH] test: check if yield and throw newline work --- test/index.test.js | 34 +++++++++++++++++++++++++++ test/snapshots/index.test.js.snapshot | 6 ++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/test/index.test.js b/test/index.test.js index b8a2cbc9e..1b47d649a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -176,3 +176,37 @@ test("should not break on return new line when stripped (alternative formatting) const result = vm.runInContext(code, vm.createContext()); assert.strictEqual(result, 7); }); + +test("should not throw on return new line when stripped", (t) => { + const inputCode = ` + function mkId() { + throw < + T + >(x: T)=>x; + } + + try { + mkId(); + } + catch(e){ + output = e(5); + }`; + const { code } = transformSync(inputCode); + t.assert.snapshot(code); + const result = vm.runInContext(code, vm.createContext()); + assert.strictEqual(result, 5); +}); + +test("should not throw on yield new line when stripped", (t) => { + const inputCode = ` + function* mkId() { + yield < + T + >(x: T)=>x; + } + output= mkId().next().value(5);`; + const { code } = transformSync(inputCode); + t.assert.snapshot(code); + const result = vm.runInContext(code, vm.createContext()); + assert.strictEqual(result, 5); +}); diff --git a/test/snapshots/index.test.js.snapshot b/test/snapshots/index.test.js.snapshot index 13fd5e438..ccc56b221 100644 --- a/test/snapshots/index.test.js.snapshot +++ b/test/snapshots/index.test.js.snapshot @@ -15,7 +15,11 @@ exports[`should not break on return new line when stripped 1`] = ` `; exports[`should not throw on return new line when stripped 1`] = ` -"\\n\\tfunction mkId() {\\n\\t\\tthrow \\n\\t\\t\\t \\n\\t\\t (x )=>x;\\n\\t}\\n\\n\\ttry {\\n\\t\\tmkId();\\n\\t}\\n\\tcatch(e){\\n\\t\\toutput = e(5);\\n\\t}" +"\\n\\tfunction mkId() {\\n\\t\\tthrow (\\n\\t\\t\\t \\n\\t\\t x )=>x;\\n\\t}\\n\\n\\ttry {\\n\\t\\tmkId();\\n\\t}\\n\\tcatch(e){\\n\\t\\toutput = e(5);\\n\\t}" +`; + +exports[`should not throw on yield new line when stripped 1`] = ` +"\\n\\tfunction* mkId() {\\n\\t\\tyield (\\n\\t\\t\\t\\t \\n\\t\\t x )=>x;\\n\\t}\\n\\toutput= mkId().next().value(5);" `; exports[`should perform type stripping 1`] = `