From 52c3c143f96889ba76d95ad5f19a555be8e64c2d Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sun, 14 Jun 2015 20:21:02 +0100 Subject: [PATCH] add BindingIdentifier virtual type --- src/babel/transformation/helpers/name-method.js | 7 ++----- src/babel/traversal/path/lib/virtual-types.js | 7 +++++++ src/babel/types/validators.js | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/babel/transformation/helpers/name-method.js b/src/babel/transformation/helpers/name-method.js index c930c5e9f6..0057123015 100644 --- a/src/babel/transformation/helpers/name-method.js +++ b/src/babel/transformation/helpers/name-method.js @@ -20,11 +20,8 @@ var visitor = { visitIdentifier(this, node, scope, state); }, - AssignmentExpression(node, parent, scope, state) { - var ids = this.getBindingIdentifiers(); - for (var name in ids) { - visitIdentifier(this, ids[name], scope, state); - } + BindingIdentifier(node, parent, scope, state) { + visitIdentifier(this, node, scope, state); } }; diff --git a/src/babel/traversal/path/lib/virtual-types.js b/src/babel/traversal/path/lib/virtual-types.js index f272c524fc..9dd60ae227 100644 --- a/src/babel/traversal/path/lib/virtual-types.js +++ b/src/babel/traversal/path/lib/virtual-types.js @@ -18,6 +18,13 @@ export var ReferencedIdentifier = { } }; +export var BindingIdentifier = { + types: ["Identifier"], + checkPath({ node, parent }, opts) { + return t.isBinding(node, parent); + } +}; + export var Expression = { types: ["Expression"], checkPath(path) { diff --git a/src/babel/types/validators.js b/src/babel/types/validators.js index b186db335f..4fc8aa54b2 100644 --- a/src/babel/types/validators.js +++ b/src/babel/types/validators.js @@ -1,6 +1,20 @@ +import { getBindingIdentifiers } from "./retrievers"; import esutils from "esutils"; import * as t from "./index"; +/** + * + */ + +export function isBinding(node: Object, parent: Object): boolean { + var bindingKey = getBindingIdentifiers.keys[parent.type]; + if (bindingKey) { + return parent[bindingKey] === node; + } else { + return false; + } +} + /** * Check if the input `node` is a reference to a bound variable. */