Fixed invalid number literal parsing (#473)
* Fixed invalid number literal parsing * Don't ignore period or E characters after octal numbers cherry-pick fix from acorn * Fix tests
This commit is contained in:
parent
406c3dabc0
commit
b98f463aa7
@ -564,30 +564,34 @@ export default class Tokenizer {
|
|||||||
|
|
||||||
readNumber(startsWithDot) {
|
readNumber(startsWithDot) {
|
||||||
const start = this.state.pos;
|
const start = this.state.pos;
|
||||||
const firstIsZero = this.input.charCodeAt(start) === 48; // '0'
|
let octal = this.input.charCodeAt(start) === 48; // '0'
|
||||||
let isFloat = false;
|
let isFloat = false;
|
||||||
|
|
||||||
if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
|
if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number");
|
||||||
|
if (octal && this.state.pos == start + 1) octal = false; // number === 0
|
||||||
|
|
||||||
let next = this.input.charCodeAt(this.state.pos);
|
let next = this.input.charCodeAt(this.state.pos);
|
||||||
if (next === 46) { // '.'
|
if (next === 46 && !octal) { // '.'
|
||||||
++this.state.pos;
|
++this.state.pos;
|
||||||
this.readInt(10);
|
this.readInt(10);
|
||||||
isFloat = true;
|
isFloat = true;
|
||||||
next = this.input.charCodeAt(this.state.pos);
|
next = this.input.charCodeAt(this.state.pos);
|
||||||
}
|
}
|
||||||
if (next === 69 || next === 101) { // 'eE'
|
|
||||||
|
if ((next === 69 || next === 101) && !octal) { // 'eE'
|
||||||
next = this.input.charCodeAt(++this.state.pos);
|
next = this.input.charCodeAt(++this.state.pos);
|
||||||
if (next === 43 || next === 45) ++this.state.pos; // '+-'
|
if (next === 43 || next === 45) ++this.state.pos; // '+-'
|
||||||
if (this.readInt(10) === null) this.raise(start, "Invalid number");
|
if (this.readInt(10) === null) this.raise(start, "Invalid number");
|
||||||
isFloat = true;
|
isFloat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.state.pos, "Identifier directly after number");
|
if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.state.pos, "Identifier directly after number");
|
||||||
|
|
||||||
const str = this.input.slice(start, this.state.pos);
|
const str = this.input.slice(start, this.state.pos);
|
||||||
let val;
|
let val;
|
||||||
if (isFloat) {
|
if (isFloat) {
|
||||||
val = parseFloat(str);
|
val = parseFloat(str);
|
||||||
} else if (!firstIsZero || str.length === 1) {
|
} else if (!octal || str.length === 1) {
|
||||||
val = parseInt(str, 10);
|
val = parseInt(str, 10);
|
||||||
} else if (this.state.strict) {
|
} else if (this.state.strict) {
|
||||||
this.raise(start, "Invalid number");
|
this.raise(start, "Invalid number");
|
||||||
|
|||||||
1
test/fixtures/core/uncategorised/554/actual.js
vendored
Normal file
1
test/fixtures/core/uncategorised/554/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var a = 0123.;
|
||||||
3
test/fixtures/core/uncategorised/554/options.json
vendored
Normal file
3
test/fixtures/core/uncategorised/554/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (1:13)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user