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

[Bug]: Pure annotations are incorrectly modified to wrong scope #14797

Closed
1 task
hyrious opened this issue Jul 26, 2022 · 2 comments 路 Fixed by #16104
Closed
1 task

[Bug]: Pure annotations are incorrectly modified to wrong scope #14797

hyrious opened this issue Jul 26, 2022 · 2 comments 路 Fixed by #16104
Labels
area: comments i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator

Comments

@hyrious
Copy link

hyrious commented Jul 26, 2022

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

(/* @__PURE__ */ f()).g()

REPL Link

Configuration file name

No response

Configuration

None

Current and expected behavior

Currently babel strips the parentheses of (/* @__PURE__ */ f()), causing the whole expression f().g() be marked as pure.

/* @__PURE__ */
f().g();

// expect: same as input

Environment

System:
  OS: macOS 12.5
Binaries:
  Node: 18.6.0 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 8.15.0 - /usr/local/bin/npm
npmPackages:
  @babel/core: ^7.7.4 => 7.18.9
  @babel/plugin-proposal-class-properties: ^7.7.4 => 7.18.6
  @babel/plugin-proposal-object-rest-spread: ^7.7.4 => 7.18.9
  @babel/plugin-transform-modules-commonjs: ^7.15.0 => 7.18.6
  @babel/preset-env: ^7.7.4 => 7.18.9
  @babel/preset-react: ^7.7.4 => 7.18.6
  @babel/preset-typescript: ^7.7.4 => 7.18.6
  babel-loader: ^8.0.6 => 8.2.5
  webpack: ^5.74.0 => 5.74.0

Possible solution

No response

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @hyrious! 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 Aug 2, 2022

As a workaround, you can enable the createParenthesizedExpressions parser option:

{
  // babel config
  plugins: [...],
  parserOpts: { createParenthesizedExpressions: true }
}

It will generate the ParenthesizedExpressions AST node where the pure annotation comment can be attached.

@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 17, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: comments i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants