mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(transformer): remove typescript symbols after transform (#8069)
part of #7460
This commit is contained in:
parent
8b54d898b5
commit
e632a7b158
8 changed files with 2364 additions and 11393 deletions
|
|
@ -8,9 +8,11 @@ use oxc_syntax::{
|
||||||
node::NodeId,
|
node::NodeId,
|
||||||
reference::ReferenceId,
|
reference::ReferenceId,
|
||||||
scope::{ScopeFlags, ScopeId},
|
scope::{ScopeFlags, ScopeId},
|
||||||
symbol::SymbolId,
|
symbol::{SymbolFlags, SymbolId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::SymbolTable;
|
||||||
|
|
||||||
pub(crate) type Bindings<'a> = hashbrown::HashMap<&'a str, SymbolId, FxBuildHasher, &'a Allocator>;
|
pub(crate) type Bindings<'a> = hashbrown::HashMap<&'a str, SymbolId, FxBuildHasher, &'a Allocator>;
|
||||||
pub type UnresolvedReferences<'a> =
|
pub type UnresolvedReferences<'a> =
|
||||||
hashbrown::HashMap<&'a str, ArenaVec<'a, ReferenceId>, FxBuildHasher, &'a Allocator>;
|
hashbrown::HashMap<&'a str, ArenaVec<'a, ReferenceId>, FxBuildHasher, &'a Allocator>;
|
||||||
|
|
@ -462,4 +464,19 @@ impl ScopeTree {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_typescript_bindings(&mut self, symbol_table: &SymbolTable) {
|
||||||
|
self.cell.with_dependent_mut(|_allocator, inner| {
|
||||||
|
for bindings in &mut inner.bindings {
|
||||||
|
bindings.retain(|_name, symbol_id| {
|
||||||
|
let flags = symbol_table.get_flags(*symbol_id);
|
||||||
|
!flags.intersects(
|
||||||
|
SymbolFlags::TypeAlias
|
||||||
|
| SymbolFlags::Interface
|
||||||
|
| SymbolFlags::TypeParameter,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ impl<'a, 'ctx> Traverse<'a> for TypeScript<'a, 'ctx> {
|
||||||
fn exit_program(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
|
fn exit_program(&mut self, program: &mut Program<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||||
self.annotations.exit_program(program, ctx);
|
self.annotations.exit_program(program, ctx);
|
||||||
self.module.exit_program(program, ctx);
|
self.module.exit_program(program, ctx);
|
||||||
|
ctx.scoping.delete_typescript_bindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_arrow_function_expression(
|
fn enter_arrow_function_expression(
|
||||||
|
|
|
||||||
|
|
@ -435,6 +435,10 @@ impl TraverseScoping {
|
||||||
.map(CompactStr::from)
|
.map(CompactStr::from)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delete_typescript_bindings(&mut self) {
|
||||||
|
self.scopes.delete_typescript_bindings(&self.symbols);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create base for UID name based on provided `name`.
|
/// Create base for UID name based on provided `name`.
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
semantic_misc Summary:
|
semantic_misc Summary:
|
||||||
AST Parsed : 30/30 (100.00%)
|
AST Parsed : 30/30 (100.00%)
|
||||||
Positive Passed: 18/30 (60.00%)
|
Positive Passed: 19/30 (63.33%)
|
||||||
tasks/coverage/misc/pass/oxc-1288.ts
|
tasks/coverage/misc/pass/oxc-1288.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["from"]
|
after transform: ScopeId(0): ["from"]
|
||||||
|
|
@ -12,37 +12,22 @@ after transform: ScopeId(0): ["infer", "target", "type"]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-2087.ts
|
tasks/coverage/misc/pass/oxc-2087.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(0): ["Helpers"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(0): [ScopeId(1)]
|
after transform: ScopeId(0): [ScopeId(1)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-2394.ts
|
tasks/coverage/misc/pass/oxc-2394.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(0): ["A"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(0): [ScopeId(1)]
|
after transform: ScopeId(0): [ScopeId(1)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-2592.ts
|
tasks/coverage/misc/pass/oxc-2592.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(0): ["Foo"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(0): [ScopeId(1)]
|
after transform: ScopeId(0): [ScopeId(1)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-3443.tsx
|
tasks/coverage/misc/pass/oxc-3443.tsx
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Unresolved references mismatch:
|
||||||
after transform: ScopeId(1): ["T"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(2): ["T"]
|
|
||||||
rebuilt : ScopeId(2): []
|
|
||||||
Unresolved references mismatch:
|
|
||||||
after transform: ["F"]
|
after transform: ["F"]
|
||||||
rebuilt : []
|
rebuilt : []
|
||||||
|
|
||||||
|
|
@ -176,23 +161,12 @@ after transform: SymbolId(14): SymbolFlags(RegularEnum)
|
||||||
rebuilt : SymbolId(14): SymbolFlags(FunctionScopedVariable)
|
rebuilt : SymbolId(14): SymbolFlags(FunctionScopedVariable)
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-5177.ts
|
tasks/coverage/misc/pass/oxc-5177.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(0): ["Bang", "Foo"]
|
|
||||||
rebuilt : ScopeId(0): ["Bang"]
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): [ScopeId(1)]
|
rebuilt : ScopeId(0): [ScopeId(1)]
|
||||||
|
|
||||||
tasks/coverage/misc/pass/oxc-5955.ts
|
tasks/coverage/misc/pass/oxc-5955.ts
|
||||||
semantic error: Bindings mismatch:
|
semantic error: Scope children mismatch:
|
||||||
after transform: ScopeId(0): ["B", "C", "a"]
|
|
||||||
rebuilt : ScopeId(0): ["B", "a"]
|
|
||||||
Scope children mismatch:
|
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3)]
|
||||||
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
|
rebuilt : ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
|
|
||||||
tasks/coverage/misc/pass/swc-7187.ts
|
|
||||||
semantic error: Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["K"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
||||||
commit: 54a8389f
|
commit: 54a8389f
|
||||||
|
|
||||||
Passed: 602/927
|
Passed: 604/927
|
||||||
|
|
||||||
# All Passed:
|
# All Passed:
|
||||||
* babel-plugin-transform-class-static-block
|
* babel-plugin-transform-class-static-block
|
||||||
|
|
@ -1111,7 +1111,7 @@ x Output mismatch
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
|
|
||||||
# babel-preset-typescript (10/17)
|
# babel-preset-typescript (11/17)
|
||||||
* jsx-compat/ts-invalid/input.ts
|
* jsx-compat/ts-invalid/input.ts
|
||||||
|
|
||||||
x Expected `>` but found `/`
|
x Expected `>` but found `/`
|
||||||
|
|
@ -1130,11 +1130,6 @@ Unresolved references mismatch:
|
||||||
after transform: ["T", "x"]
|
after transform: ["T", "x"]
|
||||||
rebuilt : ["x"]
|
rebuilt : ["x"]
|
||||||
|
|
||||||
* node-extensions/type-param-arrow-in-ts/input.ts
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(1): ["T"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
|
|
||||||
* opts/optimizeConstEnums/input.ts
|
* opts/optimizeConstEnums/input.ts
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
|
|
@ -1145,7 +1140,7 @@ x Output mismatch
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
|
|
||||||
# babel-plugin-transform-typescript (46/156)
|
# babel-plugin-transform-typescript (47/156)
|
||||||
* cast/as-expression/input.ts
|
* cast/as-expression/input.ts
|
||||||
Unresolved references mismatch:
|
Unresolved references mismatch:
|
||||||
after transform: ["T", "x"]
|
after transform: ["T", "x"]
|
||||||
|
|
@ -1181,9 +1176,6 @@ rebuilt : ["x"]
|
||||||
|
|
||||||
|
|
||||||
* class/head/input.ts
|
* class/head/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(1): ["T"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Unresolved references mismatch:
|
Unresolved references mismatch:
|
||||||
after transform: ["D", "I"]
|
after transform: ["D", "I"]
|
||||||
rebuilt : ["D"]
|
rebuilt : ["D"]
|
||||||
|
|
@ -1208,7 +1200,7 @@ rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
* declarations/erased/input.ts
|
* declarations/erased/input.ts
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["E", "I", "M", "N", "T", "m", "x"]
|
after transform: ScopeId(0): ["E", "M", "N", "m", "x"]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7), ScopeId(8)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7), ScopeId(8)]
|
||||||
|
|
@ -1509,9 +1501,6 @@ after transform: ScopeId(0): [SymbolId(0), SymbolId(1)]
|
||||||
rebuilt : ScopeId(0): [SymbolId(0), SymbolId(1)]
|
rebuilt : ScopeId(0): [SymbolId(0), SymbolId(1)]
|
||||||
|
|
||||||
* exports/export-type/input.ts
|
* exports/export-type/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["A"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1)]
|
after transform: ScopeId(0): [ScopeId(1)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
@ -1530,9 +1519,6 @@ rebuilt : ScopeId(0): ["C"]
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
* exports/issue-9916-1/input.ts
|
* exports/issue-9916-1/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["PromiseRejectCb", "PromiseResolveCb", "a"]
|
|
||||||
rebuilt : ScopeId(0): ["a"]
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
@ -1541,9 +1527,6 @@ after transform: ["PromiseLike"]
|
||||||
rebuilt : []
|
rebuilt : []
|
||||||
|
|
||||||
* exports/issue-9916-2/input.ts
|
* exports/issue-9916-2/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["PromiseRejectCb", "PromiseResolveCb"]
|
|
||||||
rebuilt : ScopeId(0): []
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
@ -1552,9 +1535,6 @@ after transform: ["PromiseLike"]
|
||||||
rebuilt : []
|
rebuilt : []
|
||||||
|
|
||||||
* exports/issue-9916-3/input.ts
|
* exports/issue-9916-3/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["PromiseRejectCb", "PromiseResolveCb", "a"]
|
|
||||||
rebuilt : ScopeId(0): ["a"]
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
@ -1577,11 +1557,6 @@ Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): [ScopeId(1)]
|
rebuilt : ScopeId(0): [ScopeId(1)]
|
||||||
|
|
||||||
* function/parameters/input.ts
|
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(1): ["T", "x", "y"]
|
|
||||||
rebuilt : ScopeId(1): ["x", "y"]
|
|
||||||
|
|
||||||
* imports/elide-preact/input.ts
|
* imports/elide-preact/input.ts
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["FooBar", "Fragment", "h", "x"]
|
after transform: ScopeId(0): ["FooBar", "Fragment", "h", "x"]
|
||||||
|
|
@ -1626,7 +1601,7 @@ rebuilt : ScopeId(0): ["A", "B"]
|
||||||
|
|
||||||
* imports/elision-locations/input.ts
|
* imports/elision-locations/input.ts
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["A", "B", "C", "Class", "D", "E", "F", "G", "H", "Iface", "x", "y"]
|
after transform: ScopeId(0): ["A", "B", "C", "Class", "D", "E", "F", "G", "H", "x", "y"]
|
||||||
rebuilt : ScopeId(0): ["A", "Class", "x", "y"]
|
rebuilt : ScopeId(0): ["A", "Class", "x", "y"]
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
|
|
@ -1750,9 +1725,6 @@ rebuilt : ScopeId(0): []
|
||||||
x Output mismatch
|
x Output mismatch
|
||||||
|
|
||||||
* lvalues/TSTypeParameterInstantiation/input.ts
|
* lvalues/TSTypeParameterInstantiation/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(1): ["M"]
|
|
||||||
rebuilt : ScopeId(1): []
|
|
||||||
Symbol reference IDs mismatch for "AbstractClass":
|
Symbol reference IDs mismatch for "AbstractClass":
|
||||||
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3)]
|
after transform: SymbolId(0): [ReferenceId(0), ReferenceId(1), ReferenceId(3)]
|
||||||
rebuilt : SymbolId(0): [ReferenceId(0)]
|
rebuilt : SymbolId(0): [ReferenceId(0)]
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ Missing ReferenceId: "_Name"
|
||||||
Missing ReferenceId: "Name"
|
Missing ReferenceId: "Name"
|
||||||
Missing ReferenceId: "Name"
|
Missing ReferenceId: "Name"
|
||||||
Bindings mismatch:
|
Bindings mismatch:
|
||||||
after transform: ScopeId(0): ["Baq", "Bar", "Baz", "Foo", "Func", "Im", "Name", "Ok", "T"]
|
after transform: ScopeId(0): ["Bar", "Foo", "Func", "Im", "Name", "Ok"]
|
||||||
rebuilt : ScopeId(0): ["Bar", "Foo", "Func", "Im", "Name", "Ok", "T"]
|
rebuilt : ScopeId(0): ["Bar", "Foo", "Func", "Im", "Name", "Ok", "T"]
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(7)]
|
||||||
|
|
@ -159,14 +159,14 @@ after transform: SymbolId(7) "Name"
|
||||||
rebuilt : SymbolId(5) "Name"
|
rebuilt : SymbolId(5) "Name"
|
||||||
|
|
||||||
* exports/type-and-non-type/input.ts
|
* exports/type-and-non-type/input.ts
|
||||||
Bindings mismatch:
|
|
||||||
after transform: ScopeId(0): ["ToastProps", "ToastViewport"]
|
|
||||||
rebuilt : ScopeId(0): ["ToastViewport"]
|
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1)]
|
after transform: ScopeId(0): [ScopeId(1)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
||||||
* redeclarations/input.ts
|
* redeclarations/input.ts
|
||||||
|
Bindings mismatch:
|
||||||
|
after transform: ScopeId(0): ["A"]
|
||||||
|
rebuilt : ScopeId(0): ["A", "B", "T"]
|
||||||
Scope children mismatch:
|
Scope children mismatch:
|
||||||
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
|
||||||
rebuilt : ScopeId(0): []
|
rebuilt : ScopeId(0): []
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue