New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
id in import attributes should not be referenced #13733
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,14 @@ export default function isReferenced( | |
// yes: NODE.child | ||
// no: parent.NODE | ||
case "MemberExpression": | ||
case "JSXMemberExpression": | ||
case "OptionalMemberExpression": | ||
if (parent.property === node) { | ||
// @ts-expect-error todo(flow->ts): computed is missing on JSXMemberExpression | ||
return !!parent.computed; | ||
} | ||
return parent.object === node; | ||
|
||
case "JSXMemberExpression": | ||
return parent.object === node; | ||
// no: let NODE = init; | ||
// yes: let id = NODE; | ||
case "VariableDeclarator": | ||
|
@@ -44,31 +44,34 @@ export default function isReferenced( | |
case "ClassMethod": | ||
case "ClassPrivateMethod": | ||
case "ObjectMethod": | ||
// @ts-expect-error todo(flow->ts) params have more specific type comparing to node | ||
if (parent.params.includes(node)) { | ||
return false; | ||
if (parent.key === node) { | ||
return !!parent.computed; | ||
} | ||
// fall through | ||
return false; | ||
|
||
// yes: { [NODE]: "" } | ||
// no: { NODE: "" } | ||
// depends: { NODE } | ||
// depends: { key: NODE } | ||
// fall through | ||
case "ObjectProperty": | ||
if (parent.key === node) { | ||
return !!parent.computed; | ||
} | ||
if (parent.value === node) { | ||
return !grandparent || grandparent.type !== "ObjectPattern"; | ||
} | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When can the node be neither the key nor the value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question! I have updated |
||
// no: class { NODE = value; } | ||
// yes: class { [NODE] = value; } | ||
// yes: class { key = NODE; } | ||
// fall through | ||
case "ClassProperty": | ||
case "ClassPrivateProperty": | ||
if (parent.key === node) { | ||
// @ts-expect-error todo(flow->ts): computed might not exist | ||
return !!parent.computed; | ||
} | ||
// @ts-expect-error todo(flow->ts): ObjectMethod does not have value property | ||
if (parent.value === node) { | ||
return !grandparent || grandparent.type !== "ObjectPattern"; | ||
return true; | ||
case "ClassPrivateProperty": | ||
if (parent.key === node) { | ||
return false; | ||
} | ||
return true; | ||
JLHwung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -136,6 +139,10 @@ export default function isReferenced( | |
case "ImportSpecifier": | ||
return false; | ||
|
||
// no: import "foo" assert { NODE: "json" } | ||
case "ImportAttribute": | ||
return false; | ||
|
||
// no: <div NODE="foo" /> | ||
case "JSXAttribute": | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR we checked
key
andparams
and return true ifnode
is neither inparams
nor inkey
. But thereturn true
branch is unreachable, unless the inputnode
does not have parental relationships withparent
.