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

TypeScript non-null assertion operator not stripped off with deep optional chaining #12386

Closed
1 task
maxdavidson opened this issue Nov 23, 2020 · 3 comments · Fixed by #12391
Closed
1 task
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse Spec: Optional Chaining

Comments

@maxdavidson
Copy link

Bug Report

  • I would like to work on a fix!

I noticed a really strange regression in in @babel/core 7.12.7. When used with optional chaining, the TypeScript postfix "!" operator (non-null assertion) sometimes won't get stripped off, resulting in a syntax error.

Input:

const a = 1;
const b = () => a?.b?.c!.d

Output with @babel/core@7.12.3:

const a = 1;

const b = () => {
  var _a$b;

  return a === null || a === void 0 ? void 0 : (_a$b = a.b) === null || _a$b === void 0 ? void 0 : _a$b.c.d;
};

Output with @babel/core@7.12.7:

const a = 1;

const b = () => {
  var _a$b;

  return a === null || a === void 0 ? void 0 : (_a$b = a.b) === null || _a$b === void 0 ? void 0 : _a$b.c!.d;
};

Notice the _a$b.c!.d at the end

Plugins used:

  • @babel/preset-typescript@7.12.7
  • @babel/plugin-proposal-optional-chaining@7.12.7 (via preset-env)
@babel-bot
Copy link
Collaborator

Hey @maxdavidson! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@JLHwung
Copy link
Contributor

JLHwung commented Nov 23, 2020

Another minimal test case:

a => a?.b!?.c

This is likely a regression introduced at #12302.

@nicolo-ribaudo
Copy link
Member

Fixed in 7.12.9

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Feb 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: traverse Spec: Optional Chaining
Projects
None yet
4 participants