fixes #2224: various issues related to number lexing
This was... embarrassing. I'm just really glad we didn't cut a release before this got fixed.
This commit is contained in:
parent
ddd6e9a48b
commit
6a88ce7d1e
|
@ -112,13 +112,13 @@
|
|||
var binaryLiteral, lexedLength, match, number, octalLiteral;
|
||||
if (!(match = NUMBER.exec(this.chunk))) return 0;
|
||||
number = match[0];
|
||||
if (/E/.test(number)) {
|
||||
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
||||
} else if (/[BOX]/.test(number)) {
|
||||
if (/^0[BOX]/.test(number)) {
|
||||
this.error("radix prefix '" + number + "' must be lowercase");
|
||||
} else if (/^0[89]/.test(number)) {
|
||||
} else if (/E/.test(number) && !/^0x/.test(number)) {
|
||||
this.error("exponential notation '" + number + "' must be indicated with a lowercase 'e'");
|
||||
} else if (/^0\d*[89]/.test(number)) {
|
||||
this.error("decimal literal '" + number + "' must not be prefixed with '0'");
|
||||
} else if (/^0[0-7]/.test(number)) {
|
||||
} else if (/^0\d+/.test(number)) {
|
||||
this.error("octal literal '" + number + "' must be prefixed with '0o'");
|
||||
}
|
||||
lexedLength = number.length;
|
||||
|
|
|
@ -133,13 +133,13 @@ exports.Lexer = class Lexer
|
|||
numberToken: ->
|
||||
return 0 unless match = NUMBER.exec @chunk
|
||||
number = match[0]
|
||||
if /E/.test number
|
||||
@error "exponential notation '#{number}' must be indicated with a lowercase 'e'"
|
||||
else if /[BOX]/.test number
|
||||
if /^0[BOX]/.test number
|
||||
@error "radix prefix '#{number}' must be lowercase"
|
||||
else if /^0[89]/.test number
|
||||
else if /E/.test(number) and not /^0x/.test number
|
||||
@error "exponential notation '#{number}' must be indicated with a lowercase 'e'"
|
||||
else if /^0\d*[89]/.test number
|
||||
@error "decimal literal '#{number}' must not be prefixed with '0'"
|
||||
else if /^0[0-7]/.test number
|
||||
else if /^0\d+/.test number
|
||||
@error "octal literal '#{number}' must be prefixed with '0o'"
|
||||
lexedLength = number.length
|
||||
if octalLiteral = /0o([0-7]+)/.exec number
|
||||
|
|
|
@ -69,3 +69,8 @@ test "#2060: Disallow uppercase radix prefixes and exponential notation", ->
|
|||
program = "0#{char}0"
|
||||
doesNotThrow -> CoffeeScript.compile program, bare: yes
|
||||
throws -> CoffeeScript.compile program.toUpperCase(), bare: yes
|
||||
|
||||
test "#2224: hex literals with 0b or B or E", ->
|
||||
eq 176, 0x0b0
|
||||
eq 177, 0x0B1
|
||||
eq 225, 0xE1
|
||||
|
|
Loading…
Reference in New Issue