From 43de33afc7fcc4cab25f578566e225ba9e4d4258 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 7 Jun 2022 22:32:46 -0700 Subject: 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> --- integration/bunjs-only-snippets/transpiler.test.js | 110 ++++++++++++++++++--- 1 file changed, 97 insertions(+), 13 deletions(-) (limited to 'integration/bunjs-only-snippets/transpiler.test.js') 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 =
{123}
+export var hiWithKey =
{123}
+export var hiWithRef =
{123}
+ +export var ComponentThatChecksDefaultProps = +export var ComponentThatChecksDefaultPropsAndHasChildren = my child +export var ComponentThatHasSpreadCausesDeopt = + +`.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`"); -- cgit v1.2.3