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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional chaining is not working with dynamic property name imported from another file #8186

Closed
ivanStraltsou opened this issue Jun 2, 2022 · 0 comments 路 Fixed by #8187
Closed

Comments

@ivanStraltsou
Copy link

馃悰 bug report

2.6.0 regression (works fine in 2.4.0); ??

result code is not using imports correctly, so optionally chained property is used from global context and not imported module, which was never defined (Uncaught ReferenceError: XXX is not defined)

馃帥 Configuration (.babelrc, package.json, cli command)

src/constants.js

export const RANDOM_REASON = 'random';

src/index.js

import { RANDOM_REASON } from "./constants";

fetch('something').then((data) => {
    console.log(data.reasons?.[RANDOM_REASON]);
});

parcel build index.js --no-optimize

(() => {
const $995a17657784c9af$export$19a494d0e5fb84be = "random";

fetch("something").then((data)=>{
    console.log(data.reasons?.[RANDOM_REASON]); // <--- RANDOM_REASON never defined
});

})();

馃 Expected Behavior

v 2.4.0 output:

(() => {
const $995a17657784c9af$export$19a494d0e5fb84be = 'random';

fetch('something').then((data)=>{
    console.log(data.reasons?.[$995a17657784c9af$export$19a494d0e5fb84be]);
});

})();

馃拋 Possible Solution

guess its related to a recent fix (#8121) associated with:

#7937
#8102

馃敠 Context

馃捇 Code Sample

馃實 Your Environment

full example (branch: issue-2.6.0-chaining): https://github.com/ivanStraltsou/parcel2-issue/blob/issue-2.6.0-chaining/src/index.js

Software Version(s)
Parcel 2.6.0
Node 17.9.0
npm/Yarn npm 8.5.5
Operating System Win 10 Pro 19043.1586
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