Skip to content

Commit

Permalink
fix(semantic): transform checker check symbol redeclarations (#5089)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 22, 2024
1 parent 205bff7 commit a8005b9
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/oxc_semantic/src/post_transform_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ impl<'s> PostTransformChecker<'s> {
return;
}

// Check whether symbols match
for symbol_ids in self
.after_transform
.ids
Expand Down Expand Up @@ -467,6 +466,20 @@ impl<'s> PostTransformChecker<'s> {
reference_ids,
);
}

// Check redeclarations match
let redeclaration_spans = self.get_pair(symbol_ids, |data, symbol_id| {
let mut spans = data.symbols.get_redeclarations(symbol_id).to_vec();
spans.sort_unstable();
spans
});
if redeclaration_spans.is_mismatch() {
self.errors.push_mismatch(
"Symbol redeclarations mismatch",
symbol_ids,
redeclaration_spans,
);
}
}
}

Expand Down
87 changes: 87 additions & 0 deletions tasks/coverage/semantic_babel.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,9 @@ rebuilt : ScopeId(0): [ScopeId(1)]
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(Class | Interface)
rebuilt : SymbolId(0): SymbolFlags(Class)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 21, end: 22 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-const-type/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1439,6 +1442,9 @@ rebuilt : ScopeId(0): []
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | TypeAlias)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 19, end: 20 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-constenum-constenum/input.ts
semantic error: Scope flags mismatch:
Expand All @@ -1450,6 +1456,9 @@ rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(ConstEnum)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 29, end: 32 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-enum-enum/input.ts
semantic error: Scope flags mismatch:
Expand All @@ -1461,6 +1470,9 @@ rebuilt : ScopeId(2): ScopeFlags(StrictMode | Function)
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(RegularEnum)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 17, end: 20 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-function-interface/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1469,6 +1481,9 @@ rebuilt : ScopeId(0): [ScopeId(1)]
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Function | Interface)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Function)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 26, end: 27 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-function-type/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1477,6 +1492,9 @@ rebuilt : ScopeId(0): [ScopeId(1)]
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Function | TypeAlias)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Function)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 21, end: 22 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-import-ambient-class/input.ts
semantic error: Bindings mismatch:
Expand All @@ -1500,6 +1518,9 @@ rebuilt : SymbolId(1): Span { start: 104, end: 124 }
Symbol reference IDs mismatch:
after transform: SymbolId(1): [ReferenceId(0)]
rebuilt : SymbolId(1): []
Symbol redeclarations mismatch:
after transform: SymbolId(1): [Span { start: 104, end: 124 }]
rebuilt : SymbolId(1): []
Symbol flags mismatch:
after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | Import)
rebuilt : SymbolId(2): SymbolFlags(BlockScopedVariable)
Expand All @@ -1509,6 +1530,9 @@ rebuilt : SymbolId(2): Span { start: 156, end: 160 }
Symbol reference IDs mismatch:
after transform: SymbolId(2): [ReferenceId(2)]
rebuilt : SymbolId(2): []
Symbol redeclarations mismatch:
after transform: SymbolId(2): [Span { start: 156, end: 160 }]
rebuilt : SymbolId(2): []
Symbol flags mismatch:
after transform: SymbolId(3): SymbolFlags(BlockScopedVariable | Import)
rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable)
Expand All @@ -1518,6 +1542,9 @@ rebuilt : SymbolId(3): Span { start: 170, end: 174 }
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(3)]
rebuilt : SymbolId(3): []
Symbol redeclarations mismatch:
after transform: SymbolId(3): [Span { start: 170, end: 174 }]
rebuilt : SymbolId(3): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-import-type-let/input.ts
semantic error: Symbol flags mismatch:
Expand All @@ -1529,6 +1556,9 @@ rebuilt : SymbolId(1): Span { start: 119, end: 139 }
Symbol reference IDs mismatch:
after transform: SymbolId(1): [ReferenceId(0)]
rebuilt : SymbolId(1): []
Symbol redeclarations mismatch:
after transform: SymbolId(1): [Span { start: 119, end: 139 }]
rebuilt : SymbolId(1): []
Symbol flags mismatch:
after transform: SymbolId(2): SymbolFlags(BlockScopedVariable | TypeImport)
rebuilt : SymbolId(2): SymbolFlags(BlockScopedVariable)
Expand All @@ -1538,6 +1568,9 @@ rebuilt : SymbolId(2): Span { start: 171, end: 175 }
Symbol reference IDs mismatch:
after transform: SymbolId(2): [ReferenceId(2)]
rebuilt : SymbolId(2): []
Symbol redeclarations mismatch:
after transform: SymbolId(2): [Span { start: 171, end: 175 }]
rebuilt : SymbolId(2): []
Symbol flags mismatch:
after transform: SymbolId(3): SymbolFlags(BlockScopedVariable | TypeImport)
rebuilt : SymbolId(3): SymbolFlags(BlockScopedVariable)
Expand All @@ -1547,6 +1580,9 @@ rebuilt : SymbolId(3): Span { start: 185, end: 189 }
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(3)]
rebuilt : SymbolId(3): []
Symbol redeclarations mismatch:
after transform: SymbolId(3): [Span { start: 185, end: 189 }]
rebuilt : SymbolId(3): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-import-type-type/input.ts
semantic error: Bindings mismatch:
Expand All @@ -1566,6 +1602,9 @@ rebuilt : SymbolId(1): Span { start: 119, end: 139 }
Symbol reference IDs mismatch:
after transform: SymbolId(1): [ReferenceId(0)]
rebuilt : SymbolId(1): []
Symbol redeclarations mismatch:
after transform: SymbolId(1): [Span { start: 119, end: 139 }]
rebuilt : SymbolId(1): []
Symbol flags mismatch:
after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable | TypeImport)
rebuilt : SymbolId(2): SymbolFlags(FunctionScopedVariable)
Expand All @@ -1575,6 +1614,9 @@ rebuilt : SymbolId(2): Span { start: 171, end: 175 }
Symbol reference IDs mismatch:
after transform: SymbolId(2): [ReferenceId(2)]
rebuilt : SymbolId(2): []
Symbol redeclarations mismatch:
after transform: SymbolId(2): [Span { start: 171, end: 175 }]
rebuilt : SymbolId(2): []
Symbol flags mismatch:
after transform: SymbolId(3): SymbolFlags(FunctionScopedVariable | TypeImport)
rebuilt : SymbolId(3): SymbolFlags(FunctionScopedVariable)
Expand All @@ -1584,6 +1626,9 @@ rebuilt : SymbolId(3): Span { start: 185, end: 189 }
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(3)]
rebuilt : SymbolId(3): []
Symbol redeclarations mismatch:
after transform: SymbolId(3): [Span { start: 185, end: 189 }]
rebuilt : SymbolId(3): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-import-var/input.ts
semantic error: Symbol flags mismatch:
Expand All @@ -1595,6 +1640,9 @@ rebuilt : SymbolId(1): Span { start: 104, end: 124 }
Symbol reference IDs mismatch:
after transform: SymbolId(1): [ReferenceId(0)]
rebuilt : SymbolId(1): []
Symbol redeclarations mismatch:
after transform: SymbolId(1): [Span { start: 104, end: 124 }]
rebuilt : SymbolId(1): []
Symbol flags mismatch:
after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable | Import)
rebuilt : SymbolId(2): SymbolFlags(FunctionScopedVariable)
Expand All @@ -1604,6 +1652,9 @@ rebuilt : SymbolId(2): Span { start: 156, end: 160 }
Symbol reference IDs mismatch:
after transform: SymbolId(2): [ReferenceId(2)]
rebuilt : SymbolId(2): []
Symbol redeclarations mismatch:
after transform: SymbolId(2): [Span { start: 156, end: 160 }]
rebuilt : SymbolId(2): []
Symbol flags mismatch:
after transform: SymbolId(3): SymbolFlags(FunctionScopedVariable | Import)
rebuilt : SymbolId(3): SymbolFlags(FunctionScopedVariable)
Expand All @@ -1613,6 +1664,9 @@ rebuilt : SymbolId(3): Span { start: 170, end: 174 }
Symbol reference IDs mismatch:
after transform: SymbolId(3): [ReferenceId(3)]
rebuilt : SymbolId(3): []
Symbol redeclarations mismatch:
after transform: SymbolId(3): [Span { start: 170, end: 174 }]
rebuilt : SymbolId(3): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-in-different-module/input.ts
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -1651,6 +1705,9 @@ rebuilt : SymbolId(0): SymbolFlags(Class)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 10, end: 11 }
rebuilt : SymbolId(0): Span { start: 21, end: 22 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 21, end: 22 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-interface-function/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1662,6 +1719,9 @@ rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Function)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 10, end: 11 }
rebuilt : SymbolId(0): Span { start: 24, end: 25 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 24, end: 25 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-interface-interface/input.ts
semantic error: Bindings mismatch:
Expand All @@ -1681,6 +1741,9 @@ rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 10, end: 11 }
rebuilt : SymbolId(0): Span { start: 19, end: 20 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 19, end: 20 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-interface-var/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1692,6 +1755,9 @@ rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 10, end: 11 }
rebuilt : SymbolId(0): Span { start: 19, end: 20 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 19, end: 20 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-let-interface/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1700,6 +1766,9 @@ rebuilt : ScopeId(0): []
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Interface)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 17, end: 18 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-let-type/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1708,6 +1777,9 @@ rebuilt : ScopeId(0): []
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | TypeAlias)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 17, end: 18 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-type-function/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1719,6 +1791,9 @@ rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Function)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 5, end: 6 }
rebuilt : SymbolId(0): Span { start: 26, end: 27 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 26, end: 27 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-type-let/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1730,6 +1805,9 @@ rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 5, end: 6 }
rebuilt : SymbolId(0): Span { start: 21, end: 22 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 21, end: 22 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-type-var/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1741,6 +1819,9 @@ rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol span mismatch:
after transform: SymbolId(0): Span { start: 5, end: 6 }
rebuilt : SymbolId(0): Span { start: 21, end: 22 }
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 21, end: 22 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-var-interface/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1749,6 +1830,9 @@ rebuilt : ScopeId(0): []
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Interface)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 17, end: 18 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/scope/redeclaration-var-type/input.ts
semantic error: Scope children mismatch:
Expand All @@ -1757,6 +1841,9 @@ rebuilt : ScopeId(0): []
Symbol flags mismatch:
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | TypeAlias)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)
Symbol redeclarations mismatch:
after transform: SymbolId(0): [Span { start: 17, end: 18 }]
rebuilt : SymbolId(0): []

tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/input.ts
semantic error: Bindings mismatch:
Expand Down
Loading

0 comments on commit a8005b9

Please sign in to comment.