diff options
author | 2022-06-07 22:32:46 -0700 | |
---|---|---|
committer | 2022-06-07 22:32:46 -0700 | |
commit | 43de33afc7fcc4cab25f578566e225ba9e4d4258 (patch) | |
tree | 141676095981741c3a5740093fee79ed12d4edcd /integration/bunjs-only-snippets/transpiler.test.js | |
parent | 958fc3d4f5ba2a1fb5b5e1e2b9fe3a4500dbefc6 (diff) | |
download | bun-43de33afc7fcc4cab25f578566e225ba9e4d4258.tar.gz bun-43de33afc7fcc4cab25f578566e225ba9e4d4258.tar.zst bun-43de33afc7fcc4cab25f578566e225ba9e4d4258.zip |
Web Streams API (#176)
* [bun.js] `WritableStream`, `ReadableStream`, `TransformStream`, `WritableStreamDefaultController`, `ReadableStreamDefaultController` & more
* Implement `Blob.stream()`
* Update streams.test.js
* Fix sourcemaps crash
* [TextEncoder] 3x faster in hot loops
* reading almost works
* start to implement native streams
* Implement `Blob.stream()`
* Implement `Bun.file(pathOrFd).stream()`
* Add an extra function
* [fs.readFile] Improve performance
* make jsc bindings a little easier to work with
* fix segfault
* faster async/await + readablestream optimizations
* WebKit updates
* More WebKit updates
* Add releaseWEakrefs binding
* `bun:jsc`
* More streams
* Update streams.test.js
* Update Makefile
* Update mimalloc
* Update WebKit
* Create bun-jsc.test.js
* Faster ReadableStream
* Fix off by one & exceptions
* Handle empty files/blobs
* Update streams.test.js
* Move streams to it's own file
* temp
* impl #1
* take two
* good enough for now
* Implement `readableStreamToArray`, `readableStreamToArrayBuffer`, `concatArrayBuffers`
* jsxOptimizationInlining
* Fix crash
* Add `jsxOptimizationInline` to Bun.Transpiler
* Update Transpiler types
* Update js_ast.zig
* Automatically choose production mode when NODE_ENV="production"
* Update cli.zig
* [jsx] Handle defaultProps when inlining
* Update transpiler.test.js
* uncomment some tests
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'integration/bunjs-only-snippets/transpiler.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/transpiler.test.js | 110 |
1 files changed, 97 insertions, 13 deletions
diff --git a/integration/bunjs-only-snippets/transpiler.test.js b/integration/bunjs-only-snippets/transpiler.test.js index dd0ffdc8f..30fc2afde 100644 --- a/integration/bunjs-only-snippets/transpiler.test.js +++ b/integration/bunjs-only-snippets/transpiler.test.js @@ -291,6 +291,89 @@ describe("Bun.Transpiler", () => { ); }); + describe("inline JSX", () => { + const inliner = new Bun.Transpiler({ + loader: "tsx", + define: { + "process.env.NODE_ENV": JSON.stringify("production"), + user_undefined: "undefined", + }, + platform: "bun", + jsxOptimizationInline: true, + treeShaking: false, + }); + + it("inlines static JSX into object literals", () => { + expect( + inliner + .transformSync( + ` +export var hi = <div>{123}</div> +export var hiWithKey = <div key="hey">{123}</div> +export var hiWithRef = <div ref={foo}>{123}</div> + +export var ComponentThatChecksDefaultProps = <Hello></Hello> +export var ComponentThatChecksDefaultPropsAndHasChildren = <Hello>my child</Hello> +export var ComponentThatHasSpreadCausesDeopt = <Hello {...spread} /> + +`.trim() + ) + .trim() + ).toBe( + `var $$typeof = Symbol.for("react.element"); +export var hi = { + $$typeof, + type: "div", + key: null, + ref: null, + props: { + children: 123 + }, + _owner: null +}; +export var hiWithKey = { + $$typeof, + type: "div", + key: "hey", + ref: null, + props: { + children: 123 + }, + _owner: null +}; +export var hiWithRef = jsx("div", { + ref: foo, + children: 123 +}); +export var ComponentThatChecksDefaultProps = { + $$typeof, + type: Hello, + key: null, + ref: null, + props: Hello.defaultProps || {}, + _owner: null +}; +export var ComponentThatChecksDefaultPropsAndHasChildren = { + $$typeof, + type: Hello, + key: null, + ref: null, + props: !Hello.defaultProps ? { + children: "my child" + } : { + ...Hello.defaultProps, + children: "my child" + }, + _owner: null +}; +export var ComponentThatHasSpreadCausesDeopt = jsx(Hello, { + ...spread +}); +`.trim() + ); + }); + }); + it("require with a dynamic non-string expression", () => { var nodeTranspiler = new Bun.Transpiler({ platform: "node" }); expect(nodeTranspiler.transformSync("require('hi' + bar)")).toBe( @@ -1355,21 +1438,22 @@ class Foo { expectPrinted("'a' != '\\x62'", "true"); expectPrinted("'a' != 'abc'", "true"); - // TODO: string simplification - // expectPrinted("'a' + 'b'", '"ab"'); - // expectPrinted("'a' + 'bc'", '"abc"'); - // expectPrinted("'ab' + 'c'", '"abc"'); - // expectPrinted("x + 'a' + 'b'", 'x + "ab"'); - // expectPrinted("x + 'a' + 'bc'", 'x + "abc"'); - // expectPrinted("x + 'ab' + 'c'", 'x + "abc"'); - // expectPrinted("'a' + 1", '"a" + 1;'); - // expectPrinted("x * 'a' + 'b'", 'x * "a" + "b"'); - - // TODO: string simplification - // expectPrinted("'string' + `template`", "`stringtemplate`"); + expectPrinted("'a' + 'b'", '"ab"'); + expectPrinted("'a' + 'bc'", '"abc"'); + expectPrinted("'ab' + 'c'", '"abc"'); + expectPrinted("x + 'a' + 'b'", 'x + "ab"'); + expectPrinted("x + 'a' + 'bc'", 'x + "abc"'); + expectPrinted("x + 'ab' + 'c'", 'x + "abc"'); + expectPrinted("'a' + 1", '"a" + 1'); + expectPrinted("x * 'a' + 'b'", 'x * "a" + "b"'); + + expectPrinted("'string' + `template`", `"stringtemplate"`); + + expectPrinted("`template` + 'string'", "`templatestring`"); + + // TODO: string template simplification // expectPrinted("'string' + `a${foo}b`", "`stringa${foo}b`"); // expectPrinted("'string' + tag`template`", '"string" + tag`template`;'); - // expectPrinted("`template` + 'string'", "`templatestring`"); // expectPrinted("`a${foo}b` + 'string'", "`a${foo}bstring`"); // expectPrinted("tag`template` + 'string'", 'tag`template` + "string"'); // expectPrinted("`template` + `a${foo}b`", "`templatea${foo}b`"); |