Skip to content

Commit 157ff18

Browse files
committed
fixup: handle e.g. function foo(a=1){}
1 parent 9ff54ab commit 157ff18

File tree

1 file changed

+11
-4
lines changed
  • packages/async-rewriter3/src

1 file changed

+11
-4
lines changed

packages/async-rewriter3/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Borrow, collections::VecDeque};
22
use wasm_bindgen::prelude::*;
3-
use rslint_parser::{ast::{ArrowExpr, AssignExpr, CallExpr, ClassDecl, Expr, ExprOrBlock, ExprStmt, FnDecl, FnExpr, ObjectPatternProp, Pattern, PropName, ReturnStmt, UnaryExpr, VarDecl}, parse_text, AstNode, SyntaxNode, TextSize};
3+
use rslint_parser::{ast::{ArrowExpr, AssignExpr, CallExpr, ClassDecl, Expr, ExprOrBlock, ExprStmt, FnDecl, FnExpr, ObjectPatternProp, ParameterList, Pattern, PropName, ReturnStmt, UnaryExpr, VarDecl}, parse_text, AstNode, SyntaxNode, TextSize};
44

55
#[derive(Debug)]
66
enum InsertionText {
@@ -289,15 +289,19 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
289289
let is_returned_expression = ReturnStmt::can_cast(as_expr.syntax().parent().unwrap().kind());
290290
let is_called_expression = CallExpr::can_cast(as_expr.syntax().parent().unwrap().kind());
291291
let mut is_dot_call_expression = false;
292+
let mut pushed_insertions = 0;
292293
if is_returned_expression {
293294
insertions.push_back(Insertion::new(range.start(), "(_synchronousReturnValue = "));
295+
pushed_insertions += 1;
294296
}
295297
let is_lhs_of_assign_expr = (AssignExpr::can_cast(as_expr.syntax().parent().unwrap().kind()) &&
296298
AssignExpr::cast(as_expr.syntax().parent().unwrap()).unwrap().lhs().unwrap().syntax().text_range() ==
297299
as_expr.syntax().text_range()) || UnaryExpr::can_cast(as_expr.syntax().parent().unwrap().kind());
300+
let is_argument_default_value = ParameterList::can_cast(as_expr.syntax().parent().unwrap().parent().unwrap().kind());
298301

299-
if !is_lhs_of_assign_expr {
302+
if !is_lhs_of_assign_expr && !is_argument_default_value {
300303
insertions.push_back(Insertion::new(range.start(), "(_ex = "));
304+
pushed_insertions += 1;
301305
}
302306

303307
match as_expr {
@@ -320,15 +324,18 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
320324
Expr::DotExpr(_) => {
321325
if is_called_expression {
322326
is_dot_call_expression = true;
323-
insertions.pop_back();
327+
while pushed_insertions > 0 {
328+
pushed_insertions -= 1;
329+
insertions.pop_back();
330+
}
324331
}
325332
insertions.append(child_insertions);
326333
}
327334
_ => {
328335
insertions.append(child_insertions);
329336
},
330337
}
331-
if !is_dot_call_expression && !is_lhs_of_assign_expr {
338+
if !is_dot_call_expression && !is_lhs_of_assign_expr && !is_argument_default_value {
332339
insertions.push_back(Insertion::new(range.end(), ", _isp(_ex) ? await _ex : _ex)"));
333340
}
334341
if is_returned_expression {

0 commit comments

Comments
 (0)