diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 5af6f4500377b..bb60dd5433c9d 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -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(), diff --git a/tasks/coverage/snapshots/runtime.snap b/tasks/coverage/snapshots/runtime.snap index 6495fe37c72bd..d37836e39677d 100644 --- a/tasks/coverage/snapshots/runtime.snap +++ b/tasks/coverage/snapshots/runtime.snap @@ -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 @@ -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 diff --git a/tasks/coverage/snapshots/semantic_misc.snap b/tasks/coverage/snapshots/semantic_misc.snap index 3a3c38216dd29..1e99c994b8f70 100644 --- a/tasks/coverage/snapshots/semantic_misc.snap +++ b/tasks/coverage/snapshots/semantic_misc.snap @@ -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"] diff --git a/tasks/coverage/snapshots/semantic_test262.snap b/tasks/coverage/snapshots/semantic_test262.snap index d08917755a042..77fc7b096a2c2 100644 --- a/tasks/coverage/snapshots/semantic_test262.snap +++ b/tasks/coverage/snapshots/semantic_test262.snap @@ -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: @@ -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: @@ -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: diff --git a/tasks/coverage/snapshots/semantic_typescript.snap b/tasks/coverage/snapshots/semantic_typescript.snap index c3ce32da04eb5..bb9e85f8d251a 100644 --- a/tasks/coverage/snapshots/semantic_typescript.snap +++ b/tasks/coverage/snapshots/semantic_typescript.snap @@ -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)] @@ -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"] @@ -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): [] @@ -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"] @@ -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"] @@ -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 : [] @@ -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 : @@ -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)] @@ -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" @@ -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"] @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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 : diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 6d32e6444f46e..956d9922446d7 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: d20b314c -Passed: 66/75 +Passed: 67/76 # All Passed: * babel-plugin-transform-class-static-block @@ -13,7 +13,7 @@ Passed: 66/75 * regexp -# babel-plugin-transform-typescript (1/8) +# babel-plugin-transform-typescript (2/9) * class-property-definition/input.ts Unresolved references mismatch: after transform: ["const"] diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/input.ts b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/input.ts new file mode 100644 index 0000000000000..11e943b9f2056 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/input.ts @@ -0,0 +1,3 @@ +export {} from 'mod'; +export {} from './app.ts'; +export {} \ No newline at end of file diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/output.js new file mode 100644 index 0000000000000..11e943b9f2056 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/elimination-empty-export-named/output.js @@ -0,0 +1,3 @@ +export {} from 'mod'; +export {} from './app.ts'; +export {} \ No newline at end of file