fix(es/utils): Keep arguments to super call (#3570)

This commit is contained in:
Austaras 2022-02-15 14:42:40 +08:00 committed by GitHub
parent 7351ec2477
commit f67796a962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 13 deletions

View File

@ -1907,6 +1907,34 @@ class A {
"
);
test!(
syntax(),
|_| parameters(Default::default()),
issue_3569,
"
export class TableView extends React.Component {
constructor(props){
super(props);
this.getSearchForm = (innerWidth = 0)=>{
this.getProps();
};
}
}
",
"
export class TableView extends React.Component {
constructor(props){
var _this;
super(props), _this = this;
this.getSearchForm = function () {
let innerWidth = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
_this.getProps();
};
}
}
"
);
test!(
syntax(),
|_| tr(Config {

View File

@ -556,23 +556,20 @@ impl<'a> VisitMut for InitThis<'a> {
fn visit_mut_expr(&mut self, expr: &mut Expr) {
expr.visit_mut_children_with(self);
if let Expr::Call(CallExpr {
callee: Callee::Super(Super { span: super_span }),
span,
..
}) = expr
if let Expr::Call(
call_expr @ CallExpr {
callee: Callee::Super(..),
..
},
) = expr
{
let span = call_expr.span;
*expr = Expr::Paren(ParenExpr {
span: *span,
span,
expr: Box::new(Expr::Seq(SeqExpr {
span: *span,
span,
exprs: vec![
Box::new(Expr::Call(CallExpr {
span: *span,
callee: Callee::Super(Super { span: *super_span }),
args: Vec::new(),
type_args: None,
})),
Box::new(Expr::Call(call_expr.take())),
Box::new(Expr::Assign(AssignExpr {
span: DUMMY_SP,
left: PatOrExpr::Pat(self.this_id.clone().into()),