Skip to content

Commit a940a77

Browse files
author
Alexander Pánek
committed
Pass through octal and binary literals as-is
See coffeescript6/discuss#45
1 parent c3f5b8d commit a940a77

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/lexer.coffee

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ exports.Lexer = class Lexer
191191
# Be careful not to interfere with ranges-in-progress.
192192
numberToken: ->
193193
return 0 unless match = NUMBER.exec @chunk
194+
194195
number = match[0]
195196
lexedLength = number.length
197+
196198
if /^0[BOX]/.test number
197199
@error "radix prefix in '#{number}' must be lowercase", offset: 1
198200
else if /E/.test(number) and not /^0x/.test number
@@ -202,14 +204,12 @@ exports.Lexer = class Lexer
202204
@error "decimal literal '#{number}' must not be prefixed with '0'", length: lexedLength
203205
else if /^0\d+/.test number
204206
@error "octal literal '#{number}' must be prefixed with '0o'", length: lexedLength
205-
if octalLiteral = /^0o([0-7]+)/.exec number
206-
numberValue = parseInt(octalLiteral[1], 8)
207-
number = "0x#{numberValue.toString 16}"
208-
else if binaryLiteral = /^0b([01]+)/.exec number
209-
numberValue = parseInt(binaryLiteral[1], 2)
210-
number = "0x#{numberValue.toString 16}"
211-
else
207+
208+
numberValue = number
209+
210+
unless /^(0o[0-7]+)/.test(number) or /^(0b[01]+)/.test(number)
212211
numberValue = parseFloat(number)
212+
213213
tag = if numberValue is Infinity then 'INFINITY' else 'NUMBER'
214214
@token tag, number, 0, lexedLength
215215
lexedLength

0 commit comments

Comments
 (0)