Strip bodyless functions.

Closes #357.
This commit is contained in:
강동윤 2019-04-11 21:20:50 +09:00
parent 9e333a153c
commit 0ffd075588
2 changed files with 62 additions and 1 deletions

View File

@ -229,6 +229,22 @@ impl Fold<Vec<ModuleItem>> for Strip {
decl: Decl::TsTypeAlias(..), 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 { | ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl {
decl: DefaultDecl::TsInterfaceDecl(..), decl: DefaultDecl::TsInterfaceDecl(..),
.. ..
@ -349,7 +365,11 @@ impl Fold<Ident> for Strip {
.imported_idents .imported_idents
.entry((i.sym.clone(), i.span.ctxt())) .entry((i.sym.clone(), i.span.ctxt()))
.and_modify(|v| v.has_concrete = true); .and_modify(|v| v.has_concrete = true);
i.fold_children(self)
Ident {
optional: false,
..i.fold_children(self)
}
} }
} }

View File

@ -89,6 +89,47 @@ to!(
"function foo($scope){}" "function foo($scope){}"
); );
to!(
issue_357,
"export function addProp<T, K extends string, V>(
obj: T,
prop: K,
value: V
): T & { [x in K]: V };
export function addProp<T, K extends string, V>(
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!( to!(
issue_366_01, issue_366_01,
" "