summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-10-02 19:17:47 +0800
committerGitHub <noreply@github.com>2020-10-02 13:17:47 +0200
commit5cd29b37f7946ac05783bae777be8503182a8b8e (patch)
treeedc05600e554133bc0a230de70d53c3a2ff9d243
parent6825d7f13d51006967c2638b4433fb582cd6ddbc (diff)
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.
-rw-r--r--cli/repl.rs8
-rw-r--r--cli/tests/integration_tests.rs39
2 files changed, 41 insertions, 6 deletions
diff --git a/cli/repl.rs b/cli/repl.rs
index 57e517bd7..1c723ec59 100644
--- a/cli/repl.rs
+++ b/cli/repl.rs
@@ -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?;
@@ -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?
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 2e2f91d0a..8e2007b42 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1167,6 +1167,45 @@ fn repl_test_block_expression() {
}
#[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(
true,