Skip to content

Commit

Permalink
test: check if yield and throw newline work
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Jan 27, 2025
1 parent fe0f570 commit 96dba79
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
34 changes: 34 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
6 changes: 5 additions & 1 deletion test/snapshots/index.test.js.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down

0 comments on commit 96dba79

Please sign in to comment.