From 73537de184ed1f34c81838dc239d13fbf2f3983a Mon Sep 17 00:00:00 2001 From: Grigory Date: Thu, 10 Oct 2024 03:13:42 +0500 Subject: [PATCH 1/3] docs(bundler): add missing `codetabs` closing tag (#14443) --- docs/bundler/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/bundler/index.md b/docs/bundler/index.md index 0a5d40b6221a6..21bb749f04335 100644 --- a/docs/bundler/index.md +++ b/docs/bundler/index.md @@ -1108,6 +1108,8 @@ await Bun.build({ $ bun build ./index.tsx --outdir ./out --banner "\"use client\";" ``` +{% /codetabs %} + ### `footer` A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg. From def454d859e04220fcc11b178b0816c25d5c8e7b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Wed, 9 Oct 2024 18:20:19 -0700 Subject: [PATCH 2/3] Bump --- LATEST | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LATEST b/LATEST index fae04a2a19450..321b7ce4c0f41 100644 --- a/LATEST +++ b/LATEST @@ -1 +1 @@ -1.1.29 \ No newline at end of file +1.1.30 \ No newline at end of file diff --git a/package.json b/package.json index da6cb1394fb4c..38cb4c6cdfb69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "bun", - "version": "1.1.30", + "version": "1.1.31", "workspaces": [ "./packages/bun-types" ], From ff476313a8b62480b4acece512cfa57f807a9e59 Mon Sep 17 00:00:00 2001 From: snwy Date: Wed, 9 Oct 2024 19:14:22 -0700 Subject: [PATCH 3/3] 'let' statements before using statements are now properly converted into 'var' statements (#14260) --- src/js_parser.zig | 23 ++++++++++++++++------- test/bundler/bundler_edgecase.test.ts | 3 ++- test/bundler/bundler_npm.test.ts | 14 +++++++------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/js_parser.zig b/src/js_parser.zig index 57fb249dd4a98..4c9ce810bd6f3 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -19430,6 +19430,7 @@ fn NewParser_( } } + data.kind = kind; try stmts.append(stmt.*); if (p.options.features.react_fast_refresh and p.current_scope == p.module_scope) { @@ -22155,29 +22156,37 @@ fn NewParser_( switch (stmt.data) { .s_empty, .s_comment, .s_directive, .s_debugger, .s_type_script => continue, .s_local => |local| { - if (!local.is_export and local.kind == .k_const and !local.was_commonjs_export) { + if (!local.is_export and !local.was_commonjs_export) { var decls: []Decl = local.decls.slice(); var end: usize = 0; + var any_decl_in_const_values = local.kind == .k_const; for (decls) |decl| { if (decl.binding.data == .b_identifier) { - const symbol = p.symbols.items[decl.binding.data.b_identifier.ref.innerIndex()]; - if (p.const_values.contains(decl.binding.data.b_identifier.ref) and symbol.use_count_estimate == 0) { - continue; + if (p.const_values.contains(decl.binding.data.b_identifier.ref)) { + any_decl_in_const_values = true; + const symbol = p.symbols.items[decl.binding.data.b_identifier.ref.innerIndex()]; + if (symbol.use_count_estimate == 0) { + // Skip declarations that are constants with zero usage + continue; + } } } decls[end] = decl; end += 1; } local.decls.len = @as(u32, @truncate(end)); - if (end == 0) { - stmt.* = stmt.*.toEmpty(); + if (any_decl_in_const_values) { + if (end == 0) { + stmt.* = stmt.*.toEmpty(); + } + continue; } - continue; } }, else => {}, } + // Break after processing relevant statements break; } } diff --git a/test/bundler/bundler_edgecase.test.ts b/test/bundler/bundler_edgecase.test.ts index 6755ba65d1c66..fc0116cf23af8 100644 --- a/test/bundler/bundler_edgecase.test.ts +++ b/test/bundler/bundler_edgecase.test.ts @@ -1121,7 +1121,7 @@ describe("bundler", () => { snapshotSourceMap: { "entry.js.map": { files: ["../node_modules/react/index.js", "../entry.js"], - mappingsExactMatch: "uYACA,WAAW,IAAQ,EAAE,ICDrB,eACA,QAAQ,IAAI,CAAK", + mappingsExactMatch: "qYACA,WAAW,IAAQ,EAAE,ICDrB,eACA,QAAQ,IAAI,CAAK", }, }, }); @@ -1883,6 +1883,7 @@ describe("bundler", () => { target: "browser", run: { stdout: `123` }, }); + itBundled("edgecase/UninitializedVariablesMoved", { files: { "/entry.ts": ` diff --git a/test/bundler/bundler_npm.test.ts b/test/bundler/bundler_npm.test.ts index b765e58598072..73d4b1556ef70 100644 --- a/test/bundler/bundler_npm.test.ts +++ b/test/bundler/bundler_npm.test.ts @@ -57,17 +57,17 @@ describe("bundler", () => { "../entry.tsx", ], mappings: [ - ["react.development.js:524:'getContextName'", "1:5428:Y1"], - ["react.development.js:2495:'actScopeDepth'", "1:26053:GJ++"], - ["react.development.js:696:''Component'", '1:7490:\'Component "%s"'], - ["entry.tsx:6:'\"Content-Type\"'", '1:221655:"Content-Type"'], - ["entry.tsx:11:''", "1:221911:void"], - ["entry.tsx:23:'await'", "1:222013:await"], + ["react.development.js:524:'getContextName'", "1:5426:Y1"], + ["react.development.js:2495:'actScopeDepth'", "1:26051:GJ++"], + ["react.development.js:696:''Component'", '1:7488:\'Component "%s"'], + ["entry.tsx:6:'\"Content-Type\"'", '1:221651:"Content-Type"'], + ["entry.tsx:11:''", "1:221905:void"], + ["entry.tsx:23:'await'", "1:222005:await"], ], }, }, expectExactFilesize: { - "out/entry.js": 222283, + "out/entry.js": 222273, }, run: { stdout: "

Hello World

This is an example.

",