Skip to content

Numeric Separator: Stage 1 #5783

@hzoo

Description

@hzoo

Original issue submitted by @hzoo in babel/babylon#538

Advance Numeric separators proposal to Stage 1 slides (Sam Goto) (@samuelgoto)
cc @ajklein and @domenic

Info

Proposed at TC39 Meeting: May 2017
Slides at the meeting: https://docs.google.com/presentation/d/1hcajTemZB2Ruo4EePOyFiva1xpyv5ukKk4aQ0B83dUA/edit#slide=id.p
Proposal Repo: https://github.com/samuelgoto/proposal-numeric-separator

Example

var thousands = 10_000; // Instead of 10000.
var credit_card_number = 1234_5678_9012_3456; // Instead of 123456789012345.
var social_security_number = 999_99_9999; // Instead of 999999999.
var pi = 3.14_15; // Instead of 3.1415
var bytes = 0b11010010_01101001_10010100_10010010; // Instead of 0b11010010011010011001010010010010.
var 0xCAFE_F00D; // Instead of 0XCAFEF00D.

Basic Rules

  • to use the _ character.
  • only one consecutive underscore is allowed.
  • only between digits (not allowed at the beginning or end of literals)

Parser

Done in babel/babylon#541 by @rwaldron

Plugin: numericSeparator

0b0_1_1;
{
  "type": "NumericLiteral",
  "extra": {
    "rawValue": 3,
    "raw": "0b0_1_1"
  },
  "value": 3
}

Transform

  • if the AST is simple (just the value/raw) would be trivial to remove

https://github.com/babel/babel/wiki/Adding-a-new-Proposal-to-Babel

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRSpec: Numeric SeparatoroutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions