-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
fix(semantic): reference flags not correctly resolved when after an export stmt #8134
fix(semantic): reference flags not correctly resolved when after an export stmt #8134
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Performance ReportMerging #8134 will not alter performanceComparing Summary
|
8f63540
to
2601a3a
Compare
cdd121b
to
21c1cc7
Compare
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.
Thank you for working on this!
self.current_reference_flags.is_empty() is not empty, which causes the current ref flags to be used (this is incorrect, we should be using a fresh version of reference flags). Buy setting ref flags to None on exit export node, this issue is avoided
This is not the root cause, after resolving reference flags, the flags should be empty because it took, so the problem is why it still has ReferenceFlags::Type
. After debugging, I found the problem is related to export if has source
, you can see playground, and then I look through the AST, just found that if there is a source in export, all ExportSpeicifer
are IdentifierName
than IdentifierReference
, so it cannot reset.
How to solve?
We should not set current reference flags if the export has source
, and call visit_export_specifiers
instead. The code looks like:
- for specifier in &it.specifiers {
- // `export type { a }` or `export { type a }` -> `a` is a type reference
- if it.export_kind.is_type() || specifier.export_kind.is_type() {
- self.current_reference_flags = ReferenceFlags::Type;
- } else {
- // If the export specifier is not a explicit type export, we consider it as a potential
- // type and value reference. If it references to a value in the end, we would delete the
- // `ReferenceFlags::Type` flag in `fn resolve_references_for_current_scope`.
- self.current_reference_flags = ReferenceFlags::Read | ReferenceFlags::Type;
- }
- self.visit_export_specifier(specifier);
- }
--
if let Some(source) = &it.source {
self.visit_string_literal(source);
+ self.visit_export_specifiers(&it.specifiers);
+ } else {
+ for specifier in &it.specifiers {
+ // `export type { a }` or `export { type a }` -> `a` is a type reference
+ if it.export_kind.is_type() || specifier.export_kind.is_type() {
+ self.current_reference_flags = ReferenceFlags::Type;
+ } else {
+ // If the export specifier is not a explicit type export, we conside
r it as a potential
+ // type and value reference. If it references to a value in the end,
we would delete the
+ // `ReferenceFlags::Type` flag in `fn resolve_references_for_current
_scope`.
+ self.current_reference_flags = ReferenceFlags::Read | ReferenceFlags
::Type;
+ }
+ self.visit_export_specifier(specifier);
+ }
}
Feel free to make it better!
21c1cc7
to
ca9fba8
Compare
ohhh @Dunqing this makes so much sense, thanks for taking the time to help investigate this. So basically what was happening is:
Dunqing fixes this by:
|
Yes, it is complex and unintuitive, but I haven't found a way to make it better, If you are interested in finding a way to sort it out, do it!
Exactly, Thank you for summing it up! |
Merge activity
|
…xport stmt (#8134) fixes #7879 (comment) TLDR is curently here: https://github.com/oxc-project/oxc/blob/cdd121bfa4a66d5b2cf72a444f35e82daf81d11e/crates/oxc_semantic/src/builder.rs#L2130-L2135 `self.current_reference_flags.is_empty()` is not empty, which causes the current ref flags to be used (this is incorrect, we should be using a fresh version of reference flags). Buy setting ref flags to `None` on exit export node, this issue is avoided `export` **BEFORE** the reference ( incorrect reference flags) https://playground.oxc.rs/#eNpVjjuOwzAMRK8isElj7A/YxtttkVOkkR3aECCJBskkdgzdPZISG0ilGc3DcFbooQUXJmI1q/m3bJIZmII5fHx2lg9/p4hzTXWZsCL3N+RekB3qvRUxRyKDs2I8S61cEzRA0K7Al1geWaLaGVrlCzbgXdRNS08T7mYJHfnNKdsoA3GAdrBeMDUwWRbk3Jh1adn0jtYPUMsj5hOA8vP1/QuZ6OmMI5Yx2QQX3eCebLBx9K8FlYvK5I+ebiW9InckOX4uSOkBCrdvkw== `export` **AFTER** the reference ( correct reference flags) https://playground.oxc.rs/#eNpVjj2uwjAQhK9ibZMmen/Sa0JHwSlonLCJLNm70a6BhMh3xzEEQeUZz6fZWaCDBlwYWaJZzN6KSaYXDqb6+m6tVLsjHQmnknfeqpoDs8EpIp208Et6Q+I8Yum5ffTcqh3UwNAsIGdaH50p2gmaKGeswTuKm9aOR3yZObTsNxfFkvYsAZreesVUw2hFUXJj1mvLpl9o+YBoZcB8AlD/fn7/IRMdn3DAdUw2wZHr3YMNlgb/XFA4isL+4Pm6pheUljXHjwUp3QEtmnBd this PR fixes this issue by resetting the reference flags after exising an export stmt
ca9fba8
to
79af100
Compare
fixes #7879 (comment)
TLDR is curently here:
oxc/crates/oxc_semantic/src/builder.rs
Lines 2130 to 2135 in cdd121b
self.current_reference_flags.is_empty()
is not empty, which causes the current ref flags to be used (this is incorrect, we should be using a fresh version of reference flags). Buy setting ref flags toNone
on exit export node, this issue is avoidedexport
BEFORE the reference ( incorrect reference flags)https://playground.oxc.rs/#eNpVjjuOwzAMRK8isElj7A/YxtttkVOkkR3aECCJBskkdgzdPZISG0ilGc3DcFbooQUXJmI1q/m3bJIZmII5fHx2lg9/p4hzTXWZsCL3N+RekB3qvRUxRyKDs2I8S61cEzRA0K7Al1geWaLaGVrlCzbgXdRNS08T7mYJHfnNKdsoA3GAdrBeMDUwWRbk3Jh1adn0jtYPUMsj5hOA8vP1/QuZ6OmMI5Yx2QQX3eCebLBx9K8FlYvK5I+ebiW9InckOX4uSOkBCrdvkw==
export
AFTER the reference ( correct reference flags)https://playground.oxc.rs/#eNpVjj2uwjAQhK9ibZMmen/Sa0JHwSlonLCJLNm70a6BhMh3xzEEQeUZz6fZWaCDBlwYWaJZzN6KSaYXDqb6+m6tVLsjHQmnknfeqpoDs8EpIp208Et6Q+I8Yum5ffTcqh3UwNAsIGdaH50p2gmaKGeswTuKm9aOR3yZObTsNxfFkvYsAZreesVUw2hFUXJj1mvLpl9o+YBoZcB8AlD/fn7/IRMdn3DAdUw2wZHr3YMNlgb/XFA4isL+4Pm6pheUljXHjwUp3QEtmnBd
this PR fixes this issue by resetting the reference flags after exising an export stmt