Mark FOO in "var { x: FOO }˝ as a binding, not as a reference (#9492)

This commit is contained in:
Nicolò Ribaudo
2019-02-27 00:17:11 +01:00
committed by GitHub
parent 43eed1ac92
commit 5c8cc0d536
6 changed files with 95 additions and 16 deletions

View File

@@ -4,7 +4,8 @@ import * as t from "@babel/types";
export const ReferencedIdentifier = {
types: ["Identifier", "JSXIdentifier"],
checkPath({ node, parent }: NodePath, opts?: Object): boolean {
checkPath(path: NodePath, opts?: Object): boolean {
const { node, parent } = path;
if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) {
if (t.isJSXIdentifier(node, opts)) {
if (react.isCompatTag(node.name)) return false;
@@ -15,7 +16,7 @@ export const ReferencedIdentifier = {
}
// check if node is referenced
return t.isReferenced(node, parent);
return t.isReferenced(node, parent, path.parentPath.parent);
},
};
@@ -28,8 +29,10 @@ export const ReferencedMemberExpression = {
export const BindingIdentifier = {
types: ["Identifier"],
checkPath({ node, parent }: NodePath): boolean {
return t.isIdentifier(node) && t.isBinding(node, parent);
checkPath(path: NodePath): boolean {
const { node, parent } = path;
const grandparent = path.parentPath.parent;
return t.isIdentifier(node) && t.isBinding(node, parent, grandparent);
},
};