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

Bundled code is not working. Optional chaining property is renamed when using the same name as export #7937

Closed
ivanStraltsou opened this issue Apr 11, 2022 · 2 comments

Comments

@ivanStraltsou
Copy link

ivanStraltsou commented Apr 11, 2022

馃悰 bug report

bundler renames object properties used via optional chaining and having the same names as exports

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

default getting started template from home page

repo: https://github.com/ivanStraltsou/parcel2-issue

parcel build ./src/index.html --no-optimize

src/index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
    <title>My First Parcel App</title>
    <script type="module" src="index.js"></script>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

src/index.js

import { isAValue, isBValue } from "./lib";

console.log(isAValue({ isAValue: true }));
console.log(isBValue({ isBValue: true }));

src/lib.js

// broken
export const isAValue = (payload) => payload?.isAValue === true;

// broken
export const isAAValue = (payload) => payload?.isAValue === true;

// works
export const isAValue = (payload) => payload.isAValue === true;

// works
export const isBValue = (payload) => payload?.bValue === true; 

馃 Expected Behavior

result bundle produces valid code, object properties are not renamed

馃槸 Current Behavior

result bundle contains:

const hash$export$hash = (payload)=>payload?.hash$export$hash === true

//---
// broken
const $2e312cb5ec191554$export$33f07d46bc452aa4 = (payload)=>payload?.$2e312cb5ec191554$export$33f07d46bc452aa4 === true
;
const $2e312cb5ec191554$export$3100cf595abe3c86 = (payload)=>payload?.bValue === true
;


console.log($2e312cb5ec191554$export$33f07d46bc452aa4({
    isAValue: true
}));
console.log($2e312cb5ec191554$export$3100cf595abe3c86({
    isBValue: true
}));
;

So this value is always undefined and logic is corrupted

馃敠 Context

  • production code is broken, hard to capture this type of issues
  • using obj?.['property'] style is converted correctly
  • using obj.property is converted correctly
  • dev server mode is working fine as long as cache is empty
  • dev server mode is broken as well when running with cache and bundle first

馃捇 Code Sample

repo: https://github.com/ivanStraltsou/parcel2-issue

parcel build ./src/index.html --no-optimize

馃實 Your Environment

Software Version(s)
Parcel 2.4.1
Node 17.9.0 (same on 14.15.4)
npm/Yarn npm 8.5.5 (same on npm 6.14.10)
Operating System Win 10 Pro 19043.1586
@ivanStraltsou
Copy link
Author

seems to be fixed in 2.6.0

@ivanStraltsou
Copy link
Author

ivanStraltsou commented Jun 1, 2022

duplicated by #8102, fixed in #8121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant