Skip to content

Commit

Permalink
fix(es/typescript): Strip exported default overload function declarat…
Browse files Browse the repository at this point in the history
…ion (#9412)
  • Loading branch information
magic-akari authored Aug 9, 2024
1 parent 8c161a0 commit b395f48
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-plants-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
swc_fast_ts_strip: patch
---

fix(es/typescript): Strip exported default overload function declaration
26 changes: 18 additions & 8 deletions crates/swc_fast_ts_strip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use swc_common::{
};
use swc_ecma_ast::{
ArrayPat, ArrowExpr, AutoAccessor, BindingIdent, Class, ClassDecl, ClassMethod, ClassProp,
Constructor, Decl, DoWhileStmt, EsVersion, ExportAll, ExportDecl, ExportDefaultDecl,
ExportSpecifier, FnDecl, ForInStmt, ForOfStmt, ForStmt, IfStmt, ImportDecl, ImportSpecifier,
NamedExport, ObjectPat, Param, Pat, PrivateMethod, PrivateProp, Program, Stmt, TsAsExpr,
TsConstAssertion, TsEnumDecl, TsExportAssignment, TsImportEqualsDecl, TsIndexSignature,
TsInstantiation, TsModuleDecl, TsModuleName, TsNamespaceDecl, TsNonNullExpr, TsParamPropParam,
TsSatisfiesExpr, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeParamDecl,
TsTypeParamInstantiation, VarDeclarator, WhileStmt,
Constructor, Decl, DefaultDecl, DoWhileStmt, EsVersion, ExportAll, ExportDecl,
ExportDefaultDecl, ExportSpecifier, FnDecl, ForInStmt, ForOfStmt, ForStmt, IfStmt, ImportDecl,
ImportSpecifier, NamedExport, ObjectPat, Param, Pat, PrivateMethod, PrivateProp, Program, Stmt,
TsAsExpr, TsConstAssertion, TsEnumDecl, TsExportAssignment, TsImportEqualsDecl,
TsIndexSignature, TsInstantiation, TsModuleDecl, TsModuleName, TsNamespaceDecl, TsNonNullExpr,
TsParamPropParam, TsSatisfiesExpr, TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion,
TsTypeParamDecl, TsTypeParamInstantiation, VarDeclarator, WhileStmt,
};
use swc_ecma_parser::{
lexer::Lexer,
Expand Down Expand Up @@ -775,7 +775,7 @@ impl Visit for TsStrip {
}

fn visit_export_default_decl(&mut self, n: &ExportDefaultDecl) {
if n.decl.is_ts_interface_decl() {
if n.decl.is_ts_declare() {
self.add_replacement(n.span);
self.fix_asi(n.span);
return;
Expand Down Expand Up @@ -1100,6 +1100,16 @@ impl IsTsDecl for Stmt {
}
}

impl IsTsDecl for DefaultDecl {
fn is_ts_declare(&self) -> bool {
match self {
Self::Class(..) => false,
DefaultDecl::Fn(r#fn) => r#fn.function.body.is_none(),
DefaultDecl::TsInterfaceDecl(..) => true,
}
}
}

trait U8Helper {
fn is_utf8_char_boundary(&self) -> bool;
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit b395f48

Please sign in to comment.