Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(shell-api): provide lazily-connecting Mongo ctor #2405

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fixup: handle e.g. function foo(a=1){}
addaleax committed Mar 10, 2025
commit 07b6b281954a2a4379741b87451c895036fbe17e
15 changes: 11 additions & 4 deletions packages/async-rewriter3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Borrow, collections::VecDeque};
use wasm_bindgen::prelude::*;
use rslint_parser::{ast::{ArrowExpr, AssignExpr, CallExpr, ClassDecl, Expr, ExprOrBlock, ExprStmt, FnDecl, FnExpr, ObjectPatternProp, Pattern, PropName, ReturnStmt, UnaryExpr, VarDecl}, parse_text, AstNode, SyntaxNode, TextSize};
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};

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

if !is_lhs_of_assign_expr {
if !is_lhs_of_assign_expr && !is_argument_default_value {
insertions.push_back(Insertion::new(range.start(), "(_ex = "));
pushed_insertions += 1;
}

match as_expr {
@@ -320,15 +324,18 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
Expr::DotExpr(_) => {
if is_called_expression {
is_dot_call_expression = true;
insertions.pop_back();
while pushed_insertions > 0 {
pushed_insertions -= 1;
insertions.pop_back();
}
}
insertions.append(child_insertions);
}
_ => {
insertions.append(child_insertions);
},
}
if !is_dot_call_expression && !is_lhs_of_assign_expr {
if !is_dot_call_expression && !is_lhs_of_assign_expr && !is_argument_default_value {
insertions.push_back(Insertion::new(range.end(), ", _isp(_ex) ? await _ex : _ex)"));
}
if is_returned_expression {