Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2942 #2947

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/bundler/bundle_v2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7397,7 +7397,20 @@ const LinkerContext = struct {
var clone = std.ArrayList(G.Decl).initCapacity(allocator, before.decls.len + after.decls.len) catch unreachable;
clone.appendSliceAssumeCapacity(before.decls.slice());
clone.appendSliceAssumeCapacity(after.decls.slice());
before.decls.update(clone);
// we must clone instead of overwrite in-place incase the same S.Local is used across threads
// https://github.com/oven-sh/bun/issues/2942
stmts.items[end - 1] = Stmt.allocate(
allocator,
S.Local,
S.Local{
.decls = BabyList(G.Decl).fromList(clone),
.is_export = before.is_export,
.was_commonjs_export = before.was_commonjs_export,
.was_ts_import_equals = before.was_ts_import_equals,
.kind = before.kind,
},
stmts.items[end - 1].loc,
);
}
continue;
}
Expand Down
140 changes: 140 additions & 0 deletions test/bundler/bundler_regressions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import assert from "assert";
import dedent from "dedent";
import { itBundled, testForFile } from "./expectBundled";
var { describe, test, expect } = testForFile(import.meta.path);

describe("bundler", () => {
itBundled("regression/MergeAdjacentDecl#2942", {
files: {
"/shared.js": `
// Current version.
export var VERSION = '1.13.6';

// Establish the root object, \`window\` (\`self\`) in the browser, \`global\`
// on the server, or \`this\` in some virtual machines. We use \`self\`
// instead of \`window\` for \`WebWorker\` support.
export var root = (typeof self == 'object' && self.self === self && self) ||
(typeof global == 'object' && global.global === global && global) ||
Function('return this')() ||
{};

// Save bytes in the minified (but not gzipped) version:
export var ArrayProto = Array.prototype, ObjProto = Object.prototype;
export var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;

// Create quick reference variables for speed access to core prototypes.
export var push = ArrayProto.push,
slice = ArrayProto.slice,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;

// Modern feature detection.
export var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
supportsDataView = typeof DataView !== 'undefined';

// All **ECMAScript 5+** native function implementations that we hope to use
// are declared here.
export var nativeIsArray = Array.isArray,
nativeKeys = Object.keys,
nativeCreate = Object.create,
nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;

// Create references to these builtin functions because we override them.
export var _isNaN = isNaN,
_isFinite = isFinite;

// Keys in IE < 9 that won't be iterated by \`for key in ...\` and thus missed.
export var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
export var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];

// The largest integer that can be represented exactly.
export var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;

`,
// This was a race condition, so we want to add a lot of files to maximize the chances of hitting it
"/a.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/b.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/c.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/d.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/e.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/g.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/h.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/i.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/j.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/k.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/l.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/m.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/n.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_1.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/a_2.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_3.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/a_4.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_5.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_6.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_7.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_8.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_9.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_10.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_11.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_12.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/a_13.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_1.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/b_2.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_3.js": "import * as ABC from './shared.js';; console.log(ABC);",
"/b_4.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_5.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_6.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_7.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_8.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_9.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_10.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_11.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_12.js": "import * as ABC from './shared.js'; console.log(ABC);",
"/b_13.js": "import * as ABC from './shared.js'; console.log(ABC);",
},
minifySyntax: true,

entryPoints: [
"/a.js",
"/b.js",
"/c.js",
"/d.js",
"/e.js",
"/g.js",
"/h.js",
"/i.js",
"/j.js",
"/k.js",
"/l.js",
"/m.js",
"/n.js",
"/a_1.js",
"/a_2.js",
"/a_3.js",
"/a_4.js",
"/a_5.js",
"/a_6.js",
"/a_7.js",
"/a_8.js",
"/a_9.js",
"/a_10.js",
"/a_11.js",
"/a_12.js",
"/a_13.js",
"/b_1.js",
"/b_2.js",
"/b_3.js",
"/b_4.js",
"/b_5.js",
"/b_6.js",
"/b_7.js",
"/b_8.js",
"/b_9.js",
"/b_10.js",
"/b_11.js",
"/b_12.js",
"/b_13.js",
],
});
});