Skip to content

Commit

Permalink
Revert "Remove refDestructuringErrors references from acorn plugins."
Browse files Browse the repository at this point in the history
This reverts commit 4062794.
  • Loading branch information
jdalton committed Nov 25, 2017
1 parent 3ab002c commit c89e922
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/acorn-ext/async-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// https://github.com/babel/babel/blob/master/packages/babylon/src/parser/expression.js
// https://github.com/babel/babel/blob/master/packages/babylon/src/parser/statement.js

import { DestructuringErrors } from "../vendor/acorn/src/parseutil.js"

import { types as tt } from "../vendor/acorn/src/tokentype.js"
import wrap from "../util/wrap.js"

Expand Down Expand Up @@ -140,7 +142,8 @@ function parseForStatement(node) {
return this.parseFor(node, init)
}

const init = this.parseExpression(true)
const refDestructuringErrors = new DestructuringErrors
const init = this.parseExpression(true, refDestructuringErrors)

if (this.type === tt._in ||
this.isContextual("of")) {
Expand Down Expand Up @@ -195,7 +198,7 @@ function parseFunction(node, isStatement, allowExpressionBody, isAsync) {
}

function parseProperty(func, args) {
const [isPattern] = args
const [isPattern, refDestructuringErrors] = args

if (this.type === tt.ellipsis) {
return func.apply(this, args)
Expand All @@ -209,7 +212,8 @@ function parseProperty(func, args) {
let startPos
let startLoc

if (isPattern) {
if (isPattern ||
refDestructuringErrors) {
startPos = this.start
startLoc = this.startLoc
}
Expand Down Expand Up @@ -238,7 +242,7 @@ function parseProperty(func, args) {
this.parsePropertyName(propNode)
}

this.parsePropertyValue(propNode, isPattern, isGenerator, isAsync, startPos, startLoc)
this.parsePropertyValue(propNode, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors)
return this.finishNode(propNode, "Property")
}

Expand Down
9 changes: 7 additions & 2 deletions src/acorn-ext/object-rest-spread.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ function enable(parser) {
}

function parseProperty(func, args) {
const [isPattern] = args
const [isPattern, refDestructuringErrors] = args

if (this.type !== tt.ellipsis) {
return func.apply(this, args)
}

const propNode = this.parseSpread()
const propNode = this.parseSpread(refDestructuringErrors)

if (isPattern) {
propNode.type = "RestElement"
propNode.value = this.toAssignable(propNode.argument)
}

if (this.type === tt.comma &&
refDestructuringErrors && refDestructuringErrors.trailingComma === -1) {
refDestructuringErrors.trailingComma = this.start
}

return propNode
}

Expand Down
10 changes: 9 additions & 1 deletion src/acorn-ext/tolerance.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const engineTypePostfix = "may only be used in ES modules"
const parserTypePostfix = "may appear only with 'sourceType: module'"

function enable(parser) {
parser.checkExpressionErrors =
parser.isDirectiveCandidate =
parser.strictDirective = alwaysFalse

Expand All @@ -35,6 +34,7 @@ function enable(parser) {
parser.exitFunctionScope =
parser.exitLexicalScope = noop

parser.checkExpressionErrors = checkExpressionErrors
parser.checkLVal = wrap(parser.checkLVal, strictWrapper)
parser.raise = raise
parser.raiseRecoverable = raiseRecoverable
Expand All @@ -43,6 +43,14 @@ function enable(parser) {
return parser
}

function checkExpressionErrors(refDestructuringErrors) {
if (refDestructuringErrors) {
return refDestructuringErrors.shorthandAssign !== -1
}

return false
}

function raise(pos, message) {
// Correct message for `let default`:
// https://github.com/ternjs/acorn/issues/544
Expand Down

0 comments on commit c89e922

Please sign in to comment.