Skip to content
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Grammars:
- enh(cmake) support bracket comments [Hirse][]
- enh(java) add yield keyword to java [MBoegers][]
- enh(java) add permits keyword to java [MBoegers][]
- fix(javascript/typescript) correct identifier matching when using numbers [Lachlan Heywood][]

[Josh Goebel]: https://github.com/joshgoebel
[Josh Temple]: https://github.com/joshtemple
Expand All @@ -26,6 +27,7 @@ Grammars:
[Hirse]: https://github.com/Hirse
[The Flix Organisation]: https://github.com/flix
[MBoegers]: https://github.com/MBoegers
[Lachlan Heywood]: https://github.com/lachieh

## Version 11.6.0

Expand Down
4 changes: 4 additions & 0 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export default function(hljs) {
HTML_TEMPLATE,
CSS_TEMPLATE,
TEMPLATE_STRING,
// Skip numbers when they are part of a variable name
{ match: /\$\d+/ },
NUMBER,
// This is intentional:
// See https://github.com/highlightjs/highlight.js/issues/3288
Expand Down Expand Up @@ -453,6 +455,8 @@ export default function(hljs) {
CSS_TEMPLATE,
TEMPLATE_STRING,
COMMENT,
// Skip numbers when they are part of a variable name
{ match: /\$\d+/ },
NUMBER,
CLASS_REFERENCE,
{
Expand Down
21 changes: 21 additions & 0 deletions test/markup/javascript/numbers.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,24 @@ x0.<span class="hljs-property">e1</span>
0b1e1
0N
<span class="hljs-number">00</span>.

<span class="hljs-comment">// numbers in identifiers</span>
<span class="hljs-keyword">const</span> num = $1
<span class="hljs-keyword">const</span> num = $0n9
<span class="hljs-keyword">const</span> num = $abc012
<span class="hljs-keyword">const</span> num = $0x9
<span class="hljs-keyword">const</span> num = $0o0
<span class="hljs-keyword">const</span> num = $09
<span class="hljs-keyword">const</span> num = $9<span class="hljs-number">.09</span>
<span class="hljs-keyword">const</span> num = $a9
<span class="hljs-keyword">const</span> num = <span class="hljs-number">1</span>
<span class="hljs-keyword">const</span> num = 0n9
<span class="hljs-keyword">const</span> num = <span class="hljs-number">0x9</span>
<span class="hljs-keyword">const</span> num = <span class="hljs-number">0o0</span>
<span class="hljs-keyword">const</span> num = <span class="hljs-number">09</span>
<span class="hljs-keyword">const</span> num = <span class="hljs-number">9.09</span>
<span class="hljs-keyword">const</span> num = a9

<span class="hljs-comment">// numbers in identifiers in template strings</span>
cosnt string = <span class="hljs-string">`<span class="hljs-subst">${$0}</span>`</span>
cosnt string = <span class="hljs-string">`<span class="hljs-subst">${<span class="hljs-number">0</span>}</span>`</span>
21 changes: 21 additions & 0 deletions test/markup/javascript/numbers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,24 @@ x0.e1
0b1e1
0N
00.

// numbers in identifiers
const num = $1
const num = $0n9
const num = $abc012
const num = $0x9
const num = $0o0
const num = $09
const num = $9.09
const num = $a9
const num = 1
const num = 0n9
const num = 0x9
const num = 0o0
const num = 09
const num = 9.09
const num = a9

// numbers in identifiers in template strings
cosnt string = `${$0}`
cosnt string = `${0}`