diff --git a/packages/babel-plugin-check-es2015-constants/src/index.js b/packages/babel-plugin-check-es2015-constants/src/index.js index 7a983364a5..ccbe33aea1 100644 --- a/packages/babel-plugin-check-es2015-constants/src/index.js +++ b/packages/babel-plugin-check-es2015-constants/src/index.js @@ -36,13 +36,13 @@ export default function({ messages, types: t }) { violation.get("right").node, ), ); - } else if (violation.parentPath.isUpdateExpression()) { - violation.parentPath.replaceWith( - statementBeforeExpression(throwNode, violation.parent), + } else if (violation.isUpdateExpression()) { + violation.replaceWith( + statementBeforeExpression(throwNode, violation.node), ); - } else if (violation.parentPath.isForXStatement()) { - violation.parentPath.ensureBlock(); - violation.parentPath.node.body.body.unshift(throwNode); + } else if (violation.isForXStatement()) { + violation.ensureBlock(); + violation.node.body.body.unshift(throwNode); } } } diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index 356b063980..b2cdc4238e 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -104,7 +104,7 @@ const collectorVisitor = { ForXStatement(path, state) { const left = path.get("left"); if (left.isPattern() || left.isIdentifier()) { - state.constantViolations.push(left); + state.constantViolations.push(path); } }, @@ -140,12 +140,12 @@ const collectorVisitor = { }, UpdateExpression(path, state) { - state.constantViolations.push(path.get("argument")); + state.constantViolations.push(path); }, UnaryExpression(path, state) { if (path.node.operator === "delete") { - state.constantViolations.push(path.get("argument")); + state.constantViolations.push(path); } }, diff --git a/packages/babel-types/src/retrievers.js b/packages/babel-types/src/retrievers.js index 8deb4053bf..7abdd1f333 100644 --- a/packages/babel-types/src/retrievers.js +++ b/packages/babel-types/src/retrievers.js @@ -89,6 +89,9 @@ getBindingIdentifiers.keys = { FunctionDeclaration: ["id", "params"], FunctionExpression: ["id", "params"], + ForInStatement: ["left"], + ForOfStatement: ["left"], + ClassDeclaration: ["id"], ClassExpression: ["id"],