Skip to content

Commit

Permalink
fix(semantic): transform checker compare scope children (#5056)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 22, 2024
1 parent b52c6a4 commit f187b71
Show file tree
Hide file tree
Showing 7 changed files with 7,811 additions and 52 deletions.
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

0 comments on commit f187b71

Please sign in to comment.