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

ES2019 Feature: Numeric Separator #1989

Open
3 tasks
JosephPecoraro opened this issue Aug 15, 2019 · 2 comments
Open
3 tasks

ES2019 Feature: Numeric Separator #1989

JosephPecoraro opened this issue Aug 15, 2019 · 2 comments

Comments

@JosephPecoraro
Copy link
Contributor

JosephPecoraro commented Aug 15, 2019

Syntax:

New NumericLiteral syntax that allows for an _ separator in numbers.

let fee = 123_00;   // $123 (12300 cents, apparently)
let fee = 12_300;   // $12,300 (woah, that fee!)
let value = 1_000_000_000;

Grammar changes are to NumericLiteral, allowing the _ separator to show up in numbers.

+NumericLiteralSeparator::
+    _

 DecimalIntegerLiteral::
     0
-    NonZeroDigit DecimalDigits?
+    NonZeroDigit
+    NonZeroDigit NumericLiteralSeparator? DecimalDigits

 DecimalDigits::
     DecimalDigit
-    DecimalDigits DecimalDigit
+    DecimalDigits NumericLiteralSeparator? DecimalDigit

 BinaryDigits::
     BinaryDigit
-    BinaryDigits BinaryDigit
+    BinaryDigits NumericLiteralSeparator? BinaryDigit

 OctalDigits::
     OctalDigit
-    OctalDigits OctalDigit
+    OctalDigits NumericLiteralSeparator? OctalDigit

 HexDigits::
     HexDigit
-    HexDigits HexDigit
+    HexDigits NumericLiteralSeparator? HexDigit

Spec:

TC39:
https://github.com/tc39/proposal-numeric-separator
https://tc39.es/proposal-numeric-separator/

ESTree:
No node changes proposed, numeric Literal node value will just be the value

Additional considerations

Remaining Tasks:

  • Update Scanner (scanner.ts changes for _ numeric separator)
  • Provide Unit Tests and Coverage
  • Update test262 (~test262.git#2ee3864136) / test262-stream (~1.3.0)

Test Cases

Valid:

1_2_3_4
1_000_000
10000_00
1_000000_0_0_0
1_2.3_4e5_6
1_1.2_2
1_1e2_2
0x1_0
0o1_0
0b1_0

Invalid:

1__1
1.2__2
1e2__2
1_
1_.2
1_e2
1._2
1.2_
1e_2
1e2_
0x_1
0x1__1
0o_1
0o1__1
0b_1
0b1__1
001_2   // Leading Zero (Legacy Hex) does not allow
09_1    // Leading Zero does not allow
yury-s pushed a commit to yury-s/webkit-http that referenced this issue Aug 16, 2019
…eatures

https://bugs.webkit.org/show_bug.cgi?id=200796

Reviewed by Ross Kirsling.

Source/WebInspectorUI:

Use a fork of Esprima to support modern JavaScript language features
while going through the process to upstream support:

  ES2018 Feature: Async Iteration (for-await-of)
  jquery/esprima#1990

  ES2019 Feature: Numeric Separator
  jquery/esprima#1989

  ES2019 Feature: Optional catch binding
  jquery/esprima#1953

  ES2020 Feature: BigInt
  jquery/esprima#1988

ESTree compatible AST changes are summarized as:

  - CatchClause `param` property is now nullable
  - ForOfStatement now has a boolean `await` property
  - Literal can be a `"bigint"` type (works if the environment has BigInt or not)

The pretty printer only needed to have additional handling for `for-await-of`.

* UserInterface/External/Esprima/esprima.js:
New version. Typescript output expects a modern JavaScript environment
instead of just ES6.

* Tools/Formatting/index.html:
Update the formatting tool for easier use in case of errors.

* UserInterface/Models/ScriptSyntaxTree.js:
(WI.ScriptSyntaxTree.prototype._createInternalSyntaxTree):

* UserInterface/Test/TestHarness.js:
(TestHarness.prototype.passOrFail):
Convenience for pass/fail with the same message based on a condition.

* UserInterface/Workers/Formatter/EsprimaFormatter.js:
(EsprimaFormatter.prototype._handleTokenAtNode):
Ensure a space after `await` in `for await` syntax.

LayoutTests:

* inspector/formatting/resources/javascript-tests/classes-expected.js:
* inspector/formatting/resources/javascript-tests/classes.js:
* inspector/formatting/resources/javascript-tests/for-statements-expected.js:
* inspector/formatting/resources/javascript-tests/for-statements.js:
* inspector/formatting/resources/javascript-tests/generators-expected.js:
* inspector/formatting/resources/javascript-tests/generators.js:
* inspector/formatting/resources/javascript-tests/numbers-expected.js: Added.
* inspector/formatting/resources/javascript-tests/numbers.js: Added.
* inspector/formatting/resources/javascript-tests/try-catch-finally-statements-expected.js:
* inspector/formatting/resources/javascript-tests/try-catch-finally-statements.js:
* inspector/formatting/resources/javascript-tests/unary-binary-expressions-expected.js:
* inspector/formatting/resources/javascript-tests/unary-binary-expressions.js:
Test formatting of new JavaScript language features.

* inspector/formatting/formatting-css-expected.txt:
* inspector/formatting/formatting-javascript-expected.txt:
* inspector/formatting/formatting-javascript.html:
* inspector/formatting/resources/utilities.js:
(TestPage.registerInitializer.async.runFormattingTest):
(TestPage.registerInitializer.window.addFormattingTests):
(TestPage.registerInitializer):
Cleaner output and better handling for debugging failures.

* inspector/model/parse-script-syntax-tree.html:
Test new AST permutations.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@248760 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@ljqx
Copy link
Contributor

ljqx commented Dec 6, 2020

This is actually ES2021 feature instead of ES2019. See https://github.com/tc39/proposals/blob/master/finished-proposals.md

@jogibear9988
Copy link

I've created a pull for this in my fork: node-projects/esprima-next#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants