esprima
Advanced tools
Comparing version 0.9.1 to 0.9.2
126
esprima.js
@@ -43,9 +43,8 @@ /* | ||
EOF: 2, | ||
FutureReservedWord: 3, | ||
Identifier: 4, | ||
Keyword: 5, | ||
NullLiteral: 6, | ||
NumericLiteral: 7, | ||
Punctuator: 8, | ||
StringLiteral: 9 | ||
Identifier: 3, | ||
Keyword: 4, | ||
NullLiteral: 5, | ||
NumericLiteral: 6, | ||
Punctuator: 7, | ||
StringLiteral: 8 | ||
}; | ||
@@ -55,2 +54,3 @@ | ||
AssignmentExpression: 'AssignmentExpression', | ||
ArrayExpression: 'ArrayExpression', | ||
BlockStatement: 'BlockStatement', | ||
@@ -78,2 +78,3 @@ BinaryExpression: 'BinaryExpression', | ||
NewExpression: 'NewExpression', | ||
ObjectExpression: 'ObjectExpression', | ||
Program: 'Program', | ||
@@ -145,5 +146,8 @@ ReturnStatement: 'ReturnStatement', | ||
// 7.6.1.1 Keywords | ||
// 7.6.1.2 Future Reserved Words | ||
function isKeyword(id) { | ||
switch (id) { | ||
// Keywords. | ||
case 'break': | ||
@@ -175,11 +179,4 @@ case 'case': | ||
case 'with': | ||
return true; | ||
} | ||
return false; | ||
} | ||
// 7.6.1.2 Future Reserved Words | ||
function isFutureReservedWord(id) { | ||
switch (id) { | ||
// Future reserved words. | ||
case 'class': | ||
@@ -205,2 +202,3 @@ case 'const': | ||
} | ||
return false; | ||
@@ -286,5 +284,7 @@ } | ||
if (isKeyword(id)) { | ||
// There is no keyword or literal with only one character. | ||
// Thus, it must be an identifier. | ||
if (id.length === 1) { | ||
return { | ||
type: Token.Keyword, | ||
type: Token.Identifier, | ||
value: id | ||
@@ -294,5 +294,5 @@ }; | ||
if (isFutureReservedWord(id)) { | ||
if (isKeyword(id)) { | ||
return { | ||
type: Token.FutureReservedKeyword, | ||
type: Token.Keyword, | ||
value: id | ||
@@ -537,5 +537,3 @@ }; | ||
} | ||
throw { | ||
message: 'Unexpected ' + ch + ' after the exponent sign' | ||
}; | ||
throw new Error('Unexpected ' + ch + ' after the exponent sign'); | ||
} | ||
@@ -545,5 +543,3 @@ } | ||
if (number === '.') { | ||
throw { | ||
message: 'Expecting decimal digits after the dot sign' | ||
}; | ||
throw new Error('Expecting decimal digits after the dot sign'); | ||
} | ||
@@ -573,5 +569,3 @@ | ||
if (typeof ch === 'undefined') { | ||
throw { | ||
message: 'Unterminated string' | ||
}; | ||
throw new Error('Unterminated string'); | ||
} | ||
@@ -625,5 +619,3 @@ | ||
if (isLineTerminator(ch)) { | ||
throw { | ||
message: 'Unexpected line terminator in a regular expression' | ||
}; | ||
throw new Error('Unexpected line terminator in a regular expression'); | ||
} | ||
@@ -676,5 +668,3 @@ } | ||
throw { | ||
message: 'Unknown token from character ' + nextChar() | ||
}; | ||
throw new Error('Unknown token from character ' + nextChar()); | ||
} | ||
@@ -703,5 +693,3 @@ | ||
if (token.type === Token.EOF) { | ||
throw { | ||
message: 'Unexpected <EOF>' | ||
}; | ||
throw new Error('Unexpected <EOF>'); | ||
} | ||
@@ -713,5 +701,3 @@ | ||
} | ||
throw { | ||
message: 'Unexpected token ' + s | ||
}; | ||
throw new Error('Unexpected token ' + s); | ||
} | ||
@@ -813,3 +799,3 @@ | ||
return { | ||
type: 'ArrayExpression', | ||
type: Syntax.ArrayExpression, | ||
elements: elements | ||
@@ -870,3 +856,3 @@ }; | ||
return { | ||
type: 'ObjectExpression', | ||
type: Syntax.ObjectExpression, | ||
properties: properties | ||
@@ -986,5 +972,3 @@ }; | ||
if (token.type !== Token.Identifier) { | ||
throw { | ||
message: 'Expecting an identifier after dot (.)' | ||
}; | ||
throw new Error('Expecting an identifier after dot (.)'); | ||
} | ||
@@ -1381,3 +1365,4 @@ property = { | ||
function parseStatementList() { | ||
var list = []; | ||
var list = [], | ||
statement; | ||
@@ -1388,3 +1373,7 @@ while (index < length) { | ||
} | ||
list.push(parseStatement()); | ||
statement = parseStatement(); | ||
if (typeof statement === 'undefined') { | ||
break; | ||
} | ||
list.push(statement); | ||
} | ||
@@ -1417,5 +1406,3 @@ | ||
if (token.type !== Token.Identifier) { | ||
throw { | ||
message: 'Expected an identifier' | ||
}; | ||
throw new Error('Expected an identifier'); | ||
} | ||
@@ -1470,2 +1457,21 @@ | ||
// http://wiki.ecmascript.org/doku.php?id=harmony:let. | ||
// Warning: This is experimental and not in the specification yet. | ||
function parseLetStatement() { | ||
var declarations; | ||
expectKeyword('let'); | ||
declarations = parseVariableDeclarationList(); | ||
consumeSemicolon(); | ||
return { | ||
type: Syntax.VariableDeclaration, | ||
declarations: declarations, | ||
kind: 'let' | ||
}; | ||
} | ||
// 12.3 Empty Statement | ||
@@ -1568,3 +1574,3 @@ | ||
function parseForStatement() { | ||
var init, test, update, left, right, body; | ||
var kind, init, test, update, left, right, body; | ||
@@ -1580,8 +1586,8 @@ init = test = update = null; | ||
} else { | ||
if (matchKeyword('var')) { | ||
lex(); | ||
if (matchKeyword('var') || matchKeyword('let')) { | ||
kind = lex().value; | ||
init = { | ||
type: Syntax.VariableDeclaration, | ||
declarations: parseVariableDeclarationList(), | ||
kind: 'var' | ||
kind: kind | ||
}; | ||
@@ -1740,3 +1746,3 @@ | ||
function parseSwitchStatement() { | ||
var discriminant, cases, test, consequent; | ||
var discriminant, cases, test, consequent, statement; | ||
@@ -1783,3 +1789,7 @@ expectKeyword('switch'); | ||
} | ||
consequent.push(parseStatement()); | ||
statement = parseStatement(); | ||
if (typeof statement === 'undefined') { | ||
break; | ||
} | ||
consequent.push(statement); | ||
} | ||
@@ -1912,2 +1922,4 @@ | ||
return parseIfStatement(); | ||
case 'let': | ||
return parseLetStatement(); | ||
case 'return': | ||
@@ -2098,4 +2110,4 @@ return parseReturnStatement(); | ||
// Sync with package.json. | ||
exports.version = '0.9.1'; | ||
exports.version = '0.9.2'; | ||
}(typeof exports === 'undefined' ? (esprima = {}) : exports)); |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.4.0" |
@@ -59,3 +59,5 @@ /*jslint browser: true */ | ||
el = document.getElementById('narcissus-time'); | ||
el.textContent = (1000 * totalTime.narcissus).toFixed(1) + ' ms'; | ||
if (totalTime.narcissus > 0) { | ||
el.textContent = (1000 * totalTime.narcissus).toFixed(1) + ' ms'; | ||
} | ||
el = document.getElementById('parsejs-time'); | ||
@@ -72,3 +74,7 @@ el.textContent = (1000 * totalTime.parsejs).toFixed(1) + ' ms'; | ||
el = document.getElementById(parser + '-' + name); | ||
el.textContent = (1000 * stats.mean).toFixed(1) + ' ms'; | ||
if (stats.size === 0) { | ||
el.textContent = 'N/A'; | ||
} else { | ||
el.textContent = (1000 * stats.mean).toFixed(1) + ' ms'; | ||
} | ||
} | ||
@@ -75,0 +81,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
3316161
18059