0
0
Fork 0
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:
Ayato Tokubi 2021-07-19 12:38:13 +00:00 committed by GitHub
parent 7b82ef9ded
commit af4912ed0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -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() {

View file

@ -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));
}
}
}
_ => {}
}
}