ES2019 Feature: Numeric Separator
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
Description
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
- Supported in Chrome, Safari. (Firefox?)
- Supported in Node, jsc
- May have interaction with
BigInt(https://github.com/jquery/esprima/issues/1988)
Remaining Tasks:
- Update Scanner (
scanner.tschanges 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in scanner.ts, where numeric literal scanning must be updated for the separator rules shown in the issue. Add unit tests covering the listed valid and invalid cases, then update test262 and test262-stream as requested. Done means separators parse only in permitted positions, with the expected errors for invalid forms and coverage for the syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100