Skip to content

Commit

Permalink
Don't ignore period or E characters after octal numbers
Browse files Browse the repository at this point in the history
Closes #466
  • Loading branch information
marijnh committed Sep 11, 2016
1 parent d437659 commit b14cb8b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,15 @@ pp.readRadixNumber = function(radix) {
pp.readNumber = function(startsWithDot) {
let start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48
if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number")
if (octal && this.pos == start + 1) octal = false
let next = this.input.charCodeAt(this.pos)
if (next === 46) { // '.'
if (next === 46 && !octal) { // '.'
++this.pos
this.readInt(10)
isFloat = true
next = this.input.charCodeAt(this.pos)
}
if (next === 69 || next === 101) { // 'eE'
if ((next === 69 || next === 101) && !octal) { // 'eE'
next = this.input.charCodeAt(++this.pos)
if (next === 43 || next === 45) ++this.pos // '+-'
if (this.readInt(10) === null) this.raise(start, "Invalid number")
Expand Down
38 changes: 38 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29129,3 +29129,41 @@ testFail("/[a-z]/y", "Invalid regular expression flag (1:1)");
testFail("/[a-z]/s", "Invalid regular expression flag (1:1)");

testFail("function(){}", "Unexpected token (1:8)");

test("0123. in/foo/i", {
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"left": {
"type": "BinaryExpression",
"left": {
"type": "MemberExpression",
"object": {
"type": "Literal",
"value": 83,
"raw": "0123"
},
"property": {
"type": "Identifier",
"name": "in"
},
"computed": false
},
"operator": "/",
"right": {
"type": "Identifier",
"name": "foo"
}
},
"operator": "/",
"right": {
"type": "Identifier",
"name": "i"
}
}
}
]
})

0 comments on commit b14cb8b

Please sign in to comment.