Comparing version 2.5.9 to 2.5.10
{ | ||
"name": "jshint", | ||
"version": "2.5.9", | ||
"version": "2.5.10", | ||
"homepage": "http://jshint.com/", | ||
@@ -5,0 +5,0 @@ "description": "Static analysis tool for JavaScript", |
140
src/lex.js
@@ -678,2 +678,5 @@ /* | ||
var bad; | ||
var isAllowedDigit = isDecimalDigit; | ||
var base = 10; | ||
var isLegacy = false; | ||
@@ -688,2 +691,6 @@ function isDecimalDigit(str) { | ||
function isBinaryDigit(str) { | ||
return (/^[01]$/).test(str); | ||
} | ||
function isHexDigit(str) { | ||
@@ -712,71 +719,54 @@ return (/^[0-9a-fA-F]$/).test(str); | ||
if (char === "x" || char === "X") { | ||
isAllowedDigit = isHexDigit; | ||
base = 16; | ||
index += 1; | ||
value += char; | ||
} | ||
while (index < length) { | ||
char = this.peek(index); | ||
if (!isHexDigit(char)) { | ||
break; | ||
} | ||
value += char; | ||
index += 1; | ||
} | ||
// Base-8 numbers. | ||
if (char === "o" || char === "O") { | ||
isAllowedDigit = isOctalDigit; | ||
base = 8; | ||
if (value.length <= 2) { // 0x | ||
return { | ||
type: Token.NumericLiteral, | ||
value: value, | ||
isMalformed: true | ||
}; | ||
if (!state.option.esnext) { | ||
this.trigger("warning", { | ||
code: "W119", | ||
line: this.line, | ||
character: this.char, | ||
data: [ "Octal integer literal" ] | ||
}); | ||
} | ||
if (index < length) { | ||
char = this.peek(index); | ||
if (isIdentifierStart(char)) { | ||
return null; | ||
} | ||
index += 1; | ||
value += char; | ||
} | ||
// Base-2 numbers. | ||
if (char === "b" || char === "B") { | ||
isAllowedDigit = isBinaryDigit; | ||
base = 2; | ||
if (!state.option.esnext) { | ||
this.trigger("warning", { | ||
code: "W119", | ||
line: this.line, | ||
character: this.char, | ||
data: [ "Binary integer literal" ] | ||
}); | ||
} | ||
return { | ||
type: Token.NumericLiteral, | ||
value: value, | ||
base: 16, | ||
isMalformed: false | ||
}; | ||
index += 1; | ||
value += char; | ||
} | ||
// Base-8 numbers. | ||
// Legacy base-8 numbers. | ||
if (isOctalDigit(char)) { | ||
isAllowedDigit = isOctalDigit; | ||
base = 8; | ||
isLegacy = true; | ||
bad = false; | ||
index += 1; | ||
value += char; | ||
bad = false; | ||
while (index < length) { | ||
char = this.peek(index); | ||
// Numbers like '019' (note the 9) are not valid octals | ||
// but we still parse them and mark as malformed. | ||
if (isDecimalDigit(char)) { | ||
bad = true; | ||
} else if (!isOctalDigit(char)) { | ||
break; | ||
} | ||
value += char; | ||
index += 1; | ||
} | ||
if (index < length) { | ||
char = this.peek(index); | ||
if (isIdentifierStart(char)) { | ||
return null; | ||
} | ||
} | ||
return { | ||
type: Token.NumericLiteral, | ||
value: value, | ||
base: 8, | ||
isMalformed: false | ||
}; | ||
} | ||
@@ -787,3 +777,3 @@ | ||
if (isDecimalDigit(char)) { | ||
if (!isOctalDigit(char) && isDecimalDigit(char)) { | ||
index += 1; | ||
@@ -796,3 +786,8 @@ value += char; | ||
char = this.peek(index); | ||
if (!isDecimalDigit(char)) { | ||
if (isLegacy && isDecimalDigit(char)) { | ||
// Numbers like '019' (note the 9) are not valid octals | ||
// but we still parse them and mark as malformed. | ||
bad = true; | ||
} else if (!isAllowedDigit(char)) { | ||
break; | ||
@@ -803,2 +798,27 @@ } | ||
} | ||
if (isAllowedDigit !== isDecimalDigit) { | ||
if (!isLegacy && value.length <= 2) { // 0x | ||
return { | ||
type: Token.NumericLiteral, | ||
value: value, | ||
isMalformed: true | ||
}; | ||
} | ||
if (index < length) { | ||
char = this.peek(index); | ||
if (isIdentifierStart(char)) { | ||
return null; | ||
} | ||
} | ||
return { | ||
type: Token.NumericLiteral, | ||
value: value, | ||
base: base, | ||
isLegacy: isLegacy, | ||
isMalformed: false | ||
}; | ||
} | ||
} | ||
@@ -862,3 +882,3 @@ | ||
value: value, | ||
base: 10, | ||
base: base, | ||
isMalformed: !isFinite(value) | ||
@@ -1672,3 +1692,3 @@ }; | ||
}, checks, function () { | ||
return state.directive["use strict"] && token.base === 8; | ||
return state.directive["use strict"] && token.base === 8 && token.isLegacy; | ||
}); | ||
@@ -1675,0 +1695,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1771066
30910