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

Updated parcelRequire.register to be minifiable #9216

Merged
merged 5 commits into from
Sep 26, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
marcins marked this conversation as resolved.
Show resolved Hide resolved
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