Comparing version 0.9.2 to 0.9.3
245
esprima.js
@@ -26,3 +26,3 @@ /* | ||
/*global esprima:true, exports:true, | ||
parseAssignmentExpression: true, parseExpression: true, | ||
parseAssignmentExpression: true, parseBlock: true, parseExpression: true, | ||
parseFunctionDeclaration: true, parseFunctionExpression: true, | ||
@@ -38,2 +38,3 @@ parseStatement: true */ | ||
index, | ||
lineNumber, | ||
length, | ||
@@ -122,4 +123,4 @@ buffer; | ||
// TODO Unicode "space separator" | ||
return (ch === '\u0009') || (ch === '\u000B') || (ch === '\u000C') || | ||
(ch === ' ') || (ch === '\u00A0') || (ch === '\uFEFF'); | ||
return (ch === ' ') || (ch === '\u0009') || (ch === '\u000B') || | ||
(ch === '\u000C') || (ch === '\u00A0') || (ch === '\uFEFF'); | ||
} | ||
@@ -231,2 +232,3 @@ | ||
lineComment = false; | ||
lineNumber += 1; | ||
} | ||
@@ -241,2 +243,4 @@ } else if (blockComment) { | ||
} | ||
} else if (isLineTerminator(ch)) { | ||
lineNumber += 1; | ||
} | ||
@@ -260,2 +264,3 @@ } else if (ch === '/') { | ||
nextChar(); | ||
lineNumber += 1; | ||
} else { | ||
@@ -535,10 +540,7 @@ break; | ||
} | ||
throw new Error('Unexpected ' + ch + ' after the exponent sign'); | ||
throw new Error('Line ' + lineNumber + ': Unexpected ' + ch + | ||
' after the exponent sign'); | ||
} | ||
} | ||
if (number === '.') { | ||
throw new Error('Expecting decimal digits after the dot sign'); | ||
} | ||
return { | ||
@@ -552,3 +554,3 @@ type: Token.NumericLiteral, | ||
// TODO Unicode, line continuiation | ||
// TODO Unicode | ||
function scanStringLiteral() { | ||
@@ -566,11 +568,11 @@ var str = '', quote, ch; | ||
if (typeof ch === 'undefined') { | ||
throw new Error('Unterminated string'); | ||
} | ||
if (ch === quote) { | ||
quote = ''; | ||
break; | ||
} else if (ch === '\\') { | ||
str += ch; | ||
str += nextChar(); | ||
ch = nextChar(); | ||
if (!isLineTerminator(ch)) { | ||
str += '\\'; | ||
str += ch; | ||
} | ||
} else { | ||
@@ -581,2 +583,6 @@ str += ch; | ||
if (quote !== '') { | ||
throw new Error('Line ' + lineNumber + ': Unterminated string constant'); | ||
} | ||
return { | ||
@@ -618,3 +624,4 @@ type: Token.StringLiteral, | ||
if (isLineTerminator(ch)) { | ||
throw new Error('Unexpected line terminator in a regular expression'); | ||
throw new Error('Line ' + lineNumber + | ||
': Unexpected line terminator in a regular expression'); | ||
} | ||
@@ -667,7 +674,8 @@ } | ||
throw new Error('Unknown token from character ' + nextChar()); | ||
throw new Error('Line ' + lineNumber + | ||
': Unknown token from character ' + nextChar()); | ||
} | ||
function lookahead() { | ||
var pos, token; | ||
var pos, line, token; | ||
@@ -679,4 +687,6 @@ if (buffer !== null) { | ||
pos = index; | ||
line = lineNumber; | ||
token = lex(); | ||
index = pos; | ||
lineNumber = line; | ||
@@ -687,2 +697,17 @@ buffer = token; | ||
// Return true if there is a line terminator before the next token. | ||
function peekLineTerminator() { | ||
var pos, line, found; | ||
pos = index; | ||
line = lineNumber; | ||
skipComment(); | ||
found = lineNumber !== line; | ||
index = pos; | ||
lineNumber = line; | ||
return found; | ||
} | ||
// Throw an exception because of the token. | ||
@@ -694,3 +719,3 @@ | ||
if (token.type === Token.EOF) { | ||
throw new Error('Unexpected <EOF>'); | ||
throw new Error('Line ' + lineNumber + ': Unexpected <EOF>'); | ||
} | ||
@@ -702,3 +727,3 @@ | ||
} | ||
throw new Error('Unexpected token ' + s); | ||
throw new Error('Line ' + lineNumber + ': Unexpected token ' + s); | ||
} | ||
@@ -765,5 +790,26 @@ | ||
function consumeSemicolon() { | ||
var token, line; | ||
// Catch the very common case first. | ||
if (source[index] === ';') { | ||
lex(); | ||
return; | ||
} | ||
line = lineNumber; | ||
skipComment(); | ||
if (lineNumber !== line) { | ||
return; | ||
} | ||
if (match(';')) { | ||
lex(); | ||
return; | ||
} | ||
token = lookahead(); | ||
if (token.type !== Token.EOF && !match('}')) { | ||
throwUnexpected(token); | ||
} | ||
return; | ||
} | ||
@@ -811,8 +857,2 @@ | ||
function isPropertyName(t) { | ||
return t === Token.Identifier || | ||
t === Token.StringLiteral || | ||
t === Token.NumericLiteral; | ||
} | ||
expect('{'); | ||
@@ -827,5 +867,40 @@ | ||
if (isPropertyName(token.type)) { | ||
property = {}; | ||
if (token.type === Token.Identifier) { | ||
property = {}; | ||
switch (token.type) { | ||
case Token.Identifier: | ||
property.key = { | ||
type: Syntax.Identifier, | ||
name: token.value | ||
}; | ||
// Property Assignment: Getter and Setter. | ||
if (token.value === 'get' && !match(':')) { | ||
token = lex(); | ||
if (token.type !== Token.Identifier) { | ||
throwUnexpected(token); | ||
} | ||
expect('('); | ||
expect(')'); | ||
property = { | ||
key: { | ||
type: Syntax.Identifier, | ||
name: token.value | ||
}, | ||
value: { | ||
type: Syntax.FunctionExpression, | ||
id: null, | ||
params: [], | ||
body: parseBlock() | ||
}, | ||
kind: 'get' | ||
}; | ||
break; | ||
} | ||
if (token.value === 'set' && !match(':')) { | ||
token = lex(); | ||
if (token.type !== Token.Identifier) { | ||
throwUnexpected(token); | ||
} | ||
property.key = { | ||
@@ -835,7 +910,19 @@ type: Syntax.Identifier, | ||
}; | ||
} else { | ||
property.key = { | ||
type: Syntax.Literal, | ||
value: token.value | ||
expect('('); | ||
token = lex(); | ||
if (token.type !== Token.Identifier) { | ||
throwUnexpected(token); | ||
} | ||
expect(')'); | ||
property.value = { | ||
type: Syntax.FunctionExpression, | ||
id: null, | ||
params: [{ | ||
type: Syntax.Identifier, | ||
name: token.value | ||
}], | ||
body: parseBlock() | ||
}; | ||
property.kind = 'set'; | ||
break; | ||
} | ||
@@ -845,7 +932,18 @@ | ||
property.value = parseAssignmentExpression(); | ||
break; | ||
properties.push(property); | ||
} else { | ||
case Token.StringLiteral: | ||
case Token.NumericLiteral: | ||
property.key = { | ||
type: Syntax.Literal, | ||
value: token.value | ||
}; | ||
expect(':'); | ||
property.value = parseAssignmentExpression(); | ||
break; | ||
default: | ||
throwUnexpected(token); | ||
} | ||
properties.push(property); | ||
@@ -976,3 +1074,4 @@ token = lookahead(); | ||
if (token.type !== Token.Identifier) { | ||
throw new Error('Expecting an identifier after dot (.)'); | ||
throw new Error('Line ' + lineNumber + | ||
': Expecting an identifier after dot (.)'); | ||
} | ||
@@ -1068,3 +1167,3 @@ property = { | ||
if (match('++') || match('--')) { | ||
if ((match('++') || match('--')) && !peekLineTerminator()) { | ||
expr = { | ||
@@ -1409,3 +1508,3 @@ type: Syntax.UpdateExpression, | ||
if (token.type !== Token.Identifier) { | ||
throw new Error('Expected an identifier'); | ||
throw new Error('Line ' + lineNumber + ': Expected an identifier'); | ||
} | ||
@@ -1658,2 +1757,18 @@ | ||
// Optimize the most common form: 'continue;'. | ||
if (source[index] === ';') { | ||
lex(); | ||
return { | ||
type: Syntax.ContinueStatement, | ||
label: null | ||
}; | ||
} | ||
if (peekLineTerminator()) { | ||
return { | ||
type: Syntax.ContinueStatement, | ||
label: null | ||
}; | ||
} | ||
token = lookahead(); | ||
@@ -1683,2 +1798,18 @@ if (token.type === Token.Identifier) { | ||
// Optimize the most common form: 'break;'. | ||
if (source[index] === ';') { | ||
lex(); | ||
return { | ||
type: Syntax.BreakStatement, | ||
label: null | ||
}; | ||
} | ||
if (peekLineTerminator()) { | ||
return { | ||
type: Syntax.BreakStatement, | ||
label: null | ||
}; | ||
} | ||
token = lookahead(); | ||
@@ -1708,2 +1839,21 @@ if (token.type === Token.Identifier) { | ||
// 'return' followed by a space and an identifier is very common. | ||
if (source[index] === ' ') { | ||
if (isIdentifierStart(source[index + 1])) { | ||
argument = parseExpression().expression; | ||
consumeSemicolon(); | ||
return { | ||
type: Syntax.ReturnStatement, | ||
argument: argument | ||
}; | ||
} | ||
} | ||
if (peekLineTerminator()) { | ||
return { | ||
type: Syntax.ReturnStatement, | ||
argument: null | ||
}; | ||
} | ||
if (!match(';')) { | ||
@@ -1817,13 +1967,13 @@ token = lookahead(); | ||
function parseThrowStatement() { | ||
var token, argument = null; | ||
var argument; | ||
expectKeyword('throw'); | ||
if (!match(';')) { | ||
token = lookahead(); | ||
if (token.type !== Token.EOF) { | ||
argument = parseExpression().expression; | ||
} | ||
if (peekLineTerminator()) { | ||
throw new Error('Line ' + lineNumber + | ||
': Unexpected line terminator after throw'); | ||
} | ||
argument = parseExpression().expression; | ||
consumeSemicolon(); | ||
@@ -1945,3 +2095,3 @@ | ||
stat = parseExpressionStatement(); | ||
stat = parseExpression(); | ||
@@ -1969,2 +2119,4 @@ if (stat.expression.type === Syntax.FunctionExpression) { | ||
consumeSemicolon(); | ||
return stat; | ||
@@ -2107,2 +2259,3 @@ } | ||
index = 0; | ||
lineNumber = (source.length > 0) ? 1 : 0; | ||
length = source.length; | ||
@@ -2114,4 +2267,4 @@ buffer = null; | ||
// Sync with package.json. | ||
exports.version = '0.9.2'; | ||
exports.version = '0.9.3'; | ||
}(typeof exports === 'undefined' ? (esprima = {}) : exports)); |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.4.0" |
@@ -1,2 +0,2 @@ | ||
Esprima ([esprima.org](http://esprima.org)) is an experimental ECMAScript | ||
Esprima ([esprima.org](http://esprima.org)) is an educational ECMAScript | ||
(also popularly known as JavaScript) parsing infrastructure for multipurpose | ||
@@ -28,2 +28,4 @@ analysis. It is also written in ECMAScript. | ||
and [future plans](http://code.google.com/p/esprima/issues/list?q=Enhancement). | ||
Esprima is supported on [many browsers](http://code.google.com/p/esprima/wiki/BrowserCompatibility): | ||
IE 8+, Firefox 3.5+, Safari 4+, Chrome 7+, and Opera 10.5+. | ||
@@ -30,0 +32,0 @@ Feedback and contribution are welcomed! Please join the |
@@ -257,5 +257,5 @@ /*********************************************************************** | ||
this.message = message; | ||
this.line = line; | ||
this.col = col; | ||
this.pos = pos; | ||
this.line = line + 1; | ||
this.col = col + 1; | ||
this.pos = pos + 1; | ||
this.stack = new Error().stack; | ||
@@ -330,8 +330,9 @@ }; | ||
var ret = { | ||
type : type, | ||
value : value, | ||
line : S.tokline, | ||
col : S.tokcol, | ||
pos : S.tokpos, | ||
nlb : S.newline_before | ||
type : type, | ||
value : value, | ||
line : S.tokline, | ||
col : S.tokcol, | ||
pos : S.tokpos, | ||
endpos : S.pos, | ||
nlb : S.newline_before | ||
}; | ||
@@ -473,4 +474,3 @@ if (!is_comment) { | ||
var i = find("*/", true), | ||
text = S.text.substring(S.pos, i), | ||
tok = token("comment2", text, true); | ||
text = S.text.substring(S.pos, i); | ||
S.pos = i + 2; | ||
@@ -487,3 +487,3 @@ S.line += text.split("\n").length - 1; | ||
return tok; | ||
return token("comment2", text, true); | ||
}); | ||
@@ -939,3 +939,3 @@ }; | ||
var function_ = maybe_embed_tokens(function(in_statement) { | ||
var function_ = function(in_statement) { | ||
var name = is("name") ? prog1(S.token.value, next) : null; | ||
@@ -968,3 +968,3 @@ if (in_statement && !name) | ||
})()); | ||
}); | ||
}; | ||
@@ -971,0 +971,0 @@ function if_() { |
@@ -12,20 +12,20 @@ /*jslint browser: true */ | ||
'esprima jquery-1.7.1', | ||
'narcissus jquery-1.7.1', | ||
'parsejs jquery-1.7.1', | ||
'zeparser jquery-1.7.1', | ||
'narcissus jquery-1.7.1', | ||
'esprima prototype-1.7.0.0', | ||
'narcissus prototype-1.7.0.0', | ||
'parsejs prototype-1.7.0.0', | ||
'zeparser prototype-1.7.0.0', | ||
'narcissus prototype-1.7.0.0', | ||
'esprima mootools-1.4.1', | ||
'narcissus mootools-1.4.1', | ||
'parsejs mootools-1.4.1', | ||
'zeparser mootools-1.4.1', | ||
'narcissus mootools-1.4.1', | ||
'esprima ext-core-3.1.0', | ||
'narcissus ext-core-3.1.0', | ||
'parsejs ext-core-3.1.0', | ||
'zeparser ext-core-3.1.0' | ||
'zeparser ext-core-3.1.0', | ||
'narcissus ext-core-3.1.0' | ||
]; | ||
@@ -32,0 +32,0 @@ |
@@ -384,2 +384,13 @@ // This is modified from Mozilla Reflect.parse test suite (the file is located | ||
// getters and setters | ||
assertExpr("({ get x() { return 42 } })", | ||
objExpr([ { key: ident("x"), | ||
value: funExpr(null, [], blockStmt([returnStmt(lit(42))])), | ||
kind: "get" } ])); | ||
assertExpr("({ set x(v) { return 42 } })", | ||
objExpr([ { key: ident("x"), | ||
value: funExpr(null, [ident("v")], blockStmt([returnStmt(lit(42))])), | ||
kind: "set" } ])); | ||
} |
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 not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
3342791
28
0
100
18662
63