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

Wrong grouping in optional chaining with --loader=ts #168

Closed
AngusFu opened this issue Jun 3, 2020 · 1 comment
Closed

Wrong grouping in optional chaining with --loader=ts #168

AngusFu opened this issue Jun 3, 2020 · 1 comment

Comments

@AngusFu
Copy link

AngusFu commented Jun 3, 2020

I get some code like

declare var el: HTMLElement | undefined;
const div = el?.querySelector<HTMLDivElement>('div');
const div2 = el?.querySelector('div');

which would be transformed to the following code by esbuild@0.4.3:

const div = (el == null ? void 0 : el.querySelector)("div");
const div2 = el == null ? void 0 : el.querySelector("div");

The script is

echo -e "
  declare var el: HTMLElement | undefined;
  const div = el?.querySelector<HTMLDivElement>('div');
  const div2 = el?.querySelector('div');
" | npx esbuild --target=es2019 --loader=ts

Note: the target es2019 can be changed to any one in es2015 es2016 es2017 es2018 es2019 es2020

image

However, the first statement const div = (el == null ? void 0 : el.querySelector)("div") would cause a Illegal invocation error in browsers.

Seems that the result is not consistent with the proposal, since there is NO grouping in el?.querySelector<HTMLDivElement>('div')).

Then I paste the same inputs to TypeScript Playground, the result seems to be correct:

image

Note: the target es2019 can be changed to any one in es2015 es2016 es2017 es2018 es2019 es2020
image

@AngusFu AngusFu changed the title Wrong grouping in optional chaining Wrong grouping in optional chaining with --loader=ts Jun 3, 2020
@evanw
Copy link
Owner

evanw commented Jun 3, 2020

Thanks for reporting this. This was an unintentional regression due to the work for #156. I will fix this soon.

@evanw evanw closed this as completed in eabfb60 Jun 3, 2020
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

2 participants