Comparing version 1.0.3 to 1.1.0
@@ -91,2 +91,7 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).loose = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
case "ParenthesizedExpression": | ||
expr.expression = this.checkLVal(expr.expression, binding); | ||
return expr; | ||
// FIXME recursively check contents | ||
case "ObjectPattern": | ||
@@ -1015,4 +1020,3 @@ case "ArrayPattern": | ||
var method = this.startNode(), | ||
isGenerator = undefined, | ||
start = undefined; | ||
isGenerator = undefined; | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -1249,3 +1253,3 @@ method["static"] = false; | ||
} | ||
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number/i.test(msg)) { | ||
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number|expected number in radix/i.test(msg)) { | ||
while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos; | ||
@@ -1252,0 +1256,0 @@ } else if (/character escape|expected hexadecimal/i.test(msg)) { |
@@ -57,3 +57,3 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.acorn || (g.acorn = {})).walk = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
function simple(node, visitors, base, state) { | ||
function simple(node, visitors, base, state, override) { | ||
if (!base) base = exports.base;(function c(node, st, override) { | ||
@@ -64,3 +64,3 @@ var type = override || node.type, | ||
if (found) found(node, st); | ||
})(node, state); | ||
})(node, state, override); | ||
} | ||
@@ -82,6 +82,6 @@ | ||
function recursive(node, state, funcs, base) { | ||
function recursive(node, state, funcs, base, override) { | ||
var visitor = funcs ? exports.make(funcs, base) : base;(function c(node, st, override) { | ||
visitor[override || node.type](node, st, c); | ||
})(node, state); | ||
})(node, state, override); | ||
} | ||
@@ -228,3 +228,3 @@ | ||
}; | ||
base.ThrowStatement = base.SpreadElement = base.RestElement = function (node, st, c) { | ||
base.ThrowStatement = base.SpreadElement = function (node, st, c) { | ||
return c(node.argument, st, "Expression"); | ||
@@ -234,3 +234,6 @@ }; | ||
c(node.block, st, "Statement"); | ||
if (node.handler) c(node.handler.body, st, "ScopeBody"); | ||
if (node.handler) { | ||
c(node.handler.param, st, "Pattern"); | ||
c(node.handler.body, st, "ScopeBody"); | ||
} | ||
if (node.finalizer) c(node.finalizer, st, "Statement"); | ||
@@ -264,2 +267,3 @@ }; | ||
var decl = node.declarations[i]; | ||
c(decl.id, st, "Pattern"); | ||
if (decl.init) c(decl.init, st, "Expression"); | ||
@@ -270,3 +274,5 @@ } | ||
base.Function = function (node, st, c) { | ||
return c(node.body, st, "ScopeBody"); | ||
for (var i = 0; i < node.params.length; i++) { | ||
c(node.params[i], st, "Pattern"); | ||
}c(node.body, st, "ScopeBody"); | ||
}; | ||
@@ -277,5 +283,25 @@ base.ScopeBody = function (node, st, c) { | ||
base.Pattern = function (node, st, c) { | ||
if (node.type == "Identifier") c(node, st, "VariablePattern");else if (node.type == "MemberExpression") c(node, st, "MemberPattern");else c(node, st); | ||
}; | ||
base.VariablePattern = ignore; | ||
base.MemberPattern = skipThrough; | ||
base.RestElement = function (node, st, c) { | ||
return c(node.argument, st, "Pattern"); | ||
}; | ||
base.ArrayPattern = function (node, st, c) { | ||
for (var i = 0; i < node.elements.length; ++i) { | ||
var elt = node.elements[i]; | ||
if (elt) c(elt, st, "Pattern"); | ||
} | ||
}; | ||
base.ObjectPattern = function (node, st, c) { | ||
for (var i = 0; i < node.properties.length; ++i) { | ||
c(node.properties[i].value, st, "Pattern"); | ||
} | ||
}; | ||
base.Expression = skipThrough; | ||
base.ThisExpression = base.Super = base.MetaProperty = ignore; | ||
base.ArrayExpression = base.ArrayPattern = function (node, st, c) { | ||
base.ArrayExpression = function (node, st, c) { | ||
for (var i = 0; i < node.elements.length; ++i) { | ||
@@ -286,3 +312,3 @@ var elt = node.elements[i]; | ||
}; | ||
base.ObjectExpression = base.ObjectPattern = function (node, st, c) { | ||
base.ObjectExpression = function (node, st, c) { | ||
for (var i = 0; i < node.properties.length; ++i) { | ||
@@ -301,6 +327,10 @@ c(node.properties[i], st); | ||
}; | ||
base.BinaryExpression = base.AssignmentExpression = base.AssignmentPattern = base.LogicalExpression = function (node, st, c) { | ||
base.BinaryExpression = base.LogicalExpression = function (node, st, c) { | ||
c(node.left, st, "Expression"); | ||
c(node.right, st, "Expression"); | ||
}; | ||
base.AssignmentExpression = base.AssignmentPattern = function (node, st, c) { | ||
c(node.left, st, "Pattern"); | ||
c(node.right, st, "Expression"); | ||
}; | ||
base.ConditionalExpression = function (node, st, c) { | ||
@@ -322,3 +352,3 @@ c(node.test, st, "Expression"); | ||
base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st, c) { | ||
return c(node.declaration, st); | ||
if (node.declaration) c(node.declaration, st); | ||
}; | ||
@@ -337,2 +367,6 @@ base.ImportDeclaration = function (node, st, c) { | ||
base.ClassDeclaration = base.ClassExpression = function (node, st, c) { | ||
return c(node, st, "Class"); | ||
}; | ||
base.Class = function (node, st, c) { | ||
c(node.id, st, "Pattern"); | ||
if (node.superClass) c(node.superClass, st, "Expression"); | ||
@@ -339,0 +373,0 @@ for (var i = 0; i < node.body.body.length; i++) { |
@@ -6,3 +6,3 @@ { | ||
"main": "dist/acorn.js", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"engines": { | ||
@@ -9,0 +9,0 @@ "node": ">=0.4.0" |
@@ -73,3 +73,3 @@ # Acorn | ||
(as in Internet Explorer's old parser). | ||
- **allowReturnOutsideFunction**: By default, a return statement at | ||
@@ -116,3 +116,3 @@ the top level raises an error. Set this to `true` to accept such | ||
to it as object in Esprima format: | ||
```javascript | ||
@@ -310,2 +310,4 @@ { | ||
- `--allow-hash-bang`: If the code starts with the characters #! (as in a shellscript), the first line will be treated as a comment. | ||
- `--compact`: No whitespace is used in the AST output. | ||
@@ -312,0 +314,0 @@ |
@@ -71,6 +71,6 @@ // A recursive descent parser operates by defining functions for all | ||
pp.parseExpression = function(noIn, refShorthandDefaultPos) { | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let expr = this.parseMaybeAssign(noIn, refShorthandDefaultPos) | ||
if (this.type === tt.comma) { | ||
let node = this.startNodeAt(start) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.expressions = [expr] | ||
@@ -86,3 +86,3 @@ while (this.eat(tt.comma)) node.expressions.push(this.parseMaybeAssign(noIn, refShorthandDefaultPos)) | ||
pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos) { | ||
pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) { | ||
if (this.type == tt._yield && this.inGenerator) return this.parseYield() | ||
@@ -97,9 +97,12 @@ | ||
} | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
if (this.type == tt.parenL || this.type == tt.name) | ||
this.potentialArrowAt = this.start | ||
let left = this.parseMaybeConditional(noIn, refShorthandDefaultPos) | ||
if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc) | ||
if (this.type.isAssign) { | ||
let node = this.startNodeAt(start) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.operator = this.value | ||
node.left = this.type === tt.eq ? this.toAssignable(left) : left | ||
refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly | ||
refShorthandDefaultPos.start = 0 // reset because shorthand default was used correctly | ||
this.checkLVal(left) | ||
@@ -118,7 +121,7 @@ this.next() | ||
pp.parseMaybeConditional = function(noIn, refShorthandDefaultPos) { | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let expr = this.parseExprOps(noIn, refShorthandDefaultPos) | ||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr | ||
if (this.eat(tt.question)) { | ||
let node = this.startNodeAt(start) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.test = expr | ||
@@ -136,6 +139,6 @@ node.consequent = this.parseMaybeAssign() | ||
pp.parseExprOps = function(noIn, refShorthandDefaultPos) { | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let expr = this.parseMaybeUnary(refShorthandDefaultPos) | ||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr | ||
return this.parseExprOp(expr, start, -1, noIn) | ||
return this.parseExprOp(expr, startPos, startLoc, -1, noIn) | ||
} | ||
@@ -149,7 +152,7 @@ | ||
pp.parseExprOp = function(left, leftStart, minPrec, noIn) { | ||
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { | ||
let prec = this.type.binop | ||
if (prec != null && (!noIn || this.type !== tt._in)) { | ||
if (prec > minPrec) { | ||
let node = this.startNodeAt(leftStart) | ||
let node = this.startNodeAt(leftStartPos, leftStartLoc) | ||
node.left = left | ||
@@ -159,6 +162,6 @@ node.operator = this.value | ||
this.next() | ||
let start = this.markPosition() | ||
node.right = this.parseExprOp(this.parseMaybeUnary(), start, prec, noIn) | ||
let startPos = this.start, startLoc = this.startLoc | ||
node.right = this.parseExprOp(this.parseMaybeUnary(), startPos, startLoc, prec, noIn) | ||
this.finishNode(node, (op === tt.logicalOR || op === tt.logicalAND) ? "LogicalExpression" : "BinaryExpression") | ||
return this.parseExprOp(node, leftStart, minPrec, noIn) | ||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn) | ||
} | ||
@@ -185,7 +188,7 @@ } | ||
} | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let expr = this.parseExprSubscripts(refShorthandDefaultPos) | ||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr | ||
while (this.type.postfix && !this.canInsertSemicolon()) { | ||
let node = this.startNodeAt(start) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.operator = this.value | ||
@@ -204,33 +207,37 @@ node.prefix = false | ||
pp.parseExprSubscripts = function(refShorthandDefaultPos) { | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let expr = this.parseExprAtom(refShorthandDefaultPos) | ||
if (refShorthandDefaultPos && refShorthandDefaultPos.start) return expr | ||
return this.parseSubscripts(expr, start) | ||
return this.parseSubscripts(expr, startPos, startLoc) | ||
} | ||
pp.parseSubscripts = function(base, start, noCalls) { | ||
if (this.eat(tt.dot)) { | ||
let node = this.startNodeAt(start) | ||
node.object = base | ||
node.property = this.parseIdent(true) | ||
node.computed = false | ||
return this.parseSubscripts(this.finishNode(node, "MemberExpression"), start, noCalls) | ||
} else if (this.eat(tt.bracketL)) { | ||
let node = this.startNodeAt(start) | ||
node.object = base | ||
node.property = this.parseExpression() | ||
node.computed = true | ||
this.expect(tt.bracketR) | ||
return this.parseSubscripts(this.finishNode(node, "MemberExpression"), start, noCalls) | ||
} else if (!noCalls && this.eat(tt.parenL)) { | ||
let node = this.startNodeAt(start) | ||
node.callee = base | ||
node.arguments = this.parseExprList(tt.parenR, false) | ||
return this.parseSubscripts(this.finishNode(node, "CallExpression"), start, noCalls) | ||
} else if (this.type === tt.backQuote) { | ||
let node = this.startNodeAt(start) | ||
node.tag = base | ||
node.quasi = this.parseTemplate() | ||
return this.parseSubscripts(this.finishNode(node, "TaggedTemplateExpression"), start, noCalls) | ||
} return base | ||
pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { | ||
for (;;) { | ||
if (this.eat(tt.dot)) { | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.object = base | ||
node.property = this.parseIdent(true) | ||
node.computed = false | ||
base = this.finishNode(node, "MemberExpression") | ||
} else if (this.eat(tt.bracketL)) { | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.object = base | ||
node.property = this.parseExpression() | ||
node.computed = true | ||
this.expect(tt.bracketR) | ||
base = this.finishNode(node, "MemberExpression") | ||
} else if (!noCalls && this.eat(tt.parenL)) { | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.callee = base | ||
node.arguments = this.parseExprList(tt.parenR, false) | ||
base = this.finishNode(node, "CallExpression") | ||
} else if (this.type === tt.backQuote) { | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.tag = base | ||
node.quasi = this.parseTemplate() | ||
base = this.finishNode(node, "TaggedTemplateExpression") | ||
} else { | ||
return base | ||
} | ||
} | ||
} | ||
@@ -244,3 +251,3 @@ | ||
pp.parseExprAtom = function(refShorthandDefaultPos) { | ||
let node | ||
let node, canBeArrow = this.potentialArrowAt == this.start | ||
switch (this.type) { | ||
@@ -258,7 +265,6 @@ case tt._this: | ||
case tt.name: | ||
let start = this.markPosition() | ||
let startPos = this.start, startLoc = this.startLoc | ||
let id = this.parseIdent(this.type !== tt.name) | ||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) { | ||
return this.parseArrowExpression(this.startNodeAt(start), [id]) | ||
} | ||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]) | ||
return id | ||
@@ -283,3 +289,3 @@ | ||
case tt.parenL: | ||
return this.parseParenAndDistinguishExpression() | ||
return this.parseParenAndDistinguishExpression(canBeArrow) | ||
@@ -333,4 +339,4 @@ case tt.bracketL: | ||
pp.parseParenAndDistinguishExpression = function() { | ||
let start = this.markPosition(), val | ||
pp.parseParenAndDistinguishExpression = function(canBeArrow) { | ||
let startPos = this.start, startLoc = this.startLoc, val | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -340,6 +346,7 @@ this.next() | ||
if (this.options.ecmaVersion >= 7 && this.type === tt._for) { | ||
return this.parseComprehension(this.startNodeAt(start), true) | ||
return this.parseComprehension(this.startNodeAt(startPos, startLoc), true) | ||
} | ||
let innerStart = this.markPosition(), exprList = [], first = true | ||
let innerStartPos = this.start, innerStartLoc = this.startLoc | ||
let exprList = [], first = true | ||
let refShorthandDefaultPos = {start: 0}, spreadStart, innerParenStart | ||
@@ -350,3 +357,3 @@ while (this.type !== tt.parenR) { | ||
spreadStart = this.start | ||
exprList.push(this.parseRest()) | ||
exprList.push(this.parseParenItem(this.parseRest())) | ||
break | ||
@@ -357,11 +364,11 @@ } else { | ||
} | ||
exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos)) | ||
exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem)) | ||
} | ||
} | ||
let innerEnd = this.markPosition() | ||
let innerEndPos = this.start, innerEndLoc = this.startLoc | ||
this.expect(tt.parenR) | ||
if (!this.canInsertSemicolon() && this.eat(tt.arrow)) { | ||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { | ||
if (innerParenStart) this.unexpected(innerParenStart) | ||
return this.parseArrowExpression(this.startNodeAt(start), exprList) | ||
return this.parseParenArrowList(startPos, startLoc, exprList) | ||
} | ||
@@ -374,5 +381,5 @@ | ||
if (exprList.length > 1) { | ||
val = this.startNodeAt(innerStart) | ||
val = this.startNodeAt(innerStartPos, innerStartLoc) | ||
val.expressions = exprList | ||
this.finishNodeAt(val, "SequenceExpression", innerEnd) | ||
this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc) | ||
} else { | ||
@@ -386,3 +393,3 @@ val = exprList[0] | ||
if (this.options.preserveParens) { | ||
let par = this.startNodeAt(start) | ||
let par = this.startNodeAt(startPos, startLoc) | ||
par.expression = val | ||
@@ -395,2 +402,10 @@ return this.finishNode(par, "ParenthesizedExpression") | ||
pp.parseParenItem = function(item) { | ||
return item | ||
} | ||
pp.parseParenArrowList = function(startPos, startLoc, exprList) { | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList) | ||
} | ||
// New's precedence is slightly tricky. It must allow its argument | ||
@@ -412,4 +427,4 @@ // to be a `[]` or dot subscript expression, but not a call — at | ||
} | ||
let start = this.markPosition() | ||
node.callee = this.parseSubscripts(this.parseExprAtom(), start, true) | ||
let startPos = this.start, startLoc = this.startLoc | ||
node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true) | ||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false) | ||
@@ -461,8 +476,10 @@ else node.arguments = empty | ||
let prop = this.startNode(), isGenerator, start | ||
let prop = this.startNode(), isGenerator, startPos, startLoc | ||
if (this.options.ecmaVersion >= 6) { | ||
prop.method = false | ||
prop.shorthand = false | ||
if (isPattern || refShorthandDefaultPos) | ||
start = this.markPosition() | ||
if (isPattern || refShorthandDefaultPos) { | ||
startPos = this.start | ||
startLoc = this.startLoc | ||
} | ||
if (!isPattern) | ||
@@ -472,4 +489,12 @@ isGenerator = this.eat(tt.star) | ||
this.parsePropertyName(prop) | ||
if (this.eat(tt.colon)) { | ||
prop.value = isPattern ? this.parseMaybeDefault() : this.parseMaybeAssign(false, refShorthandDefaultPos) | ||
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos) | ||
this.checkPropClash(prop, propHash) | ||
node.properties.push(this.finishNode(prop, "Property")) | ||
} | ||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") | ||
} | ||
pp.parsePropertyValue = function(prop, isPattern, isGenerator, startPos, startLoc, refShorthandDefaultPos) { | ||
if (this.eat(tt.colon)) { | ||
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos) | ||
prop.kind = "init" | ||
@@ -495,7 +520,7 @@ } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) { | ||
this.raise(prop.key.start, "Binding " + prop.key.name) | ||
prop.value = this.parseMaybeDefault(start, prop.key) | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key) | ||
} else if (this.type === tt.eq && refShorthandDefaultPos) { | ||
if (!refShorthandDefaultPos.start) | ||
refShorthandDefaultPos.start = this.start | ||
prop.value = this.parseMaybeDefault(start, prop.key) | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key) | ||
} else { | ||
@@ -506,7 +531,2 @@ prop.value = prop.key | ||
} else this.unexpected() | ||
this.checkPropClash(prop, propHash) | ||
node.properties.push(this.finishNode(prop, "Property")) | ||
} | ||
return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression") | ||
} | ||
@@ -634,3 +654,3 @@ | ||
(this.strict && reservedWords.strict(this.value)) && | ||
(this.options.ecmaVersion >= 6 || | ||
(this.options.ecmaVersion >= 6 || | ||
this.input.slice(this.start, this.end).indexOf("\\") == -1))) | ||
@@ -637,0 +657,0 @@ this.raise(this.start, "The keyword '" + this.value + "' is reserved") |
@@ -40,3 +40,3 @@ // Acorn is a tiny, fast JavaScript parser written in JavaScript. | ||
export const version = "1.0.3" | ||
export const version = "1.1.0" | ||
@@ -52,5 +52,5 @@ // The main exported interface (under `self.acorn` when in the | ||
let p = parser(options, input) | ||
let startPos = p.options.locations ? [p.pos, p.curPosition()] : p.pos | ||
let startPos = p.pos, startLoc = p.options.locations && p.curPosition() | ||
p.nextToken() | ||
return p.parseTopLevel(p.options.program || p.startNodeAt(startPos)) | ||
return p.parseTopLevel(p.options.program || p.startNodeAt(startPos, startLoc)) | ||
} | ||
@@ -57,0 +57,0 @@ |
@@ -64,5 +64,1 @@ import {Parser} from "./state" | ||
} | ||
pp.markPosition = function() { | ||
return this.options.locations ? [this.start, this.startLoc] : this.start | ||
} |
@@ -16,2 +16,7 @@ import {LooseParser} from "./state" | ||
case "ParenthesizedExpression": | ||
expr.expression = this.checkLVal(expr.expression, binding) | ||
return expr | ||
// FIXME recursively check contents | ||
case "ObjectPattern": | ||
@@ -18,0 +23,0 @@ case "ArrayPattern": |
@@ -257,3 +257,3 @@ import {LooseParser} from "./state" | ||
if (this.semicolon()) continue | ||
let method = this.startNode(), isGenerator, start | ||
let method = this.startNode(), isGenerator | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -260,0 +260,0 @@ method['static'] = false |
@@ -57,3 +57,3 @@ import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from ".." | ||
} | ||
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number/i.test(msg)) { | ||
} else if (/invalid (unicode|regexp|number)|expecting unicode|octal literal|is reserved|directly after number|expected number in radix/i.test(msg)) { | ||
while (pos < this.input.length && !isSpace(this.input.charCodeAt(pos))) ++pos | ||
@@ -60,0 +60,0 @@ } else if (/character escape|expected hexadecimal/i.test(msg)) { |
@@ -42,2 +42,6 @@ import {types as tt} from "./tokentype" | ||
case "ParenthesizedExpression": | ||
node.expression = this.toAssignable(node.expression, isBinding) | ||
break | ||
case "MemberExpression": | ||
@@ -125,7 +129,11 @@ if (!isBinding) break | ||
} else if (this.type === tt.ellipsis) { | ||
elts.push(this.parseRest()) | ||
let rest = this.parseRest() | ||
this.parseBindingListItem(rest) | ||
elts.push(rest) | ||
this.expect(close) | ||
break | ||
} else { | ||
elts.push(this.parseMaybeDefault()) | ||
let elem = this.parseMaybeDefault(this.start, this.startLoc) | ||
this.parseBindingListItem(elem) | ||
elts.push(elem) | ||
} | ||
@@ -136,9 +144,12 @@ } | ||
pp.parseBindingListItem = function(param) { | ||
return param | ||
} | ||
// Parses assignment pattern around given atom if possible. | ||
pp.parseMaybeDefault = function(startPos, left) { | ||
startPos = startPos || this.markPosition() | ||
pp.parseMaybeDefault = function(startPos, startLoc, left) { | ||
left = left || this.parseBindingAtom() | ||
if (!this.eat(tt.eq)) return left | ||
let node = this.startNodeAt(startPos) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.operator = "=" | ||
@@ -189,2 +200,6 @@ node.left = left | ||
case "ParenthesizedExpression": | ||
this.checkLVal(expr.expression, isBinding, checkClashes) | ||
break | ||
default: | ||
@@ -191,0 +206,0 @@ this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue") |
@@ -22,13 +22,11 @@ import {Parser} from "./state" | ||
pp.startNodeAt = function(pos) { | ||
let node = new Node, start = pos | ||
if (this.options.locations) { | ||
node.loc = new SourceLocation(this, start[1]) | ||
start = pos[0] | ||
} | ||
node.start = start | ||
pp.startNodeAt = function(pos, loc) { | ||
let node = new Node | ||
node.start = pos | ||
if (this.options.locations) | ||
node.loc = new SourceLocation(this, loc) | ||
if (this.options.directSourceFile) | ||
node.sourceFile = this.options.directSourceFile | ||
if (this.options.ranges) | ||
node.range = [start, 0] | ||
node.range = [pos, 0] | ||
return node | ||
@@ -51,6 +49,7 @@ } | ||
pp.finishNodeAt = function(node, type, pos) { | ||
if (this.options.locations) { node.loc.end = pos[1]; pos = pos[0] } | ||
pp.finishNodeAt = function(node, type, pos, loc) { | ||
node.type = type | ||
node.end = pos | ||
if (this.options.locations) | ||
node.loc.end = loc | ||
if (this.options.ranges) | ||
@@ -57,0 +56,0 @@ node.range[1] = pos |
@@ -48,2 +48,5 @@ import {reservedWords, keywords} from "./identifier" | ||
// Used to signify the start of a potential arrow function | ||
this.potentialArrowAt = -1 | ||
// Flags to track whether we are in a function, a generator. | ||
@@ -50,0 +53,0 @@ this.inFunction = this.inGenerator = false |
@@ -372,4 +372,3 @@ import {types as tt} from "./tokentype" | ||
let decl = this.startNode() | ||
decl.id = this.parseBindingAtom() | ||
this.checkLVal(decl.id, true) | ||
this.parseVarId(decl) | ||
if (this.eat(tt.eq)) { | ||
@@ -390,2 +389,7 @@ decl.init = this.parseMaybeAssign(isFor) | ||
pp.parseVarId = function(decl) { | ||
decl.id = this.parseBindingAtom() | ||
this.checkLVal(decl.id, true) | ||
} | ||
// Parse a function declaration or literal (depending on the | ||
@@ -400,4 +404,3 @@ // `isStatement` parameter). | ||
node.id = this.parseIdent() | ||
this.expect(tt.parenL) | ||
node.params = this.parseBindingList(tt.parenR, false, false) | ||
this.parseFunctionParams(node) | ||
this.parseFunctionBody(node, allowExpressionBody) | ||
@@ -407,2 +410,7 @@ return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
pp.parseFunctionParams = function(node) { | ||
this.expect(tt.parenL) | ||
node.params = this.parseBindingList(tt.parenR, false, false) | ||
} | ||
// Parse a class declaration or literal (depending on the | ||
@@ -413,4 +421,4 @@ // `isStatement` parameter). | ||
this.next() | ||
node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null | ||
node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null | ||
this.parseClassId(node, isStatement) | ||
this.parseClassSuper(node) | ||
let classBody = this.startNode() | ||
@@ -446,4 +454,3 @@ classBody.body = [] | ||
} | ||
method.value = this.parseMethod(isGenerator) | ||
classBody.body.push(this.finishNode(method, "MethodDefinition")) | ||
this.parseClassMethod(classBody, method, isGenerator) | ||
} | ||
@@ -454,2 +461,15 @@ node.body = this.finishNode(classBody, "ClassBody") | ||
pp.parseClassMethod = function(classBody, method, isGenerator) { | ||
method.value = this.parseMethod(isGenerator) | ||
classBody.body.push(this.finishNode(method, "MethodDefinition")) | ||
} | ||
pp.parseClassId = function(node, isStatement) { | ||
node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null | ||
} | ||
pp.parseClassSuper = function(node) { | ||
node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null | ||
} | ||
// Parses module export declaration. | ||
@@ -483,3 +503,3 @@ | ||
// export var|const|let|function|class ... | ||
if (this.type.keyword) { | ||
if (this.shouldParseExportStatement()) { | ||
node.declaration = this.parseStatement(true) | ||
@@ -501,2 +521,6 @@ node.specifiers = [] | ||
pp.shouldParseExportStatement = function() { | ||
return this.type.keyword | ||
} | ||
// Parses a comma-separated list of module exports. | ||
@@ -503,0 +527,0 @@ |
@@ -273,3 +273,3 @@ import {isIdentifierStart, isIdentifierChar} from "./identifier" | ||
this.input.charCodeAt(this.pos + 3) == 45) { | ||
if (this.inModule) unexpected() | ||
if (this.inModule) this.unexpected() | ||
// `<!--`, an XML-style comment that should be interpreted as a line comment | ||
@@ -276,0 +276,0 @@ this.skipLineComment(4) |
@@ -116,3 +116,3 @@ // ## Token types | ||
kw("for", {isLoop: true}) | ||
kw("function") | ||
kw("function", startsExpr) | ||
kw("if") | ||
@@ -119,0 +119,0 @@ kw("return", beforeExpr) |
@@ -19,3 +19,3 @@ // AST walker module for Mozilla Parser API compatible trees | ||
export function simple(node, visitors, base, state) { | ||
export function simple(node, visitors, base, state, override) { | ||
if (!base) base = exports.base | ||
@@ -26,3 +26,3 @@ ;(function c(node, st, override) { | ||
if (found) found(node, st) | ||
})(node, state) | ||
})(node, state, override) | ||
} | ||
@@ -51,7 +51,7 @@ | ||
// nodes). | ||
export function recursive(node, state, funcs, base) { | ||
export function recursive(node, state, funcs, base, override) { | ||
let visitor = funcs ? exports.make(funcs, base) : base | ||
;(function c(node, st, override) { | ||
visitor[override || node.type](node, st, c) | ||
})(node, state) | ||
})(node, state, override) | ||
} | ||
@@ -193,7 +193,10 @@ | ||
} | ||
base.ThrowStatement = base.SpreadElement = base.RestElement = | ||
base.ThrowStatement = base.SpreadElement = | ||
(node, st, c) => c(node.argument, st, "Expression") | ||
base.TryStatement = (node, st, c) => { | ||
c(node.block, st, "Statement") | ||
if (node.handler) c(node.handler.body, st, "ScopeBody") | ||
if (node.handler) { | ||
c(node.handler.param, st, "Pattern") | ||
c(node.handler.body, st, "ScopeBody") | ||
} | ||
if (node.finalizer) c(node.finalizer, st, "Statement") | ||
@@ -226,2 +229,3 @@ } | ||
let decl = node.declarations[i] | ||
c(decl.id, st, "Pattern") | ||
if (decl.init) c(decl.init, st, "Expression") | ||
@@ -231,8 +235,34 @@ } | ||
base.Function = (node, st, c) => c(node.body, st, "ScopeBody") | ||
base.Function = (node, st, c) => { | ||
for (let i = 0; i < node.params.length; i++) | ||
c(node.params[i], st, "Pattern") | ||
c(node.body, st, "ScopeBody") | ||
} | ||
base.ScopeBody = (node, st, c) => c(node, st, "Statement") | ||
base.Pattern = (node, st, c) => { | ||
if (node.type == "Identifier") | ||
c(node, st, "VariablePattern") | ||
else if (node.type == "MemberExpression") | ||
c(node, st, "MemberPattern") | ||
else | ||
c(node, st) | ||
} | ||
base.VariablePattern = ignore | ||
base.MemberPattern = skipThrough | ||
base.RestElement = (node, st, c) => c(node.argument, st, "Pattern") | ||
base.ArrayPattern = (node, st, c) => { | ||
for (let i = 0; i < node.elements.length; ++i) { | ||
let elt = node.elements[i] | ||
if (elt) c(elt, st, "Pattern") | ||
} | ||
} | ||
base.ObjectPattern = (node, st, c) => { | ||
for (let i = 0; i < node.properties.length; ++i) | ||
c(node.properties[i].value, st, "Pattern") | ||
} | ||
base.Expression = skipThrough | ||
base.ThisExpression = base.Super = base.MetaProperty = ignore | ||
base.ArrayExpression = base.ArrayPattern = (node, st, c) => { | ||
base.ArrayExpression = (node, st, c) => { | ||
for (let i = 0; i < node.elements.length; ++i) { | ||
@@ -243,3 +273,3 @@ let elt = node.elements[i] | ||
} | ||
base.ObjectExpression = base.ObjectPattern = (node, st, c) => { | ||
base.ObjectExpression = (node, st, c) => { | ||
for (let i = 0; i < node.properties.length; ++i) | ||
@@ -256,6 +286,10 @@ c(node.properties[i], st) | ||
} | ||
base.BinaryExpression = base.AssignmentExpression = base.AssignmentPattern = base.LogicalExpression = (node, st, c) => { | ||
base.BinaryExpression = base.LogicalExpression = (node, st, c) => { | ||
c(node.left, st, "Expression") | ||
c(node.right, st, "Expression") | ||
} | ||
base.AssignmentExpression = base.AssignmentPattern = (node, st, c) => { | ||
c(node.left, st, "Pattern") | ||
c(node.right, st, "Expression") | ||
} | ||
base.ConditionalExpression = (node, st, c) => { | ||
@@ -275,3 +309,5 @@ c(node.test, st, "Expression") | ||
} | ||
base.ExportNamedDeclaration = base.ExportDefaultDeclaration = (node, st, c) => c(node.declaration, st) | ||
base.ExportNamedDeclaration = base.ExportDefaultDeclaration = (node, st, c) => { | ||
if (node.declaration) c(node.declaration, st) | ||
} | ||
base.ImportDeclaration = (node, st, c) => { | ||
@@ -287,3 +323,5 @@ for (let i = 0; i < node.specifiers.length; i++) | ||
} | ||
base.ClassDeclaration = base.ClassExpression = (node, st, c) => { | ||
base.ClassDeclaration = base.ClassExpression = (node, st, c) => c(node, st, "Class") | ||
base.Class = (node, st, c) => { | ||
c(node.id, st, "Pattern") | ||
if (node.superClass) c(node.superClass, st, "Expression") | ||
@@ -290,0 +328,0 @@ for (let i = 0; i < node.body.body.length; i++) |
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
466646
11291
378
1