diff options
author | 2022-11-09 01:30:02 -0800 | |
---|---|---|
committer | 2022-11-09 01:30:02 -0800 | |
commit | 565996a087df6d06b2b5109b6825c720d4c8b168 (patch) | |
tree | 4a4595327fe85ddccc44070c1aa7241c924a7d48 /test/bun.js/transpiler.test.js | |
parent | fac1c49727ec76387ada0ad2e4bfa32385b4ceb1 (diff) | |
download | bun-565996a087df6d06b2b5109b6825c720d4c8b168.tar.gz bun-565996a087df6d06b2b5109b6825c720d4c8b168.tar.zst bun-565996a087df6d06b2b5109b6825c720d4c8b168.zip |
Support TypeScript `satisfies`
Credit: @magic-akari, almost identical diff in https://github.com/evanw/esbuild/pull/2509/files#diff-ccc0bde7223236d93490b727b272f15765a2674be12a4c310b83b9555bef8816
Diffstat (limited to 'test/bun.js/transpiler.test.js')
-rw-r--r-- | test/bun.js/transpiler.test.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/bun.js/transpiler.test.js b/test/bun.js/transpiler.test.js index 179097144..91803ef9b 100644 --- a/test/bun.js/transpiler.test.js +++ b/test/bun.js/transpiler.test.js @@ -105,6 +105,90 @@ describe("Bun.Transpiler", () => { it("export = {foo: 123}", () => { ts.expectPrinted_("export = {foo: 123}", "module.exports = { foo: 123 }"); }); + + it("satisfies", () => { + ts.expectPrinted_( + "const t1 = { a: 1 } satisfies I1;", + "const t1 = { a: 1 };\n" + ); + ts.expectPrinted_( + "const t2 = { a: 1, b: 1 } satisfies I1;", + "const t2 = { a: 1, b: 1 };\n" + ); + ts.expectPrinted_("const t3 = { } satisfies I1;", "const t3 = {};\n"); + ts.expectPrinted_( + "const t4: T1 = { a: 'a' } satisfies T1;", + 'const t4 = { a: "a" };\n' + ); + ts.expectPrinted_( + "const t5 = (m => m.substring(0)) satisfies T2;", + "const t5 = (m) => m.substring(0);\n" + ); + ts.expectPrinted_( + "const t6 = [1, 2] satisfies [number, number];", + "const t6 = [1, 2];\n" + ); + ts.expectPrinted_( + "let t7 = { a: 'test' } satisfies A;", + 'let t7 = { a: "test" };\n' + ); + ts.expectPrinted_( + "let t8 = { a: 'test', b: 'test' } satisfies A;", + 'let t8 = { a: "test", b: "test" };\n' + ); + ts.expectPrinted_( + "export default {} satisfies Foo;", + "export default {};\n" + ); + ts.expectPrinted_( + "export default { a: 1 } satisfies Foo;", + "export default { a: 1 };\n" + ); + ts.expectPrinted_( + "const p = { isEven: n => n % 2 === 0, isOdd: n => n % 2 === 1 } satisfies Predicates;", + "const p = { isEven: (n) => n % 2 === 0, isOdd: (n) => n % 2 === 1 };\n" + ); + ts.expectPrinted_( + "let obj: { f(s: string): void } & Record<string, unknown> = { f(s) { }, g(s) { } } satisfies { g(s: string): void } & Record<string, unknown>;", + "let obj = { f(s) {\n}, g(s) {\n} };\n" + ); + ts.expectPrinted_( + "const car = { start() { }, move(d) { }, stop() { } } satisfies Movable & Record<string, unknown>;", + "const car = { start() {\n}, move(d) {\n}, stop() {\n} };\n" + ); + ts.expectPrinted_( + "var v = undefined satisfies 1;", + "var v = undefined;\n" + ); + ts.expectPrinted_( + "const a = { x: 10 } satisfies Partial<Point2d>;", + "const a = { x: 10 };\n" + ); + ts.expectPrinted_( + 'const p = { a: 0, b: "hello", x: 8 } satisfies Partial<Record<Keys, unknown>>;', + 'const p = { a: 0, b: "hello", x: 8 };\n' + ); + ts.expectPrinted_( + 'const p = { a: 0, b: "hello", x: 8 } satisfies Record<Keys, unknown>;', + 'const p = { a: 0, b: "hello", x: 8 };\n' + ); + ts.expectPrinted_( + 'const x2 = { m: true, s: "false" } satisfies Facts;', + 'const x2 = { m: true, s: "false" };\n' + ); + ts.expectPrinted_( + "export const Palette = { white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, blue: { r: 0, g: 0, b: 255 }, } satisfies Record<string, Color>;", + "export const Palette = { white: { r: 255, g: 255, b: 255 }, black: { r: 0, g: 0, d: 0 }, blue: { r: 0, g: 0, b: 255 } };\n" + ); + ts.expectPrinted_( + 'const a: "baz" = "foo" satisfies "foo" | "bar";', + 'const a = "foo";\n' + ); + ts.expectPrinted_( + 'const b: { xyz: "baz" } = { xyz: "foo" } satisfies { xyz: "foo" | "bar" };', + 'const b = { xyz: "foo" };\n' + ); + }); }); describe("generated closures", () => { |