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

[hotfix] Use same targets for fields as for private methods #11633

Merged

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues? https://twitter.com/IAmTrySound/status/1265639257571540993
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT
babel.transformSync("class A { x }", {
  configFile: false,
  presets: [
    ["@babel/env", {
      targets: { node: 12 },
      shippedProposals: true,
    }],
  ],
});

The above code doesn't work with Babel 7.10.0 because

  1. Class fields are supported, so the plugin is not enabled
  2. Private methods are not supported, so the plugin is enabled and we use create-class-features
  3. When transforming a class with the create-class-features, we check if all the eeded features are enabled. We don't support transforming private methods without transforming private fields, so we throw an error

I'm working on removing the dependency between the two plugins, but this quick and dirty hack makes preset-env work until I open a better PR. I would like to merge this one for the next patch release (today?).

cc @TrySound

@babel-bot
Copy link
Collaborator

babel-bot commented May 27, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/23004/

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 0c6350d:

Sandbox Source
ecstatic-elbakyan-xiyow Configuration
musing-field-r3ilg Configuration

@nicolo-ribaudo nicolo-ribaudo merged commit 32bd530 into babel:master May 27, 2020
@nicolo-ribaudo nicolo-ribaudo deleted the env-fields-targets-methods branch May 27, 2020 20:43
@TrySound
Copy link
Contributor

Yay, thanks!

@TrySound
Copy link
Contributor

TrySound commented May 28, 2020

@nicolo-ribaudo I just got the same problem with numeric separators in node 13

@nicolo-ribaudo
Copy link
Member Author

That is unexpected 🤔

The problem fixed by this PR is that the private methods and class fields plugins depend on each other, and on Node.js 12 only one of them was enabled.

Numeric separators don't have such hidden dependency 🤔

@TrySound
Copy link
Contributor

TrySound commented May 28, 2020

This is weird, I got syntax error similar to class properties. And only in node 13 but not 12

@nicolo-ribaudo
Copy link
Member Author

What is the exact error?

@TrySound
Copy link
Contributor

[!] Error: Identifier directly after number points to object with numeric separator.

This is very weird, syntax plugin is included. Here's debug output

@babel/preset-env: `DEBUG` option

Using targets:
{
  "node": "13.12"
}

Using modules transform: false

Using plugins:
  syntax-numeric-separator { "node":"13.12" }
  proposal-class-properties { "node":"13.12" }
  proposal-private-methods { "node":"13.12" }
  proposal-nullish-coalescing-operator { "node":"13.12" }
  proposal-optional-chaining { "node":"13.12" }
  syntax-json-strings { "node":"13.12" }
  syntax-optional-catch-binding { "node":"13.12" }
  syntax-async-generators { "node":"13.12" }
  syntax-object-rest-spread { "node":"13.12" }
  syntax-dynamic-import { "node":"13.12" }
  syntax-top-level-await { "node":"13.12" }

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.

By the way same problem with 14.3. Though I cannot reproduce it in isolated example.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented May 28, 2020

Could you share your lockfile in a gist?

Also, if you can put Error.stackTraceLimit = Infinity somewhere (for example, in your Babel config, but it could be anywhere) the full stack trace would help.

@TrySound
Copy link
Contributor

Oh, I get it. Sorry, it's rollup syntax error 🤦

@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 Aug 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: preset-env PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields Spec: Private Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants