Comparing version 3.3.0 to 4.0.0
@@ -0,1 +1,29 @@ | ||
## 4.0.0 (2016-08-07) | ||
### Breaking changes | ||
The default `ecmaVersion` option value is now 7. | ||
A number of internal method signatures changed, so plugins might need | ||
to be updated. | ||
### Bug fixes | ||
The parser now raises errors on duplicated export names. | ||
`arguments` and `eval` can now be used in shorthand properties. | ||
Duplicate parameter names in non-simple argument lists now always | ||
produce an error. | ||
### New features | ||
The `ecmaVersion` option now also accepts year-style version numbers | ||
(2015, etc). | ||
Support for `async`/`await` syntax when `ecmaVersion` is >= 8. | ||
Support for trailing commas in call expressions when `ecmaVersion` is | ||
>= 8. | ||
## 3.3.0 (2016-07-25) | ||
@@ -2,0 +30,0 @@ |
@@ -1,2 +0,2 @@ | ||
import acorn, { SourceLocation, tokTypes, tokenizer, Node, lineBreak, isNewLine, getLineInfo, Token, lineBreakG } from './acorn.js'; | ||
import { defaultOptions, addLooseExports, SourceLocation, tokTypes, tokenizer, Node, lineBreak, isNewLine, getLineInfo, Token, lineBreakG } from './acorn.js'; | ||
@@ -22,2 +22,3 @@ // Registered plugins | ||
this.nextLineStart = this.lineEnd(this.curLineStart) + 1 | ||
this.inAsync = false | ||
// Load plugins | ||
@@ -460,2 +461,7 @@ this.options.pluginsLoose = options.pluginsLoose || {} | ||
default: | ||
if (this.toks.isAsyncFunction()) { | ||
this.next() | ||
this.next() | ||
return this.parseFunction(node, true, true) | ||
} | ||
var expr = this.parseExpression() | ||
@@ -554,3 +560,3 @@ if (isDummy(expr)) { | ||
if (this$1.semicolon()) continue | ||
var method = this$1.startNode(), isGenerator | ||
var method = this$1.startNode(), isGenerator, isAsync | ||
if (this$1.options.ecmaVersion >= 6) { | ||
@@ -570,2 +576,10 @@ method.static = false | ||
} | ||
if (!method.computed && | ||
method.key.type === "Identifier" && method.key.name === "async" && this$1.tok.type !== tokTypes.parenL && | ||
!this$1.canInsertSemicolon()) { | ||
this$1.parsePropertyName(method) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (this$1.options.ecmaVersion >= 5 && method.key.type === "Identifier" && | ||
@@ -578,3 +592,3 @@ !method.computed && (method.key.name === "get" || method.key.name === "set") && | ||
} else { | ||
if (!method.computed && !method.static && !isGenerator && ( | ||
if (!method.computed && !method.static && !isGenerator && !isAsync && ( | ||
method.key.type === "Identifier" && method.key.name === "constructor" || | ||
@@ -586,3 +600,3 @@ method.key.type === "Literal" && method.key.value === "constructor")) { | ||
} | ||
method.value = this$1.parseMethod(isGenerator) | ||
method.value = this$1.parseMethod(isGenerator, isAsync) | ||
} | ||
@@ -603,3 +617,4 @@ node.body.body.push(this$1.finishNode(method, "MethodDefinition")) | ||
lp$1.parseFunction = function(node, isStatement) { | ||
lp$1.parseFunction = function(node, isStatement, isAsync) { | ||
var oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
@@ -609,6 +624,11 @@ if (this.options.ecmaVersion >= 6) { | ||
} | ||
if (this.options.ecmaVersion >= 8) { | ||
node.async = !!isAsync | ||
} | ||
if (this.tok.type === tokTypes.name) node.id = this.parseIdent() | ||
else if (isStatement) node.id = this.dummyIdent() | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.body = this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
@@ -625,4 +645,6 @@ } | ||
if (this.eat(tokTypes._default)) { | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
var isParenL = this.tok.type === tokTypes.parenL | ||
var expr = this.parseMaybeAssign() | ||
if (expr.id) { | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
@@ -637,3 +659,3 @@ case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
} | ||
if (this.tok.type.keyword || this.toks.isLet()) { | ||
if (this.tok.type.keyword || this.toks.isLet() || this.toks.isAsyncFunction()) { | ||
node.declaration = this.parseStatement() | ||
@@ -845,3 +867,6 @@ node.specifiers = [] | ||
var start = this.storeCurrentPos(), expr | ||
if (this.tok.type.prefix) { | ||
if (this.options.ecmaVersion >= 8 && this.inAsync && this.toks.isContextual("await")) { | ||
expr = this.parseAwait() | ||
sawUnary = true | ||
} else if (this.tok.type.prefix) { | ||
var node = this.startNode(), update = this.tok.type === tokTypes.incDec | ||
@@ -899,2 +924,4 @@ if (!update) sawUnary = true | ||
var maybeAsyncArrow = base.type === "Identifier" && base.name === "async" && !this$1.canInsertSemicolon() | ||
if (this$1.eat(tokTypes.dot)) { | ||
@@ -920,5 +947,8 @@ var node = this$1.startNodeAt(start) | ||
} else if (!noCalls && this$1.tok.type == tokTypes.parenL) { | ||
var exprList = this$1.parseExprList(tokTypes.parenR) | ||
if (maybeAsyncArrow && this$1.eat(tokTypes.arrow)) | ||
return this$1.parseArrowExpression(this$1.startNodeAt(start), exprList, true) | ||
var node$2 = this$1.startNodeAt(start) | ||
node$2.callee = base | ||
node$2.arguments = this$1.parseExprList(tokTypes.parenR) | ||
node$2.arguments = exprList | ||
base = this$1.finishNode(node$2, "CallExpression") | ||
@@ -949,3 +979,12 @@ } else if (this$1.tok.type == tokTypes.backQuote) { | ||
var id = this.parseIdent() | ||
return this.eat(tokTypes.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id]) : id | ||
var isAsync = false | ||
if (id.name === "async" && !this.canInsertSemicolon()) { | ||
if (this.eat(tokTypes._function)) | ||
return this.parseFunction(this.startNodeAt(start), false, true) | ||
if (this.tok.type === tokTypes.name) { | ||
id = this.parseIdent() | ||
isAsync = true | ||
} | ||
} | ||
return this.eat(tokTypes.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id], isAsync) : id | ||
@@ -981,3 +1020,7 @@ case tokTypes.regexp: | ||
if (this.eat(tokTypes.arrow)) { | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), inner.expressions || (isDummy(inner) ? [] : [inner])) | ||
// (a,)=>a // SequenceExpression makes dummy in the last hole. Drop the dummy. | ||
var params = inner.expressions || [inner] | ||
if (params.length && isDummy(params[params.length - 1])) | ||
params.pop() | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), params) | ||
} | ||
@@ -1082,3 +1125,3 @@ if (this.options.preserveParens) { | ||
while (!this.closes(tokTypes.braceR, indent, line)) { | ||
var prop = this$1.startNode(), isGenerator, start | ||
var prop = this$1.startNode(), isGenerator, isAsync, start | ||
if (this$1.options.ecmaVersion >= 6) { | ||
@@ -1091,2 +1134,10 @@ start = this$1.storeCurrentPos() | ||
this$1.parsePropertyName(prop) | ||
if (!prop.computed && | ||
prop.key.type === "Identifier" && prop.key.name === "async" && this$1.tok.type !== tokTypes.parenL && | ||
!this$1.canInsertSemicolon()) { | ||
this$1.parsePropertyName(prop) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (isDummy(prop.key)) { if (isDummy(this$1.parseMaybeAssign())) this$1.next(); this$1.eat(tokTypes.comma); continue } | ||
@@ -1099,3 +1150,3 @@ if (this$1.eat(tokTypes.colon)) { | ||
prop.method = true | ||
prop.value = this$1.parseMethod(isGenerator) | ||
prop.value = this$1.parseMethod(isGenerator, isAsync) | ||
} else if (this$1.options.ecmaVersion >= 5 && prop.key.type === "Identifier" && | ||
@@ -1172,2 +1223,4 @@ !prop.computed && (prop.key.name === "get" || prop.key.name === "set") && | ||
} | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = false | ||
} | ||
@@ -1220,17 +1273,27 @@ | ||
lp$2.parseMethod = function(isGenerator) { | ||
var node = this.startNode() | ||
lp$2.parseMethod = function(isGenerator, isAsync) { | ||
var node = this.startNode(), oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 6) | ||
node.generator = !!isGenerator | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.generator = isGenerator || false | ||
node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== tokTypes.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "FunctionExpression") | ||
} | ||
lp$2.parseArrowExpression = function(node, params) { | ||
lp$2.parseArrowExpression = function(node, params, isAsync) { | ||
var oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.toAssignableList(params, true) | ||
node.expression = this.tok.type !== tokTypes.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "ArrowFunctionExpression") | ||
@@ -1269,4 +1332,11 @@ } | ||
acorn.defaultOptions.tabSize = 4 | ||
lp$2.parseAwait = function() { | ||
var node = this.startNode() | ||
this.next() | ||
node.argument = this.parseMaybeUnary() | ||
return this.finishNode(node, "AwaitExpression") | ||
} | ||
defaultOptions.tabSize = 4 | ||
function parse_dammit(input, options) { | ||
@@ -1278,6 +1348,4 @@ var p = new LooseParser(input, options) | ||
acorn.parse_dammit = parse_dammit | ||
acorn.LooseParser = LooseParser | ||
acorn.pluginsLoose = pluginsLoose | ||
addLooseExports(parse_dammit, LooseParser, pluginsLoose) | ||
export { parse_dammit, LooseParser, pluginsLoose }; |
@@ -5,6 +5,4 @@ (function (global, factory) { | ||
(factory((global.acorn = global.acorn || {}, global.acorn.loose = global.acorn.loose || {}),global.acorn)); | ||
}(this, function (exports,acorn) { 'use strict'; | ||
}(this, function (exports,__acorn_js) { 'use strict'; | ||
var acorn__default = 'default' in acorn ? acorn['default'] : acorn; | ||
// Registered plugins | ||
@@ -16,9 +14,9 @@ var pluginsLoose = {} | ||
this.toks = acorn.tokenizer(input, options) | ||
this.toks = __acorn_js.tokenizer(input, options) | ||
this.options = this.toks.options | ||
this.input = this.toks.input | ||
this.tok = this.last = {type: acorn.tokTypes.eof, start: 0, end: 0} | ||
this.tok = this.last = {type: __acorn_js.tokTypes.eof, start: 0, end: 0} | ||
if (this.options.locations) { | ||
var here = this.toks.curPosition() | ||
this.tok.loc = new acorn.SourceLocation(this.toks, here, here) | ||
this.tok.loc = new __acorn_js.SourceLocation(this.toks, here, here) | ||
} | ||
@@ -30,2 +28,3 @@ this.ahead = [] // Tokens ahead | ||
this.nextLineStart = this.lineEnd(this.curLineStart) + 1 | ||
this.inAsync = false | ||
// Load plugins | ||
@@ -37,3 +36,3 @@ this.options.pluginsLoose = options.pluginsLoose || {} | ||
LooseParser.prototype.startNode = function startNode () { | ||
return new acorn.Node(this.toks, this.tok.start, this.options.locations ? this.tok.loc.start : null) | ||
return new __acorn_js.Node(this.toks, this.tok.start, this.options.locations ? this.tok.loc.start : null) | ||
}; | ||
@@ -47,5 +46,5 @@ | ||
if (this.options.locations) { | ||
return new acorn.Node(this.toks, pos[0], pos[1]) | ||
return new __acorn_js.Node(this.toks, pos[0], pos[1]) | ||
} else { | ||
return new acorn.Node(this.toks, pos) | ||
return new __acorn_js.Node(this.toks, pos) | ||
} | ||
@@ -72,3 +71,3 @@ }; | ||
dummy.range[1] = dummy.start | ||
this.last = {type: acorn.tokTypes.name, start: dummy.start, end: dummy.start, loc: dummy.loc} | ||
this.last = {type: __acorn_js.tokTypes.name, start: dummy.start, end: dummy.start, loc: dummy.loc} | ||
return dummy | ||
@@ -99,16 +98,16 @@ }; | ||
LooseParser.prototype.isContextual = function isContextual (name) { | ||
return this.tok.type === acorn.tokTypes.name && this.tok.value === name | ||
return this.tok.type === __acorn_js.tokTypes.name && this.tok.value === name | ||
}; | ||
LooseParser.prototype.eatContextual = function eatContextual (name) { | ||
return this.tok.value === name && this.eat(acorn.tokTypes.name) | ||
return this.tok.value === name && this.eat(__acorn_js.tokTypes.name) | ||
}; | ||
LooseParser.prototype.canInsertSemicolon = function canInsertSemicolon () { | ||
return this.tok.type === acorn.tokTypes.eof || this.tok.type === acorn.tokTypes.braceR || | ||
acorn.lineBreak.test(this.input.slice(this.last.end, this.tok.start)) | ||
return this.tok.type === __acorn_js.tokTypes.eof || this.tok.type === __acorn_js.tokTypes.braceR || | ||
__acorn_js.lineBreak.test(this.input.slice(this.last.end, this.tok.start)) | ||
}; | ||
LooseParser.prototype.semicolon = function semicolon () { | ||
return this.eat(acorn.tokTypes.semi) | ||
return this.eat(__acorn_js.tokTypes.semi) | ||
}; | ||
@@ -137,3 +136,3 @@ | ||
LooseParser.prototype.lineEnd = function lineEnd (pos) { | ||
while (pos < this.input.length && !acorn.isNewLine(this.input.charCodeAt(pos))) ++pos | ||
while (pos < this.input.length && !__acorn_js.isNewLine(this.input.charCodeAt(pos))) ++pos | ||
return pos | ||
@@ -154,3 +153,3 @@ }; | ||
LooseParser.prototype.closes = function closes (closeTok, indent, line, blockHeuristic) { | ||
if (this.tok.type === closeTok || this.tok.type === acorn.tokTypes.eof) return true | ||
if (this.tok.type === closeTok || this.tok.type === __acorn_js.tokTypes.eof) return true | ||
return line != this.curLineStart && this.curIndent < indent && this.tokenStartsLine() && | ||
@@ -188,3 +187,3 @@ (!blockHeuristic || this.nextLineStart >= this.input.length || | ||
function isSpace(ch) { | ||
return (ch < 14 && ch > 8) || ch === 32 || ch === 160 || acorn.isNewLine(ch) | ||
return (ch < 14 && ch > 8) || ch === 32 || ch === 160 || __acorn_js.isNewLine(ch) | ||
} | ||
@@ -216,9 +215,9 @@ | ||
this$1.toks.next() | ||
if (this$1.toks.type === acorn.tokTypes.dot && | ||
if (this$1.toks.type === __acorn_js.tokTypes.dot && | ||
this$1.input.substr(this$1.toks.end, 1) === "." && | ||
this$1.options.ecmaVersion >= 6) { | ||
this$1.toks.end++ | ||
this$1.toks.type = acorn.tokTypes.ellipsis | ||
this$1.toks.type = __acorn_js.tokTypes.ellipsis | ||
} | ||
return new acorn.Token(this$1.toks) | ||
return new __acorn_js.Token(this$1.toks) | ||
} catch(e) { | ||
@@ -232,10 +231,10 @@ if (!(e instanceof SyntaxError)) throw e | ||
if (/string/.test(msg)) { | ||
replace = {start: e.pos, end: pos, type: acorn.tokTypes.string, value: this$1.input.slice(e.pos + 1, pos)} | ||
replace = {start: e.pos, end: pos, type: __acorn_js.tokTypes.string, value: this$1.input.slice(e.pos + 1, pos)} | ||
} else if (/regular expr/i.test(msg)) { | ||
var re = this$1.input.slice(e.pos, pos) | ||
try { re = new RegExp(re) } catch(e) {} | ||
replace = {start: e.pos, end: pos, type: acorn.tokTypes.regexp, value: re} | ||
replace = {start: e.pos, end: pos, type: __acorn_js.tokTypes.regexp, value: re} | ||
} else if (/template/.test(msg)) { | ||
replace = {start: e.pos, end: pos, | ||
type: acorn.tokTypes.template, | ||
type: __acorn_js.tokTypes.template, | ||
value: this$1.input.slice(e.pos, pos)} | ||
@@ -250,3 +249,3 @@ } else { | ||
var ch = this$1.input.charCodeAt(pos++) | ||
if (ch === 34 || ch === 39 || acorn.isNewLine(ch)) break | ||
if (ch === 34 || ch === 39 || __acorn_js.isNewLine(ch)) break | ||
} | ||
@@ -262,9 +261,9 @@ } else if (/unexpected character/i.test(msg)) { | ||
this$1.resetTo(pos) | ||
if (replace === true) replace = {start: pos, end: pos, type: acorn.tokTypes.name, value: "✖"} | ||
if (replace === true) replace = {start: pos, end: pos, type: __acorn_js.tokTypes.name, value: "✖"} | ||
if (replace) { | ||
if (this$1.options.locations) | ||
replace.loc = new acorn.SourceLocation( | ||
replace.loc = new __acorn_js.SourceLocation( | ||
this$1.toks, | ||
acorn.getLineInfo(this$1.input, replace.start), | ||
acorn.getLineInfo(this$1.input, replace.end)) | ||
__acorn_js.getLineInfo(this$1.input, replace.start), | ||
__acorn_js.getLineInfo(this$1.input, replace.end)) | ||
return replace | ||
@@ -287,5 +286,5 @@ } | ||
this.toks.curLine = 1 | ||
this.toks.lineStart = acorn.lineBreakG.lastIndex = 0 | ||
this.toks.lineStart = __acorn_js.lineBreakG.lastIndex = 0 | ||
var match | ||
while ((match = acorn.lineBreakG.exec(this.input)) && match.index < pos) { | ||
while ((match = __acorn_js.lineBreakG.exec(this.input)) && match.index < pos) { | ||
++this$1.toks.curLine | ||
@@ -312,5 +311,5 @@ this$1.toks.lineStart = match.index + match[0].length | ||
var node = this.startNodeAt(this.options.locations ? [0, acorn.getLineInfo(this.input, 0)] : 0) | ||
var node = this.startNodeAt(this.options.locations ? [0, __acorn_js.getLineInfo(this.input, 0)] : 0) | ||
node.body = [] | ||
while (this.tok.type !== acorn.tokTypes.eof) node.body.push(this$1.parseStatement()) | ||
while (this.tok.type !== __acorn_js.tokTypes.eof) node.body.push(this$1.parseStatement()) | ||
this.last = this.tok | ||
@@ -329,3 +328,3 @@ if (this.options.ecmaVersion >= 6) { | ||
if (this.toks.isLet()) { | ||
starttype = acorn.tokTypes._var | ||
starttype = __acorn_js.tokTypes._var | ||
kind = "let" | ||
@@ -335,9 +334,9 @@ } | ||
switch (starttype) { | ||
case acorn.tokTypes._break: case acorn.tokTypes._continue: | ||
case __acorn_js.tokTypes._break: case __acorn_js.tokTypes._continue: | ||
this.next() | ||
var isBreak = starttype === acorn.tokTypes._break | ||
var isBreak = starttype === __acorn_js.tokTypes._break | ||
if (this.semicolon() || this.canInsertSemicolon()) { | ||
node.label = null | ||
} else { | ||
node.label = this.tok.type === acorn.tokTypes.name ? this.parseIdent() : null | ||
node.label = this.tok.type === __acorn_js.tokTypes.name ? this.parseIdent() : null | ||
this.semicolon() | ||
@@ -347,3 +346,3 @@ } | ||
case acorn.tokTypes._debugger: | ||
case __acorn_js.tokTypes._debugger: | ||
this.next() | ||
@@ -353,18 +352,18 @@ this.semicolon() | ||
case acorn.tokTypes._do: | ||
case __acorn_js.tokTypes._do: | ||
this.next() | ||
node.body = this.parseStatement() | ||
node.test = this.eat(acorn.tokTypes._while) ? this.parseParenExpression() : this.dummyIdent() | ||
node.test = this.eat(__acorn_js.tokTypes._while) ? this.parseParenExpression() : this.dummyIdent() | ||
this.semicolon() | ||
return this.finishNode(node, "DoWhileStatement") | ||
case acorn.tokTypes._for: | ||
case __acorn_js.tokTypes._for: | ||
this.next() | ||
this.pushCx() | ||
this.expect(acorn.tokTypes.parenL) | ||
if (this.tok.type === acorn.tokTypes.semi) return this.parseFor(node, null) | ||
this.expect(__acorn_js.tokTypes.parenL) | ||
if (this.tok.type === __acorn_js.tokTypes.semi) return this.parseFor(node, null) | ||
var isLet = this.toks.isLet() | ||
if (isLet || this.tok.type === acorn.tokTypes._var || this.tok.type === acorn.tokTypes._const) { | ||
if (isLet || this.tok.type === __acorn_js.tokTypes._var || this.tok.type === __acorn_js.tokTypes._const) { | ||
var init$1 = this.parseVar(true, isLet ? "let" : this.tok.value) | ||
if (init$1.declarations.length === 1 && (this.tok.type === acorn.tokTypes._in || this.isContextual("of"))) { | ||
if (init$1.declarations.length === 1 && (this.tok.type === __acorn_js.tokTypes._in || this.isContextual("of"))) { | ||
return this.parseForIn(node, init$1) | ||
@@ -375,24 +374,24 @@ } | ||
var init = this.parseExpression(true) | ||
if (this.tok.type === acorn.tokTypes._in || this.isContextual("of")) | ||
if (this.tok.type === __acorn_js.tokTypes._in || this.isContextual("of")) | ||
return this.parseForIn(node, this.toAssignable(init)) | ||
return this.parseFor(node, init) | ||
case acorn.tokTypes._function: | ||
case __acorn_js.tokTypes._function: | ||
this.next() | ||
return this.parseFunction(node, true) | ||
case acorn.tokTypes._if: | ||
case __acorn_js.tokTypes._if: | ||
this.next() | ||
node.test = this.parseParenExpression() | ||
node.consequent = this.parseStatement() | ||
node.alternate = this.eat(acorn.tokTypes._else) ? this.parseStatement() : null | ||
node.alternate = this.eat(__acorn_js.tokTypes._else) ? this.parseStatement() : null | ||
return this.finishNode(node, "IfStatement") | ||
case acorn.tokTypes._return: | ||
case __acorn_js.tokTypes._return: | ||
this.next() | ||
if (this.eat(acorn.tokTypes.semi) || this.canInsertSemicolon()) node.argument = null | ||
if (this.eat(__acorn_js.tokTypes.semi) || this.canInsertSemicolon()) node.argument = null | ||
else { node.argument = this.parseExpression(); this.semicolon() } | ||
return this.finishNode(node, "ReturnStatement") | ||
case acorn.tokTypes._switch: | ||
case __acorn_js.tokTypes._switch: | ||
var blockIndent = this.curIndent, line = this.curLineStart | ||
@@ -403,8 +402,8 @@ this.next() | ||
this.pushCx() | ||
this.expect(acorn.tokTypes.braceL) | ||
this.expect(__acorn_js.tokTypes.braceL) | ||
var cur | ||
while (!this.closes(acorn.tokTypes.braceR, blockIndent, line, true)) { | ||
if (this$1.tok.type === acorn.tokTypes._case || this$1.tok.type === acorn.tokTypes._default) { | ||
var isCase = this$1.tok.type === acorn.tokTypes._case | ||
while (!this.closes(__acorn_js.tokTypes.braceR, blockIndent, line, true)) { | ||
if (this$1.tok.type === __acorn_js.tokTypes._case || this$1.tok.type === __acorn_js.tokTypes._default) { | ||
var isCase = this$1.tok.type === __acorn_js.tokTypes._case | ||
if (cur) this$1.finishNode(cur, "SwitchCase") | ||
@@ -416,3 +415,3 @@ node.cases.push(cur = this$1.startNode()) | ||
else cur.test = null | ||
this$1.expect(acorn.tokTypes.colon) | ||
this$1.expect(__acorn_js.tokTypes.colon) | ||
} else { | ||
@@ -429,6 +428,6 @@ if (!cur) { | ||
this.popCx() | ||
this.eat(acorn.tokTypes.braceR) | ||
this.eat(__acorn_js.tokTypes.braceR) | ||
return this.finishNode(node, "SwitchStatement") | ||
case acorn.tokTypes._throw: | ||
case __acorn_js.tokTypes._throw: | ||
this.next() | ||
@@ -439,24 +438,24 @@ node.argument = this.parseExpression() | ||
case acorn.tokTypes._try: | ||
case __acorn_js.tokTypes._try: | ||
this.next() | ||
node.block = this.parseBlock() | ||
node.handler = null | ||
if (this.tok.type === acorn.tokTypes._catch) { | ||
if (this.tok.type === __acorn_js.tokTypes._catch) { | ||
var clause = this.startNode() | ||
this.next() | ||
this.expect(acorn.tokTypes.parenL) | ||
this.expect(__acorn_js.tokTypes.parenL) | ||
clause.param = this.toAssignable(this.parseExprAtom(), true) | ||
this.expect(acorn.tokTypes.parenR) | ||
this.expect(__acorn_js.tokTypes.parenR) | ||
clause.body = this.parseBlock() | ||
node.handler = this.finishNode(clause, "CatchClause") | ||
} | ||
node.finalizer = this.eat(acorn.tokTypes._finally) ? this.parseBlock() : null | ||
node.finalizer = this.eat(__acorn_js.tokTypes._finally) ? this.parseBlock() : null | ||
if (!node.handler && !node.finalizer) return node.block | ||
return this.finishNode(node, "TryStatement") | ||
case acorn.tokTypes._var: | ||
case acorn.tokTypes._const: | ||
case __acorn_js.tokTypes._var: | ||
case __acorn_js.tokTypes._const: | ||
return this.parseVar(false, kind || this.tok.value) | ||
case acorn.tokTypes._while: | ||
case __acorn_js.tokTypes._while: | ||
this.next() | ||
@@ -467,3 +466,3 @@ node.test = this.parseParenExpression() | ||
case acorn.tokTypes._with: | ||
case __acorn_js.tokTypes._with: | ||
this.next() | ||
@@ -474,25 +473,30 @@ node.object = this.parseParenExpression() | ||
case acorn.tokTypes.braceL: | ||
case __acorn_js.tokTypes.braceL: | ||
return this.parseBlock() | ||
case acorn.tokTypes.semi: | ||
case __acorn_js.tokTypes.semi: | ||
this.next() | ||
return this.finishNode(node, "EmptyStatement") | ||
case acorn.tokTypes._class: | ||
case __acorn_js.tokTypes._class: | ||
return this.parseClass(true) | ||
case acorn.tokTypes._import: | ||
case __acorn_js.tokTypes._import: | ||
return this.parseImport() | ||
case acorn.tokTypes._export: | ||
case __acorn_js.tokTypes._export: | ||
return this.parseExport() | ||
default: | ||
if (this.toks.isAsyncFunction()) { | ||
this.next() | ||
this.next() | ||
return this.parseFunction(node, true, true) | ||
} | ||
var expr = this.parseExpression() | ||
if (isDummy(expr)) { | ||
this.next() | ||
if (this.tok.type === acorn.tokTypes.eof) return this.finishNode(node, "EmptyStatement") | ||
if (this.tok.type === __acorn_js.tokTypes.eof) return this.finishNode(node, "EmptyStatement") | ||
return this.parseStatement() | ||
} else if (starttype === acorn.tokTypes.name && expr.type === "Identifier" && this.eat(acorn.tokTypes.colon)) { | ||
} else if (starttype === __acorn_js.tokTypes.name && expr.type === "Identifier" && this.eat(__acorn_js.tokTypes.colon)) { | ||
node.body = this.parseStatement() | ||
@@ -514,9 +518,9 @@ node.label = expr | ||
this.pushCx() | ||
this.expect(acorn.tokTypes.braceL) | ||
this.expect(__acorn_js.tokTypes.braceL) | ||
var blockIndent = this.curIndent, line = this.curLineStart | ||
node.body = [] | ||
while (!this.closes(acorn.tokTypes.braceR, blockIndent, line, true)) | ||
while (!this.closes(__acorn_js.tokTypes.braceR, blockIndent, line, true)) | ||
node.body.push(this$1.parseStatement()) | ||
this.popCx() | ||
this.eat(acorn.tokTypes.braceR) | ||
this.eat(__acorn_js.tokTypes.braceR) | ||
return this.finishNode(node, "BlockStatement") | ||
@@ -528,6 +532,6 @@ } | ||
node.test = node.update = null | ||
if (this.eat(acorn.tokTypes.semi) && this.tok.type !== acorn.tokTypes.semi) node.test = this.parseExpression() | ||
if (this.eat(acorn.tokTypes.semi) && this.tok.type !== acorn.tokTypes.parenR) node.update = this.parseExpression() | ||
if (this.eat(__acorn_js.tokTypes.semi) && this.tok.type !== __acorn_js.tokTypes.semi) node.test = this.parseExpression() | ||
if (this.eat(__acorn_js.tokTypes.semi) && this.tok.type !== __acorn_js.tokTypes.parenR) node.update = this.parseExpression() | ||
this.popCx() | ||
this.expect(acorn.tokTypes.parenR) | ||
this.expect(__acorn_js.tokTypes.parenR) | ||
node.body = this.parseStatement() | ||
@@ -538,3 +542,3 @@ return this.finishNode(node, "ForStatement") | ||
lp$1.parseForIn = function(node, init) { | ||
var type = this.tok.type === acorn.tokTypes._in ? "ForInStatement" : "ForOfStatement" | ||
var type = this.tok.type === __acorn_js.tokTypes._in ? "ForInStatement" : "ForOfStatement" | ||
this.next() | ||
@@ -544,3 +548,3 @@ node.left = init | ||
this.popCx() | ||
this.expect(acorn.tokTypes.parenR) | ||
this.expect(__acorn_js.tokTypes.parenR) | ||
node.body = this.parseStatement() | ||
@@ -560,5 +564,5 @@ return this.finishNode(node, type) | ||
decl.id = this$1.options.ecmaVersion >= 6 ? this$1.toAssignable(this$1.parseExprAtom(), true) : this$1.parseIdent() | ||
decl.init = this$1.eat(acorn.tokTypes.eq) ? this$1.parseMaybeAssign(noIn) : null | ||
decl.init = this$1.eat(__acorn_js.tokTypes.eq) ? this$1.parseMaybeAssign(noIn) : null | ||
node.declarations.push(this$1.finishNode(decl, "VariableDeclarator")) | ||
} while (this.eat(acorn.tokTypes.comma)) | ||
} while (this.eat(__acorn_js.tokTypes.comma)) | ||
if (!node.declarations.length) { | ||
@@ -578,6 +582,6 @@ var decl$1 = this.startNode() | ||
this.next() | ||
if (this.tok.type === acorn.tokTypes.name) node.id = this.parseIdent() | ||
if (this.tok.type === __acorn_js.tokTypes.name) node.id = this.parseIdent() | ||
else if (isStatement) node.id = this.dummyIdent() | ||
else node.id = null | ||
node.superClass = this.eat(acorn.tokTypes._extends) ? this.parseExpression() : null | ||
node.superClass = this.eat(__acorn_js.tokTypes._extends) ? this.parseExpression() : null | ||
node.body = this.startNode() | ||
@@ -587,17 +591,17 @@ node.body.body = [] | ||
var indent = this.curIndent + 1, line = this.curLineStart | ||
this.eat(acorn.tokTypes.braceL) | ||
this.eat(__acorn_js.tokTypes.braceL) | ||
if (this.curIndent + 1 < indent) { indent = this.curIndent; line = this.curLineStart } | ||
while (!this.closes(acorn.tokTypes.braceR, indent, line)) { | ||
while (!this.closes(__acorn_js.tokTypes.braceR, indent, line)) { | ||
if (this$1.semicolon()) continue | ||
var method = this$1.startNode(), isGenerator | ||
var method = this$1.startNode(), isGenerator, isAsync | ||
if (this$1.options.ecmaVersion >= 6) { | ||
method.static = false | ||
isGenerator = this$1.eat(acorn.tokTypes.star) | ||
isGenerator = this$1.eat(__acorn_js.tokTypes.star) | ||
} | ||
this$1.parsePropertyName(method) | ||
if (isDummy(method.key)) { if (isDummy(this$1.parseMaybeAssign())) this$1.next(); this$1.eat(acorn.tokTypes.comma); continue } | ||
if (isDummy(method.key)) { if (isDummy(this$1.parseMaybeAssign())) this$1.next(); this$1.eat(__acorn_js.tokTypes.comma); continue } | ||
if (method.key.type === "Identifier" && !method.computed && method.key.name === "static" && | ||
(this$1.tok.type != acorn.tokTypes.parenL && this$1.tok.type != acorn.tokTypes.braceL)) { | ||
(this$1.tok.type != __acorn_js.tokTypes.parenL && this$1.tok.type != __acorn_js.tokTypes.braceL)) { | ||
method.static = true | ||
isGenerator = this$1.eat(acorn.tokTypes.star) | ||
isGenerator = this$1.eat(__acorn_js.tokTypes.star) | ||
this$1.parsePropertyName(method) | ||
@@ -607,5 +611,13 @@ } else { | ||
} | ||
if (!method.computed && | ||
method.key.type === "Identifier" && method.key.name === "async" && this$1.tok.type !== __acorn_js.tokTypes.parenL && | ||
!this$1.canInsertSemicolon()) { | ||
this$1.parsePropertyName(method) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (this$1.options.ecmaVersion >= 5 && method.key.type === "Identifier" && | ||
!method.computed && (method.key.name === "get" || method.key.name === "set") && | ||
this$1.tok.type !== acorn.tokTypes.parenL && this$1.tok.type !== acorn.tokTypes.braceL) { | ||
this$1.tok.type !== __acorn_js.tokTypes.parenL && this$1.tok.type !== __acorn_js.tokTypes.braceL) { | ||
method.kind = method.key.name | ||
@@ -615,3 +627,3 @@ this$1.parsePropertyName(method) | ||
} else { | ||
if (!method.computed && !method.static && !isGenerator && ( | ||
if (!method.computed && !method.static && !isGenerator && !isAsync && ( | ||
method.key.type === "Identifier" && method.key.name === "constructor" || | ||
@@ -623,3 +635,3 @@ method.key.type === "Literal" && method.key.value === "constructor")) { | ||
} | ||
method.value = this$1.parseMethod(isGenerator) | ||
method.value = this$1.parseMethod(isGenerator, isAsync) | ||
} | ||
@@ -629,3 +641,3 @@ node.body.body.push(this$1.finishNode(method, "MethodDefinition")) | ||
this.popCx() | ||
if (!this.eat(acorn.tokTypes.braceR)) { | ||
if (!this.eat(__acorn_js.tokTypes.braceR)) { | ||
// If there is no closing brace, make the node span to the start | ||
@@ -641,11 +653,17 @@ // of the next token (this is useful for Tern) | ||
lp$1.parseFunction = function(node, isStatement) { | ||
lp$1.parseFunction = function(node, isStatement, isAsync) { | ||
var oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 6) { | ||
node.generator = this.eat(acorn.tokTypes.star) | ||
node.generator = this.eat(__acorn_js.tokTypes.star) | ||
} | ||
if (this.tok.type === acorn.tokTypes.name) node.id = this.parseIdent() | ||
if (this.options.ecmaVersion >= 8) { | ||
node.async = !!isAsync | ||
} | ||
if (this.tok.type === __acorn_js.tokTypes.name) node.id = this.parseIdent() | ||
else if (isStatement) node.id = this.dummyIdent() | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.body = this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
@@ -657,9 +675,11 @@ } | ||
this.next() | ||
if (this.eat(acorn.tokTypes.star)) { | ||
if (this.eat(__acorn_js.tokTypes.star)) { | ||
node.source = this.eatContextual("from") ? this.parseExprAtom() : this.dummyString() | ||
return this.finishNode(node, "ExportAllDeclaration") | ||
} | ||
if (this.eat(acorn.tokTypes._default)) { | ||
if (this.eat(__acorn_js.tokTypes._default)) { | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
var isParenL = this.tok.type === __acorn_js.tokTypes.parenL | ||
var expr = this.parseMaybeAssign() | ||
if (expr.id) { | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
@@ -674,3 +694,3 @@ case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
} | ||
if (this.tok.type.keyword || this.toks.isLet()) { | ||
if (this.tok.type.keyword || this.toks.isLet() || this.toks.isAsyncFunction()) { | ||
node.declaration = this.parseStatement() | ||
@@ -691,3 +711,3 @@ node.specifiers = [] | ||
this.next() | ||
if (this.tok.type === acorn.tokTypes.string) { | ||
if (this.tok.type === __acorn_js.tokTypes.string) { | ||
node.specifiers = [] | ||
@@ -698,10 +718,10 @@ node.source = this.parseExprAtom() | ||
var elt | ||
if (this.tok.type === acorn.tokTypes.name && this.tok.value !== "from") { | ||
if (this.tok.type === __acorn_js.tokTypes.name && this.tok.value !== "from") { | ||
elt = this.startNode() | ||
elt.local = this.parseIdent() | ||
this.finishNode(elt, "ImportDefaultSpecifier") | ||
this.eat(acorn.tokTypes.comma) | ||
this.eat(__acorn_js.tokTypes.comma) | ||
} | ||
node.specifiers = this.parseImportSpecifierList() | ||
node.source = this.eatContextual("from") && this.tok.type == acorn.tokTypes.string ? this.parseExprAtom() : this.dummyString() | ||
node.source = this.eatContextual("from") && this.tok.type == __acorn_js.tokTypes.string ? this.parseExprAtom() : this.dummyString() | ||
if (elt) node.specifiers.unshift(elt) | ||
@@ -717,3 +737,3 @@ } | ||
var elts = [] | ||
if (this.tok.type === acorn.tokTypes.star) { | ||
if (this.tok.type === __acorn_js.tokTypes.star) { | ||
var elt = this.startNode() | ||
@@ -726,7 +746,7 @@ this.next() | ||
this.pushCx() | ||
this.eat(acorn.tokTypes.braceL) | ||
this.eat(__acorn_js.tokTypes.braceL) | ||
if (this.curLineStart > continuedLine) continuedLine = this.curLineStart | ||
while (!this.closes(acorn.tokTypes.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) { | ||
while (!this.closes(__acorn_js.tokTypes.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) { | ||
var elt$1 = this$1.startNode() | ||
if (this$1.eat(acorn.tokTypes.star)) { | ||
if (this$1.eat(__acorn_js.tokTypes.star)) { | ||
elt$1.local = this$1.eatContextual("as") ? this$1.parseIdent() : this$1.dummyIdent() | ||
@@ -742,5 +762,5 @@ this$1.finishNode(elt$1, "ImportNamespaceSpecifier") | ||
elts.push(elt$1) | ||
this$1.eat(acorn.tokTypes.comma) | ||
this$1.eat(__acorn_js.tokTypes.comma) | ||
} | ||
this.eat(acorn.tokTypes.braceR) | ||
this.eat(__acorn_js.tokTypes.braceR) | ||
this.popCx() | ||
@@ -757,5 +777,5 @@ } | ||
this.pushCx() | ||
this.eat(acorn.tokTypes.braceL) | ||
this.eat(__acorn_js.tokTypes.braceL) | ||
if (this.curLineStart > continuedLine) continuedLine = this.curLineStart | ||
while (!this.closes(acorn.tokTypes.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) { | ||
while (!this.closes(__acorn_js.tokTypes.braceR, indent + (this.curLineStart <= continuedLine ? 1 : 0), line)) { | ||
if (this$1.isContextual("from")) break | ||
@@ -768,5 +788,5 @@ var elt = this$1.startNode() | ||
elts.push(elt) | ||
this$1.eat(acorn.tokTypes.comma) | ||
this$1.eat(__acorn_js.tokTypes.comma) | ||
} | ||
this.eat(acorn.tokTypes.braceR) | ||
this.eat(__acorn_js.tokTypes.braceR) | ||
this.popCx() | ||
@@ -799,6 +819,6 @@ return elts | ||
var expr = this.parseMaybeAssign(noIn) | ||
if (this.tok.type === acorn.tokTypes.comma) { | ||
if (this.tok.type === __acorn_js.tokTypes.comma) { | ||
var node = this.startNodeAt(start) | ||
node.expressions = [expr] | ||
while (this.eat(acorn.tokTypes.comma)) node.expressions.push(this$1.parseMaybeAssign(noIn)) | ||
while (this.eat(__acorn_js.tokTypes.comma)) node.expressions.push(this$1.parseMaybeAssign(noIn)) | ||
return this.finishNode(node, "SequenceExpression") | ||
@@ -811,6 +831,6 @@ } | ||
this.pushCx() | ||
this.expect(acorn.tokTypes.parenL) | ||
this.expect(__acorn_js.tokTypes.parenL) | ||
var val = this.parseExpression() | ||
this.popCx() | ||
this.expect(acorn.tokTypes.parenR) | ||
this.expect(__acorn_js.tokTypes.parenR) | ||
return val | ||
@@ -823,7 +843,7 @@ } | ||
this.next() | ||
if (this.semicolon() || this.canInsertSemicolon() || (this.tok.type != acorn.tokTypes.star && !this.tok.type.startsExpr)) { | ||
if (this.semicolon() || this.canInsertSemicolon() || (this.tok.type != __acorn_js.tokTypes.star && !this.tok.type.startsExpr)) { | ||
node.delegate = false | ||
node.argument = null | ||
} else { | ||
node.delegate = this.eat(acorn.tokTypes.star) | ||
node.delegate = this.eat(__acorn_js.tokTypes.star) | ||
node.argument = this.parseMaybeAssign() | ||
@@ -839,3 +859,3 @@ } | ||
node$1.operator = this.tok.value | ||
node$1.left = this.tok.type === acorn.tokTypes.eq ? this.toAssignable(left) : this.checkLVal(left) | ||
node$1.left = this.tok.type === __acorn_js.tokTypes.eq ? this.toAssignable(left) : this.checkLVal(left) | ||
this.next() | ||
@@ -851,7 +871,7 @@ node$1.right = this.parseMaybeAssign(noIn) | ||
var expr = this.parseExprOps(noIn) | ||
if (this.eat(acorn.tokTypes.question)) { | ||
if (this.eat(__acorn_js.tokTypes.question)) { | ||
var node = this.startNodeAt(start) | ||
node.test = expr | ||
node.consequent = this.parseMaybeAssign() | ||
node.alternate = this.expect(acorn.tokTypes.colon) ? this.parseMaybeAssign(noIn) : this.dummyIdent() | ||
node.alternate = this.expect(__acorn_js.tokTypes.colon) ? this.parseMaybeAssign(noIn) : this.dummyIdent() | ||
return this.finishNode(node, "ConditionalExpression") | ||
@@ -871,3 +891,3 @@ } | ||
var prec = this.tok.type.binop | ||
if (prec != null && (!noIn || this.tok.type !== acorn.tokTypes._in)) { | ||
if (prec != null && (!noIn || this.tok.type !== __acorn_js.tokTypes._in)) { | ||
if (prec > minPrec) { | ||
@@ -895,4 +915,7 @@ var node = this.startNodeAt(start) | ||
var start = this.storeCurrentPos(), expr | ||
if (this.tok.type.prefix) { | ||
var node = this.startNode(), update = this.tok.type === acorn.tokTypes.incDec | ||
if (this.options.ecmaVersion >= 8 && this.inAsync && this.toks.isContextual("await")) { | ||
expr = this.parseAwait() | ||
sawUnary = true | ||
} else if (this.tok.type.prefix) { | ||
var node = this.startNode(), update = this.tok.type === __acorn_js.tokTypes.incDec | ||
if (!update) sawUnary = true | ||
@@ -905,3 +928,3 @@ node.operator = this.tok.value | ||
expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression") | ||
} else if (this.tok.type === acorn.tokTypes.ellipsis) { | ||
} else if (this.tok.type === __acorn_js.tokTypes.ellipsis) { | ||
var node$1 = this.startNode() | ||
@@ -923,3 +946,3 @@ this.next() | ||
if (!sawUnary && this.eat(acorn.tokTypes.starstar)) { | ||
if (!sawUnary && this.eat(__acorn_js.tokTypes.starstar)) { | ||
var node$3 = this.startNodeAt(start) | ||
@@ -945,3 +968,3 @@ node$3.operator = "**" | ||
if (this$1.curLineStart != line && this$1.curIndent <= startIndent && this$1.tokenStartsLine()) { | ||
if (this$1.tok.type == acorn.tokTypes.dot && this$1.curIndent == startIndent) | ||
if (this$1.tok.type == __acorn_js.tokTypes.dot && this$1.curIndent == startIndent) | ||
--startIndent | ||
@@ -952,3 +975,5 @@ else | ||
if (this$1.eat(acorn.tokTypes.dot)) { | ||
var maybeAsyncArrow = base.type === "Identifier" && base.name === "async" && !this$1.canInsertSemicolon() | ||
if (this$1.eat(__acorn_js.tokTypes.dot)) { | ||
var node = this$1.startNodeAt(start) | ||
@@ -962,3 +987,3 @@ node.object = base | ||
base = this$1.finishNode(node, "MemberExpression") | ||
} else if (this$1.tok.type == acorn.tokTypes.bracketL) { | ||
} else if (this$1.tok.type == __acorn_js.tokTypes.bracketL) { | ||
this$1.pushCx() | ||
@@ -971,10 +996,13 @@ this$1.next() | ||
this$1.popCx() | ||
this$1.expect(acorn.tokTypes.bracketR) | ||
this$1.expect(__acorn_js.tokTypes.bracketR) | ||
base = this$1.finishNode(node$1, "MemberExpression") | ||
} else if (!noCalls && this$1.tok.type == acorn.tokTypes.parenL) { | ||
} else if (!noCalls && this$1.tok.type == __acorn_js.tokTypes.parenL) { | ||
var exprList = this$1.parseExprList(__acorn_js.tokTypes.parenR) | ||
if (maybeAsyncArrow && this$1.eat(__acorn_js.tokTypes.arrow)) | ||
return this$1.parseArrowExpression(this$1.startNodeAt(start), exprList, true) | ||
var node$2 = this$1.startNodeAt(start) | ||
node$2.callee = base | ||
node$2.arguments = this$1.parseExprList(acorn.tokTypes.parenR) | ||
node$2.arguments = exprList | ||
base = this$1.finishNode(node$2, "CallExpression") | ||
} else if (this$1.tok.type == acorn.tokTypes.backQuote) { | ||
} else if (this$1.tok.type == __acorn_js.tokTypes.backQuote) { | ||
var node$3 = this$1.startNodeAt(start) | ||
@@ -993,5 +1021,5 @@ node$3.tag = base | ||
switch (this.tok.type) { | ||
case acorn.tokTypes._this: | ||
case acorn.tokTypes._super: | ||
var type = this.tok.type === acorn.tokTypes._this ? "ThisExpression" : "Super" | ||
case __acorn_js.tokTypes._this: | ||
case __acorn_js.tokTypes._super: | ||
var type = this.tok.type === __acorn_js.tokTypes._this ? "ThisExpression" : "Super" | ||
node = this.startNode() | ||
@@ -1001,8 +1029,17 @@ this.next() | ||
case acorn.tokTypes.name: | ||
case __acorn_js.tokTypes.name: | ||
var start = this.storeCurrentPos() | ||
var id = this.parseIdent() | ||
return this.eat(acorn.tokTypes.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id]) : id | ||
var isAsync = false | ||
if (id.name === "async" && !this.canInsertSemicolon()) { | ||
if (this.eat(__acorn_js.tokTypes._function)) | ||
return this.parseFunction(this.startNodeAt(start), false, true) | ||
if (this.tok.type === __acorn_js.tokTypes.name) { | ||
id = this.parseIdent() | ||
isAsync = true | ||
} | ||
} | ||
return this.eat(__acorn_js.tokTypes.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id], isAsync) : id | ||
case acorn.tokTypes.regexp: | ||
case __acorn_js.tokTypes.regexp: | ||
node = this.startNode() | ||
@@ -1016,3 +1053,3 @@ var val = this.tok.value | ||
case acorn.tokTypes.num: case acorn.tokTypes.string: | ||
case __acorn_js.tokTypes.num: case __acorn_js.tokTypes.string: | ||
node = this.startNode() | ||
@@ -1024,5 +1061,5 @@ node.value = this.tok.value | ||
case acorn.tokTypes._null: case acorn.tokTypes._true: case acorn.tokTypes._false: | ||
case __acorn_js.tokTypes._null: case __acorn_js.tokTypes._true: case __acorn_js.tokTypes._false: | ||
node = this.startNode() | ||
node.value = this.tok.type === acorn.tokTypes._null ? null : this.tok.type === acorn.tokTypes._true | ||
node.value = this.tok.type === __acorn_js.tokTypes._null ? null : this.tok.type === __acorn_js.tokTypes._true | ||
node.raw = this.tok.type.keyword | ||
@@ -1032,9 +1069,13 @@ this.next() | ||
case acorn.tokTypes.parenL: | ||
case __acorn_js.tokTypes.parenL: | ||
var parenStart = this.storeCurrentPos() | ||
this.next() | ||
var inner = this.parseExpression() | ||
this.expect(acorn.tokTypes.parenR) | ||
if (this.eat(acorn.tokTypes.arrow)) { | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), inner.expressions || (isDummy(inner) ? [] : [inner])) | ||
this.expect(__acorn_js.tokTypes.parenR) | ||
if (this.eat(__acorn_js.tokTypes.arrow)) { | ||
// (a,)=>a // SequenceExpression makes dummy in the last hole. Drop the dummy. | ||
var params = inner.expressions || [inner] | ||
if (params.length && isDummy(params[params.length - 1])) | ||
params.pop() | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), params) | ||
} | ||
@@ -1048,14 +1089,14 @@ if (this.options.preserveParens) { | ||
case acorn.tokTypes.bracketL: | ||
case __acorn_js.tokTypes.bracketL: | ||
node = this.startNode() | ||
node.elements = this.parseExprList(acorn.tokTypes.bracketR, true) | ||
node.elements = this.parseExprList(__acorn_js.tokTypes.bracketR, true) | ||
return this.finishNode(node, "ArrayExpression") | ||
case acorn.tokTypes.braceL: | ||
case __acorn_js.tokTypes.braceL: | ||
return this.parseObj() | ||
case acorn.tokTypes._class: | ||
case __acorn_js.tokTypes._class: | ||
return this.parseClass() | ||
case acorn.tokTypes._function: | ||
case __acorn_js.tokTypes._function: | ||
node = this.startNode() | ||
@@ -1065,6 +1106,6 @@ this.next() | ||
case acorn.tokTypes._new: | ||
case __acorn_js.tokTypes._new: | ||
return this.parseNew() | ||
case acorn.tokTypes.backQuote: | ||
case __acorn_js.tokTypes.backQuote: | ||
return this.parseTemplate() | ||
@@ -1080,3 +1121,3 @@ | ||
var meta = this.parseIdent(true) | ||
if (this.options.ecmaVersion >= 6 && this.eat(acorn.tokTypes.dot)) { | ||
if (this.options.ecmaVersion >= 6 && this.eat(__acorn_js.tokTypes.dot)) { | ||
node.meta = meta | ||
@@ -1088,4 +1129,4 @@ node.property = this.parseIdent(true) | ||
node.callee = this.parseSubscripts(this.parseExprAtom(), start, true, startIndent, line) | ||
if (this.tok.type == acorn.tokTypes.parenL) { | ||
node.arguments = this.parseExprList(acorn.tokTypes.parenR) | ||
if (this.tok.type == __acorn_js.tokTypes.parenL) { | ||
node.arguments = this.parseExprList(__acorn_js.tokTypes.parenR) | ||
} else { | ||
@@ -1104,3 +1145,3 @@ node.arguments = [] | ||
this.next() | ||
elem.tail = this.tok.type === acorn.tokTypes.backQuote | ||
elem.tail = this.tok.type === __acorn_js.tokTypes.backQuote | ||
return this.finishNode(elem, "TemplateElement") | ||
@@ -1120,3 +1161,3 @@ } | ||
node.expressions.push(this$1.parseExpression()) | ||
if (this$1.expect(acorn.tokTypes.braceR)) { | ||
if (this$1.expect(__acorn_js.tokTypes.braceR)) { | ||
curElt = this$1.parseTemplateElement() | ||
@@ -1131,3 +1172,3 @@ } else { | ||
} | ||
this.expect(acorn.tokTypes.backQuote) | ||
this.expect(__acorn_js.tokTypes.backQuote) | ||
return this.finishNode(node, "TemplateLiteral") | ||
@@ -1143,6 +1184,6 @@ } | ||
var indent = this.curIndent + 1, line = this.curLineStart | ||
this.eat(acorn.tokTypes.braceL) | ||
this.eat(__acorn_js.tokTypes.braceL) | ||
if (this.curIndent + 1 < indent) { indent = this.curIndent; line = this.curLineStart } | ||
while (!this.closes(acorn.tokTypes.braceR, indent, line)) { | ||
var prop = this$1.startNode(), isGenerator, start | ||
while (!this.closes(__acorn_js.tokTypes.braceR, indent, line)) { | ||
var prop = this$1.startNode(), isGenerator, isAsync, start | ||
if (this$1.options.ecmaVersion >= 6) { | ||
@@ -1152,16 +1193,24 @@ start = this$1.storeCurrentPos() | ||
prop.shorthand = false | ||
isGenerator = this$1.eat(acorn.tokTypes.star) | ||
isGenerator = this$1.eat(__acorn_js.tokTypes.star) | ||
} | ||
this$1.parsePropertyName(prop) | ||
if (isDummy(prop.key)) { if (isDummy(this$1.parseMaybeAssign())) this$1.next(); this$1.eat(acorn.tokTypes.comma); continue } | ||
if (this$1.eat(acorn.tokTypes.colon)) { | ||
if (!prop.computed && | ||
prop.key.type === "Identifier" && prop.key.name === "async" && this$1.tok.type !== __acorn_js.tokTypes.parenL && | ||
!this$1.canInsertSemicolon()) { | ||
this$1.parsePropertyName(prop) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (isDummy(prop.key)) { if (isDummy(this$1.parseMaybeAssign())) this$1.next(); this$1.eat(__acorn_js.tokTypes.comma); continue } | ||
if (this$1.eat(__acorn_js.tokTypes.colon)) { | ||
prop.kind = "init" | ||
prop.value = this$1.parseMaybeAssign() | ||
} else if (this$1.options.ecmaVersion >= 6 && (this$1.tok.type === acorn.tokTypes.parenL || this$1.tok.type === acorn.tokTypes.braceL)) { | ||
} else if (this$1.options.ecmaVersion >= 6 && (this$1.tok.type === __acorn_js.tokTypes.parenL || this$1.tok.type === __acorn_js.tokTypes.braceL)) { | ||
prop.kind = "init" | ||
prop.method = true | ||
prop.value = this$1.parseMethod(isGenerator) | ||
prop.value = this$1.parseMethod(isGenerator, isAsync) | ||
} else if (this$1.options.ecmaVersion >= 5 && prop.key.type === "Identifier" && | ||
!prop.computed && (prop.key.name === "get" || prop.key.name === "set") && | ||
(this$1.tok.type != acorn.tokTypes.comma && this$1.tok.type != acorn.tokTypes.braceR)) { | ||
(this$1.tok.type != __acorn_js.tokTypes.comma && this$1.tok.type != __acorn_js.tokTypes.braceR)) { | ||
prop.kind = prop.key.name | ||
@@ -1173,3 +1222,3 @@ this$1.parsePropertyName(prop) | ||
if (this$1.options.ecmaVersion >= 6) { | ||
if (this$1.eat(acorn.tokTypes.eq)) { | ||
if (this$1.eat(__acorn_js.tokTypes.eq)) { | ||
var assign = this$1.startNodeAt(start) | ||
@@ -1189,6 +1238,6 @@ assign.operator = "=" | ||
node.properties.push(this$1.finishNode(prop, "Property")) | ||
this$1.eat(acorn.tokTypes.comma) | ||
this$1.eat(__acorn_js.tokTypes.comma) | ||
} | ||
this.popCx() | ||
if (!this.eat(acorn.tokTypes.braceR)) { | ||
if (!this.eat(__acorn_js.tokTypes.braceR)) { | ||
// If there is no closing brace, make the node span to the start | ||
@@ -1204,6 +1253,6 @@ // of the next token (this is useful for Tern) | ||
if (this.options.ecmaVersion >= 6) { | ||
if (this.eat(acorn.tokTypes.bracketL)) { | ||
if (this.eat(__acorn_js.tokTypes.bracketL)) { | ||
prop.computed = true | ||
prop.key = this.parseExpression() | ||
this.expect(acorn.tokTypes.bracketR) | ||
this.expect(__acorn_js.tokTypes.bracketR) | ||
return | ||
@@ -1214,3 +1263,3 @@ } else { | ||
} | ||
var key = (this.tok.type === acorn.tokTypes.num || this.tok.type === acorn.tokTypes.string) ? this.parseExprAtom() : this.parseIdent() | ||
var key = (this.tok.type === __acorn_js.tokTypes.num || this.tok.type === __acorn_js.tokTypes.string) ? this.parseExprAtom() : this.parseIdent() | ||
prop.key = key || this.dummyIdent() | ||
@@ -1220,7 +1269,7 @@ } | ||
lp$2.parsePropertyAccessor = function() { | ||
if (this.tok.type === acorn.tokTypes.name || this.tok.type.keyword) return this.parseIdent() | ||
if (this.tok.type === __acorn_js.tokTypes.name || this.tok.type.keyword) return this.parseIdent() | ||
} | ||
lp$2.parseIdent = function() { | ||
var name = this.tok.type === acorn.tokTypes.name ? this.tok.value : this.tok.type.keyword | ||
var name = this.tok.type === __acorn_js.tokTypes.name ? this.tok.value : this.tok.type.keyword | ||
if (!name) return this.dummyIdent() | ||
@@ -1240,2 +1289,4 @@ var node = this.startNode() | ||
} | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = false | ||
} | ||
@@ -1284,21 +1335,31 @@ | ||
lp$2.parseFunctionParams = function(params) { | ||
params = this.parseExprList(acorn.tokTypes.parenR) | ||
params = this.parseExprList(__acorn_js.tokTypes.parenR) | ||
return this.toAssignableList(params, true) | ||
} | ||
lp$2.parseMethod = function(isGenerator) { | ||
var node = this.startNode() | ||
lp$2.parseMethod = function(isGenerator, isAsync) { | ||
var node = this.startNode(), oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 6) | ||
node.generator = !!isGenerator | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.generator = isGenerator || false | ||
node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== acorn.tokTypes.braceL | ||
node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== __acorn_js.tokTypes.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "FunctionExpression") | ||
} | ||
lp$2.parseArrowExpression = function(node, params) { | ||
lp$2.parseArrowExpression = function(node, params, isAsync) { | ||
var oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.toAssignableList(params, true) | ||
node.expression = this.tok.type !== acorn.tokTypes.braceL | ||
node.expression = this.tok.type !== __acorn_js.tokTypes.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "ArrowFunctionExpression") | ||
@@ -1314,3 +1375,3 @@ } | ||
while (!this.closes(close, indent + 1, line)) { | ||
if (this$1.eat(acorn.tokTypes.comma)) { | ||
if (this$1.eat(__acorn_js.tokTypes.comma)) { | ||
elts.push(allowEmpty ? null : this$1.dummyIdent()) | ||
@@ -1326,3 +1387,3 @@ continue | ||
} | ||
this$1.eat(acorn.tokTypes.comma) | ||
this$1.eat(__acorn_js.tokTypes.comma) | ||
} | ||
@@ -1339,4 +1400,11 @@ this.popCx() | ||
acorn__default.defaultOptions.tabSize = 4 | ||
lp$2.parseAwait = function() { | ||
var node = this.startNode() | ||
this.next() | ||
node.argument = this.parseMaybeUnary() | ||
return this.finishNode(node, "AwaitExpression") | ||
} | ||
__acorn_js.defaultOptions.tabSize = 4 | ||
function parse_dammit(input, options) { | ||
@@ -1348,5 +1416,3 @@ var p = new LooseParser(input, options) | ||
acorn__default.parse_dammit = parse_dammit | ||
acorn__default.LooseParser = LooseParser | ||
acorn__default.pluginsLoose = pluginsLoose | ||
__acorn_js.addLooseExports(parse_dammit, LooseParser, pluginsLoose) | ||
@@ -1353,0 +1419,0 @@ exports.parse_dammit = parse_dammit; |
@@ -191,3 +191,3 @@ // AST walker module for Mozilla Parser API compatible trees | ||
} | ||
base.ReturnStatement = base.YieldExpression = function (node, st, c) { | ||
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) { | ||
if (node.argument) c(node.argument, st, "Expression") | ||
@@ -194,0 +194,0 @@ } |
@@ -197,3 +197,3 @@ (function (global, factory) { | ||
} | ||
base.ReturnStatement = base.YieldExpression = function (node, st, c) { | ||
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = function (node, st, c) { | ||
if (node.argument) c(node.argument, st, "Expression") | ||
@@ -200,0 +200,0 @@ } |
@@ -7,3 +7,3 @@ { | ||
"jsnext:main": "dist/acorn.es.js", | ||
"version": "3.3.0", | ||
"version": "4.0.0", | ||
"engines": { | ||
@@ -10,0 +10,0 @@ "node": ">=0.4.0" |
@@ -65,11 +65,12 @@ # Acorn | ||
- **ecmaVersion**: Indicates the ECMAScript version to parse. Must be | ||
either 3, 5, 6, or 7. This influences support for strict mode, the set | ||
of reserved words, and support for new syntax features. Default is 6. | ||
either 3, 5, 6 (2015) or 7 (2016). This influences support for strict | ||
mode, the set of reserved words, and support for new syntax features. | ||
Default is 7. | ||
**NOTE**: Only 'stage 4' (finalized) ECMAScript 7 features are being | ||
implemented by Acorn. That means that most of the draft standard is | ||
not yet being parsed. | ||
**NOTE**: Only 'stage 4' (finalized) ECMAScript features are being | ||
implemented by Acorn. | ||
- **sourceType**: Indicate the mode the code should be parsed in. Can be | ||
either `"script"` or `"module"`. | ||
either `"script"` or `"module"`. This influences global strict mode | ||
and parsing of `import` and `export` declarations. | ||
@@ -76,0 +77,0 @@ - **onInsertedSemicolon**: If given a callback, that callback will be |
import buble from 'rollup-plugin-buble' | ||
import {resolve} from 'path' | ||
var acorn = resolve('src/index.js') | ||
var paths = {}, globals = {} | ||
paths[acorn] = './acorn.js' | ||
globals[acorn] = 'acorn' | ||
export default { | ||
entry: 'src/loose/index.js', | ||
moduleName: 'acorn.loose', | ||
external: [ 'acorn' ], | ||
paths: { | ||
acorn: './acorn.js' | ||
}, | ||
globals: { | ||
acorn: 'acorn' | ||
}, | ||
external: [ acorn ], | ||
paths: paths, | ||
globals: globals, | ||
targets: [ | ||
@@ -14,0 +16,0 @@ { dest: 'dist/acorn_loose.js', format: 'umd' }, |
@@ -10,3 +10,3 @@ import {basename} from "path" | ||
const print = (status == 0) ? console.log : console.error | ||
print("usage: " + basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7]") | ||
print("usage: " + basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|...|--ecma2015|--ecma2016|...]") | ||
print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]") | ||
@@ -20,6 +20,2 @@ process.exit(status) | ||
else if (arg == "--" && !infile && i + 2 == process.argv.length) forceFile = infile = process.argv[++i] | ||
else if (arg == "--ecma3") options.ecmaVersion = 3 | ||
else if (arg == "--ecma5") options.ecmaVersion = 5 | ||
else if (arg == "--ecma6") options.ecmaVersion = 6 | ||
else if (arg == "--ecma7") options.ecmaVersion = 7 | ||
else if (arg == "--locations") options.locations = true | ||
@@ -32,3 +28,9 @@ else if (arg == "--allow-hash-bang") options.allowHashBang = true | ||
else if (arg == "--module") options.sourceType = 'module' | ||
else help(1) | ||
else { | ||
let match = arg.match(/^--ecma(\d+)$/) | ||
if (match) | ||
options.ecmaVersion = +match[1] | ||
else | ||
help(1) | ||
} | ||
} | ||
@@ -35,0 +37,0 @@ |
@@ -94,3 +94,3 @@ // A recursive descent parser operates by defining functions for all | ||
pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) { | ||
if (this.inGenerator && this.isContextual("yield")) return this.parseYield() | ||
if (this.inGenerator && this.isContextual("yield")) return this.parseYield(refDestructuringErrors) | ||
@@ -109,3 +109,2 @@ let ownDestructuringErrors = false | ||
this.checkPatternErrors(refDestructuringErrors, true) | ||
if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors) | ||
let node = this.startNodeAt(startPos, startLoc) | ||
@@ -117,3 +116,4 @@ node.operator = this.value | ||
this.next() | ||
node.right = this.parseMaybeAssign(noIn) | ||
node.right = this.parseMaybeAssign(noIn, refDestructuringErrors) | ||
if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true) | ||
return this.finishNode(node, "AssignmentExpression") | ||
@@ -135,5 +135,5 @@ } else { | ||
node.test = expr | ||
node.consequent = this.parseMaybeAssign() | ||
node.consequent = this.parseMaybeAssign(false, refDestructuringErrors) | ||
this.expect(tt.colon) | ||
node.alternate = this.parseMaybeAssign(noIn) | ||
node.alternate = this.parseMaybeAssign(noIn, refDestructuringErrors) | ||
return this.finishNode(node, "ConditionalExpression") | ||
@@ -150,3 +150,3 @@ } | ||
if (this.checkExpressionErrors(refDestructuringErrors)) return expr | ||
return this.parseExprOp(expr, startPos, startLoc, -1, noIn) | ||
return this.parseExprOp(expr, startPos, startLoc, -1, noIn, refDestructuringErrors) | ||
} | ||
@@ -160,3 +160,3 @@ | ||
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) { | ||
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn, refDestructuringErrors) { | ||
let prec = this.type.binop | ||
@@ -169,5 +169,5 @@ if (prec != null && (!noIn || this.type !== tt._in)) { | ||
let startPos = this.start, startLoc = this.startLoc | ||
let right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn) | ||
let right = this.parseExprOp(this.parseMaybeUnary(refDestructuringErrors, false), startPos, startLoc, prec, noIn, refDestructuringErrors) | ||
let node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical) | ||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn) | ||
return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn, refDestructuringErrors) | ||
} | ||
@@ -190,3 +190,6 @@ } | ||
let startPos = this.start, startLoc = this.startLoc, expr | ||
if (this.type.prefix) { | ||
if (this.inAsync && this.isContextual("await")) { | ||
expr = this.parseAwait(refDestructuringErrors) | ||
sawUnary = true | ||
} else if (this.type.prefix) { | ||
let node = this.startNode(), update = this.type === tt.incDec | ||
@@ -196,3 +199,3 @@ node.operator = this.value | ||
this.next() | ||
node.argument = this.parseMaybeUnary(null, true) | ||
node.argument = this.parseMaybeUnary(refDestructuringErrors, true) | ||
this.checkExpressionErrors(refDestructuringErrors, true) | ||
@@ -220,3 +223,3 @@ if (update) this.checkLVal(node.argument) | ||
if (!sawUnary && this.eat(tt.starstar)) | ||
return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) | ||
return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(refDestructuringErrors, false), "**", false) | ||
else | ||
@@ -233,7 +236,8 @@ return expr | ||
if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr | ||
return this.parseSubscripts(expr, startPos, startLoc) | ||
return this.parseSubscripts(expr, startPos, startLoc, false, refDestructuringErrors) | ||
} | ||
pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { | ||
pp.parseSubscripts = function(base, startPos, startLoc, noCalls, refContextDestructuringErrors) { | ||
for (;;) { | ||
let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon() | ||
if (this.eat(tt.dot)) { | ||
@@ -248,3 +252,3 @@ let node = this.startNodeAt(startPos, startLoc) | ||
node.object = base | ||
node.property = this.parseExpression() | ||
node.property = this.parseExpression(false, refContextDestructuringErrors) | ||
node.computed = true | ||
@@ -254,5 +258,17 @@ this.expect(tt.bracketR) | ||
} else if (!noCalls && this.eat(tt.parenL)) { | ||
let refDestructuringErrors = new DestructuringErrors | ||
let exprList = this.parseExprList(tt.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors) | ||
if (maybeAsyncArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) { | ||
this.checkPatternErrors(refDestructuringErrors, true) | ||
this.checkDefaultValueErrors(refDestructuringErrors, true, true) | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, true) | ||
} | ||
this.checkExpressionErrors(refDestructuringErrors, true) | ||
if (refContextDestructuringErrors) { | ||
refContextDestructuringErrors.yield = refContextDestructuringErrors.yield || refDestructuringErrors.yield | ||
refContextDestructuringErrors.await = refContextDestructuringErrors.await || refDestructuringErrors.await | ||
} | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.callee = base | ||
node.arguments = this.parseExprList(tt.parenR, false) | ||
node.arguments = exprList | ||
base = this.finishNode(node, "CallExpression") | ||
@@ -262,3 +278,3 @@ } else if (this.type === tt.backQuote) { | ||
node.tag = base | ||
node.quasi = this.parseTemplate() | ||
node.quasi = this.parseTemplate(refContextDestructuringErrors) | ||
base = this.finishNode(node, "TaggedTemplateExpression") | ||
@@ -292,4 +308,14 @@ } else { | ||
let id = this.parseIdent(this.type !== tt.name) | ||
if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id]) | ||
if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(tt._function)) | ||
return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) | ||
if (canBeArrow && !this.canInsertSemicolon()) { | ||
if (this.eat(tt.arrow)) | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) | ||
if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === tt.name) { | ||
id = this.parseIdent() | ||
if (this.canInsertSemicolon() || !this.eat(tt.arrow)) | ||
this.unexpected() | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true) | ||
} | ||
} | ||
return id | ||
@@ -314,3 +340,3 @@ | ||
case tt.parenL: | ||
return this.parseParenAndDistinguishExpression(canBeArrow) | ||
return this.parseParenAndDistinguishExpression(canBeArrow, refDestructuringErrors) | ||
@@ -329,12 +355,12 @@ case tt.bracketL: | ||
this.next() | ||
return this.parseFunction(node, false) | ||
return this.parseFunction(node, false, false, false) | ||
case tt._class: | ||
return this.parseClass(this.startNode(), false) | ||
return this.parseClass(this.startNode(), false, refDestructuringErrors) | ||
case tt._new: | ||
return this.parseNew() | ||
return this.parseNew(refDestructuringErrors) | ||
case tt.backQuote: | ||
return this.parseTemplate() | ||
return this.parseTemplate(refDestructuringErrors) | ||
@@ -354,5 +380,5 @@ default: | ||
pp.parseParenExpression = function() { | ||
pp.parseParenExpression = function(refDestructuringErrors) { | ||
this.expect(tt.parenL) | ||
let val = this.parseExpression() | ||
let val = this.parseExpression(false, refDestructuringErrors) | ||
this.expect(tt.parenR) | ||
@@ -362,4 +388,4 @@ return val | ||
pp.parseParenAndDistinguishExpression = function(canBeArrow) { | ||
let startPos = this.start, startLoc = this.startLoc, val | ||
pp.parseParenAndDistinguishExpression = function(canBeArrow, refContextDestructuringErrors) { | ||
let startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8 | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -369,9 +395,13 @@ this.next() | ||
let innerStartPos = this.start, innerStartLoc = this.startLoc | ||
let exprList = [], first = true | ||
let exprList = [], first = true, lastIsComma = false | ||
let refDestructuringErrors = new DestructuringErrors, spreadStart, innerParenStart | ||
while (this.type !== tt.parenR) { | ||
first ? first = false : this.expect(tt.comma) | ||
if (this.type === tt.ellipsis) { | ||
if (allowTrailingComma && this.afterTrailingComma(tt.parenR, true)) { | ||
lastIsComma = true | ||
break | ||
} else if (this.type === tt.ellipsis) { | ||
spreadStart = this.start | ||
exprList.push(this.parseParenItem(this.parseRest())) | ||
exprList.push(this.parseParenItem(this.parseRest(false, refDestructuringErrors))) | ||
if (this.type === tt.comma) this.raise(this.start, "Comma is not permitted after the rest element") | ||
break | ||
@@ -390,2 +420,3 @@ } else { | ||
this.checkPatternErrors(refDestructuringErrors, true) | ||
this.checkDefaultValueErrors(refDestructuringErrors, true, true) | ||
if (innerParenStart) this.unexpected(innerParenStart) | ||
@@ -395,5 +426,9 @@ return this.parseParenArrowList(startPos, startLoc, exprList) | ||
if (!exprList.length) this.unexpected(this.lastTokStart) | ||
if (!exprList.length || lastIsComma) this.unexpected(this.lastTokStart) | ||
if (spreadStart) this.unexpected(spreadStart) | ||
this.checkExpressionErrors(refDestructuringErrors, true) | ||
if (refContextDestructuringErrors) { | ||
refContextDestructuringErrors.yield = refContextDestructuringErrors.yield || refDestructuringErrors.yield | ||
refContextDestructuringErrors.await = refContextDestructuringErrors.await || refDestructuringErrors.await | ||
} | ||
@@ -408,3 +443,3 @@ if (exprList.length > 1) { | ||
} else { | ||
val = this.parseParenExpression() | ||
val = this.parseParenExpression(refContextDestructuringErrors) | ||
} | ||
@@ -426,3 +461,3 @@ | ||
pp.parseParenArrowList = function(startPos, startLoc, exprList) { | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList) | ||
return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList, false) | ||
} | ||
@@ -438,3 +473,3 @@ | ||
pp.parseNew = function() { | ||
pp.parseNew = function(refDestructuringErrors) { | ||
let node = this.startNode() | ||
@@ -452,4 +487,4 @@ let meta = this.parseIdent(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) | ||
node.callee = this.parseSubscripts(this.parseExprAtom(refDestructuringErrors), startPos, startLoc, true, refDestructuringErrors) | ||
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, this.options.ecmaVersion >= 8, false, refDestructuringErrors) | ||
else node.arguments = empty | ||
@@ -472,3 +507,3 @@ return this.finishNode(node, "NewExpression") | ||
pp.parseTemplate = function() { | ||
pp.parseTemplate = function(refDestructuringErrors) { | ||
let node = this.startNode() | ||
@@ -481,3 +516,3 @@ this.next() | ||
this.expect(tt.dollarBraceL) | ||
node.expressions.push(this.parseExpression()) | ||
node.expressions.push(this.parseExpression(false, refDestructuringErrors)) | ||
this.expect(tt.braceR) | ||
@@ -502,3 +537,3 @@ node.quasis.push(curElt = this.parseTemplateElement()) | ||
let prop = this.startNode(), isGenerator, startPos, startLoc | ||
let prop = this.startNode(), isGenerator, isAsync, startPos, startLoc | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -514,4 +549,12 @@ prop.method = false | ||
} | ||
this.parsePropertyName(prop) | ||
this.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) | ||
this.parsePropertyName(prop, refDestructuringErrors) | ||
if (!isPattern && this.options.ecmaVersion >= 8 && !isGenerator && !prop.computed && | ||
prop.key.type === "Identifier" && prop.key.name === "async" && this.type !== tt.parenL && | ||
!this.canInsertSemicolon()) { | ||
isAsync = true | ||
this.parsePropertyName(prop, refDestructuringErrors) | ||
} else { | ||
isAsync = false | ||
} | ||
this.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) | ||
this.checkPropClash(prop, propHash) | ||
@@ -523,5 +566,8 @@ node.properties.push(this.finishNode(prop, "Property")) | ||
pp.parsePropertyValue = function(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) { | ||
pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) { | ||
if ((isGenerator || isAsync) && this.type === tt.colon) | ||
this.unexpected() | ||
if (this.eat(tt.colon)) { | ||
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors) | ||
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc, null, refDestructuringErrors) : this.parseMaybeAssign(false, refDestructuringErrors) | ||
prop.kind = "init" | ||
@@ -532,10 +578,10 @@ } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) { | ||
prop.method = true | ||
prop.value = this.parseMethod(isGenerator) | ||
prop.value = this.parseMethod(isGenerator, isAsync) | ||
} else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" && | ||
(prop.key.name === "get" || prop.key.name === "set") && | ||
(this.type != tt.comma && this.type != tt.braceR)) { | ||
if (isGenerator || isPattern) this.unexpected() | ||
if (isGenerator || isAsync || isPattern) this.unexpected() | ||
prop.kind = prop.key.name | ||
this.parsePropertyName(prop) | ||
prop.value = this.parseMethod(false) | ||
this.parsePropertyName(prop, refDestructuringErrors) | ||
prop.value = this.parseMethod(false, false) | ||
let paramCount = prop.kind === "get" ? 0 : 1 | ||
@@ -548,17 +594,19 @@ if (prop.value.params.length !== paramCount) { | ||
this.raiseRecoverable(start, "setter should have exactly one param") | ||
} else { | ||
if (prop.kind === "set" && prop.value.params[0].type === "RestElement") | ||
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params") | ||
} | ||
if (prop.kind === "set" && prop.value.params[0].type === "RestElement") | ||
this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params") | ||
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { | ||
if (this.keywords.test(prop.key.name) || | ||
(this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) || | ||
(this.inGenerator && prop.key.name == "yield")) | ||
(this.strict ? this.reservedWordsStrict : this.reservedWords).test(prop.key.name) || | ||
(this.inGenerator && prop.key.name == "yield") || | ||
(this.inAsync && prop.key.name == "await")) | ||
this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property") | ||
prop.kind = "init" | ||
if (isPattern) { | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key) | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key, refDestructuringErrors) | ||
} else if (this.type === tt.eq && refDestructuringErrors) { | ||
if (!refDestructuringErrors.shorthandAssign) | ||
refDestructuringErrors.shorthandAssign = this.start | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key) | ||
prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key, refDestructuringErrors) | ||
} else { | ||
@@ -571,7 +619,7 @@ prop.value = prop.key | ||
pp.parsePropertyName = function(prop) { | ||
pp.parsePropertyName = function(prop, refDestructuringErrors) { | ||
if (this.options.ecmaVersion >= 6) { | ||
if (this.eat(tt.bracketL)) { | ||
prop.computed = true | ||
prop.key = this.parseMaybeAssign() | ||
prop.key = this.parseMaybeAssign(false, refDestructuringErrors) | ||
this.expect(tt.bracketR) | ||
@@ -583,3 +631,3 @@ return prop.key | ||
} | ||
return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true) | ||
return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom(refDestructuringErrors) : this.parseIdent(true) | ||
} | ||
@@ -595,2 +643,4 @@ | ||
} | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = false | ||
} | ||
@@ -600,12 +650,17 @@ | ||
pp.parseMethod = function(isGenerator) { | ||
let node = this.startNode(), oldInGen = this.inGenerator | ||
this.inGenerator = isGenerator | ||
pp.parseMethod = function(isGenerator, isAsync) { | ||
let node = this.startNode(), refDestructuringErrors = new DestructuringErrors, oldInGen = this.inGenerator, oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
this.expect(tt.parenL) | ||
node.params = this.parseBindingList(tt.parenR, false, false) | ||
if (this.options.ecmaVersion >= 6) | ||
node.generator = isGenerator | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inGenerator = node.generator | ||
this.inAsync = node.async | ||
this.expect(tt.parenL) | ||
node.params = this.parseBindingList(tt.parenR, false, this.options.ecmaVersion >= 8, false, refDestructuringErrors) | ||
this.checkDefaultValueErrors(refDestructuringErrors, false, true) | ||
this.parseFunctionBody(node, false) | ||
this.inGenerator = oldInGen | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "FunctionExpression") | ||
@@ -616,9 +671,13 @@ } | ||
pp.parseArrowExpression = function(node, params) { | ||
let oldInGen = this.inGenerator | ||
pp.parseArrowExpression = function(node, params, isAsync) { | ||
let oldInGen = this.inGenerator, oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inGenerator = false | ||
this.initFunction(node) | ||
this.inAsync = node.async | ||
node.params = this.toAssignableList(params, true) | ||
this.parseFunctionBody(node, true) | ||
this.inGenerator = oldInGen | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "ArrowFunctionExpression") | ||
@@ -648,3 +707,6 @@ } | ||
// or `arguments`. | ||
let useStrict = (!isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) ? node.body.body[0] : null; | ||
let useStrict = (!isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) ? node.body.body[0] : null | ||
if (useStrict && this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params)) | ||
this.raiseRecoverable(useStrict.start, "Illegal 'use strict' directive in function with non-simple parameter list") | ||
if (this.strict || useStrict) { | ||
@@ -655,19 +717,21 @@ let oldStrict = this.strict | ||
this.checkLVal(node.id, true) | ||
this.checkParams(node, useStrict) | ||
this.checkParams(node) | ||
this.strict = oldStrict | ||
} else if (isArrowFunction) { | ||
this.checkParams(node, useStrict) | ||
} else if (isArrowFunction || !this.isSimpleParamList(node.params)) { | ||
this.checkParams(node) | ||
} | ||
} | ||
pp.isSimpleParamList = function(params) { | ||
for (let i = 0; i < params.length; i++) | ||
if (params[i].type !== "Identifier") return false | ||
return true | ||
} | ||
// Checks function params for various disallowed patterns such as using "eval" | ||
// or "arguments" and duplicate parameters. | ||
pp.checkParams = function(node, useStrict) { | ||
let nameHash = {} | ||
for (let i = 0; i < node.params.length; i++) { | ||
if (useStrict && this.options.ecmaVersion >= 7 && node.params[i].type !== "Identifier") | ||
this.raiseRecoverable(useStrict.start, "Illegal 'use strict' directive in function with non-simple parameter list"); | ||
this.checkLVal(node.params[i], true, nameHash) | ||
} | ||
pp.checkParams = function(node) { | ||
let nameHash = {} | ||
for (let i = 0; i < node.params.length; i++) this.checkLVal(node.params[i], true, nameHash) | ||
} | ||
@@ -695,3 +759,3 @@ | ||
if (this.type === tt.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) { | ||
refDestructuringErrors.trailingComma = this.lastTokStart | ||
refDestructuringErrors.trailingComma = this.start | ||
} | ||
@@ -717,4 +781,6 @@ } else | ||
this.raiseRecoverable(this.start, "The keyword '" + this.value + "' is reserved") | ||
if (!liberal && this.inGenerator && this.value === "yield") | ||
if (this.inGenerator && this.value === "yield") | ||
this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator") | ||
if (this.inAsync && this.value === "await") | ||
this.raiseRecoverable(this.start, "Can not use 'await' as identifier inside an async function") | ||
node.name = this.value | ||
@@ -732,4 +798,5 @@ } else if (liberal && this.type.keyword) { | ||
pp.parseYield = function() { | ||
pp.parseYield = function(refDestructuringErrors) { | ||
let node = this.startNode() | ||
if (refDestructuringErrors) refDestructuringErrors.yield = this.start | ||
this.next() | ||
@@ -741,5 +808,13 @@ if (this.type == tt.semi || this.canInsertSemicolon() || (this.type != tt.star && !this.type.startsExpr)) { | ||
node.delegate = this.eat(tt.star) | ||
node.argument = this.parseMaybeAssign() | ||
node.argument = this.parseMaybeAssign(false, refDestructuringErrors) | ||
} | ||
return this.finishNode(node, "YieldExpression") | ||
} | ||
pp.parseAwait = function(refDestructuringErrors) { | ||
let node = this.startNode() | ||
if (refDestructuringErrors) refDestructuringErrors.await = this.start | ||
this.next() | ||
node.argument = this.parseMaybeUnary(refDestructuringErrors, true) | ||
return this.finishNode(node, "AwaitExpression") | ||
} |
@@ -39,3 +39,3 @@ // Acorn is a tiny, fast JavaScript parser written in JavaScript. | ||
export const version = "3.3.0" | ||
export const version = "4.0.0" | ||
@@ -69,1 +69,11 @@ // The main exported interface (under `self.acorn` when in the | ||
} | ||
// This is a terrible kludge to support the existing, pre-ES6 | ||
// interface where the loose parser module retroactively adds exports | ||
// to this module. | ||
export let parse_dammit, LooseParser, pluginsLoose | ||
export function addLooseExports(parse, Parser, plugins) { | ||
parse_dammit = parse | ||
LooseParser = Parser | ||
pluginsLoose = plugins | ||
} |
import {LooseParser} from "./state" | ||
import {isDummy} from "./parseutil" | ||
import {tokTypes as tt} from "acorn" | ||
import {tokTypes as tt} from "../index" | ||
@@ -114,3 +114,6 @@ const lp = LooseParser.prototype | ||
let start = this.storeCurrentPos(), expr | ||
if (this.tok.type.prefix) { | ||
if (this.options.ecmaVersion >= 8 && this.inAsync && this.toks.isContextual("await")) { | ||
expr = this.parseAwait() | ||
sawUnary = true | ||
} else if (this.tok.type.prefix) { | ||
let node = this.startNode(), update = this.tok.type === tt.incDec | ||
@@ -166,2 +169,4 @@ if (!update) sawUnary = true | ||
let maybeAsyncArrow = base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon() | ||
if (this.eat(tt.dot)) { | ||
@@ -187,5 +192,8 @@ let node = this.startNodeAt(start) | ||
} else if (!noCalls && this.tok.type == tt.parenL) { | ||
let exprList = this.parseExprList(tt.parenR) | ||
if (maybeAsyncArrow && this.eat(tt.arrow)) | ||
return this.parseArrowExpression(this.startNodeAt(start), exprList, true) | ||
let node = this.startNodeAt(start) | ||
node.callee = base | ||
node.arguments = this.parseExprList(tt.parenR) | ||
node.arguments = exprList | ||
base = this.finishNode(node, "CallExpression") | ||
@@ -216,3 +224,12 @@ } else if (this.tok.type == tt.backQuote) { | ||
let id = this.parseIdent() | ||
return this.eat(tt.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id]) : id | ||
let isAsync = false | ||
if (id.name === "async" && !this.canInsertSemicolon()) { | ||
if (this.eat(tt._function)) | ||
return this.parseFunction(this.startNodeAt(start), false, true) | ||
if (this.tok.type === tt.name) { | ||
id = this.parseIdent() | ||
isAsync = true | ||
} | ||
} | ||
return this.eat(tt.arrow) ? this.parseArrowExpression(this.startNodeAt(start), [id], isAsync) : id | ||
@@ -248,3 +265,7 @@ case tt.regexp: | ||
if (this.eat(tt.arrow)) { | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), inner.expressions || (isDummy(inner) ? [] : [inner])) | ||
// (a,)=>a // SequenceExpression makes dummy in the last hole. Drop the dummy. | ||
let params = inner.expressions || [inner] | ||
if (params.length && isDummy(params[params.length - 1])) | ||
params.pop() | ||
return this.parseArrowExpression(this.startNodeAt(parenStart), params) | ||
} | ||
@@ -345,3 +366,3 @@ if (this.options.preserveParens) { | ||
while (!this.closes(tt.braceR, indent, line)) { | ||
let prop = this.startNode(), isGenerator, start | ||
let prop = this.startNode(), isGenerator, isAsync, start | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -354,2 +375,10 @@ start = this.storeCurrentPos() | ||
this.parsePropertyName(prop) | ||
if (!prop.computed && | ||
prop.key.type === "Identifier" && prop.key.name === "async" && this.tok.type !== tt.parenL && | ||
!this.canInsertSemicolon()) { | ||
this.parsePropertyName(prop) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (isDummy(prop.key)) { if (isDummy(this.parseMaybeAssign())) this.next(); this.eat(tt.comma); continue } | ||
@@ -362,3 +391,3 @@ if (this.eat(tt.colon)) { | ||
prop.method = true | ||
prop.value = this.parseMethod(isGenerator) | ||
prop.value = this.parseMethod(isGenerator, isAsync) | ||
} else if (this.options.ecmaVersion >= 5 && prop.key.type === "Identifier" && | ||
@@ -435,2 +464,4 @@ !prop.computed && (prop.key.name === "get" || prop.key.name === "set") && | ||
} | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = false | ||
} | ||
@@ -479,17 +510,27 @@ | ||
lp.parseMethod = function(isGenerator) { | ||
let node = this.startNode() | ||
lp.parseMethod = function(isGenerator, isAsync) { | ||
let node = this.startNode(), oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 6) | ||
node.generator = !!isGenerator | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.generator = isGenerator || false | ||
node.expression = this.options.ecmaVersion >= 6 && this.tok.type !== tt.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "FunctionExpression") | ||
} | ||
lp.parseArrowExpression = function(node, params) { | ||
lp.parseArrowExpression = function(node, params, isAsync) { | ||
let oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
this.inAsync = node.async | ||
node.params = this.toAssignableList(params, true) | ||
node.expression = this.tok.type !== tt.braceL | ||
node.body = node.expression ? this.parseMaybeAssign() : this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, "ArrowFunctionExpression") | ||
@@ -525,1 +566,8 @@ } | ||
} | ||
lp.parseAwait = function() { | ||
let node = this.startNode() | ||
this.next() | ||
node.argument = this.parseMaybeUnary() | ||
return this.finishNode(node, "AwaitExpression") | ||
} |
@@ -32,3 +32,3 @@ // Acorn: Loose parser | ||
import acorn from "acorn" | ||
import {addLooseExports, defaultOptions} from "../index" | ||
import {LooseParser, pluginsLoose} from "./state" | ||
@@ -41,3 +41,3 @@ import "./tokenize" | ||
acorn.defaultOptions.tabSize = 4 | ||
defaultOptions.tabSize = 4 | ||
@@ -50,4 +50,2 @@ export function parse_dammit(input, options) { | ||
acorn.parse_dammit = parse_dammit | ||
acorn.LooseParser = LooseParser | ||
acorn.pluginsLoose = pluginsLoose | ||
addLooseExports(parse_dammit, LooseParser, pluginsLoose) |
@@ -1,2 +0,2 @@ | ||
import {tokenizer, SourceLocation, tokTypes as tt, Node, lineBreak, isNewLine} from "acorn" | ||
import {tokenizer, SourceLocation, tokTypes as tt, Node, lineBreak, isNewLine} from "../index" | ||
@@ -21,2 +21,3 @@ // Registered plugins | ||
this.nextLineStart = this.lineEnd(this.curLineStart) + 1 | ||
this.inAsync = false | ||
// Load plugins | ||
@@ -23,0 +24,0 @@ this.options.pluginsLoose = options.pluginsLoose || {} |
import {LooseParser} from "./state" | ||
import {isDummy} from "./parseutil" | ||
import {getLineInfo, tokTypes as tt} from "acorn" | ||
import {getLineInfo, tokTypes as tt} from "../index" | ||
@@ -174,2 +174,7 @@ const lp = LooseParser.prototype | ||
default: | ||
if (this.toks.isAsyncFunction()) { | ||
this.next() | ||
this.next() | ||
return this.parseFunction(node, true, true) | ||
} | ||
let expr = this.parseExpression() | ||
@@ -262,3 +267,3 @@ if (isDummy(expr)) { | ||
if (this.semicolon()) continue | ||
let method = this.startNode(), isGenerator | ||
let method = this.startNode(), isGenerator, isAsync | ||
if (this.options.ecmaVersion >= 6) { | ||
@@ -278,2 +283,10 @@ method.static = false | ||
} | ||
if (!method.computed && | ||
method.key.type === "Identifier" && method.key.name === "async" && this.tok.type !== tt.parenL && | ||
!this.canInsertSemicolon()) { | ||
this.parsePropertyName(method) | ||
isAsync = true | ||
} else { | ||
isAsync = false | ||
} | ||
if (this.options.ecmaVersion >= 5 && method.key.type === "Identifier" && | ||
@@ -286,3 +299,3 @@ !method.computed && (method.key.name === "get" || method.key.name === "set") && | ||
} else { | ||
if (!method.computed && !method.static && !isGenerator && ( | ||
if (!method.computed && !method.static && !isGenerator && !isAsync && ( | ||
method.key.type === "Identifier" && method.key.name === "constructor" || | ||
@@ -294,3 +307,3 @@ method.key.type === "Literal" && method.key.value === "constructor")) { | ||
} | ||
method.value = this.parseMethod(isGenerator) | ||
method.value = this.parseMethod(isGenerator, isAsync) | ||
} | ||
@@ -311,3 +324,4 @@ node.body.body.push(this.finishNode(method, "MethodDefinition")) | ||
lp.parseFunction = function(node, isStatement) { | ||
lp.parseFunction = function(node, isStatement, isAsync) { | ||
let oldInAsync = this.inAsync | ||
this.initFunction(node) | ||
@@ -317,6 +331,11 @@ if (this.options.ecmaVersion >= 6) { | ||
} | ||
if (this.options.ecmaVersion >= 8) { | ||
node.async = !!isAsync | ||
} | ||
if (this.tok.type === tt.name) node.id = this.parseIdent() | ||
else if (isStatement) node.id = this.dummyIdent() | ||
this.inAsync = node.async | ||
node.params = this.parseFunctionParams() | ||
node.body = this.parseBlock() | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
@@ -333,4 +352,6 @@ } | ||
if (this.eat(tt._default)) { | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
let isParenL = this.tok.type === tt.parenL | ||
let expr = this.parseMaybeAssign() | ||
if (expr.id) { | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
@@ -345,3 +366,3 @@ case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
} | ||
if (this.tok.type.keyword || this.toks.isLet()) { | ||
if (this.tok.type.keyword || this.toks.isLet() || this.toks.isAsyncFunction()) { | ||
node.declaration = this.parseStatement() | ||
@@ -348,0 +369,0 @@ node.specifiers = [] |
@@ -1,2 +0,2 @@ | ||
import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from "acorn" | ||
import {tokTypes as tt, Token, isNewLine, SourceLocation, getLineInfo, lineBreakG} from "../index" | ||
import {LooseParser} from "./state" | ||
@@ -3,0 +3,0 @@ |
@@ -14,2 +14,6 @@ import {types as tt} from "./tokentype" | ||
case "Identifier": | ||
if (this.inAsync && node.name === "await") | ||
this.raise(node.start, "Can not use 'await' as identifier inside an async function") | ||
break | ||
case "ObjectPattern": | ||
@@ -37,2 +41,3 @@ case "ArrayPattern": | ||
delete node.operator | ||
this.toAssignable(node.left, isBinding) | ||
// falls through to AssignmentPattern | ||
@@ -45,4 +50,2 @@ } else { | ||
case "AssignmentPattern": | ||
if (node.right.type === "YieldExpression") | ||
this.raise(node.right.start, "Yield expression cannot be a default value") | ||
break | ||
@@ -100,3 +103,3 @@ | ||
pp.parseRest = function(allowNonIdent) { | ||
pp.parseRest = function(allowNonIdent, refDestructuringErrors) { | ||
let node = this.startNode() | ||
@@ -107,3 +110,3 @@ this.next() | ||
if (allowNonIdent) node.argument = this.type === tt.name ? this.parseIdent() : this.unexpected() | ||
else node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected() | ||
else node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom(refDestructuringErrors) : this.unexpected() | ||
@@ -115,3 +118,3 @@ return this.finishNode(node, "RestElement") | ||
pp.parseBindingAtom = function() { | ||
pp.parseBindingAtom = function(refDestructuringErrors) { | ||
if (this.options.ecmaVersion < 6) return this.parseIdent() | ||
@@ -125,7 +128,7 @@ switch (this.type) { | ||
this.next() | ||
node.elements = this.parseBindingList(tt.bracketR, true, true) | ||
node.elements = this.parseBindingList(tt.bracketR, true, true, false, refDestructuringErrors) | ||
return this.finishNode(node, "ArrayPattern") | ||
case tt.braceL: | ||
return this.parseObj(true) | ||
return this.parseObj(true, refDestructuringErrors) | ||
@@ -137,3 +140,3 @@ default: | ||
pp.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowNonIdent) { | ||
pp.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowNonIdent, refDestructuringErrors) { | ||
let elts = [], first = true | ||
@@ -148,3 +151,3 @@ while (!this.eat(close)) { | ||
} else if (this.type === tt.ellipsis) { | ||
let rest = this.parseRest(allowNonIdent) | ||
let rest = this.parseRest(allowNonIdent, refDestructuringErrors) | ||
this.parseBindingListItem(rest) | ||
@@ -156,3 +159,3 @@ elts.push(rest) | ||
} else { | ||
let elem = this.parseMaybeDefault(this.start, this.startLoc) | ||
let elem = this.parseMaybeDefault(this.start, this.startLoc, null, refDestructuringErrors) | ||
this.parseBindingListItem(elem) | ||
@@ -171,8 +174,8 @@ elts.push(elem) | ||
pp.parseMaybeDefault = function(startPos, startLoc, left) { | ||
left = left || this.parseBindingAtom() | ||
pp.parseMaybeDefault = function(startPos, startLoc, left, refDestructuringErrors) { | ||
left = left || this.parseBindingAtom(refDestructuringErrors) | ||
if (this.options.ecmaVersion < 6 || !this.eat(tt.eq)) return left | ||
let node = this.startNodeAt(startPos, startLoc) | ||
node.left = left | ||
node.right = this.parseMaybeAssign() | ||
node.right = this.parseMaybeAssign(false, refDestructuringErrors) | ||
return this.finishNode(node, "AssignmentPattern") | ||
@@ -179,0 +182,0 @@ } |
@@ -9,7 +9,9 @@ import {has, isArray} from "./util" | ||
// `ecmaVersion` indicates the ECMAScript version to parse. Must | ||
// be either 3, or 5, or 6. This influences support for strict | ||
// mode, the set of reserved words, support for getters and | ||
// setters and other features. The default is 6. | ||
ecmaVersion: 6, | ||
// Source type ("script" or "module") for different semantics | ||
// be either 3, 5, 6 (2015), or 7 (2016). This influences support | ||
// for strict mode, the set of reserved words, and support for | ||
// new syntax features. The default is 7. | ||
ecmaVersion: 7, | ||
// `sourceType` indicates the mode the code should be parsed in. | ||
// Can be either `"script"` or `"module"`. This influences global | ||
// strict mode and parsing of `import` and `export` declarations. | ||
sourceType: "script", | ||
@@ -92,4 +94,9 @@ // `onInsertedSemicolon` can be a callback that will be called | ||
let options = {} | ||
for (let opt in defaultOptions) | ||
options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt] | ||
if (options.ecmaVersion >= 2015) | ||
options.ecmaVersion -= 2009 | ||
if (options.allowReserved == null) | ||
@@ -96,0 +103,0 @@ options.allowReserved = options.ecmaVersion < 5 |
@@ -70,7 +70,8 @@ import {types as tt} from "./tokentype" | ||
pp.afterTrailingComma = function(tokType) { | ||
pp.afterTrailingComma = function(tokType, notNext) { | ||
if (this.type == tokType) { | ||
if (this.options.onTrailingComma) | ||
this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc) | ||
this.next() | ||
if (!notNext) | ||
this.next() | ||
return true | ||
@@ -97,2 +98,4 @@ } | ||
this.trailingComma = 0 | ||
this.yield = 0 | ||
this.await = 0 | ||
} | ||
@@ -112,1 +115,9 @@ } | ||
} | ||
pp.checkDefaultValueErrors = function(refDestructuringErrors, isArrow, andThrow) { | ||
let yieldPos = (isArrow || this.inGenerator) && refDestructuringErrors && refDestructuringErrors.yield | ||
let awaitPos = (isArrow || this.inAsync) && refDestructuringErrors && refDestructuringErrors.await | ||
if (!andThrow) return !!(yieldPos || awaitPos) | ||
if (yieldPos && (!awaitPos || yieldPos < awaitPos)) this.raise(yieldPos, "Yield expression cannot be a default value") | ||
if (awaitPos) this.raise(awaitPos, "Await expression cannot be a default value") | ||
} |
@@ -39,3 +39,3 @@ import {reservedWords, keywords} from "./identifier" | ||
this.pos = startPos | ||
this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos)) | ||
this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1 | ||
this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length | ||
@@ -74,4 +74,4 @@ } else { | ||
// Flags to track whether we are in a function, a generator. | ||
this.inFunction = this.inGenerator = false | ||
// Flags to track whether we are in a function, a generator, an async function. | ||
this.inFunction = this.inGenerator = this.inAsync = false | ||
// Labels in scope. | ||
@@ -78,0 +78,0 @@ this.labels = [] |
@@ -17,6 +17,6 @@ import {types as tt} from "./tokentype" | ||
pp.parseTopLevel = function(node) { | ||
let first = true | ||
let first = true, exports = {} | ||
if (!node.body) node.body = [] | ||
while (this.type !== tt.eof) { | ||
let stmt = this.parseStatement(true, true) | ||
let stmt = this.parseStatement(true, true, exports) | ||
node.body.push(stmt) | ||
@@ -51,2 +51,17 @@ if (first) { | ||
// check 'async [no LineTerminator here] function' | ||
// - 'async /*foo*/ function' is OK. | ||
// - 'async /*\n*/ function' is invalid. | ||
pp.isAsyncFunction = function() { | ||
if (this.type !== tt.name || this.options.ecmaVersion < 8 || this.value != "async") | ||
return false | ||
skipWhiteSpace.lastIndex = this.pos | ||
let skip = skipWhiteSpace.exec(this.input) | ||
let next = this.pos + skip[0].length | ||
return !lineBreak.test(this.input.slice(this.pos, next)) && | ||
this.input.slice(next, next + 8) === "function" && | ||
(next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8))) | ||
} | ||
// Parse a single statement. | ||
@@ -59,3 +74,3 @@ // | ||
pp.parseStatement = function(declaration, topLevel) { | ||
pp.parseStatement = function(declaration, topLevel, exports) { | ||
let starttype = this.type, node = this.startNode(), kind | ||
@@ -78,4 +93,4 @@ | ||
case tt._function: | ||
if (!declaration && this.options.ecmaVersion >= 6) this.unexpected() | ||
return this.parseFunctionStatement(node) | ||
if (!declaration && this.options.ecmaVersion >= 6) break | ||
return this.parseFunctionStatement(node, false) | ||
case tt._class: | ||
@@ -105,15 +120,19 @@ if (!declaration) this.unexpected() | ||
} | ||
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node) | ||
return starttype === tt._import ? this.parseImport(node) : this.parseExport(node, exports) | ||
} | ||
// If the statement does not start with a statement keyword or a | ||
// brace, it's an ExpressionStatement or LabeledStatement. We | ||
// simply start parsing an expression, and afterwards, if the | ||
// next token is a colon and the expression was a simple | ||
// Identifier node, we switch to interpreting it as a label. | ||
default: | ||
let maybeName = this.value, expr = this.parseExpression() | ||
if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) | ||
return this.parseLabeledStatement(node, maybeName, expr) | ||
else return this.parseExpressionStatement(node, expr) | ||
if (this.isAsyncFunction() && declaration) { | ||
this.next() | ||
return this.parseFunctionStatement(node, true) | ||
} | ||
// If the statement does not start with a statement keyword or a | ||
// brace, it's an ExpressionStatement or LabeledStatement. We | ||
// simply start parsing an expression, and afterwards, if the | ||
// next token is a colon and the expression was a simple | ||
// Identifier node, we switch to interpreting it as a label. | ||
let maybeName = this.value, expr = this.parseExpression() | ||
if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon)) | ||
return this.parseLabeledStatement(node, maybeName, expr) | ||
else return this.parseExpressionStatement(node, expr) | ||
} | ||
@@ -201,5 +220,5 @@ | ||
pp.parseFunctionStatement = function(node) { | ||
pp.parseFunctionStatement = function(node, isAsync) { | ||
this.next() | ||
return this.parseFunction(node, true) | ||
return this.parseFunction(node, true, false, isAsync) | ||
} | ||
@@ -434,9 +453,14 @@ | ||
pp.parseFunction = function(node, isStatement, allowExpressionBody) { | ||
pp.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) { | ||
this.initFunction(node) | ||
if (this.options.ecmaVersion >= 6) | ||
if (this.options.ecmaVersion >= 6 && !isAsync) | ||
node.generator = this.eat(tt.star) | ||
var oldInGen = this.inGenerator | ||
if (this.options.ecmaVersion >= 8) | ||
node.async = !!isAsync | ||
if (isStatement) | ||
node.id = this.parseIdent() | ||
var oldInGen = this.inGenerator, oldInAsync = this.inAsync | ||
this.inGenerator = node.generator | ||
if (isStatement || this.type === tt.name) | ||
this.inAsync = node.async | ||
if (!isStatement && this.type === tt.name) | ||
node.id = this.parseIdent() | ||
@@ -446,2 +470,3 @@ this.parseFunctionParams(node) | ||
this.inGenerator = oldInGen | ||
this.inAsync = oldInAsync | ||
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
@@ -452,3 +477,6 @@ } | ||
this.expect(tt.parenL) | ||
node.params = this.parseBindingList(tt.parenR, false, false, true) | ||
let refDestructuringErrors = new DestructuringErrors | ||
node.params = this.parseBindingList(tt.parenR, false, this.options.ecmaVersion >= 8, true, refDestructuringErrors) | ||
this.checkDefaultValueErrors(refDestructuringErrors, false, true) | ||
} | ||
@@ -459,6 +487,6 @@ | ||
pp.parseClass = function(node, isStatement) { | ||
pp.parseClass = function(node, isStatement, refDestructuringErrors) { | ||
this.next() | ||
this.parseClassId(node, isStatement) | ||
this.parseClassSuper(node) | ||
this.parseClassSuper(node, refDestructuringErrors) | ||
let classBody = this.startNode() | ||
@@ -472,4 +500,5 @@ let hadConstructor = false | ||
let isGenerator = this.eat(tt.star) | ||
let isAsync = false | ||
let isMaybeStatic = this.type === tt.name && this.value === "static" | ||
this.parsePropertyName(method) | ||
this.parsePropertyName(method, refDestructuringErrors) | ||
method.static = isMaybeStatic && this.type !== tt.parenL | ||
@@ -479,4 +508,10 @@ if (method.static) { | ||
isGenerator = this.eat(tt.star) | ||
this.parsePropertyName(method) | ||
this.parsePropertyName(method, refDestructuringErrors) | ||
} | ||
if (this.options.ecmaVersion >= 8 && !isGenerator && !method.computed && | ||
method.key.type === "Identifier" && method.key.name === "async" && this.type !== tt.parenL && | ||
!this.canInsertSemicolon()) { | ||
isAsync = true | ||
this.parsePropertyName(method, refDestructuringErrors) | ||
} | ||
method.kind = "method" | ||
@@ -486,6 +521,6 @@ let isGetSet = false | ||
let {key} = method | ||
if (!isGenerator && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) { | ||
if (!isGenerator && !isAsync && key.type === "Identifier" && this.type !== tt.parenL && (key.name === "get" || key.name === "set")) { | ||
isGetSet = true | ||
method.kind = key.name | ||
key = this.parsePropertyName(method) | ||
key = this.parsePropertyName(method, refDestructuringErrors) | ||
} | ||
@@ -497,2 +532,3 @@ if (!method.static && (key.type === "Identifier" && key.name === "constructor" || | ||
if (isGenerator) this.raise(key.start, "Constructor can't be a generator") | ||
if (isAsync) this.raise(key.start, "Constructor can't be an async method") | ||
method.kind = "constructor" | ||
@@ -502,3 +538,3 @@ hadConstructor = true | ||
} | ||
this.parseClassMethod(classBody, method, isGenerator) | ||
this.parseClassMethod(classBody, method, isGenerator, isAsync) | ||
if (isGetSet) { | ||
@@ -512,5 +548,6 @@ let paramCount = method.kind === "get" ? 0 : 1 | ||
this.raiseRecoverable(start, "setter should have exactly one param") | ||
} else { | ||
if (method.kind === "set" && method.value.params[0].type === "RestElement") | ||
this.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params") | ||
} | ||
if (method.kind === "set" && method.value.params[0].type === "RestElement") | ||
this.raise(method.value.params[0].start, "Setter cannot use rest params") | ||
} | ||
@@ -522,4 +559,4 @@ } | ||
pp.parseClassMethod = function(classBody, method, isGenerator) { | ||
method.value = this.parseMethod(isGenerator) | ||
pp.parseClassMethod = function(classBody, method, isGenerator, isAsync) { | ||
method.value = this.parseMethod(isGenerator, isAsync) | ||
classBody.body.push(this.finishNode(method, "MethodDefinition")) | ||
@@ -532,4 +569,4 @@ } | ||
pp.parseClassSuper = function(node) { | ||
node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null | ||
pp.parseClassSuper = function(node, refDestructuringErrors) { | ||
node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts(refDestructuringErrors) : null | ||
} | ||
@@ -539,3 +576,3 @@ | ||
pp.parseExport = function(node) { | ||
pp.parseExport = function(node, exports) { | ||
this.next() | ||
@@ -550,2 +587,3 @@ // export * from '...' | ||
if (this.eat(tt._default)) { // export default ... | ||
pp.checkExport(exports, "default", this.lastTokStart) | ||
let parens = this.type == tt.parenL | ||
@@ -570,2 +608,6 @@ let expr = this.parseMaybeAssign() | ||
node.declaration = this.parseStatement(true) | ||
if (node.declaration.type === "VariableDeclaration") | ||
this.checkVariableExport(exports, node.declaration.declarations) | ||
else | ||
this.checkExport(exports, node.declaration.id.name, node.declaration.id.start) | ||
node.specifiers = [] | ||
@@ -575,3 +617,3 @@ node.source = null | ||
node.declaration = null | ||
node.specifiers = this.parseExportSpecifiers() | ||
node.specifiers = this.parseExportSpecifiers(exports) | ||
if (this.eatContextual("from")) { | ||
@@ -594,4 +636,35 @@ node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected() | ||
pp.checkExport = function(exports, name, pos) { | ||
if (!exports) return | ||
if (Object.prototype.hasOwnProperty.call(exports, name)) | ||
this.raiseRecoverable(pos, "Duplicate export '" + name + "'") | ||
exports[name] = true | ||
} | ||
pp.checkPatternExport = function(exports, pat) { | ||
let type = pat.type | ||
if (type == "Identifier") | ||
this.checkExport(exports, pat.name, pat.start) | ||
else if (type == "ObjectPattern") | ||
for (let i = 0; i < pat.properties.length; ++i) | ||
this.checkPatternExport(exports, pat.properties[i].value) | ||
else if (type == "ArrayPattern") | ||
for (let i = 0; i < pat.elements.length; ++i) { | ||
let elt = pat.elements[i] | ||
if (elt) this.checkPatternExport(exports, elt) | ||
} | ||
else if (type == "AssignmentPattern") | ||
this.checkPatternExport(exports, pat.left) | ||
else if (type == "ParenthesizedExpression") | ||
this.checkPatternExport(exports, pat.expression) | ||
} | ||
pp.checkVariableExport = function(exports, decls) { | ||
if (!exports) return | ||
for (let i = 0; i < decls.length; i++) | ||
this.checkPatternExport(exports, decls[i].id) | ||
} | ||
pp.shouldParseExportStatement = function() { | ||
return this.type.keyword || this.isLet() | ||
return this.type.keyword || this.isLet() || this.isAsyncFunction() | ||
} | ||
@@ -601,3 +674,3 @@ | ||
pp.parseExportSpecifiers = function() { | ||
pp.parseExportSpecifiers = function(exports) { | ||
let nodes = [], first = true | ||
@@ -614,2 +687,3 @@ // export { x, y as z } [from '...'] | ||
node.local = this.parseIdent(this.type === tt._default) | ||
this.checkExport(exports, node.local.name, node.local.start) | ||
node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local | ||
@@ -616,0 +690,0 @@ nodes.push(this.finishNode(node, "ExportSpecifier")) |
@@ -193,3 +193,3 @@ // AST walker module for Mozilla Parser API compatible trees | ||
} | ||
base.ReturnStatement = base.YieldExpression = (node, st, c) => { | ||
base.ReturnStatement = base.YieldExpression = base.AwaitExpression = (node, st, c) => { | ||
if (node.argument) c(node.argument, st, "Expression") | ||
@@ -196,0 +196,0 @@ } |
@@ -8,3 +8,3 @@ // Matches a whole line break (where CRLF is considered a single | ||
export function isNewLine(code) { | ||
return code === 10 || code === 13 || code === 0x2028 || code == 0x2029 | ||
return code === 10 || code === 13 || code === 0x2028 || code === 0x2029 | ||
} | ||
@@ -11,0 +11,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 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
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
580230
13466
409