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

fix(cli/repl): enable await and let re-declarations #7784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cli/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ pub async fn run(
Some(json!({
"expression": format!("'use strict'; void 0;\n{}", &wrapped_line),
"contextId": context_id,
// TODO(caspervonb) set repl mode to true to enable const redeclarations and top
// level await
"replMode": false,
"replMode": true,
})),
)
.await?;
Expand All @@ -145,9 +143,7 @@ pub async fn run(
Some(json!({
"expression": format!("'use strict'; void 0;\n{}", &line),
"contextId": context_id,
// TODO(caspervonb) set repl mode to true to enable const redeclarations and top
// level await
"replMode": false,
"replMode": true,
})),
)
.await?
Expand Down
39 changes: 39 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,45 @@ fn repl_test_block_expression() {
assert!(err.is_empty());
}

#[test]
fn repl_test_await_resolve() {
let (out, err) = util::run_and_collect_output(
true,
"repl",
Some(vec!["await Promise.resolve('done')"]),
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
false,
);
assert!(out.ends_with("\"done\"\n"));
assert!(err.is_empty());
}

#[test]
fn repl_test_await_timeout() {
let (out, err) = util::run_and_collect_output(
true,
"repl",
Some(vec!["await new Promise((r) => setTimeout(r, 0, 'done'))"]),
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
false,
);
assert!(out.ends_with("\"done\"\n"));
assert!(err.is_empty());
}

#[test]
fn repl_test_let_redeclaration() {
let (out, err) = util::run_and_collect_output(
true,
"repl",
Some(vec!["let foo = 0;", "foo", "let foo = 1;", "foo"]),
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
false,
);
assert!(out.ends_with("undefined\n0\nundefined\n1\n"));
assert!(err.is_empty());
}

#[test]
fn repl_cwd() {
let (_out, err) = util::run_and_collect_output(
Expand Down