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 binding symbol IDs #5057

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
32 changes: 29 additions & 3 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,35 @@ impl<'s> PostTransformChecker<'s> {
(None, None) => continue,
(Some(scope_id_after_transform), Some(scope_id_rebuilt)) => {
let scope_ids = Pair::new(scope_id_after_transform, scope_id_rebuilt);
let bindings = self.get_pair(scope_ids, get_sorted_bindings);
if bindings.is_mismatch() {
self.errors.push_mismatch("Bindings mismatch", scope_ids, bindings);
let binding_names = self.get_pair(scope_ids, get_sorted_bindings);
if binding_names.is_mismatch() {
self.errors.push_mismatch("Bindings mismatch", scope_ids, binding_names);
} else {
let symbol_ids = self.get_pair(scope_ids, |data, scope_id| {
data.scopes.get_bindings(scope_id).values().copied().collect::<Vec<_>>()
});

let mut symbol_ids_after_transform = symbol_ids
.after_transform
.iter()
.map(|symbol_id| self.symbol_ids_map.get(symbol_id).copied())
.collect::<Vec<_>>();
symbol_ids_after_transform.sort_unstable();
let mut symbol_ids_rebuilt = symbol_ids
.rebuilt
.iter()
.copied()
.map(Option::Some)
.collect::<Vec<_>>();
symbol_ids_rebuilt.sort_unstable();

if symbol_ids_after_transform != symbol_ids_rebuilt {
self.errors.push_mismatch(
"Binding symbols mismatch",
scope_ids,
symbol_ids,
);
}
}
scope_ids
}
Expand Down
12 changes: 11 additions & 1 deletion tasks/coverage/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 12619ffe

semantic_babel Summary:
AST Parsed : 2101/2101 (100.00%)
Positive Passed: 1792/2101 (85.29%)
Positive Passed: 1790/2101 (85.20%)
tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.3-function-in-if-body/input.js
semantic error: Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
Expand All @@ -27,6 +27,11 @@ semantic error: Scope children mismatch:
after transform: ScopeId(3): [ScopeId(4)]
rebuilt : ScopeId(3): [ScopeId(4)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/230/input.js
semantic error: Binding symbols mismatch:
after transform: ScopeId(0): [SymbolId(0)]
rebuilt : ScopeId(0): [SymbolId(0)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/core/uncategorised/327/input.js
semantic error: A 'return' statement can only be used within a function body.

Expand Down Expand Up @@ -133,6 +138,11 @@ semantic error: Bindings mismatch:
after transform: ScopeId(0): ["nil"]
rebuilt : ScopeId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/statement-if/migrated_0002/input.js
semantic error: Binding symbols mismatch:
after transform: ScopeId(0): [SymbolId(0)]
rebuilt : ScopeId(0): [SymbolId(0)]

tasks/coverage/babel/packages/babel-parser/test/fixtures/esprima/statement-if/migrated_0003/input.js
semantic error: Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1)]
Expand Down
Loading