diff --git a/ecmascript/transforms/src/typescript/mod.rs b/ecmascript/transforms/src/typescript/mod.rs index 66c9997cb30..f723d801666 100644 --- a/ecmascript/transforms/src/typescript/mod.rs +++ b/ecmascript/transforms/src/typescript/mod.rs @@ -229,6 +229,22 @@ impl Fold> for Strip { decl: Decl::TsTypeAlias(..), .. })) + | ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { + decl: + Decl::Fn(FnDecl { + function: Function { body: None, .. }, + .. + }), + .. + })) + | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { + decl: + DefaultDecl::Fn(FnExpr { + function: Function { body: None, .. }, + .. + }), + .. + })) | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl { decl: DefaultDecl::TsInterfaceDecl(..), .. @@ -349,7 +365,11 @@ impl Fold for Strip { .imported_idents .entry((i.sym.clone(), i.span.ctxt())) .and_modify(|v| v.has_concrete = true); - i.fold_children(self) + + Ident { + optional: false, + ..i.fold_children(self) + } } } diff --git a/ecmascript/transforms/src/typescript/tests.rs b/ecmascript/transforms/src/typescript/tests.rs index 9c6f6322e9e..57b63f2a83b 100644 --- a/ecmascript/transforms/src/typescript/tests.rs +++ b/ecmascript/transforms/src/typescript/tests.rs @@ -89,6 +89,47 @@ to!( "function foo($scope){}" ); +to!( + issue_357, + "export function addProp( + obj: T, + prop: K, + value: V +): T & { [x in K]: V }; +export function addProp( + prop: K, + value: V +): (obj: T) => T & { [x in K]: V }; + +export function addProp(arg1: any, arg2: any, arg3?: any): any { + if (arguments.length === 2) { + return (object: any) => _addProp(object, arg1, arg2); + } + return _addProp(arg1, arg2, arg3); +} + +function _addProp(obj: any, prop: string, value: any) { + return { + ...obj, + [prop]: value, + }; +}", + "export function addProp(arg1, arg2, arg3) { + if (arguments.length === 2) { + return (object) => _addProp(object, arg1, arg2); + } + return _addProp(arg1, arg2, arg3); +} + +function _addProp(obj, prop, value) { + return { + ...obj, + [prop]: value, + }; +} +" +); + to!( issue_366_01, "