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 check reference symbol IDs #5090

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
14 changes: 9 additions & 5 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ impl<'s> PostTransformChecker<'s> {
return;
}

// Check whether symbols match
for reference_ids in self
.after_transform
.ids
Expand All @@ -509,13 +508,18 @@ impl<'s> PostTransformChecker<'s> {
.zip(self.rebuilt.ids.reference_ids.iter().copied())
.map(Pair::from_tuple)
{
// Check symbol IDs match
let symbol_ids = self.get_pair(reference_ids, |data, reference_id| {
data.symbols.references[reference_id].symbol_id()
});
let symbol_names = self.get_pair(symbol_ids, |data, symbol_id| {
symbol_id.map(|symbol_id| data.symbols.names[symbol_id].clone())
});
if symbol_names.is_mismatch() {
let symbol_ids_remapped = Pair::new(
symbol_ids.after_transform.map(|symbol_id| self.symbol_ids_map.get(symbol_id)),
symbol_ids.rebuilt.map(Option::Some),
);
if symbol_ids_remapped.is_mismatch() {
let symbol_names = self.get_pair(symbol_ids, |data, symbol_id| {
symbol_id.map(|symbol_id| data.symbols.names[symbol_id].clone())
});
self.errors.push_mismatch("Reference mismatch", reference_ids, symbol_names);
}
}
Expand Down
3 changes: 3 additions & 0 deletions tasks/coverage/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21348,6 +21348,9 @@ rebuilt : SymbolId(0): [ReferenceId(6)]
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)]
rebuilt : SymbolId(1): [ReferenceId(0), ReferenceId(1), ReferenceId(2), ReferenceId(3), ReferenceId(4), ReferenceId(5)]
Reference mismatch:
after transform: ReferenceId(0): Some("E")
rebuilt : ReferenceId(4): Some("E")

tasks/coverage/typescript/tests/cases/compiler/underscoreMapFirst.ts
semantic error: Bindings mismatch:
Expand Down