Skip to content

Commit

Permalink
JS: Added support for numeric separators (#1895)
Browse files Browse the repository at this point in the history
This adds support for JavaScript's new numeric separators. E.g. `123_456`.
  • Loading branch information
RunDevelopment authored May 18, 2019
1 parent f0a1066 commit 6068bf1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
],
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ Prism.languages.javascript = Prism.languages.extend('clike', {
lookbehind: true
},
],
'number': /\b(?:(?:0[xX][\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+)n?|\d+n|NaN|Infinity)\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,
'number': /\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,
'operator': /-[-=]?|\+[+=]?|!=?=?|<<?=?|>>?>?=?|=(?:==?|>)?|&[&=]?|\|[|=]?|\*\*?=?|\/=?|~|\^=?|%=?|\?|\.{3}/
Expand Down
21 changes: 20 additions & 1 deletion tests/languages/javascript/number_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
0o571
0xbabe
0xBABE

NaN
Infinity

123n
0x123n

1_000_000_000_000
1_000_000.220_720
0b0101_0110_0011_1000
0o12_34_56
0x40_76_38_6A_73
4_642_473_943_484_686_707n
0.000_001
1e10_000

----------------------------------------------------

[
Expand All @@ -27,7 +38,15 @@ Infinity
["number", "NaN"],
["number", "Infinity"],
["number", "123n"],
["number", "0x123n"]
["number", "0x123n"],
["number", "1_000_000_000_000"],
["number", "1_000_000.220_720"],
["number", "0b0101_0110_0011_1000"],
["number", "0o12_34_56"],
["number", "0x40_76_38_6A_73"],
["number", "4_642_473_943_484_686_707n"],
["number", "0.000_001"],
["number", "1e10_000"]
]

----------------------------------------------------
Expand Down

0 comments on commit 6068bf1

Please sign in to comment.