1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

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

This enables `replMode` during evaluations which allows for top level
await and let re-declarations.
This commit is contained in:
Casper Beyer 2020-10-02 19:17:47 +08:00 committed by GitHub
parent 6825d7f13d
commit 5cd29b37f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 6 deletions

View file

@ -126,9 +126,7 @@ pub async fn run(
Some(json!({ Some(json!({
"expression": format!("'use strict'; void 0;\n{}", &wrapped_line), "expression": format!("'use strict'; void 0;\n{}", &wrapped_line),
"contextId": context_id, "contextId": context_id,
// TODO(caspervonb) set repl mode to true to enable const redeclarations and top "replMode": true,
// level await
"replMode": false,
})), })),
) )
.await?; .await?;
@ -145,9 +143,7 @@ pub async fn run(
Some(json!({ Some(json!({
"expression": format!("'use strict'; void 0;\n{}", &line), "expression": format!("'use strict'; void 0;\n{}", &line),
"contextId": context_id, "contextId": context_id,
// TODO(caspervonb) set repl mode to true to enable const redeclarations and top "replMode": true,
// level await
"replMode": false,
})), })),
) )
.await? .await?

View file

@ -1166,6 +1166,45 @@ fn repl_test_block_expression() {
assert!(err.is_empty()); 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] #[test]
fn repl_cwd() { fn repl_cwd() {
let (_out, err) = util::run_and_collect_output( let (_out, err) = util::run_and_collect_output(