|
@@ -130,22 +130,12 @@ define([
|
|
|
i2 >= 48 && i2 <= 57; // 0-9
|
|
i2 >= 48 && i2 <= 57; // 0-9
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Token = {
|
|
|
|
|
- Identifier: "Identifier",
|
|
|
|
|
- NumericLiteral: "NumericLiteral",
|
|
|
|
|
- StringLiteral: "StringLiteral",
|
|
|
|
|
- Punctuator: "Punctuator"
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
function Lexer(expression) {
|
|
function Lexer(expression) {
|
|
|
this.input = expression;
|
|
this.input = expression;
|
|
|
this.char = 1;
|
|
this.char = 1;
|
|
|
this.from = 1;
|
|
this.from = 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Lexer.Token = Token;
|
|
|
|
|
-
|
|
|
|
|
Lexer.prototype = {
|
|
Lexer.prototype = {
|
|
|
|
|
|
|
|
peek: function (i) {
|
|
peek: function (i) {
|
|
@@ -344,7 +334,7 @@ define([
|
|
|
|
|
|
|
|
switch (id) {
|
|
switch (id) {
|
|
|
default:
|
|
default:
|
|
|
- type = Token.Identifier;
|
|
|
|
|
|
|
+ type = "identifier";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -415,7 +405,7 @@ define([
|
|
|
|
|
|
|
|
if (value.length <= 2) { // 0x
|
|
if (value.length <= 2) { // 0x
|
|
|
return {
|
|
return {
|
|
|
- type: Token.NumericLiteral,
|
|
|
|
|
|
|
+ type: 'number',
|
|
|
value: value,
|
|
value: value,
|
|
|
isMalformed: true
|
|
isMalformed: true
|
|
|
};
|
|
};
|
|
@@ -429,7 +419,7 @@ define([
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- type: Token.NumericLiteral,
|
|
|
|
|
|
|
+ type: 'number',
|
|
|
value: value,
|
|
value: value,
|
|
|
base: 16,
|
|
base: 16,
|
|
|
isMalformed: false
|
|
isMalformed: false
|
|
@@ -465,7 +455,7 @@ define([
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- type: Token.NumericLiteral,
|
|
|
|
|
|
|
+ type: 'number',
|
|
|
value: value,
|
|
value: value,
|
|
|
base: 8,
|
|
base: 8,
|
|
|
isMalformed: false
|
|
isMalformed: false
|
|
@@ -545,7 +535,7 @@ define([
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
- type: Token.NumericLiteral,
|
|
|
|
|
|
|
+ type: 'number',
|
|
|
value: value,
|
|
value: value,
|
|
|
base: 10,
|
|
base: 10,
|
|
|
isMalformed: !isFinite(value)
|
|
isMalformed: !isFinite(value)
|
|
@@ -563,7 +553,7 @@ define([
|
|
|
case "{":
|
|
case "{":
|
|
|
case "}":
|
|
case "}":
|
|
|
return {
|
|
return {
|
|
|
- type: Token.Punctuator,
|
|
|
|
|
|
|
+ type: ch1,
|
|
|
value: ch1
|
|
value: ch1
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -594,93 +584,22 @@ define([
|
|
|
var value = "";
|
|
var value = "";
|
|
|
var startLine = this.line;
|
|
var startLine = this.line;
|
|
|
var startChar = this.char;
|
|
var startChar = this.char;
|
|
|
- var allowNewLine = false;
|
|
|
|
|
|
|
|
|
|
this.skip();
|
|
this.skip();
|
|
|
|
|
|
|
|
while (this.peek() !== quote) {
|
|
while (this.peek() !== quote) {
|
|
|
- while (this.peek() === "") { // End Of Line
|
|
|
|
|
-
|
|
|
|
|
- // If an EOL is not preceded by a backslash, show a warning
|
|
|
|
|
- // and proceed like it was a legit multi-line string where
|
|
|
|
|
- // author simply forgot to escape the newline symbol.
|
|
|
|
|
- //
|
|
|
|
|
- // Another approach is to implicitly close a string on EOL
|
|
|
|
|
- // but it generates too many false positives.
|
|
|
|
|
-
|
|
|
|
|
- if (!allowNewLine) {
|
|
|
|
|
- this.trigger("warning", {
|
|
|
|
|
- code: "W112",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- allowNewLine = false;
|
|
|
|
|
-
|
|
|
|
|
- // Otherwise show a warning if multistr option was not set.
|
|
|
|
|
- // For JSON, show warning no matter what.
|
|
|
|
|
-
|
|
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W043",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char
|
|
|
|
|
- }, checks, function () { return !state.option.multistr; });
|
|
|
|
|
-
|
|
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W042",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char
|
|
|
|
|
- }, checks, function () { return state.jsonMode && state.option.multistr; });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // If we get an EOF inside of an unclosed string, show an
|
|
|
|
|
- // error and implicitly close it at the EOF point.
|
|
|
|
|
-
|
|
|
|
|
- if (!this.nextLine()) {
|
|
|
|
|
- this.trigger("error", {
|
|
|
|
|
- code: "E029",
|
|
|
|
|
- line: startLine,
|
|
|
|
|
- character: startChar
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- return {
|
|
|
|
|
- type: Token.StringLiteral,
|
|
|
|
|
- value: value,
|
|
|
|
|
- isUnclosed: true,
|
|
|
|
|
- quote: quote
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- allowNewLine = false;
|
|
|
|
|
var char = this.peek();
|
|
var char = this.peek();
|
|
|
var jump = 1; // A length of a jump, after we're done
|
|
var jump = 1; // A length of a jump, after we're done
|
|
|
// parsing this character.
|
|
// parsing this character.
|
|
|
|
|
|
|
|
- if (char < " ") {
|
|
|
|
|
- // Warn about a control character in a string.
|
|
|
|
|
- this.trigger("warning", {
|
|
|
|
|
- code: "W113",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char,
|
|
|
|
|
- data: [ "<non-printable>" ]
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// Special treatment for some escaped characters.
|
|
// Special treatment for some escaped characters.
|
|
|
-
|
|
|
|
|
if (char === "\\") {
|
|
if (char === "\\") {
|
|
|
this.skip();
|
|
this.skip();
|
|
|
char = this.peek();
|
|
char = this.peek();
|
|
|
|
|
|
|
|
switch (char) {
|
|
switch (char) {
|
|
|
case "'":
|
|
case "'":
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W114",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char,
|
|
|
|
|
- data: [ "\\'" ]
|
|
|
|
|
- }, checks, function () {return state.jsonMode; });
|
|
|
|
|
break;
|
|
break;
|
|
|
case "b":
|
|
case "b":
|
|
|
char = "\b";
|
|
char = "\b";
|
|
@@ -699,41 +618,16 @@ define([
|
|
|
break;
|
|
break;
|
|
|
case "0":
|
|
case "0":
|
|
|
char = "\0";
|
|
char = "\0";
|
|
|
-
|
|
|
|
|
- // Octal literals fail in strict mode.
|
|
|
|
|
- // Check if the number is between 00 and 07.
|
|
|
|
|
- var n = parseInt(this.peek(1), 10);
|
|
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W115",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char
|
|
|
|
|
- }, checks,
|
|
|
|
|
- function () { return n >= 0 && n <= 7 && state.directive["use strict"]; });
|
|
|
|
|
break;
|
|
break;
|
|
|
case "u":
|
|
case "u":
|
|
|
char = String.fromCharCode(parseInt(this.input.substr(1, 4), 16));
|
|
char = String.fromCharCode(parseInt(this.input.substr(1, 4), 16));
|
|
|
jump = 5;
|
|
jump = 5;
|
|
|
break;
|
|
break;
|
|
|
case "v":
|
|
case "v":
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W114",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char,
|
|
|
|
|
- data: [ "\\v" ]
|
|
|
|
|
- }, checks, function () { return state.jsonMode; });
|
|
|
|
|
-
|
|
|
|
|
char = "\v";
|
|
char = "\v";
|
|
|
break;
|
|
break;
|
|
|
case "x":
|
|
case "x":
|
|
|
var x = parseInt(this.input.substr(1, 2), 16);
|
|
var x = parseInt(this.input.substr(1, 2), 16);
|
|
|
-
|
|
|
|
|
- this.triggerAsync("warning", {
|
|
|
|
|
- code: "W114",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char,
|
|
|
|
|
- data: [ "\\x-" ]
|
|
|
|
|
- }, checks, function () { return state.jsonMode; });
|
|
|
|
|
-
|
|
|
|
|
char = String.fromCharCode(x);
|
|
char = String.fromCharCode(x);
|
|
|
jump = 3;
|
|
jump = 3;
|
|
|
break;
|
|
break;
|
|
@@ -742,7 +636,6 @@ define([
|
|
|
case "/":
|
|
case "/":
|
|
|
break;
|
|
break;
|
|
|
case "":
|
|
case "":
|
|
|
- allowNewLine = true;
|
|
|
|
|
char = "";
|
|
char = "";
|
|
|
break;
|
|
break;
|
|
|
case "!":
|
|
case "!":
|
|
@@ -753,11 +646,6 @@ define([
|
|
|
/*falls through */
|
|
/*falls through */
|
|
|
default:
|
|
default:
|
|
|
// Weird escaping.
|
|
// Weird escaping.
|
|
|
- this.trigger("warning", {
|
|
|
|
|
- code: "W044",
|
|
|
|
|
- line: this.line,
|
|
|
|
|
- character: this.char
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -767,7 +655,7 @@ define([
|
|
|
|
|
|
|
|
this.skip();
|
|
this.skip();
|
|
|
return {
|
|
return {
|
|
|
- type: Token.StringLiteral,
|
|
|
|
|
|
|
+ type: 'string',
|
|
|
value: value,
|
|
value: value,
|
|
|
isUnclosed: false,
|
|
isUnclosed: false,
|
|
|
quote: quote
|
|
quote: quote
|