fix(semantic): transform checker check symbol IDs (#5078)

This commit is contained in:
overlookmotel 2024-08-22 15:08:48 +00:00
parent ea7d2163e3
commit 4a57086d79
3 changed files with 65 additions and 3 deletions

View file

@ -389,9 +389,8 @@ impl<'s> PostTransformChecker<'s> {
self.get_pair(scope_ids, |data, scope_id| data.scopes.get_parent_id(scope_id));
let is_match = match parent_ids.into_parts() {
(Some(parent_id_after_transform), Some(parent_id_rebuilt)) => {
let parent_id_after_transform =
self.scope_ids_map.get(&parent_id_after_transform);
parent_id_after_transform == Some(&parent_id_rebuilt)
let parent_ids = Pair::new(parent_id_after_transform, parent_id_rebuilt);
self.remap_scope_ids(parent_ids).is_match()
}
(None, None) => true,
_ => false,
@ -455,6 +454,13 @@ impl<'s> PostTransformChecker<'s> {
if spans.is_mismatch() {
self.errors.push_mismatch("Symbol span mismatch", symbol_ids, spans);
}
// Check scope IDs match
let scope_ids =
self.get_pair(symbol_ids, |data, symbol_id| data.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);
}
}
}
@ -512,6 +518,14 @@ impl<'s> PostTransformChecker<'s> {
fn get_static_pair<R, F: Fn(&SemanticData) -> R>(&self, getter: F) -> Pair<R> {
Pair::new(getter(&self.after_transform), getter(&self.rebuilt))
}
/// Map `after_transform` scope ID to `rebuilt` scope ID
fn remap_scope_ids(&self, scope_ids: Pair<ScopeId>) -> Pair<Option<ScopeId>> {
Pair::new(
self.scope_ids_map.get(&scope_ids.after_transform).copied(),
Some(scope_ids.rebuilt),
)
}
}
/// Collection of `ScopeId`s, `SymbolId`s and `ReferenceId`s from an AST.

View file

@ -1331,6 +1331,10 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable |
| CatchVariable)
x Symbol scope ID mismatch:
| after transform: SymbolId(0): ScopeId(0)
| rebuilt : SymbolId(0): ScopeId(3)
* optional-catch-bindings/try-catch-finally-no-binding/input.js
x Bindings mismatch:
@ -1358,6 +1362,10 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable |
| CatchVariable)
x Symbol scope ID mismatch:
| after transform: SymbolId(0): ScopeId(0)
| rebuilt : SymbolId(0): ScopeId(3)
# babel-plugin-transform-exponentiation-operator (3/4)
@ -1383,11 +1391,19 @@ preset-env: unknown field `shippedProposals`, expected `targets` or `bugfixes`
| after transform: ScopeId(6): ["_this2"]
| rebuilt : ScopeId(6): []
x Symbol scope ID mismatch:
| after transform: SymbolId(6): ScopeId(6)
| rebuilt : SymbolId(1): ScopeId(1)
x Symbol flags mismatch:
| after transform: SymbolId(2): SymbolFlags(FunctionScopedVariable |
| ArrowFunction)
| rebuilt : SymbolId(3): SymbolFlags(FunctionScopedVariable)
x Symbol scope ID mismatch:
| after transform: SymbolId(5): ScopeId(5)
| rebuilt : SymbolId(6): ScopeId(4)
* assumption-newableArrowFunctions-false/naming/input.js
x Symbol flags mismatch:
@ -4978,6 +4994,14 @@ transform-typescript: unknown field `optimizeConstEnums`, expected one of `jsxPr
| after transform: ScopeId(4): ["_this2"]
| rebuilt : ScopeId(4): []
x Symbol scope ID mismatch:
| after transform: SymbolId(2): ScopeId(2)
| rebuilt : SymbolId(1): ScopeId(1)
x Symbol scope ID mismatch:
| after transform: SymbolId(3): ScopeId(4)
| rebuilt : SymbolId(3): ScopeId(3)
* react/should-disallow-valueless-key/input.js
! Please provide an explicit key value. Using "key" as a shorthand for
@ -5026,6 +5050,14 @@ transform-typescript: unknown field `optimizeConstEnums`, expected one of `jsxPr
| after transform: ScopeId(4): ["_this2"]
| rebuilt : ScopeId(4): []
x Symbol scope ID mismatch:
| after transform: SymbolId(3): ScopeId(2)
| rebuilt : SymbolId(2): ScopeId(1)
x Symbol scope ID mismatch:
| after transform: SymbolId(4): ScopeId(4)
| rebuilt : SymbolId(4): ScopeId(3)
* react-automatic/does-not-add-source-self-automatic/input.mjs
transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `development`, `throwIfNamespace`, `pure`, `importSource`, `pragma`, `pragmaFrag`, `useBuiltIns`, `useSpread`, `refresh`
@ -5079,6 +5111,14 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev
| after transform: ScopeId(3): ["_this2"]
| rebuilt : ScopeId(3): []
x Symbol scope ID mismatch:
| after transform: SymbolId(1): ScopeId(1)
| rebuilt : SymbolId(0): ScopeId(0)
x Symbol scope ID mismatch:
| after transform: SymbolId(2): ScopeId(3)
| rebuilt : SymbolId(2): ScopeId(2)
# babel-plugin-transform-react-jsx-development (7/10)

View file

@ -33,6 +33,10 @@ Passed: 8/35
| rebuilt : SymbolId(1): SymbolFlags(FunctionScopedVariable |
| CatchVariable)
x Symbol scope ID mismatch:
| after transform: SymbolId(1): ScopeId(0)
| rebuilt : SymbolId(1): ScopeId(3)
# babel-plugin-transform-typescript (2/7)
@ -221,6 +225,10 @@ Passed: 8/35
| after transform: ScopeId(1): ["_s"]
| rebuilt : ScopeId(1): []
x Symbol scope ID mismatch:
| after transform: SymbolId(1): ScopeId(1)
| rebuilt : SymbolId(0): ScopeId(0)
x Reference mismatch:
| after transform: ReferenceId(3): Some("_s")
| rebuilt : ReferenceId(1): None