Implement Numeric Separator#6143
Conversation
| { | ||
| name: "Strings parsed as number do not support numeric separators for decimal literals", | ||
| body: function () { | ||
| assert.areEqual(NaN, Number('12_34'), "NaN === Number('12_34')"); |
There was a problem hiding this comment.
Thanks for noticing. There were tab characters on this line.
| if (*psz == '_' && isNumericSeparatorEnabled && pszSave < psz && psz[-1] == '0' && FHexDigit(psz[1], &unused)) | ||
| { | ||
| psz++; | ||
| goto LSkipZeroes; |
There was a problem hiding this comment.
Oh, this file and these gotos 😆
| #define DEFAULT_CONFIG_ES6RegExSticky (true) | ||
| #define DEFAULT_CONFIG_ES2018RegExDotAll (true) | ||
| #define DEFAULT_CONFIG_ESBigInt (false) | ||
| #define DEFAULT_CONFIG_ESNumericSeparator (true) |
There was a problem hiding this comment.
Thanks for defaulting this to true. : )
At some point I think we'll need to comb through some of the old always-on feature flags and clean them up.
There was a problem hiding this comment.
Yeah. We've made passes before and took out some of the ancient flags for things which are never getting disabled. Worth looking at again.
|
Why did they pick underscores for this :-/ I like the C++ style better honestly int m = 36'000'000;Maybe there was a compatibility reason that couldn't be done but would have been much more pleasant to look at IMO. Then again I'm biased because with the exception of C I kind of hate the Also there's no good reason for |
|
@fatcerberus I've grown to like the C++ separators as well. Oh well! Multiple consecutive underscores are actually disallowed, so that helps a little : ) @boingoing What kind of error message does this generate if there are multiple consecutive underscores? Some engines actually say that multiples are allowed; we might want to do that as well (but it can be a follow-up, of course). |
|
@zenparsing Like most of our error messages, the one emitted when we find multiple consecutive underscores is a generic one. It says |
733a8d6 to
82cfbc4
Compare
Add support for numeric separator characters in numeric literals. These are just syntactic sugar which improve readability of numeric constants in source. They desugar completely out of the numbers when parsed. Numeric digits in the constant may have a single '_' character between them. The constant may not begin or end with a '_' character and there may not be multiple numeric separators in a row. All numeric constants are supported. Includes decimal, hex, octal and binary numeric constants. ```javascript 1234 === 1_2_3_4; // true 12.34e56 === 1_2.3_4e5_6; // true 0xff === 0xf_f; // true 0o17 === 0o1_7; // true 0b11 === 0b1_1; // true ``` Numeric Separator proposal is in stage 3 and implemented by JSC and V8. See proposal: https://github.com/tc39/proposal-numeric-separator Fixes: chakra-core#6060
82cfbc4 to
71adb7d
Compare
Merge pull request #6143 from boingoing:numericseparator Implement Numeric Separator Add support for numeric separator characters in numeric literals. These are just syntactic sugar which improve readability of numeric constants in source. They desugar completely out of the numbers when parsed. Numeric digits in the constant may have a single `'_'` character between them. The constant may not begin or end with a `'_'` character and there may not be multiple numeric separators in a row. All numeric constants are supported. Includes decimal, hex, octal and binary numeric constants. Legacy octal integer constants do not support numeric separators. Numeric values parsed from string functions (like ToNumber or parseInt) also do not support numeric separators. ```javascript 1234 === 1_2_3_4; // true 12.34e56 === 1_2.3_4e5_6; // true 0xff === 0xf_f; // true 0o17 === 0o1_7; // true 0b11 === 0b1_1; // true ``` Numeric Separator proposal is in stage 3 and implemented by JSC and V8. See proposal: https://github.com/tc39/proposal-numeric-separator Fixes: #6060
Implement Numeric Separator
Add support for numeric separator characters in numeric literals. These are just syntactic sugar which improve readability of numeric constants in source. They desugar completely out of the numbers when parsed.
Numeric digits in the constant may have a single
'_'character between them. The constant may not begin or end with a'_'character and there may not be multiple numeric separators in a row. All numeric constants are supported. Includes decimal, hex, octal and binary numeric constants.Legacy octal integer constants do not support numeric separators. Numeric values parsed from string functions (like ToNumber or parseInt) also do not support numeric separators.
Numeric Separator proposal is in stage 3 and implemented by JSC and V8. See proposal:
https://github.com/tc39/proposal-numeric-separator
Fixes: #6060