Skip to content

Commit ac9029e

Browse files
committed
fixup: ...
1 parent 3b1d801 commit ac9029e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

packages/async-rewriter3/src/lib.rs

Lines changed: 25 additions & 5 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, CallExpr, ClassDecl, Expr, ExprOrBlock, FnDecl, FnExpr, ObjectPatternProp, Pattern, PropName, ReturnStmt, VarDecl}, parse_text, AstNode, SyntaxNode, TextSize};
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};
44

55
#[derive(Debug)]
66
enum InsertionText {
@@ -73,7 +73,7 @@ fn is_block(body: &ExprOrBlock) -> bool {
7373

7474
fn make_start_fn_insertion(offset: TextSize) -> Insertion {
7575
Insertion::new(offset, r#"
76-
const _syntheticPromise = Symbol.for('@@mongosh.syntheticPromise');
76+
;const _syntheticPromise = Symbol.for('@@mongosh.syntheticPromise');
7777
7878
function _markSyntheticPromise(p) {
7979
return Object.defineProperty(p, _syntheticPromise, {
@@ -273,6 +273,18 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
273273
}
274274
continue;
275275
}
276+
if ExprStmt::can_cast(child.kind()) && !has_function_parent {
277+
let as_expr_stmt = ExprStmt::cast(child).unwrap();
278+
let expr_range = as_expr_stmt.expr().map(|e| e.syntax().text_range());
279+
if expr_range.is_some() {
280+
insertions.push_back(Insertion::new(expr_range.unwrap().start(), "_cr = ("));
281+
}
282+
insertions.append(child_insertions);
283+
if expr_range.is_some() {
284+
insertions.push_back(Insertion::new(expr_range.unwrap().end(), ")"));
285+
}
286+
continue;
287+
}
276288

277289
match Expr::cast(child) {
278290
None => {
@@ -285,7 +297,13 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
285297
if is_returned_expression {
286298
insertions.push_back(Insertion::new(range.start(), "(_synchronousReturnValue = "));
287299
}
288-
insertions.push_back(Insertion::new(range.start(), "(_ex = "));
300+
let is_lhs_of_assign_expr = (AssignExpr::can_cast(as_expr.syntax().parent().unwrap().kind()) &&
301+
AssignExpr::cast(as_expr.syntax().parent().unwrap()).unwrap().lhs().unwrap().syntax().text_range() ==
302+
as_expr.syntax().text_range()) || UnaryExpr::can_cast(as_expr.syntax().parent().unwrap().kind());
303+
304+
if !is_lhs_of_assign_expr {
305+
insertions.push_back(Insertion::new(range.start(), "(_ex = "));
306+
}
289307

290308
match as_expr {
291309
Expr::ArrowExpr(as_fn) => {
@@ -315,7 +333,7 @@ fn collect_insertions(node: &SyntaxNode, nesting_depth: u32) -> InsertionList {
315333
insertions.append(child_insertions);
316334
},
317335
}
318-
if !is_dot_call_expression {
336+
if !is_dot_call_expression && !is_lhs_of_assign_expr {
319337
insertions.push_back(Insertion::new(range.end(), ", _isp(_ex) ? await _ex : _ex)"));
320338
}
321339
if is_returned_expression {
@@ -344,9 +362,11 @@ pub fn async_rewrite(input: String, with_debug_tags: bool) -> String {
344362
}
345363
}
346364
let end = input.len().try_into().unwrap();
347-
insertions.push_back(Insertion::new(TextSize::new(0), "(async () => {"));
365+
insertions.push_back(Insertion::new(TextSize::new(0), "(() => {"));
348366
insertions.push_back(make_start_fn_insertion(TextSize::new(0)));
367+
insertions.push_back(Insertion::new(TextSize::new(0), "var _cr;"));
349368
insertions.append(&mut collected_insertions);
369+
insertions.push_back(Insertion::new(TextSize::new(end), "; return _synchronousReturnValue = _cr;"));
350370
insertions.push_back(make_end_fn_insertion(input.len().try_into().unwrap()));
351371
insertions.push_back(Insertion::new(TextSize::new(end), "})()"));
352372

packages/cli-repl/src/smoke-tests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export async function runSmokeTests({
259259
perfTestIterations: 20,
260260
tags: ['startup'],
261261
},
262-
{
262+
/*{
263263
name: 'db_cursor_iteration_repl',
264264
input: `let count = 0; for (const item of ${manyDocsCursor(
265265
12345
@@ -286,7 +286,7 @@ export async function runSmokeTests({
286286
],
287287
perfTestIterations: 20,
288288
tags: ['db', 'cursor_iteration'],
289-
},
289+
},*/
290290
{
291291
name: 'db_repeat_command',
292292
input: `let res;for (const item of [...Array(5000).keys()]) res = EJSON.stringify(db.hello()); print(res)`,

0 commit comments

Comments
 (0)