Skip to content
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): transform checker compare scope children #5056

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,26 @@ impl<'s> PostTransformChecker<'s> {
if !is_match {
self.errors.push_mismatch("Scope parent mismatch", scope_ids, parent_ids);
}

// Check children match
let child_ids = self.get_pair(scope_ids, |data, scope_id| {
data.scopes.get_child_ids(scope_id).cloned().unwrap_or_default()
});
let is_match = child_ids.after_transform.len() == child_ids.rebuilt.len() && {
let mut child_ids_after_transform = child_ids
.after_transform
.iter()
.map(|child_id| self.scope_ids_map.get(child_id).copied())
.collect::<Vec<_>>();
child_ids_after_transform.sort_unstable();
let mut child_ids_rebuilt =
child_ids.rebuilt.iter().copied().map(Option::Some).collect::<Vec<_>>();
child_ids_rebuilt.sort_unstable();
child_ids_after_transform == child_ids_rebuilt
};
if !is_match {
self.errors.push_mismatch("Scope children mismatch", scope_ids, child_ids);
}
}
}

Expand Down
633 changes: 632 additions & 1 deletion tasks/coverage/semantic_babel.snap

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tasks/coverage/semantic_misc.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,25 @@ tasks/coverage/misc/pass/oxc-2087.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Helpers"]
rebuilt : ScopeId(0): []
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1)]
rebuilt : ScopeId(0): []

tasks/coverage/misc/pass/oxc-2394.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["A"]
rebuilt : ScopeId(0): []
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1)]
rebuilt : ScopeId(0): []

tasks/coverage/misc/pass/oxc-2592.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["Foo"]
rebuilt : ScopeId(0): []
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1)]
rebuilt : ScopeId(0): []

tasks/coverage/misc/pass/oxc-3443.tsx
semantic error: Bindings mismatch:
Expand Down
912 changes: 911 additions & 1 deletion tasks/coverage/semantic_test262.snap

Large diffs are not rendered by default.

Loading