mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(semantic): transform checker compare scope flags (#5052)
This commit is contained in:
parent
0ba6f50f00
commit
67d1a96391
5 changed files with 689 additions and 15 deletions
|
|
@ -143,7 +143,7 @@ pub fn check_semantic_after_transform(
|
|||
rebuilt: data_rebuilt,
|
||||
errors: Errors::default(),
|
||||
};
|
||||
checker.check_bindings();
|
||||
checker.check_scopes();
|
||||
checker.check_symbols();
|
||||
checker.check_references();
|
||||
|
||||
|
|
@ -180,16 +180,16 @@ impl Errors {
|
|||
}
|
||||
|
||||
impl<'s> PostTransformChecker<'s> {
|
||||
fn check_bindings(&mut self) {
|
||||
fn check_scopes(&mut self) {
|
||||
if self.after_transform.ids.scope_ids.len() != self.rebuilt.ids.scope_ids.len() {
|
||||
self.errors.push("Scopes mismatch after transform");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check whether bindings are the same for scopes in the same visitation order.
|
||||
let PostTransformChecker { after_transform, rebuilt, .. } = self;
|
||||
for (&scope_id_after_transform, &scope_id_rebuilt) in
|
||||
self.after_transform.ids.scope_ids.iter().zip(self.rebuilt.ids.scope_ids.iter())
|
||||
after_transform.ids.scope_ids.iter().zip(rebuilt.ids.scope_ids.iter())
|
||||
{
|
||||
// Check bindings are the same
|
||||
fn get_sorted_bindings(scopes: &ScopeTree, scope_id: ScopeId) -> Vec<CompactStr> {
|
||||
let mut bindings =
|
||||
scopes.get_bindings(scope_id).keys().cloned().collect::<Vec<_>>();
|
||||
|
|
@ -201,12 +201,10 @@ impl<'s> PostTransformChecker<'s> {
|
|||
match (scope_id_after_transform, scope_id_rebuilt) {
|
||||
(None, None) => continue,
|
||||
(Some(scope_id_after_transform), Some(scope_id_rebuilt)) => {
|
||||
let bindings_after_transform = get_sorted_bindings(
|
||||
self.after_transform.scopes,
|
||||
scope_id_after_transform,
|
||||
);
|
||||
let bindings_after_transform =
|
||||
get_sorted_bindings(after_transform.scopes, scope_id_after_transform);
|
||||
let bindings_rebuilt =
|
||||
get_sorted_bindings(self.rebuilt.scopes, scope_id_rebuilt);
|
||||
get_sorted_bindings(rebuilt.scopes, scope_id_rebuilt);
|
||||
if bindings_after_transform == bindings_rebuilt {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -216,10 +214,8 @@ impl<'s> PostTransformChecker<'s> {
|
|||
)
|
||||
}
|
||||
(Some(scope_id_after_transform), None) => {
|
||||
let bindings_after_transform = get_sorted_bindings(
|
||||
self.after_transform.scopes,
|
||||
scope_id_after_transform,
|
||||
);
|
||||
let bindings_after_transform =
|
||||
get_sorted_bindings(after_transform.scopes, scope_id_after_transform);
|
||||
(
|
||||
format!("{scope_id_after_transform:?}: {bindings_after_transform:?}"),
|
||||
"No scope".to_string(),
|
||||
|
|
@ -227,7 +223,7 @@ impl<'s> PostTransformChecker<'s> {
|
|||
}
|
||||
(None, Some(scope_id_rebuilt)) => {
|
||||
let bindings_rebuilt =
|
||||
get_sorted_bindings(self.rebuilt.scopes, scope_id_rebuilt);
|
||||
get_sorted_bindings(rebuilt.scopes, scope_id_rebuilt);
|
||||
(
|
||||
"No scope".to_string(),
|
||||
format!("{scope_id_rebuilt:?}: {bindings_rebuilt:?}"),
|
||||
|
|
@ -242,6 +238,25 @@ after transform: {result_after_transform}
|
|||
rebuilt : {result_rebuilt}
|
||||
"
|
||||
));
|
||||
|
||||
let (Some(scope_id_after_transform), Some(scope_id_rebuilt)) =
|
||||
(scope_id_after_transform, scope_id_rebuilt)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// Check flags match
|
||||
let flags_after_transform = after_transform.scopes.get_flags(scope_id_after_transform);
|
||||
let flags_rebuilt = rebuilt.scopes.get_flags(scope_id_rebuilt);
|
||||
if flags_after_transform != flags_rebuilt {
|
||||
self.errors.push(format!(
|
||||
"
|
||||
Scope flags mismatch:
|
||||
after transform: {scope_id_after_transform:?}: {flags_after_transform:?}
|
||||
rebuilt : {scope_id_rebuilt:?}: {flags_rebuilt:?}
|
||||
"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -387,26 +387,41 @@ tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/members
|
|||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(1): ["A", "B", "E"]
|
||||
rebuilt : ScopeId(1): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/members-reserved-words/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(1): ["E", "const", "default"]
|
||||
rebuilt : ScopeId(1): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/members-strings/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(1): ["E", "bar", "foo"]
|
||||
rebuilt : ScopeId(1): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/members-trailing-comma/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(1): ["A", "E"]
|
||||
rebuilt : ScopeId(1): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/enum/members-trailing-comma-with-initializer/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(1): ["A", "E"]
|
||||
rebuilt : ScopeId(1): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/estree-compat/shorthand-ambient-module/input.ts
|
||||
semantic error: Bindings mismatch:
|
||||
|
|
|
|||
|
|
@ -43,15 +43,27 @@ tasks/coverage/misc/pass/oxc-4449.ts
|
|||
semantic error: Bindings mismatch:
|
||||
after transform: ScopeId(5): ["E", "baz"]
|
||||
rebuilt : ScopeId(5): ["E"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(5): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(5): ScopeFlags(StrictMode | Function)
|
||||
Bindings mismatch:
|
||||
after transform: ScopeId(6): ["F", "baz"]
|
||||
rebuilt : ScopeId(6): ["F"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(6): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(6): ScopeFlags(StrictMode | Function)
|
||||
Bindings mismatch:
|
||||
after transform: ScopeId(7): ["G", "baz"]
|
||||
rebuilt : ScopeId(7): ["G"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(7): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(7): ScopeFlags(StrictMode | Function)
|
||||
Bindings mismatch:
|
||||
after transform: ScopeId(8): ["H", "baz"]
|
||||
rebuilt : ScopeId(8): ["H"]
|
||||
Scope flags mismatch:
|
||||
after transform: ScopeId(8): ScopeFlags(StrictMode)
|
||||
rebuilt : ScopeId(8): ScopeFlags(StrictMode | Function)
|
||||
|
||||
tasks/coverage/misc/pass/swc-7187.ts
|
||||
semantic error: Bindings mismatch:
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1736,6 +1736,10 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| after transform: ScopeId(1): ["A", "x"]
|
||||
| rebuilt : ScopeId(1): ["A"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* opts/rewriteImportExtensions/input.ts
|
||||
|
||||
|
|
@ -1793,6 +1797,10 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| after transform: ScopeId(1): ["A", "E"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/constant-folding/input.ts
|
||||
x Bindings mismatch:
|
||||
|
|
@ -1800,52 +1808,92 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/enum-merging-inner-references/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["Animals", "Cat", "Dog"]
|
||||
| rebuilt : ScopeId(1): ["Animals"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["Animals", "CatDog"]
|
||||
| rebuilt : ScopeId(2): ["Animals"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/enum-merging-inner-references-shadow/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["Animals", "Cat"]
|
||||
| rebuilt : ScopeId(1): ["Animals"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["Animals", "Dog"]
|
||||
| rebuilt : ScopeId(2): ["Animals"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(3): ["Animals", "CatDog"]
|
||||
| rebuilt : ScopeId(3): ["Animals"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(3): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/export/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["A", "E"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["B", "E"]
|
||||
| rebuilt : ScopeId(2): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/inferred/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["E", "x", "y"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/inner-references/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["E", "a", "b"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/mix-references/input.ts
|
||||
x Semantic Collector failed after transform
|
||||
|
|
@ -1891,55 +1939,95 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| after transform: ScopeId(1): ["E", "a", "b"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/non-scoped/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["E", "x", "y"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["E", "z"]
|
||||
| rebuilt : ScopeId(2): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/outer-references/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["IPC", "SERVER", "SOCKET", "socketType"]
|
||||
| rebuilt : ScopeId(1): ["socketType"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["IPC", "SERVER", "SOCKET", "UV_READABLE",
|
||||
| "UV_WRITABLE", "constants"]
|
||||
| rebuilt : ScopeId(2): ["constants"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/string-value/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["A", "A2", "B", "B2", "E"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/string-value-template/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["A", "E"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/string-values-computed/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["A", "E"]
|
||||
| rebuilt : ScopeId(1): ["E"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* enum/ts5.0-const-foldable/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["First", "Second", "Third", "Values"]
|
||||
| rebuilt : ScopeId(1): ["Values"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(2): ["Invoices", "Parts", "Routes", "x", "y"]
|
||||
| rebuilt : ScopeId(2): ["Routes"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(2): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* exports/declared-types/input.ts
|
||||
x Bindings mismatch:
|
||||
|
|
@ -1951,10 +2039,18 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| after transform: ScopeId(12): ["BB", "K"]
|
||||
| rebuilt : ScopeId(2): ["BB"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(12): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(13): ["BB", "L"]
|
||||
| rebuilt : ScopeId(3): ["BB"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(13): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(3): ScopeFlags(StrictMode | Function)
|
||||
|
||||
x Reference mismatch:
|
||||
| after transform: ReferenceId(0): Some("x")
|
||||
| rebuilt : ReferenceId(0): None
|
||||
|
|
@ -2130,12 +2226,20 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
|
|||
| after transform: ScopeId(1): ["A", "Enum"]
|
||||
| rebuilt : ScopeId(1): ["Enum"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* imports/enum-value/input.ts
|
||||
x Bindings mismatch:
|
||||
| after transform: ScopeId(1): ["Enum", "id"]
|
||||
| rebuilt : ScopeId(1): ["Enum"]
|
||||
|
||||
x Scope flags mismatch:
|
||||
| after transform: ScopeId(1): ScopeFlags(StrictMode)
|
||||
| rebuilt : ScopeId(1): ScopeFlags(StrictMode | Function)
|
||||
|
||||
|
||||
* imports/import-removed-exceptions/input.ts
|
||||
x Bindings mismatch:
|
||||
|
|
|
|||
Loading…
Reference in a new issue