Skip to content

Commit fe0f570

Browse files
test: check if newline on return works
1 parent cdea312 commit fe0f570

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test/index.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { test, snapshot } = require("node:test");
22
const { transformSync } = require("../dist/index.js");
33
const path = require("node:path");
44
const assert = require("node:assert");
5+
const vm = require("node:vm");
56

67
// Set the path for the snapshots directory
78
snapshot.setResolveSnapshotPath((testPath) => {
@@ -146,3 +147,32 @@ test("should not polyfill using Symbol.asyncDispose", (t) => {
146147
const { code } = transformSync(inputCode);
147148
assert.strictEqual(code, inputCode);
148149
});
150+
151+
test("should not break on return new line when stripped", (t) => {
152+
const inputCode = `
153+
function mkId() {
154+
return <T>
155+
(x: T)=>x;
156+
}
157+
const id = mkId();
158+
output = id(5);`;
159+
const { code } = transformSync(inputCode);
160+
t.assert.snapshot(code);
161+
const result = vm.runInContext(code, vm.createContext());
162+
assert.strictEqual(result, 5);
163+
});
164+
165+
test("should not break on return new line when stripped (alternative formatting)", (t) => {
166+
const inputCode = `
167+
function mkId() {
168+
return <
169+
T
170+
>(x: T)=>x;
171+
}
172+
const id = mkId();
173+
output = id(7);`;
174+
const { code } = transformSync(inputCode);
175+
t.assert.snapshot(code);
176+
const result = vm.runInContext(code, vm.createContext());
177+
assert.strictEqual(result, 7);
178+
});

test/snapshots/index.test.js.snapshot

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ exports[`should handle class modifiers 1`] = `
66
"\\n\\t\\tclass PrivateConstructor {\\n\\t\\t constructor() {}\\n\\t\\t a() {}\\n\\t\\t b() {}\\n\\t\\t static create() {\\n\\t\\t return new PrivateConstructor()\\n\\t\\t }\\n\\t\\t}\\n\\n\\t\\tconst ins = PrivateConstructor.create()\\n\\t\\tconsole.log(ins)\\n\\t"
77
`;
88

9+
exports[`should not break on return new line when stripped (alternative formatting) 1`] = `
10+
"\\n\\tfunction mkId() {\\n\\t\\treturn (\\n\\t\\t\\t \\n\\t\\t x )=>x;\\n\\t}\\n\\tconst id = mkId();\\n\\toutput = id(7);"
11+
`;
12+
13+
exports[`should not break on return new line when stripped 1`] = `
14+
"\\n\\tfunction mkId() {\\n\\t\\treturn ( \\n\\t\\t\\t x )=>x;\\n\\t}\\n\\tconst id = mkId();\\n\\toutput = id(5);"
15+
`;
16+
17+
exports[`should not throw on return new line when stripped 1`] = `
18+
"\\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}"
19+
`;
20+
921
exports[`should perform type stripping 1`] = `
1022
"const foo = 'bar';"
1123
`;

0 commit comments

Comments
 (0)