diff options
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 17 | ||||
-rw-r--r-- | cli/tools/repl.rs | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index bfb849ed6..955c27069 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -73,6 +73,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() { use std::io::{Read, Write}; run_pty_test(|master| { diff --git a/cli/tools/repl.rs b/cli/tools/repl.rs index 8cde1e39c..b86e8ccd8 100644 --- a/cli/tools/repl.rs +++ b/cli/tools/repl.rs @@ -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)); + } + } + } _ => {} } } |