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

...$export$getBaseURL is not defined #5816

Closed
mischnic opened this issue Feb 10, 2021 · 0 comments · Fixed by #5817
Closed

...$export$getBaseURL is not defined #5816

mischnic opened this issue Feb 10, 2021 · 0 comments · Fixed by #5817

Comments

@mischnic
Copy link
Member

mischnic commented Feb 10, 2021

🐛 bug report

An error is thrown with scope-hoisting and strict mode.

cc @surma

🤔 Expected Behavior

Works

😯 Current Behavior

Uncaught ReferenceError: $10da859f8926f997eca867931986be87$export$getBaseURL is not defined
function $abc$exec() {
  $abc$exports = {};
  $abc$var$bundleURL = null;
  $abc$export$getBundleURL = $abc$var$getBundleURLCached;
  $abc$exports.getBundleURL = $abc$export$getBundleURL;
  $abc$export$getBaseURL = $abc$var$getBaseURL; // <---
  $abc$export$getOrigin = $abc$var$getOrigin;
  $abc$exports.getOrigin = $abc$export$getOrigin;
}

$abc$export$getBaseURL is never declared (and indeed unused), so that assignment should just be omitted.

💁 Possible Solution

The problem is probably somewhere in here:

AssignmentExpression(node, state, ancestors) {
if (isIdentifier(node.left)) {
let res = maybeReplaceIdentifier(node.left, ancestors);
if (isIdentifier(res) || isMemberExpression(res)) {
node.left = res;
}
return;
}
if (!isMemberExpression(node.left)) {
return;
}
let {
left: {object, property, computed},
right,
} = node;
if (
!(
isIdentifier(object) &&
((isIdentifier(property) && !computed) || isStringLiteral(property))
)
) {
return;
}
// Rename references to exported symbols to the exported name.
let exp = exportedSymbols.get(object.name);
if (exp) {
object.name = exp[0].local;
}
let asset = exportsMap.get(object.name);
if (!asset) {
return;
}
if (!needsExportsIdentifier(object.name)) {
return REMOVE;
}
if (isIdentifier(right) && !needsDeclaration(right.name)) {
return REMOVE;
}
},

💻 Code Sample

(type="module"is just so that it runs in strict mode, this isn't specific to ESM)

<script type="module" src="index.js"></script>
if (typeof process !== "undefined" && process.env.TARGET_DOMAIN) {
} else {
	let worker = new Worker("./worker.js");
}

// worker.js
console.log("worker");

Smaller reproduction:

if (Date.now() > 0) {
	console.log(require("./bundle-url").getBundleURL());
}

// bundle-url.js
function getBundleURL() {
  return "bundle";
}

function getBaseURL(url) {
  return "base";
}

exports.getBundleURL = getBundleURL;
exports.getBaseURL = getBaseURL;

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.579
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant