restructure testing infrastructure to be more modular

This commit is contained in:
Sebastian McKenzie
2015-03-28 01:21:48 +11:00
parent 5f6a216809
commit ddd173a4b3
10 changed files with 12 additions and 61591 deletions

View File

@@ -101,6 +101,13 @@ pp.parseMaybeAssign = function(noIn, refShorthandDefaultPos, afterLeftParse) {
node.left = this.type === tt.eq ? this.toAssignable(left) : left
refShorthandDefaultPos.start = 0; // reset because shorthand default was used correctly
this.checkLVal(left)
if (left.parenthesizedExpression) {
if (left.type === "ObjectPattern") {
this.raise(left.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
} else {
this.raise(left.start, "Parenthesized left hand expressions are illegal");
}
}
this.next()
node.right = this.parseMaybeAssign(noIn)
return this.finishNode(node, "AssignmentExpression")

View File

@@ -9,14 +9,6 @@ const pp = Parser.prototype
// if possible.
pp.toAssignable = function(node, isBinding) {
if (node.parenthesizedExpression) {
if (node.type === "ObjectExpression") {
this.raise(node.start, "You're trying to assign to a parenthesized expression, instead of `({ foo }) = {}` use `({ foo } = {})`");
} else {
this.raise(node.start, "Parenthesized left hand expressions are illegal");
}
}
if (this.options.ecmaVersion >= 6 && node) {
switch (node.type) {
case "Identifier":

View File

@@ -57,6 +57,10 @@ pp.updateContext = function(prevType) {
// Token-specific context update code
tt.parenR.updateContext = tt.braceR.updateContext = function() {
if (this.context.length == 1) {
this.exprAllowed = true
return
}
let out = this.context.pop()
if (out === types.b_stat && this.curContext() === types.f_expr) {
this.context.pop()
@@ -64,7 +68,7 @@ tt.parenR.updateContext = tt.braceR.updateContext = function() {
} else if (out === types.b_tmpl) {
this.exprAllowed = true
} else {
this.exprAllowed = !(out && out.isExpr)
this.exprAllowed = !out.isExpr
}
}