mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(repl): output error without hanging when input is invalid (#11426)
This commit is contained in:
parent
7b82ef9ded
commit
af4912ed0d
2 changed files with 29 additions and 0 deletions
|
@ -71,6 +71,23 @@ fn pty_bad_input() {
|
|||
});
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn pty_syntax_error_input() {
|
||||
use std::io::{Read, Write};
|
||||
run_pty_test(|master| {
|
||||
master.write_all(b"('\\u')\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("Unterminated string constant"));
|
||||
assert!(output.contains("Unexpected eof"));
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn pty_complete_symbol() {
|
||||
|
|
|
@ -29,6 +29,7 @@ use std::borrow::Cow;
|
|||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use swc_ecmascript::parser::error::SyntaxError;
|
||||
use swc_ecmascript::parser::token::{Token, Word};
|
||||
use tokio::sync::mpsc::channel;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
@ -257,6 +258,17 @@ impl Validator for EditorHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
Token::Error(error) => {
|
||||
match error.kind() {
|
||||
// If there is unterminated template, it continues to read input.
|
||||
SyntaxError::UnterminatedTpl => {}
|
||||
_ => {
|
||||
// If it failed parsing, it should be V8's task to output error instead.
|
||||
// Thus marked as valid with no info.
|
||||
return Ok(ValidationResult::Valid(None));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue