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

Parcel 2 does assignment to undeclared variable when importing bundle text a certain way #6167

Closed
danieltroger opened this issue Apr 22, 2021 · 0 comments · Fixed by #6230
Closed

Comments

@danieltroger
Copy link
Contributor

🐛 bug report

Output with --no-optimize:

(function () {
  $18334e130dafe2913541baf4ea7ba145$exports = "<!-- this is sum html-->\n  <h1>Hi I'm HTML</h1>\n";
  console.log($18334e130dafe2913541baf4ea7ba145$exports);
})();

Optimized output:

$18334e130dafe2913541baf4ea7ba145$exports="<h1>Hi I'm HTML</h1>",console.log($18334e130dafe2913541baf4ea7ba145$exports);

As you can see this will throw an error in strict mode and therefore is a bug. It happens when doing this: export * as template from "bundle-text:./html.html";

🎛 Configuration (.babelrc, package.json, cli command)

Please see the attached .zip file and don't forget to fix #5755

🤔 Expected Behavior

console.log("<h1>Hi I'm HTML</h1>");

([the function that takes an argument and returns the argument.default or the argument] wrapped around the string is also acceptable, I think it's called interopDefault)

😯 Current Behavior

Parcel gets confused and forgets to declare the variable with const.

💁 Possible Solution

Put const before $18334e130dafe2913541baf4ea7ba145$exports

🔦 Context

Coworker wanted to show me how to import things without writing

import template_html from "bundle-text:./html.html
export const template = template_html

I didn't believe him it would work and I was kind of right. (I mean it does but not in strict mode and terser doesn't mangle the variable name)

💻 Code Sample

parcel-doesnt-declare-its-variables.zip

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.643+3baf990a
Node v15.14.0
npm/Yarn npm v7.7.6
Operating System macOS 10.15.7 (19H524)
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.

2 participants