From 4f5aa438d6799f24c7a112ca8dc0910466944f2e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 4 Mar 2022 17:51:22 -0800 Subject: [JS Parser] Support JSX prop punning --- integration/bunjs-only-snippets/atob.test.js | 3 +- integration/bunjs-only-snippets/transpiler.test.js | 65 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) (limited to 'integration/bunjs-only-snippets') diff --git a/integration/bunjs-only-snippets/atob.test.js b/integration/bunjs-only-snippets/atob.test.js index c146aa855..4945829e1 100644 --- a/integration/bunjs-only-snippets/atob.test.js +++ b/integration/bunjs-only-snippets/atob.test.js @@ -1,4 +1,4 @@ -import { expect, describe, it } from "bun:test"; +import { expect, it } from "bun:test"; function expectInvalidCharacters(val) { try { @@ -49,7 +49,6 @@ it("atob", () => { expectInvalidCharacters("=="); expectInvalidCharacters("==="); expectInvalidCharacters("===="); - expectInvalidCharacters("====="); }); diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index 2859c2b02..5553c1cc6 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -47,6 +47,71 @@ describe("Bun.Transpiler", () => { `; + it("JSX", () => { + var bun = new Bun.Transpiler({ + loader: "jsx", + }); + expect(bun.transformSync("export var foo =
")).toBe( + `export var foo = jsx("div", { + foo: true +}, undefined, false, undefined, this); +` + ); + expect(bun.transformSync("export var foo =
")).toBe( + `export var foo = jsx("div", { + foo +}, undefined, false, undefined, this); +` + ); + expect(bun.transformSync("export var foo =
")).toBe( + `export var foo = jsx("div", { + ...foo +}, undefined, false, undefined, this); +` + ); + expect(bun.transformSync("export var hi =
")).toBe( + `export var hi = jsx("div", { + foo +}, undefined, false, undefined, this); +` + ); + try { + bun.transformSync("export var hi =
"); + throw new Error("Expected error"); + } catch (e) { + expect(e.errors[0].message.includes('Expected ">"')).toBe(true); + } + + expect( + bun.transformSync("export var hi =
") + ).toBe( + `export var hi = jsx("div", { + Foo, + children: jsx(Foo, {}, undefined, false, undefined, this) +}, undefined, false, undefined, this); +` + ); + expect( + bun.transformSync("export var hi =
") + ).toBe( + `export var hi = jsx("div", { + Foo, + children: jsx(Foo, {}, undefined, false, undefined, this) +}, undefined, false, undefined, this); +` + ); + + expect(bun.transformSync("export var hi =
{123}}
").trim()).toBe( + `export var hi = jsx("div", { + children: [ + 123, + "}" + ] +}, undefined, true, undefined, this); + `.trim() + ); + }); + it("require with a dynamic non-string expression", () => { var nodeTranspiler = new Bun.Transpiler({ platform: "node" }); expect(nodeTranspiler.transformSync("require('hi' + bar)")).toBe( -- cgit v1.2.3