Comparing version 0.11.1-1 to 0.11.1-2
@@ -61,10 +61,8 @@ // Acorn: Loose parser | ||
function next(forceRegexp) { | ||
function next() { | ||
lastEnd = token.end; | ||
if (options.locations) | ||
lastEndLoc = token.endLoc; | ||
if (forceRegexp) | ||
ahead.length = 0; | ||
lastEndLoc = token.loc && token.loc.end; | ||
token = ahead.shift() || readToken(forceRegexp); | ||
token = ahead.shift() || readToken(); | ||
if (options.onToken) | ||
@@ -82,6 +80,6 @@ options.onToken(token); | ||
function readToken(forceRegexp) { | ||
function readToken() { | ||
for (;;) { | ||
try { | ||
var tok = fetchToken(forceRegexp); | ||
var tok = fetchToken(); | ||
if (tok.type === tt.dot && input.substr(tok.end, 1) === '.') { | ||
@@ -134,4 +132,4 @@ tok = fetchToken(); | ||
if (options.locations) { | ||
replace.startLoc = acorn.getLineInfo(input, replace.start); | ||
replace.endLoc = acorn.getLineInfo(input, replace.end); | ||
replace.loc = new SourceLocation(acorn.getLineInfo(input, replace.start)); | ||
replace.loc.end = acorn.getLineInfo(input, replace.end); | ||
} | ||
@@ -218,3 +216,3 @@ return replace; | ||
function SourceLocation(start) { | ||
this.start = start || token.startLoc || {line: 1, column: 0}; | ||
this.start = start || token.loc.start || {line: 1, column: 0}; | ||
this.end = null; | ||
@@ -236,3 +234,3 @@ if (sourceFile !== null) this.source = sourceFile; | ||
function storeCurrentPos() { | ||
return options.locations ? [token.start, token.startLoc] : token.start; | ||
return options.locations ? [token.start, token.loc.start] : token.start; | ||
} | ||
@@ -281,5 +279,14 @@ | ||
function isContextual(name) { | ||
return token.type === tt.name && token.value === name; | ||
} | ||
function eatContextual(name) { | ||
return token.value === name && eat(tt.name); | ||
} | ||
function canInsertSemicolon() { | ||
return (token.type === tt.eof || token.type === tt.braceR || newline.test(input.slice(lastEnd, token.start))); | ||
} | ||
function semicolon() { | ||
@@ -308,3 +315,3 @@ return eat(tt.semi); | ||
case "ArrayPattern": | ||
case "SpreadElement": | ||
case "RestElement": | ||
case "AssignmentPattern": | ||
@@ -323,3 +330,3 @@ return expr; | ||
lastEnd = token.end; | ||
lastEndLoc = token.endLoc; | ||
lastEndLoc = token.loc && token.loc.end; | ||
return finishNode(node, "Program"); | ||
@@ -329,5 +336,2 @@ } | ||
function parseStatement() { | ||
if (token.type === tt.slash || token.type === tt.assign && token.value === "/=") | ||
next(true); | ||
var starttype = token.type, node = startNode(); | ||
@@ -366,3 +370,3 @@ | ||
var init = parseVar(true); | ||
if (init.declarations.length === 1 && (token.type === tt._in || token.type === tt.name && token.value === "of")) { | ||
if (init.declarations.length === 1 && (token.type === tt._in || isContextual("of"))) { | ||
return parseForIn(node, init); | ||
@@ -372,4 +376,4 @@ } | ||
} | ||
var init = parseExpression(false, true); | ||
if (token.type === tt._in || token.type === tt.name && token.value === "of") { | ||
var init = parseExpression(true); | ||
if (token.type === tt._in || isContextual("of")) { | ||
return parseForIn(node, checkLVal(init)); | ||
@@ -546,3 +550,3 @@ } | ||
decl.id = options.ecmaVersion >= 6 ? toAssignable(parseExprAtom()) : parseIdent(); | ||
decl.init = eat(tt.eq) ? parseExpression(true, noIn) : null; | ||
decl.init = eat(tt.eq) ? parseMaybeAssign(noIn) : null; | ||
node.declarations.push(finishNode(decl, "VariableDeclarator")); | ||
@@ -559,6 +563,6 @@ } while (eat(tt.comma)); | ||
function parseExpression(noComma, noIn) { | ||
function parseExpression(noIn) { | ||
var start = storeCurrentPos(); | ||
var expr = parseMaybeAssign(noIn); | ||
if (!noComma && token.type === tt.comma) { | ||
if (token.type === tt.comma) { | ||
var node = startNodeAt(start); | ||
@@ -601,4 +605,4 @@ node.expressions = [expr]; | ||
node.test = expr; | ||
node.consequent = parseExpression(true); | ||
node.alternate = expect(tt.colon) ? parseExpression(true, noIn) : dummyIdent(); | ||
node.consequent = parseMaybeAssign(); | ||
node.alternate = expect(tt.colon) ? parseMaybeAssign(noIn) : dummyIdent(); | ||
return finishNode(node, "ConditionalExpression"); | ||
@@ -793,3 +797,3 @@ } | ||
node.delegate = eat(tt.star); | ||
node.argument = parseExpression(true); | ||
node.argument = parseMaybeAssign(); | ||
} | ||
@@ -882,3 +886,3 @@ return finishNode(node, "YieldExpression"); | ||
parsePropertyName(prop); | ||
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; } | ||
if (isDummy(prop.key)) { if (isDummy(parseMaybeAssign())) next(); eat(tt.comma); continue; } | ||
if (isClass) { | ||
@@ -896,3 +900,3 @@ if (prop.key.type === "Identifier" && !prop.computed && prop.key.name === "static" && | ||
prop.kind = "init"; | ||
prop.value = parseExpression(true); | ||
prop.value = parseMaybeAssign(); | ||
} else if (options.ecmaVersion >= 6 && (token.type === tt.parenL || token.type === tt.braceL)) { | ||
@@ -933,3 +937,3 @@ if (isClass) { | ||
lastEnd = token.start; | ||
if (options.locations) lastEndLoc = token.startLoc; | ||
if (options.locations) lastEndLoc = token.loc.start; | ||
} | ||
@@ -975,4 +979,2 @@ if (isClass) { | ||
if (options.ecmaVersion >= 6) { | ||
node.defaults = []; | ||
node.rest = null; | ||
node.generator = false; | ||
@@ -993,3 +995,3 @@ node.expression = false; | ||
for (var i = 0; i < props.length; i++) { | ||
props[i].value = toAssignable(props[i].value); | ||
toAssignable(props[i].value); | ||
} | ||
@@ -1000,9 +1002,7 @@ break; | ||
node.type = "ArrayPattern"; | ||
var elms = node.elements; | ||
for (var i = 0; i < elms.length; i++) { | ||
elms[i] = toAssignable(elms[i]); | ||
} | ||
toAssignableList(node.elements); | ||
break; | ||
case "SpreadElement": | ||
node.type = "RestElement"; | ||
node.argument = toAssignable(node.argument); | ||
@@ -1019,29 +1019,13 @@ break; | ||
function parseFunctionParams(node, params) { | ||
var defaults = [], hasDefaults = false; | ||
if (!params) { | ||
pushCx(); | ||
params = parseExprList(tt.parenR); | ||
function toAssignableList(exprList) { | ||
for (var i = 0; i < exprList.length; i++) { | ||
toAssignable(exprList[i]); | ||
} | ||
for (var i = 0; i < params.length; i++) { | ||
var param = params[i], defValue = null; | ||
if (param.type === "AssignmentExpression") { | ||
defValue = param.right; | ||
param = param.left; | ||
} | ||
param = toAssignable(param); | ||
if (param.type === "SpreadElement") { | ||
param = param.argument; | ||
if (i === params.length - 1) { | ||
node.rest = param; | ||
continue; | ||
} | ||
} | ||
node.params.push(param); | ||
defaults.push(defValue); | ||
if (defValue) hasDefaults = true; | ||
} | ||
return exprList; | ||
} | ||
if (hasDefaults) node.defaults = defaults; | ||
function parseFunctionParams(params) { | ||
pushCx(); | ||
params = parseExprList(tt.parenR); | ||
return toAssignableList(params); | ||
} | ||
@@ -1056,3 +1040,3 @@ | ||
else if (isStatement) node.id = dummyIdent(); | ||
parseFunctionParams(node); | ||
node.params = parseFunctionParams(); | ||
node.body = parseBlock(); | ||
@@ -1065,6 +1049,6 @@ return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); | ||
initFunction(node); | ||
parseFunctionParams(node); | ||
node.params = parseFunctionParams(); | ||
node.generator = isGenerator || false; | ||
node.expression = options.ecmaVersion >= 6 && token.type !== tt.braceL; | ||
node.body = node.expression ? parseExpression(true) : parseBlock(); | ||
node.body = node.expression ? parseMaybeAssign() : parseBlock(); | ||
return finishNode(node, "FunctionExpression"); | ||
@@ -1075,5 +1059,5 @@ } | ||
initFunction(node); | ||
parseFunctionParams(node, params); | ||
node.params = toAssignableList(params); | ||
node.expression = token.type !== tt.braceL; | ||
node.body = node.expression ? parseExpression(true) : parseBlock(); | ||
node.body = node.expression ? parseMaybeAssign() : parseBlock(); | ||
return finishNode(node, "ArrowFunctionExpression"); | ||
@@ -1130,6 +1114,3 @@ } | ||
next(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} | ||
if (eatContextual("as")) elt.name = parseIdent(); | ||
elts.push(finishNode(elt, prefix + "BatchSpecifier")); | ||
@@ -1143,18 +1124,9 @@ } else { | ||
var elt = startNode(); | ||
if (token.type === tt.star) { | ||
next(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} | ||
if (eat(tt.star)) { | ||
if (eatContextual("as")) elt.name = parseIdent(); | ||
finishNode(elt, prefix + "BatchSpecifier"); | ||
} else { | ||
if (token.type === tt.name && token.value === "from") break; | ||
if (isContextual("from")) break; | ||
elt.id = parseIdent(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} else { | ||
elt.name = null; | ||
} | ||
elt.name = eatContextual("as") ? parseIdent() : null; | ||
finishNode(elt, prefix + "Specifier"); | ||
@@ -1168,8 +1140,3 @@ } | ||
} | ||
if (token.type === tt.name && token.value === "from") { | ||
next(); | ||
node.source = parseExprAtom(); | ||
} else { | ||
node.source = null; | ||
} | ||
node.source = eatContextual("from") ? parseExprAtom() : null; | ||
} | ||
@@ -1185,3 +1152,3 @@ | ||
} | ||
var elt = parseExpression(true); | ||
var elt = parseMaybeAssign(); | ||
if (isDummy(elt)) { | ||
@@ -1200,3 +1167,3 @@ if (closes(close, indent, line)) break; | ||
lastEnd = token.start; | ||
if (options.locations) lastEndLoc = token.startLoc; | ||
if (options.locations) lastEndLoc = token.loc.start; | ||
} | ||
@@ -1203,0 +1170,0 @@ return elts; |
@@ -6,3 +6,3 @@ { | ||
"main": "acorn.js", | ||
"version": "0.11.1-1", | ||
"version": "0.11.1-2", | ||
"engines": {"node": ">=0.4.0"}, | ||
@@ -9,0 +9,0 @@ "maintainers": [{"name": "Ingvar Stepanyan", |
@@ -69,3 +69,3 @@ (function(exports) { | ||
function ppJSON(v) { return JSON.stringify(v, null, 2); } | ||
function ppJSON(v) { return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2); } | ||
function addPath(str, pt) { | ||
@@ -80,2 +80,5 @@ if (str.charAt(str.length-1) == ")") | ||
if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act); | ||
} else if (exp instanceof RegExp || act instanceof RegExp) { | ||
var left = ppJSON(exp), right = ppJSON(act); | ||
if (left !== right) return left + " !== " + right; | ||
} else if (exp.splice) { | ||
@@ -82,0 +85,0 @@ if (!act.slice) return ppJSON(exp) + " != " + ppJSON(act); |
@@ -203,3 +203,3 @@ // AST walker module for Mozilla Parser API compatible trees | ||
}; | ||
base.ThrowStatement = base.SpreadElement = function(node, st, c) { | ||
base.ThrowStatement = base.SpreadElement = base.RestElement = function(node, st, c) { | ||
c(node.argument, st, "Expression"); | ||
@@ -253,3 +253,3 @@ }; | ||
base.ThisExpression = ignore; | ||
base.ArrayExpression = function(node, st, c) { | ||
base.ArrayExpression = base.ArrayPattern = function(node, st, c) { | ||
for (var i = 0; i < node.elements.length; ++i) { | ||
@@ -260,3 +260,3 @@ var elt = node.elements[i]; | ||
}; | ||
base.ObjectExpression = function(node, st, c) { | ||
base.ObjectExpression = base.ObjectPattern = function(node, st, c) { | ||
for (var i = 0; i < node.properties.length; ++i) | ||
@@ -273,3 +273,3 @@ c(node.properties[i], st); | ||
}; | ||
base.BinaryExpression = base.AssignmentExpression = base.LogicalExpression = function(node, st, c) { | ||
base.BinaryExpression = base.AssignmentExpression = base.AssignmentPattern = base.LogicalExpression = function(node, st, c) { | ||
c(node.left, st, "Expression"); | ||
@@ -276,0 +276,0 @@ c(node.right, st, "Expression"); |
18
x.js
@@ -5,4 +5,3 @@ var parse = require('./').parse; | ||
var tests = [ | ||
"class A { static() {} }", | ||
"class A { *static() {} }" | ||
"<div pre=\"leading\" {...props} />" | ||
]; | ||
@@ -21,10 +20,15 @@ | ||
tests.forEach(function (test) { | ||
var ast = parse(test, {ecmaVersion: 6, ranges: true}); | ||
fix(ast); | ||
console.log('test(' + serialize(test) + ", " + serialize(ast) + ", " + serialize({ | ||
var opts = { | ||
ecmaVersion: 6, | ||
ranges: true, | ||
locations: true, | ||
loose: false | ||
}) + ");\n"); | ||
}; | ||
try { | ||
var ast = parse(test, opts); | ||
fix(ast); | ||
console.log('test(' + serialize(test) + ", " + serialize(ast) + ", " + serialize(opts) + ");\n"); | ||
} catch (e) { | ||
if (!(e instanceof SyntaxError)) throw e; | ||
console.log('testFail(' + serialize(test) + ", " + serialize(e.message) + ", " + serialize(opts) + ');\n'); | ||
} | ||
}); |
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
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
2781848
93918