mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
feat(repl): Type stripping in the REPL (#10934)
This commit is contained in:
parent
f9ff981daf
commit
2d2b5625e0
2 changed files with 157 additions and 34 deletions
|
@ -2022,9 +2022,9 @@ mod integration {
|
|||
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 '}'"));
|
||||
assert!(output.contains("Unexpected token `)`"));
|
||||
assert!(output.contains("Unexpected token `]`"));
|
||||
assert!(output.contains("Unexpected token `}`"));
|
||||
|
||||
fork.wait().unwrap();
|
||||
} else {
|
||||
|
@ -2231,6 +2231,59 @@ mod integration {
|
|||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typescript() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec![
|
||||
"function add(a: number, b: number) { return a + b }",
|
||||
"const result: number = add(1, 2) as number;",
|
||||
"result",
|
||||
]),
|
||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||
false,
|
||||
);
|
||||
assert!(out.ends_with("undefined\nundefined\n3\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typescript_declarations() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec![
|
||||
"namespace Test { export enum Values { A, B, C } }",
|
||||
"Test.Values.A",
|
||||
"Test.Values.C",
|
||||
"interface MyInterface { prop: string; }",
|
||||
"type MyTypeAlias = string;",
|
||||
]),
|
||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||
false,
|
||||
);
|
||||
assert!(out.ends_with("undefined\n0\n2\nundefined\nundefined\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typescript_decorators() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec![
|
||||
"function dec(target) { target.prototype.test = () => 2; }",
|
||||
"@dec class Test {}",
|
||||
"new Test().test()",
|
||||
]),
|
||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||
false,
|
||||
);
|
||||
assert!(out.ends_with("undefined\nundefined\n2\n"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eof() {
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
|
@ -2362,11 +2415,30 @@ mod integration {
|
|||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec!["syntax error"]),
|
||||
None,
|
||||
Some(vec![
|
||||
"syntax error",
|
||||
"2", // ensure it keeps accepting input after
|
||||
]),
|
||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||
false,
|
||||
);
|
||||
assert!(out.contains("Unexpected identifier"));
|
||||
assert!(
|
||||
out.ends_with("parse error: Expected ';', '}' or <eof> at 1:7\n2\n")
|
||||
);
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn syntax_error_jsx() {
|
||||
// JSX is not supported in the REPL
|
||||
let (out, err) = util::run_and_collect_output(
|
||||
true,
|
||||
"repl",
|
||||
Some(vec!["const element = <div />;"]),
|
||||
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
||||
false,
|
||||
);
|
||||
assert!(out.contains("Unexpected token `>`"));
|
||||
assert!(err.is_empty());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue