Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(transformer/typescript): retain ExportNamedDeclaration without sp…
…ecifiers and declaration (#6848)

close: #6825
  • Loading branch information
Dunqing committed Oct 24, 2024
commit 076f5c39f4d5f5b0b2a08c9a791fee1e8a0b03e3
30 changes: 14 additions & 16 deletions crates/oxc_transformer/src/typescript/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,29 @@ impl<'a, 'ctx> Traverse<'a> for TypeScriptAnnotations<'a, 'ctx> {

program.body.retain_mut(|stmt| {
let need_retain = match stmt {
Statement::ExportNamedDeclaration(decl) if decl.declaration.is_some() => {
decl.declaration.as_ref().is_some_and(|decl| !decl.is_typescript_syntax())
}
Statement::ExportNamedDeclaration(decl) => {
if decl.export_kind.is_type() {
false
} else if decl.specifiers.is_empty() {
// `export {}` or `export {} from 'mod'`
// Keep the export declaration if there are no export specifiers
true
} else {
decl.specifiers.retain(|specifier| {
!(specifier.export_kind.is_type()
|| self.type_identifier_names.contains(&specifier.exported.name())
|| {
if let ModuleExportName::IdentifierReference(ident) =
&specifier.local
{
ident.reference_id.get().is_some_and(|id| {
ctx.symbols().get_reference(id).is_type()
})
} else {
false
}
})
|| matches!(
&specifier.local, ModuleExportName::IdentifierReference(ident)
if ident.reference_id.get().is_some_and(|reference_id| {
ctx.symbols().get_reference(reference_id).is_type()
})
))
});

// Keep the export declaration if there are still specifiers after removing type exports
!decl.specifiers.is_empty()
|| decl
.declaration
.as_ref()
.is_some_and(|decl| !decl.is_typescript_syntax())
}
}
Statement::ExportAllDeclaration(decl) => !decl.export_kind.is_type(),
Expand Down
5 changes: 1 addition & 4 deletions tasks/coverage/snapshots/runtime.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: 06454619

runtime Summary:
AST Parsed : 18444/18444 (100.00%)
Positive Passed: 18268/18444 (99.05%)
Positive Passed: 18269/18444 (99.05%)
tasks/coverage/test262/test/annexB/language/function-code/if-decl-else-decl-a-func-existing-block-fn-no-init.js
minify error: Test262Error: Expected SameValue(«function f(){}», «undefined») to be true

Expand Down Expand Up @@ -447,9 +447,6 @@ codegen error: Test262Error: descriptor should not be configurable
tasks/coverage/test262/test/language/literals/regexp/u-surrogate-pairs-atom-escape-decimal.js
codegen error: Test262Error: Expected SameValue(«true», «false») to be true

tasks/coverage/test262/test/language/module-code/eval-rqstd-order.js
transform error: Test262Error: Expected SameValue(«"12346789"», «"123456789"») to be true

tasks/coverage/test262/test/language/module-code/eval-self-once.js
codegen error: Test262Error: global property initially unset Expected SameValue(«262», «undefined») to be true

Expand Down
7 changes: 1 addition & 6 deletions tasks/coverage/snapshots/semantic_misc.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
semantic_misc Summary:
AST Parsed : 30/30 (100.00%)
Positive Passed: 17/30 (56.67%)
tasks/coverage/misc/pass/babel-16776-m.js
semantic error: Symbol flags mismatch for "x":
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)

Positive Passed: 18/30 (60.00%)
tasks/coverage/misc/pass/oxc-1288.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["from"]
Expand Down
9 changes: 9 additions & 0 deletions tasks/coverage/snapshots/semantic_test262.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ tasks/coverage/test262/test/language/module-code/eval-rqstd-once.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["dflt1", "dflt2", "dflt3", "global", "ns1", "ns3"]
rebuilt : ScopeId(0): ["global"]
Symbol flags mismatch for "global":
after transform: SymbolId(5): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)

tasks/coverage/test262/test/language/module-code/eval-rqstd-order.js
semantic error: Bindings mismatch:
Expand All @@ -1133,6 +1136,9 @@ tasks/coverage/test262/test/language/module-code/eval-self-once.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["dflt1", "dflt2", "dflt3", "global", "ns", "ns1"]
rebuilt : ScopeId(0): ["global"]
Symbol flags mismatch for "global":
after transform: SymbolId(5): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)

tasks/coverage/test262/test/language/module-code/import-attributes/allow-nlt-before-with.js
semantic error: Bindings mismatch:
Expand Down Expand Up @@ -1198,6 +1204,9 @@ tasks/coverage/test262/test/language/module-code/instn-once.js
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["dflt1", "dflt2", "dflt3", "ns", "ns1", "x"]
rebuilt : ScopeId(0): ["x"]
Symbol flags mismatch for "x":
after transform: SymbolId(5): SymbolFlags(BlockScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Export)

tasks/coverage/test262/test/language/module-code/instn-star-err-not-found.js
semantic error: Bindings mismatch:
Expand Down
90 changes: 58 additions & 32 deletions tasks/coverage/snapshots/semantic_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: df9d1650

semantic_typescript Summary:
AST Parsed : 6490/6490 (100.00%)
Positive Passed: 2676/6490 (41.23%)
Positive Passed: 2681/6490 (41.31%)
tasks/coverage/typescript/tests/cases/compiler/2dArrays.ts
semantic error: Symbol reference IDs mismatch for "Cell":
after transform: SymbolId(0): [ReferenceId(1)]
Expand Down Expand Up @@ -147,11 +147,6 @@ Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2)]
rebuilt : ScopeId(0): []

tasks/coverage/typescript/tests/cases/compiler/SystemModuleForStatementNoInitializer.ts
semantic error: Symbol flags mismatch for "i":
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)

tasks/coverage/typescript/tests/cases/compiler/abstractInterfaceIdentifierName.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["abstract"]
Expand Down Expand Up @@ -2111,9 +2106,6 @@ rebuilt : ScopeId(1): []
Bindings mismatch:
after transform: ScopeId(4): ["T"]
rebuilt : ScopeId(2): []
Symbol flags mismatch for "Bar":
after transform: SymbolId(0): SymbolFlags(Export | Class)
rebuilt : SymbolId(0): SymbolFlags(Class)
Symbol reference IDs mismatch for "Bar":
after transform: SymbolId(0): [ReferenceId(6), ReferenceId(8)]
rebuilt : SymbolId(0): []
Expand Down Expand Up @@ -17967,11 +17959,6 @@ Unresolved references mismatch:
after transform: ["Record", "Required", "genericFn1", "genericFn2", "genericFn3"]
rebuilt : ["genericFn1", "genericFn2", "genericFn3", "key", "obj"]

tasks/coverage/typescript/tests/cases/compiler/indirectGlobalSymbolPartOfObjectType.ts
semantic error: Symbol flags mismatch for "Symbol":
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable)

tasks/coverage/typescript/tests/cases/compiler/indirectTypeParameterReferences.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["B", "combined", "flowtypes", "literal", "n"]
Expand Down Expand Up @@ -20687,11 +20674,6 @@ Unresolved references mismatch:
after transform: ["shouldBeIdentity"]
rebuilt : ["p1", "shouldBeIdentity"]

tasks/coverage/typescript/tests/cases/compiler/jsFileESModuleWithEnumTag.ts
semantic error: Symbol flags mismatch for "ChangeDetectionStrategy":
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable)

tasks/coverage/typescript/tests/cases/compiler/jsdocAccessEnumType.ts
semantic error: Bindings mismatch:
after transform: ScopeId(1): ["A", "E"]
Expand Down Expand Up @@ -30367,6 +30349,9 @@ rebuilt : ScopeId(0): ["t", "y1", "y2"]
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(2), ScopeId(3), ScopeId(4), ScopeId(5), ScopeId(6), ScopeId(10), ScopeId(12), ScopeId(16), ScopeId(24), ScopeId(25), ScopeId(33), ScopeId(36), ScopeId(37), ScopeId(39), ScopeId(40), ScopeId(41), ScopeId(42), ScopeId(44), ScopeId(46)]
rebuilt : ScopeId(0): []
Symbol flags mismatch for "y1":
after transform: SymbolId(51): SymbolFlags(BlockScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Export)
Unresolved references mismatch:
after transform: ["Array"]
rebuilt : []
Expand Down Expand Up @@ -30623,6 +30608,9 @@ rebuilt : ScopeId(0): ["zipped1", "zipped2", "zipped3"]
Scope children mismatch:
after transform: ScopeId(0): [ScopeId(1), ScopeId(5), ScopeId(7), ScopeId(10), ScopeId(12)]
rebuilt : ScopeId(0): []
Symbol flags mismatch for "zipped1":
after transform: SymbolId(21): SymbolFlags(BlockScopedVariable | ConstVariable)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | ConstVariable | Export)
Reference symbol mismatch for "opt1":
after transform: SymbolId(18) "opt1"
rebuilt : <None>
Expand Down Expand Up @@ -34794,11 +34782,6 @@ Reference symbol mismatch for "bar":
after transform: SymbolId(0) "bar"
rebuilt : SymbolId(0) "bar"

tasks/coverage/typescript/tests/cases/compiler/thisInObjectJs.ts
semantic error: Symbol flags mismatch for "obj":
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable)

tasks/coverage/typescript/tests/cases/compiler/thisInPropertyBoundDeclarations.ts
semantic error: Symbol reference IDs mismatch for "Bug":
after transform: SymbolId(0): [ReferenceId(0)]
Expand Down Expand Up @@ -37022,9 +37005,6 @@ rebuilt : ScopeId(1): ["a"]
Binding symbols mismatch:
after transform: ScopeId(43): [SymbolId(30), SymbolId(31)]
rebuilt : ScopeId(43): [SymbolId(29), SymbolId(30)]
Symbol flags mismatch for "defered":
after transform: SymbolId(0): SymbolFlags(BlockScopedVariable | Export | Function)
rebuilt : SymbolId(0): SymbolFlags(BlockScopedVariable | Function)
Reference symbol mismatch for "N":
after transform: SymbolId(29) "N"
rebuilt : SymbolId(28) "N"
Expand Down Expand Up @@ -51689,11 +51669,6 @@ Binding symbols mismatch:
after transform: ScopeId(37): [SymbolId(27), SymbolId(44)]
rebuilt : ScopeId(37): [SymbolId(27), SymbolId(28)]

tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarations.15.ts
semantic error: Symbol flags mismatch for "_":
after transform: SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable)

tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsDeclarationEmit.2.ts
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["R1", "R2", "r1", "r2"]
Expand All @@ -51712,6 +51687,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C1", "C2", "C3", "C4", "dec"]
rebuilt : ScopeId(0): ["C1", "C2", "C3", "C4"]
Symbol flags mismatch for "C1":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51730,6 +51708,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51741,6 +51722,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["after", "dec"]
rebuilt : ScopeId(0): ["after"]
Symbol flags mismatch for "after":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand Down Expand Up @@ -51774,6 +51758,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51785,6 +51772,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51796,6 +51786,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["before", "dec"]
rebuilt : ScopeId(0): ["before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51807,6 +51800,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51818,6 +51814,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51829,6 +51828,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "after", "dec"]
rebuilt : ScopeId(0): ["C", "after"]
Symbol flags mismatch for "C":
after transform: SymbolId(1): SymbolFlags(Class)
rebuilt : SymbolId(0): SymbolFlags(Export | Class)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand Down Expand Up @@ -51862,6 +51864,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51873,6 +51878,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["after", "dec"]
rebuilt : ScopeId(0): ["after"]
Symbol flags mismatch for "after":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand Down Expand Up @@ -51906,6 +51914,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51917,6 +51928,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51928,6 +51942,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["before", "dec"]
rebuilt : ScopeId(0): ["before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51939,6 +51956,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51950,6 +51970,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "before", "dec"]
rebuilt : ScopeId(0): ["C", "before"]
Symbol flags mismatch for "before":
after transform: SymbolId(1): SymbolFlags(FunctionScopedVariable)
rebuilt : SymbolId(0): SymbolFlags(FunctionScopedVariable | Export)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand All @@ -51961,6 +51984,9 @@ tasks/coverage/typescript/tests/cases/conformance/statements/VariableStatements/
semantic error: Bindings mismatch:
after transform: ScopeId(0): ["C", "after", "dec"]
rebuilt : ScopeId(0): ["C", "after"]
Symbol flags mismatch for "C":
after transform: SymbolId(1): SymbolFlags(Class)
rebuilt : SymbolId(0): SymbolFlags(Export | Class)
Reference symbol mismatch for "dec":
after transform: SymbolId(0) "dec"
rebuilt : <None>
Expand Down
Loading