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
Conversation
isReferenced should return false for identifiers used in import attributes
@@ -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; |
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
and params
and return true if node
is neither in params
nor in key
. But the return true
branch is unreachable, unless the input node
does not have parental relationships with parent
.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/48560/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit a9335f3:
|
if (parent.value === node) { | ||
return !grandparent || grandparent.type !== "ObjectPattern"; | ||
} | ||
return true; |
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.
When can the node be neither the key nor the value?
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.
Good question! node
could be neither key
nor the value
when parent
is not the actual parent of node
. This is actually ill-defined behaviour of t.isReferenced(node, parent)
: It returns true
if the parent.type
is not handled by current logic and return false
if handled since the conditions may never holds. Unless we change the interface to isReferenced(NodePath)
, I don't think we can mitigate such issues.
I have updated ObjectProperty
handling to align with other types such as ClassProperty
.
t.isReferenced
returnstrue
for id in import attributes, e.g. thetype
inimport json from "./foo.json" assert { type: "json" }
This PR starts from
(todo) flow->ts
cleanups. Found this bug when reading source.Also simplified the class elements handling. All the
fall through
annotations are removed.