This repository was archived by the owner on May 19, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 254
This repository was archived by the owner on May 19, 2018. It is now read-only.
Numeric Separator: Stage 1 #538
Copy link
Copy link
Closed
Description
Advance Numeric separators proposal to Stage 1 slides (Sam Goto) (@samuelgoto)
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)
ESTree/Parsing
- looks like we need to figure out how to change the tokenizer
tt.num - Start reading a number at
getTokenFromCode:babylon/src/tokenizer/index.js
Lines 456 to 464 in 9709c8d
case 48: // '0' const next = this.input.charCodeAt(this.state.pos + 1); if (next === 120 || next === 88) return this.readRadixNumber(16); // '0x', '0X' - hex number if (next === 111 || next === 79) return this.readRadixNumber(8); // '0o', '0O' - octal number if (next === 98 || next === 66) return this.readRadixNumber(2); // '0b', '0B' - binary number // Anything else beginning with a digit is an integer, octal // number, or float. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9 return this.readNumber(false); - calls
readNumber, orreadRadixNumberorreadInt - ultimately need the
valueto include the_or to just keep the regular value + track where the_are?
Transform
- if the AST is simple (just the value/raw) would be trivial to remove (regex replace
_with '')?
ESTree: I guess there's nothing to add to the AST spec since this changes the value of the number itself?
Reactions are currently unavailable