question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ECMAScript 2020 features?

See original GitHub issue

@babel/plugin-proposal-nullish-coalescing-operator and @babel/plugin-proposal-optional-chaining were just added to @babel/preset-env with the release of 7.8.0 — should they also make an appearance here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nicolo-ribaudocommented, Feb 10, 2020

Class fields are stage 3, and shipping in browsers, which is a more important milestone for Babel imo than the stage.

preset-env has the shippedProposals option, for proposals which are not part of the specification yet but are already shipped in at least one browser/node. We should probably add class-fields to that option.

@developit Looking at your plugin, I think that you misinterpreted the reason for using the optimized [[Set]] in the plugin. Object.defineProperty is unrelated to this.bar = 2 in the constructor: it’s needed when there is a setter on the prototype of the class (almost always coming from a superclass or a subclass, but could also come from Object.prototype or from the class itself) because the setter shouldn’t be triggered. This isn’t statically analyzable, because almost always the base and derived classes are in two different files.

Also, the descriptor you pass to defineProperty must have the enumerable: true, configurable: true, writable: true properties. If you replicate this descriptor a bunch of times (for different properties), then it’s longer than using the helper.

I don’t think that it’s possible to make a spec-compliant version of the plugin smaller than the current one, and if someone isn’t concerned with spec compliancy in the [[Set]] vs [[Define]] case they can already enable loose mode, which produces this output:

class A extends B {
  x = 2;
}

// ->

class A extends B {
  constructor(...args) {
    super(...args);
    this.x = 2;
  }
}
1reaction
ljharbcommented, Feb 10, 2020

Optional chaining and nullish coalescing are standard / stage 4.

Class fields are stage 3, and shipping in browsers, which is a more important milestone for Babel imo than the stage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Latest Features Added to JavaScript in ECMAScript 2020
The Latest Features Added to JavaScript in ECMAScript 2020 · Optional Chaining · Nullish Coalescing · Private Fields · Static Fields · Top...
Read more >
JavaScript: What's New in ECMAScript 2020 - Auth0
Learn the new features introduced by ECMAScript 2020 in JavaScript.
Read more >
JavaScript: Guide to New ECMAScript 2020 Features
JavaScript: Guide to New ECMAScript 2020 Features · GlobalThis · Nullish coalescing operator · Optional chaining operator · Dynamic import · Import.
Read more >
ECMAScript 2020 biggest new features - Arek Nawo
Newsletter · Thanks! · ECMAScript 2020 biggest new features · BigInt · Dynamic imports · Nullish coalescing operator · Optional chaining operator.
Read more >
ECMAScript 2020 spec for JavaScript approved - InfoWorld
The latest standard for JavaScript, ECMAScript 2020 introduces new features for module loading, precision integers, and strings.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found