Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 6a88ce7d1e7da533a457cc8026358442bd3821a5 1 parent ddd6e9a
@michaelficarra michaelficarra authored
View
10 lib/coffee-script/lexer.js
@@ -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;
View
10 src/lexer.coffee
@@ -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
View
5 test/numbers.coffee
@@ -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

2 comments on commit 6a88ce7

@satyr
Collaborator

glad we didn't cut a release before this got fixed

We did.

$ bin/coffee -v
CoffeeScript version 1.1.3

$ bin/coffee -bce '0x0b0'
0;
@michaelficarra
Collaborator

Ah, right. I was referring to the upcoming 1.3.0 (see #2135). It should have been "another" or "a new". This'll be getting in right before the upcoming release instead of right after it, which is way more desirable.

Please sign in to comment.
Something went wrong with that request. Please try again.