Skip to content

Commit

Permalink
Updated parcelRequire.register to be minifiable (#9216)
Browse files Browse the repository at this point in the history
  • Loading branch information
alshdavid committed Sep 26, 2023
1 parent 482ef2f commit c182930
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ describe('scope hoisting', function () {
'utf8',
);
assert.strictEqual(
contents.match(/parcelRequire.register\(/g).length,
contents.match(/parcelRegister\(/g).length,
2 /* once for parent asset, once for child wrapped asset */,
);

Expand Down
9 changes: 5 additions & 4 deletions packages/packagers/js/src/ScopeHoistingPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export class ScopeHoistingPackager {
sourceMap?.offsetLines(1, 1);
lineCount++;

code = `parcelRequire.register(${JSON.stringify(
code = `parcelRegister(${JSON.stringify(
this.bundleGraph.getAssetPublicId(asset),
)}, function(module, exports) {
${code}
Expand Down Expand Up @@ -1273,9 +1273,10 @@ ${code}
}
} else {
// Otherwise, get the current parcelRequire global.
res += `var parcelRequire = $parcel$global[${JSON.stringify(
this.parcelRequireName,
)}];\n`;
const escaped = JSON.stringify(this.parcelRequireName);
res += `var parcelRequire = $parcel$global[${escaped}];\n`;
lines++;
res += `var parcelRegister = parcelRequire.register;\n`;
lines++;
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/packagers/js/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var $parcel$modules = {};
var $parcel$inits = {};
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
if (parcelRequire == null) {
parcelRequire = function(id) {
if (id in $parcel$modules) {
Expand All @@ -30,6 +31,8 @@ if (parcelRequire == null) {
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
}
var parcelRegister = parcelRequire.register;
`;

export const fnExpr = (
Expand Down

0 comments on commit c182930

Please sign in to comment.