mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
fix(repl): don't hang on unpaired braces (#8151)
Previously, entering a single ']' would cause repl to forever accepting new lines, due to that `ValidationResult::Invalid` would actually be consumed by the editor itself while continue building the lines. Instead we should mark it as `Valid` and send the bad input for evaluation to get the proper error from V8. Before: ``` > ] (you can keep entering new line here, and it will never consume input until you Ctrl-C) ``` After: ``` > ] Uncaught SyntaxError: Unexpected token ']' > ```
This commit is contained in:
parent
e01664d0ae
commit
07359b7957
2 changed files with 53 additions and 5 deletions
|
@ -171,11 +171,10 @@ impl Validator for Helper {
|
|||
left
|
||||
))))
|
||||
}
|
||||
(None, c) => {
|
||||
return Ok(ValidationResult::Invalid(Some(format!(
|
||||
"Mismatched pairs: {:?} is unpaired",
|
||||
c
|
||||
))))
|
||||
(None, _) => {
|
||||
// While technically invalid when unpaired, it should be V8's task to output error instead.
|
||||
// Thus marked as valid with no info.
|
||||
return Ok(ValidationResult::Valid(None));
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
|
|
@ -1268,6 +1268,40 @@ fn repl_test_pty_multiline() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn repl_test_pty_unpaired_braces() {
|
||||
use std::io::Read;
|
||||
use util::pty::fork::*;
|
||||
|
||||
let tests_path = util::tests_path();
|
||||
let fork = Fork::from_ptmx().unwrap();
|
||||
if let Ok(mut master) = fork.is_parent() {
|
||||
master.write_all(b")\n").unwrap();
|
||||
master.write_all(b"]\n").unwrap();
|
||||
master.write_all(b"}\n").unwrap();
|
||||
master.write_all(b"close();\n").unwrap();
|
||||
|
||||
let mut output = String::new();
|
||||
master.read_to_string(&mut output).unwrap();
|
||||
|
||||
assert!(output.contains("Unexpected token ')'"));
|
||||
assert!(output.contains("Unexpected token ']'"));
|
||||
assert!(output.contains("Unexpected token '}'"));
|
||||
|
||||
fork.wait().unwrap();
|
||||
} else {
|
||||
util::deno_cmd()
|
||||
.current_dir(tests_path)
|
||||
.env("NO_COLOR", "1")
|
||||
.arg("repl")
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait()
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_watch_with_importmap_and_relative_paths() {
|
||||
fn create_relative_tmp_file(
|
||||
|
@ -1516,6 +1550,21 @@ fn repl_test_eval_unterminated() {
|
|||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repl_test_unpaired_braces() {
|
||||
for right_brace in &[")", "]", "}"] {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec![right_brace]),
|
||||
None,
|
||||
false,
|
||||
);
|
||||
assert!(out.contains("Unexpected token"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repl_test_reference_error() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
|
|
Loading…
Reference in a new issue