Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
source-c authored Oct 10, 2024
2 parents b1c675a + ff47631 commit 1e8794b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LATEST
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.29
1.1.30
2 changes: 2 additions & 0 deletions docs/bundler/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.1.30",
"version": "1.1.31",
"workspaces": [
"./packages/bun-types"
],
Expand Down
23 changes: 16 additions & 7 deletions src/js_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/bundler/bundler_edgecase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
});
Expand Down Expand Up @@ -1883,6 +1883,7 @@ describe("bundler", () => {
target: "browser",
run: { stdout: `123` },
});

itBundled("edgecase/UninitializedVariablesMoved", {
files: {
"/entry.ts": `
Expand Down
14 changes: 7 additions & 7 deletions test/bundler/bundler_npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:'<html>'", "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:'<html>'", "1:221905:void"],
["entry.tsx:23:'await'", "1:222005:await"],
],
},
},
expectExactFilesize: {
"out/entry.js": 222283,
"out/entry.js": 222273,
},
run: {
stdout: "<!DOCTYPE html><html><body><h1>Hello World</h1><p>This is an example.</p></body></html>",
Expand Down

0 comments on commit 1e8794b

Please sign in to comment.