Comparing version 4.0.4 to 4.0.5
@@ -0,1 +1,17 @@ | ||
## 4.0.5 (2017-02-02) | ||
### Bug fixes | ||
Disallow parenthesized pattern expressions. | ||
Allow keywords as export names. | ||
Don't allow the `async` keyword to be parenthesized. | ||
Properly raise an error when a keyword contains a character escape. | ||
Allow `"use strict"` to appear after other string literal expressions. | ||
Disallow labeled declarations. | ||
## 4.0.4 (2016-12-19) | ||
@@ -2,0 +18,0 @@ |
@@ -546,2 +546,3 @@ import { defaultOptions, addLooseExports, SourceLocation, tokTypes, tokenizer, Node, lineBreak, isNewLine, getLineInfo, Token, lineBreakG } from './acorn'; | ||
this.next() | ||
if (isStatement == null) isStatement = this.tok.type === tokTypes.name | ||
if (this.tok.type === tokTypes.name) node.id = this.parseIdent() | ||
@@ -621,2 +622,3 @@ else if (isStatement) node.id = this.dummyIdent() | ||
} | ||
if (isStatement == null) isStatement = this.tok.type === tokTypes.name | ||
if (this.tok.type === tokTypes.name) node.id = this.parseIdent() | ||
@@ -640,11 +642,13 @@ else if (isStatement) node.id = this.dummyIdent() | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
var isParenL = this.tok.type === tokTypes.parenL | ||
var expr = this.parseMaybeAssign() | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
case "ClassExpression": expr.type = "ClassDeclaration"; break | ||
} | ||
var isAsync | ||
if (this.tok.type === tokTypes._function || (isAsync = this.toks.isAsyncFunction())) { | ||
var fNode = this.startNode() | ||
this.next() | ||
if (isAsync) this.next() | ||
node.declaration = this.parseFunction(fNode, null, isAsync) | ||
} else if (this.tok.type === tokTypes._class) { | ||
node.declaration = this.parseClass(null) | ||
} else { | ||
node.declaration = this.parseMaybeAssign() | ||
} | ||
node.declaration = expr | ||
this.semicolon() | ||
@@ -1031,3 +1035,3 @@ return this.finishNode(node, "ExportDefaultDeclaration") | ||
case tokTypes._class: | ||
return this.parseClass() | ||
return this.parseClass(false) | ||
@@ -1034,0 +1038,0 @@ case tokTypes._function: |
@@ -550,2 +550,3 @@ (function (global, factory) { | ||
this.next() | ||
if (isStatement == null) isStatement = this.tok.type === __acorn.tokTypes.name | ||
if (this.tok.type === __acorn.tokTypes.name) node.id = this.parseIdent() | ||
@@ -625,2 +626,3 @@ else if (isStatement) node.id = this.dummyIdent() | ||
} | ||
if (isStatement == null) isStatement = this.tok.type === __acorn.tokTypes.name | ||
if (this.tok.type === __acorn.tokTypes.name) node.id = this.parseIdent() | ||
@@ -644,11 +646,13 @@ else if (isStatement) node.id = this.dummyIdent() | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
var isParenL = this.tok.type === __acorn.tokTypes.parenL | ||
var expr = this.parseMaybeAssign() | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
case "ClassExpression": expr.type = "ClassDeclaration"; break | ||
} | ||
var isAsync | ||
if (this.tok.type === __acorn.tokTypes._function || (isAsync = this.toks.isAsyncFunction())) { | ||
var fNode = this.startNode() | ||
this.next() | ||
if (isAsync) this.next() | ||
node.declaration = this.parseFunction(fNode, null, isAsync) | ||
} else if (this.tok.type === __acorn.tokTypes._class) { | ||
node.declaration = this.parseClass(null) | ||
} else { | ||
node.declaration = this.parseMaybeAssign() | ||
} | ||
node.declaration = expr | ||
this.semicolon() | ||
@@ -1035,3 +1039,3 @@ return this.finishNode(node, "ExportDefaultDeclaration") | ||
case __acorn.tokTypes._class: | ||
return this.parseClass() | ||
return this.parseClass(false) | ||
@@ -1038,0 +1042,0 @@ case __acorn.tokTypes._function: |
@@ -7,3 +7,3 @@ { | ||
"jsnext:main": "dist/acorn.es.js", | ||
"version": "4.0.4", | ||
"version": "4.0.5", | ||
"engines": { | ||
@@ -10,0 +10,0 @@ "node": ">=0.4.0" |
# Acorn | ||
[![Build Status](https://travis-ci.org/ternjs/acorn.svg?branch=master)](https://travis-ci.org/ternjs/acorn) | ||
[![NPM version](https://img.shields.io/npm/v/acorn.svg)](https://www.npmjs.com/package/acorn) | ||
[![NPM version](https://img.shields.io/npm/v/acorn.svg)](https://www.npmjs.com/package/acorn) | ||
[![CDNJS](https://img.shields.io/cdnjs/v/acorn.svg)](https://cdnjs.com/libraries/acorn) | ||
[Author funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?force)](https://marijnhaverbeke.nl/fund/) | ||
@@ -6,0 +7,0 @@ |
@@ -112,3 +112,3 @@ // A recursive descent parser operates by defining functions for all | ||
node.left = this.type === tt.eq ? this.toAssignable(left) : left | ||
refDestructuringErrors.shorthandAssign = 0 // reset because shorthand default was used correctly | ||
refDestructuringErrors.shorthandAssign = -1 // reset because shorthand default was used correctly | ||
this.checkLVal(left) | ||
@@ -231,4 +231,5 @@ this.next() | ||
pp.parseSubscripts = function(base, startPos, startLoc, noCalls) { | ||
let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && | ||
this.lastTokEnd == base.end && !this.canInsertSemicolon() | ||
for (;;) { | ||
let maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" && !this.canInsertSemicolon() | ||
if (this.eat(tt.dot)) { | ||
@@ -329,2 +330,4 @@ let node = this.startNodeAt(startPos, startLoc) | ||
case tt.parenL: | ||
if (refDestructuringErrors && refDestructuringErrors.parenthesized < 0) | ||
refDestructuringErrors.parenthesized = this.start | ||
return this.parseParenAndDistinguishExpression(canBeArrow) | ||
@@ -583,3 +586,3 @@ | ||
} else if (this.type === tt.eq && refDestructuringErrors) { | ||
if (!refDestructuringErrors.shorthandAssign) | ||
if (refDestructuringErrors.shorthandAssign < 0) | ||
refDestructuringErrors.shorthandAssign = this.start | ||
@@ -623,3 +626,4 @@ prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key) | ||
pp.parseMethod = function(isGenerator, isAsync) { | ||
let node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos | ||
let node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync, | ||
oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction | ||
@@ -636,2 +640,3 @@ this.initFunction(node) | ||
this.awaitPos = 0 | ||
this.inFunction = true | ||
@@ -647,2 +652,3 @@ this.expect(tt.parenL) | ||
this.awaitPos = oldAwaitPos | ||
this.inFunction = oldInFunc | ||
return this.finishNode(node, "FunctionExpression") | ||
@@ -654,3 +660,4 @@ } | ||
pp.parseArrowExpression = function(node, params, isAsync) { | ||
let oldInGen = this.inGenerator, oldInAsync = this.inAsync, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos | ||
let oldInGen = this.inGenerator, oldInAsync = this.inAsync, | ||
oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction | ||
@@ -665,2 +672,3 @@ this.initFunction(node) | ||
this.awaitPos = 0 | ||
this.inFunction = true | ||
@@ -674,2 +682,3 @@ node.params = this.toAssignableList(params, true) | ||
this.awaitPos = oldAwaitPos | ||
this.inFunction = oldInFunc | ||
return this.finishNode(node, "ArrowFunctionExpression") | ||
@@ -681,3 +690,3 @@ } | ||
pp.parseFunctionBody = function(node, isArrowFunction) { | ||
let isExpression = isArrowFunction && this.type !== tt.braceL | ||
let isExpression = isArrowFunction && this.type !== tt.braceL, strict = this.strict | ||
@@ -688,9 +697,10 @@ if (isExpression) { | ||
} else { | ||
strict = strict || this.strictDirective(this.end) | ||
// Start a new scope with regard to labels and the `inFunction` | ||
// flag (restore them to their old value afterwards). | ||
let oldInFunc = this.inFunction, oldLabels = this.labels | ||
this.inFunction = true; this.labels = [] | ||
let oldLabels = this.labels, oldStrict = this.strict | ||
this.labels = []; this.strict = strict | ||
node.body = this.parseBlock(true) | ||
node.expression = false | ||
this.inFunction = oldInFunc; this.labels = oldLabels | ||
this.labels = oldLabels; this.strict = oldStrict | ||
} | ||
@@ -701,7 +711,6 @@ | ||
// or `arguments`. | ||
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 (strict && this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params)) | ||
this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list") | ||
if (this.strict || useStrict) { | ||
if (this.strict || strict) { | ||
let oldStrict = this.strict | ||
@@ -751,7 +760,7 @@ this.strict = true | ||
elt = this.parseSpread(refDestructuringErrors) | ||
if (this.type === tt.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) { | ||
if (refDestructuringErrors && this.type === tt.comma && refDestructuringErrors.trailingComma < 0) | ||
refDestructuringErrors.trailingComma = this.start | ||
} | ||
} else | ||
} else { | ||
elt = this.parseMaybeAssign(false, refDestructuringErrors) | ||
} | ||
elts.push(elt) | ||
@@ -758,0 +767,0 @@ } |
@@ -33,3 +33,3 @@ // Acorn is a tiny, fast JavaScript parser written in JavaScript. | ||
export {Node} from "./node" | ||
export {TokenType, types as tokTypes} from "./tokentype" | ||
export {TokenType, types as tokTypes, keywords as keywordTypes} from "./tokentype" | ||
export {TokContext, types as tokContexts} from "./tokencontext" | ||
@@ -40,3 +40,3 @@ export {isIdentifierChar, isIdentifierStart} from "./identifier" | ||
export const version = "4.0.4" | ||
export const version = "4.0.5" | ||
@@ -43,0 +43,0 @@ // The main exported interface (under `self.acorn` when in the |
@@ -283,3 +283,3 @@ import {LooseParser} from "./state" | ||
case tt._class: | ||
return this.parseClass() | ||
return this.parseClass(false) | ||
@@ -286,0 +286,0 @@ case tt._function: |
@@ -254,2 +254,3 @@ import {LooseParser} from "./state" | ||
this.next() | ||
if (isStatement == null) isStatement = this.tok.type === tt.name | ||
if (this.tok.type === tt.name) node.id = this.parseIdent() | ||
@@ -329,2 +330,3 @@ else if (isStatement) node.id = this.dummyIdent() | ||
} | ||
if (isStatement == null) isStatement = this.tok.type === tt.name | ||
if (this.tok.type === tt.name) node.id = this.parseIdent() | ||
@@ -348,11 +350,13 @@ else if (isStatement) node.id = this.dummyIdent() | ||
// export default (function foo() {}) // This is FunctionExpression. | ||
let isParenL = this.tok.type === tt.parenL | ||
let expr = this.parseMaybeAssign() | ||
if (!isParenL && expr.id) { | ||
switch (expr.type) { | ||
case "FunctionExpression": expr.type = "FunctionDeclaration"; break | ||
case "ClassExpression": expr.type = "ClassDeclaration"; break | ||
} | ||
let isAsync | ||
if (this.tok.type === tt._function || (isAsync = this.toks.isAsyncFunction())) { | ||
let fNode = this.startNode() | ||
this.next() | ||
if (isAsync) this.next() | ||
node.declaration = this.parseFunction(fNode, null, isAsync) | ||
} else if (this.tok.type === tt._class) { | ||
node.declaration = this.parseClass(null) | ||
} else { | ||
node.declaration = this.parseMaybeAssign() | ||
} | ||
node.declaration = expr | ||
this.semicolon() | ||
@@ -359,0 +363,0 @@ return this.finishNode(node, "ExportDefaultDeclaration") |
import {types as tt} from "./tokentype" | ||
import {Parser} from "./state" | ||
import {lineBreak} from "./whitespace" | ||
import {lineBreak, skipWhiteSpace} from "./whitespace" | ||
@@ -9,8 +9,5 @@ const pp = Parser.prototype | ||
// Test whether a statement node is the string literal `"use strict"`. | ||
pp.isUseStrict = function(stmt) { | ||
return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && | ||
stmt.expression.type === "Literal" && | ||
stmt.expression.raw.slice(1, -1) === "use strict" | ||
const useStrictRE = new RegExp(`^(${skipWhiteSpace.source}('([^\']|\\.)*'|"([^\"]|\\.)*"|;))*${skipWhiteSpace.source}('use strict'|"use strict")`) | ||
pp.strictDirective = function(start) { | ||
return useStrictRE.test(this.input.slice(start)) | ||
} | ||
@@ -96,17 +93,17 @@ | ||
constructor() { | ||
this.shorthandAssign = 0 | ||
this.trailingComma = 0 | ||
this.shorthandAssign = this.trailingComma = this.parenthesized = -1 | ||
} | ||
} | ||
pp.checkPatternErrors = function(refDestructuringErrors, andThrow) { | ||
let trailing = refDestructuringErrors && refDestructuringErrors.trailingComma | ||
if (!andThrow) return !!trailing | ||
if (trailing) this.raise(trailing, "Comma is not permitted after the rest element") | ||
pp.checkPatternErrors = function(refDestructuringErrors) { | ||
let trailing = refDestructuringErrors ? refDestructuringErrors.trailingComma : -1 | ||
let parens = refDestructuringErrors ? refDestructuringErrors.parenthesized : -1 | ||
if (trailing > -1) this.raiseRecoverable(trailing, "Comma is not permitted after the rest element") | ||
if (parens > -1) this.raiseRecoverable(parens, "Parenthesized pattern") | ||
} | ||
pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) { | ||
let pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign | ||
if (!andThrow) return !!pos | ||
if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns") | ||
let pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1 | ||
if (!andThrow) return pos >= 0 | ||
if (pos > -1) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns") | ||
} | ||
@@ -113,0 +110,0 @@ |
@@ -72,3 +72,4 @@ import {reservedWords, keywords} from "./identifier" | ||
// Figure out if it's a module code. | ||
this.strict = this.inModule = options.sourceType === "module" | ||
this.inModule = options.sourceType === "module" | ||
this.strict = this.inModule || this.strictDirective(this.pos) | ||
@@ -75,0 +76,0 @@ // Used to signify the start of a potential arrow function |
@@ -17,3 +17,3 @@ import {types as tt} from "./tokentype" | ||
pp.parseTopLevel = function(node) { | ||
let first = true, exports = {} | ||
let exports = {} | ||
if (!node.body) node.body = [] | ||
@@ -23,6 +23,2 @@ while (this.type !== tt.eof) { | ||
node.body.push(stmt) | ||
if (first) { | ||
if (this.isUseStrict(stmt)) this.setStrict(true) | ||
first = false | ||
} | ||
} | ||
@@ -208,5 +204,5 @@ this.next() | ||
if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) { | ||
this.checkPatternErrors(refDestructuringErrors, true) | ||
this.toAssignable(init) | ||
this.checkLVal(init) | ||
this.checkPatternErrors(refDestructuringErrors) | ||
return this.parseForIn(node, init) | ||
@@ -363,2 +359,6 @@ } else { | ||
node.body = this.parseStatement(true) | ||
if (node.body.type == "ClassDeclaration" || | ||
node.body.type == "VariableDeclaration" && (this.strict || node.body.kind != "var") || | ||
node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator)) | ||
this.raiseRecoverable(node.body.start, "Invalid labeled declaration") | ||
this.labels.pop() | ||
@@ -379,4 +379,4 @@ node.label = expr | ||
pp.parseBlock = function(allowStrict) { | ||
let node = this.startNode(), first = true, oldStrict | ||
pp.parseBlock = function() { | ||
let node = this.startNode() | ||
node.body = [] | ||
@@ -387,9 +387,3 @@ this.expect(tt.braceL) | ||
node.body.push(stmt) | ||
if (first && allowStrict && this.isUseStrict(stmt)) { | ||
oldStrict = this.strict | ||
this.setStrict(this.strict = true) | ||
} | ||
first = false | ||
} | ||
if (oldStrict === false) this.setStrict(false) | ||
return this.finishNode(node, "BlockStatement") | ||
@@ -466,6 +460,9 @@ } | ||
if (isStatement == null) | ||
isStatement = this.type == tt.name | ||
if (isStatement) | ||
node.id = this.parseIdent() | ||
let oldInGen = this.inGenerator, oldInAsync = this.inAsync, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos | ||
let oldInGen = this.inGenerator, oldInAsync = this.inAsync, | ||
oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction | ||
this.inGenerator = node.generator | ||
@@ -475,2 +472,3 @@ this.inAsync = node.async | ||
this.awaitPos = 0 | ||
this.inFunction = true | ||
@@ -486,2 +484,3 @@ if (!isStatement && this.type === tt.name) | ||
this.awaitPos = oldAwaitPos | ||
this.inFunction = oldInFunc | ||
return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression") | ||
@@ -501,2 +500,3 @@ } | ||
this.next() | ||
if (isStatement == null) isStatement = this.type === tt.name | ||
this.parseClassId(node, isStatement) | ||
@@ -591,16 +591,17 @@ this.parseClassSuper(node) | ||
this.checkExport(exports, "default", this.lastTokStart) | ||
let parens = this.type == tt.parenL | ||
let expr = this.parseMaybeAssign() | ||
let needsSemi = true | ||
if (!parens && (expr.type == "FunctionExpression" || | ||
expr.type == "ClassExpression")) { | ||
needsSemi = false | ||
if (expr.id) { | ||
expr.type = expr.type == "FunctionExpression" | ||
? "FunctionDeclaration" | ||
: "ClassDeclaration" | ||
} | ||
let isAsync | ||
if (this.type === tt._function || (isAsync = this.isAsyncFunction())) { | ||
let fNode = this.startNode() | ||
this.next() | ||
if (isAsync) this.next() | ||
node.declaration = this.parseFunction(fNode, null, false, isAsync) | ||
if (fNode.type == "FunctionExpression") this.semicolon() | ||
} else if (this.type === tt._class) { | ||
let cNode = this.startNode() | ||
node.declaration = this.parseClass(cNode, null) | ||
if (cNode.type == "ClassExpression") this.semicolon() | ||
} else { | ||
node.declaration = this.parseMaybeAssign() | ||
this.semicolon() | ||
} | ||
node.declaration = expr | ||
if (needsSemi) this.semicolon() | ||
return this.finishNode(node, "ExportDefaultDeclaration") | ||
@@ -690,3 +691,3 @@ } | ||
let node = this.startNode() | ||
node.local = this.parseIdent(this.type === tt._default) | ||
node.local = this.parseIdent(true) | ||
node.exported = this.eatContextual("as") ? this.parseIdent(true) : node.local | ||
@@ -693,0 +694,0 @@ this.checkExport(exports, node.exported.name, node.exported.start) |
@@ -65,15 +65,2 @@ import {isIdentifierStart, isIdentifierChar} from "./identifier" | ||
pp.setStrict = function(strict) { | ||
this.strict = strict | ||
if (this.type !== tt.num && this.type !== tt.string) return | ||
this.pos = this.start | ||
if (this.options.locations) { | ||
while (this.pos < this.lineStart) { | ||
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1 | ||
--this.curLine | ||
} | ||
} | ||
this.nextToken() | ||
} | ||
pp.curContext = function() { | ||
@@ -695,5 +682,7 @@ return this.context[this.context.length - 1] | ||
let type = tt.name | ||
if ((this.options.ecmaVersion >= 6 || !this.containsEsc) && this.keywords.test(word)) | ||
if (this.keywords.test(word)) { | ||
if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword " + word) | ||
type = keywordTypes[word] | ||
} | ||
return this.finishToken(type, word) | ||
} |
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
604153
39
13597
410