fix(es/transforms/strip): Strip types for typescript export equals (#2623)

swc_ecma_transforms_typescript:
 - `strip`: Visit the RHS of typescript export equals.
This commit is contained in:
OJ Kwon 2021-11-01 22:50:42 -07:00 committed by GitHub
parent c89a9ea171
commit d2f2409528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 1 deletions

View File

@ -2158,7 +2158,9 @@ where
}
}
ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(export)) => {
ModuleItem::ModuleDecl(ModuleDecl::TsExportAssignment(mut export)) => {
export.expr.visit_mut_with(self);
stmts.push(ModuleItem::Stmt(Stmt::Expr(ExprStmt {
span: export.span,
expr: Box::new(Expr::Assign(AssignExpr {

View File

@ -4176,6 +4176,20 @@ test_with_config!(
"
);
to!(
issue_2613,
"
export = function (foo: string, bar: number): boolean {
return true
};
",
"
module.exports = function (foo, bar) {
return true
};
"
);
#[testing::fixture("tests/fixture/**/input.ts")]
#[testing::fixture("tests/fixture/**/input.tsx")]
fn exec(input: PathBuf) {

View File

@ -0,0 +1,10 @@
{
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
}
}

View File

@ -0,0 +1,3 @@
export = function (foo: string, bar: number): boolean {
return true
}

View File

@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
module.exports = function(foo, bar) {
return true;
};