diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index fc720053ea47..b5b473e5c53d 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -1581,6 +1581,23 @@ where self.non_top_level = old; } + fn visit_default_decl(&mut self, decl: &DefaultDecl) { + decl.visit_children_with(self); + match decl { + DefaultDecl::Class(d) => { + if let Some(id) = &d.ident { + self.store(id.sym.clone(), id.span.ctxt, true); + } + } + DefaultDecl::Fn(d) => { + if let Some(id) = &d.ident { + self.store(id.sym.clone(), id.span.ctxt, true); + } + } + _ => {} + } + } + fn visit_expr(&mut self, n: &Expr) { let old = self.in_var_pat; self.in_var_pat = false; diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/input.ts b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/input.ts new file mode 100644 index 000000000000..53f12e77b49b --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/input.ts @@ -0,0 +1,15 @@ +import { Scope } from "../../scopes"; +import { + AnyNode, + TSUnknownKeywordTypeAnnotation, + tsUnknownKeywordTypeAnnotation, +} from "@internal/ast"; + +export default function TSUnknownKeywordTypeAnnotation( + node: AnyNode, + scope: Scope, +) { + node = tsUnknownKeywordTypeAnnotation.assert(node); + scope; + throw new Error("unimplemented"); +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/output.js new file mode 100644 index 000000000000..cfea4cd3f1d5 --- /dev/null +++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-6953/1/output.js @@ -0,0 +1,6 @@ +import { tsUnknownKeywordTypeAnnotation } from "@internal/ast"; +export default function TSUnknownKeywordTypeAnnotation(node, scope) { + node = tsUnknownKeywordTypeAnnotation.assert(node); + scope; + throw new Error("unimplemented"); +}