Skip to content

Commit

Permalink
test(transformer): transform checker output symbol name for mismatches
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 5, 2024
1 parent d953a6b commit 933e0b1
Show file tree
Hide file tree
Showing 7 changed files with 3,329 additions and 3,317 deletions.
34 changes: 23 additions & 11 deletions crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,28 +393,30 @@ impl<'s> PostTransformChecker<'s> {
scoping.symbols.names[symbol_id].clone()
});
if names.is_mismatch() {
self.errors.push_mismatch("Symbol name mismatch", symbol_ids, names);
self.errors.push_mismatch("Symbol name mismatch", symbol_ids, &names);
}
let symbol_name = names.rebuilt.as_str();
let mismatch_title = |field| format!("Symbol {field} mismatch for `{symbol_name}`");

// Check flags match
let flags =
self.get_pair(symbol_ids, |scoping, symbol_id| scoping.symbols.flags[symbol_id]);
if flags.is_mismatch() {
self.errors.push_mismatch("Symbol flags mismatch", symbol_ids, flags);
self.errors.push_mismatch(&mismatch_title("flags"), symbol_ids, flags);
}

// Check spans match
let spans =
self.get_pair(symbol_ids, |scoping, symbol_id| scoping.symbols.spans[symbol_id]);
if spans.is_mismatch() {
self.errors.push_mismatch("Symbol span mismatch", symbol_ids, spans);
self.errors.push_mismatch(&mismatch_title("span"), symbol_ids, spans);
}

// Check scope IDs match
let scope_ids = self
.get_pair(symbol_ids, |scoping, symbol_id| scoping.symbols.scope_ids[symbol_id]);
if self.remap_scope_ids(scope_ids).is_mismatch() {
self.errors.push_mismatch("Symbol scope ID mismatch", symbol_ids, scope_ids);
self.errors.push_mismatch(&mismatch_title("scope ID"), symbol_ids, scope_ids);
}

// NB: Skip checking declarations match - transformer does not set `NodeId`s
Expand All @@ -425,7 +427,7 @@ impl<'s> PostTransformChecker<'s> {
});
if self.remap_reference_ids_sets(&reference_ids).is_mismatch() {
self.errors.push_mismatch(
"Symbol reference IDs mismatch",
&mismatch_title("reference IDs"),
symbol_ids,
reference_ids,
);
Expand All @@ -439,7 +441,7 @@ impl<'s> PostTransformChecker<'s> {
});
if redeclaration_spans.is_mismatch() {
self.errors.push_mismatch(
"Symbol redeclarations mismatch",
&mismatch_title("redeclarations"),
symbol_ids,
redeclaration_spans,
);
Expand All @@ -457,19 +459,29 @@ impl<'s> PostTransformChecker<'s> {
symbol_ids.after_transform.map(|symbol_id| self.symbol_ids_map.get(symbol_id)),
symbol_ids.rebuilt.map(Option::Some),
);
let symbol_names = self.get_pair(symbol_ids, |scoping, symbol_id| {
symbol_id.map(|symbol_id| scoping.symbols.names[symbol_id].clone())
});
if symbol_ids_remapped.is_mismatch() {
let symbol_names = self.get_pair(symbol_ids, |scoping, symbol_id| {
symbol_id.map(|symbol_id| scoping.symbols.names[symbol_id].clone())
});
self.errors.push_mismatch("Reference symbol mismatch", reference_ids, symbol_names);
self.errors.push_mismatch(
"Reference symbol mismatch",
reference_ids,
&symbol_names,
);
}

// Check flags match
let flags = self.get_pair(reference_ids, |scoping, reference_id| {
scoping.symbols.references[reference_id].flags()
});
if flags.is_mismatch() {
self.errors.push_mismatch("Reference flags mismatch", reference_ids, flags);
let symbol_name =
symbol_names.rebuilt.as_ref().map_or("<unknown>", |name| name.as_str());
self.errors.push_mismatch(
&format!("Reference flags mismatch for `{symbol_name}`"),
reference_ids,
flags,
);
}
}
}
Expand Down
Loading

0 comments on commit 933e0b1

Please sign in to comment.