Skip to content

Commit bdcb2c7

Browse files
Revert to more complicated lexing of numbers, as the Number constructor can't handle BigInts or numbers with numeric separators (#5269)
1 parent 2635109 commit bdcb2c7

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/coffeescript/lexer.js

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,16 @@ exports.Lexer = class Lexer
272272
when /^0\d+/.test number
273273
@error "octal literal '#{number}' must be prefixed with '0o'", length: lexedLength
274274

275-
parsedValue = Number number
275+
base = switch number.charAt 1
276+
when 'b' then 2
277+
when 'o' then 8
278+
when 'x' then 16
279+
else null
280+
281+
parsedValue = if base? then parseInt(number[2..], base) else parseFloat(number)
276282
tokenData = {parsedValue}
277283

278-
tag = if Number.isFinite(parsedValue) then 'NUMBER' else 'INFINITY'
284+
tag = if parsedValue is Infinity then 'INFINITY' else 'NUMBER'
279285
if tag is 'INFINITY'
280286
tokenData.original = number
281287
@token tag, number,

0 commit comments

Comments
 (0)