diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 12 | ||||
-rw-r--r-- | cli/js/40_testing.js | 4 | ||||
-rw-r--r-- | cli/standalone.rs | 9 | ||||
-rw-r--r-- | cli/tests/repl_tests.rs | 22 | ||||
-rw-r--r-- | cli/tests/testdata/fmt/fmt_check_parse_error.out | 8 | ||||
-rw-r--r-- | cli/tests/testdata/lint/expected_json.out | 2 | ||||
-rw-r--r-- | cli/tests/testdata/run/error_syntax.js.out | 3 | ||||
-rw-r--r-- | cli/tests/testdata/run/error_syntax_empty_trailing_line.mjs.out | 3 | ||||
-rw-r--r-- | cli/tests/testdata/run/swc_syntax_error.ts.out | 3 | ||||
-rw-r--r-- | cli/tests/watcher_tests.rs | 6 | ||||
-rw-r--r-- | cli/tools/fmt.rs | 15 | ||||
-rw-r--r-- | cli/tools/repl/editor.rs | 8 | ||||
-rw-r--r-- | cli/tools/repl/session.rs | 5 |
13 files changed, 69 insertions, 31 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2747e5333..3724efe46 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -44,10 +44,10 @@ winres.workspace = true [dependencies] deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_core.workspace = true -deno_doc = "0.51.0" -deno_emit = "0.12.0" -deno_graph = "0.39.0" -deno_lint = { version = "0.35.0", features = ["docs"] } +deno_doc = "0.52.0" +deno_emit = "0.13.0" +deno_graph = "0.41.0" +deno_lint = { version = "0.37.0", features = ["docs"] } deno_runtime.workspace = true deno_task_shell = "0.8.1" napi_sym.workspace = true @@ -65,10 +65,10 @@ data-url.workspace = true dissimilar = "=1.0.4" dprint-plugin-json = "=0.17.0" dprint-plugin-markdown = "=0.15.1" -dprint-plugin-typescript = "=0.79.0" +dprint-plugin-typescript = "=0.80.2" encoding_rs.workspace = true env_logger = "=0.9.0" -eszip = "=0.31.0" +eszip = "=0.32.0" fancy-regex = "=0.10.0" flate2.workspace = true http.workspace = true diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js index f4dcf8a91..43232ef90 100644 --- a/cli/js/40_testing.js +++ b/cli/js/40_testing.js @@ -1069,7 +1069,7 @@ if (shuffle !== null) { // http://en.wikipedia.org/wiki/Linear_congruential_generator // Use BigInt for everything because the random seed is u64. - const nextInt = (function (state) { + const nextInt = function (state) { const m = 0x80000000n; const a = 1103515245n; const c = 12345n; @@ -1077,7 +1077,7 @@ return function (max) { return state = ((a * state + c) % m) % BigInt(max); }; - }(BigInt(shuffle))); + }(BigInt(shuffle)); for (let i = filtered.length - 1; i > 0; i--) { const j = nextInt(i); diff --git a/cli/standalone.rs b/cli/standalone.rs index cce494694..b37df5191 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -11,6 +11,9 @@ use deno_core::anyhow::anyhow; use deno_core::anyhow::Context; use deno_core::error::type_error; use deno_core::error::AnyError; +use deno_core::futures::io::AllowStdIo; +use deno_core::futures::AsyncReadExt; +use deno_core::futures::AsyncSeekExt; use deno_core::futures::FutureExt; use deno_core::located_script_name; use deno_core::serde::Deserialize; @@ -40,7 +43,6 @@ use std::iter::once; use std::pin::Pin; use std::rc::Rc; use std::sync::Arc; -use tokio::io::{AsyncReadExt, AsyncSeekExt}; #[derive(Deserialize, Serialize)] pub struct Metadata { @@ -74,9 +76,10 @@ pub async fn extract_standalone( ) -> Result<Option<(Metadata, eszip::EszipV2)>, AnyError> { let current_exe_path = current_exe()?; - let file = tokio::fs::File::open(current_exe_path).await?; + let file = std::fs::File::open(current_exe_path)?; - let mut bufreader = tokio::io::BufReader::new(file); + let mut bufreader = + deno_core::futures::io::BufReader::new(AllowStdIo::new(file)); let trailer_pos = bufreader.seek(SeekFrom::End(-24)).await?; let mut trailer = [0; 24]; diff --git a/cli/tests/repl_tests.rs b/cli/tests/repl_tests.rs index 418ff00d6..7a13f7553 100644 --- a/cli/tests/repl_tests.rs +++ b/cli/tests/repl_tests.rs @@ -52,17 +52,15 @@ mod repl { #[test] fn pty_unpaired_braces() { - util::with_pty(&["repl"], |mut console| { - console.write_line(")"); - console.write_line("]"); - console.write_line("}"); - console.write_line("close();"); + for right_brace in &[")", "]", "}"] { + util::with_pty(&["repl"], |mut console| { + console.write_line(right_brace); + console.write_line("close();"); - let output = console.read_all_output(); - assert_contains!(output, "Unexpected token `)`"); - assert_contains!(output, "Unexpected token `]`"); - assert_contains!(output, "Unexpected token `}`"); - }); + let output = console.read_all_output(); + assert_contains!(output, "Expression expected"); + }); + } } #[test] @@ -518,7 +516,7 @@ mod repl { None, false, ); - assert_contains!(out, "Unexpected token"); + assert_contains!(out, "Expression expected"); assert!(err.is_empty()); } } @@ -565,7 +563,7 @@ mod repl { Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]), false, ); - assert_contains!(out, "Unexpected token `>`"); + assert_contains!(out, "Expression expected"); assert!(err.is_empty()); } diff --git a/cli/tests/testdata/fmt/fmt_check_parse_error.out b/cli/tests/testdata/fmt/fmt_check_parse_error.out index d9b918af7..9854b6c97 100644 --- a/cli/tests/testdata/fmt/fmt_check_parse_error.out +++ b/cli/tests/testdata/fmt/fmt_check_parse_error.out @@ -1,6 +1,6 @@ -Error checking: [WILDCARD] - Line 2, column 7: Expected '{', got '<eof>' +Error checking: [WILDCARD]parse_error.ts + Expected '{', got '<eof>' at [WILDCARD]parse_error.ts:2:7 - class Test - ~~~~ + class Test + ~~~~ error: Found 1 not formatted file in 1 file diff --git a/cli/tests/testdata/lint/expected_json.out b/cli/tests/testdata/lint/expected_json.out index 61680607c..08ea0d3e0 100644 --- a/cli/tests/testdata/lint/expected_json.out +++ b/cli/tests/testdata/lint/expected_json.out @@ -58,7 +58,7 @@ "errors": [ { "file_path": "[WILDCARD]malformed.js", - "message": "Expected '{', got 'B' at [WILDCARD]malformed.js:4:16" + "message": "Expected '{', got 'B' at [WILDCARD]malformed.js:4:16\n\n export class A B C\n ~" } ] } diff --git a/cli/tests/testdata/run/error_syntax.js.out b/cli/tests/testdata/run/error_syntax.js.out index 6d3f05b8e..fa4d51686 100644 --- a/cli/tests/testdata/run/error_syntax.js.out +++ b/cli/tests/testdata/run/error_syntax.js.out @@ -1 +1,4 @@ error: The module's source code could not be parsed: Expected ',', got 'following' at [WILDCARD]/error_syntax.js:3:6 + + (the following is a syntax error ^^ ! ) + ~~~~~~~~~ diff --git a/cli/tests/testdata/run/error_syntax_empty_trailing_line.mjs.out b/cli/tests/testdata/run/error_syntax_empty_trailing_line.mjs.out index f4bbc6708..2eb290bb5 100644 --- a/cli/tests/testdata/run/error_syntax_empty_trailing_line.mjs.out +++ b/cli/tests/testdata/run/error_syntax_empty_trailing_line.mjs.out @@ -1 +1,4 @@ error: The module's source code could not be parsed: Unexpected eof at [WILDCARD]/error_syntax_empty_trailing_line.mjs:2:22 + + setTimeout(() => {}), + ~ diff --git a/cli/tests/testdata/run/swc_syntax_error.ts.out b/cli/tests/testdata/run/swc_syntax_error.ts.out index c968db5e9..81b0c1949 100644 --- a/cli/tests/testdata/run/swc_syntax_error.ts.out +++ b/cli/tests/testdata/run/swc_syntax_error.ts.out @@ -1 +1,4 @@ error: The module's source code could not be parsed: Unexpected token `}`. Expected an identifier, void, yield, null, await, break, a string literal, a numeric literal, true, false, `, -, import, this, typeof, {, [, ( at [WILDCARD]syntax_error.ts:4:1 + + } + ~ diff --git a/cli/tests/watcher_tests.rs b/cli/tests/watcher_tests.rs index b5c4fe5c0..0b9749e48 100644 --- a/cli/tests/watcher_tests.rs +++ b/cli/tests/watcher_tests.rs @@ -470,6 +470,9 @@ mod watcher { let next_line = stderr_lines.next().unwrap(); assert_contains!(&next_line, "Bundle started"); assert_contains!(stderr_lines.next().unwrap(), "error:"); + assert_eq!(stderr_lines.next().unwrap(), ""); + assert_eq!(stderr_lines.next().unwrap(), " syntax error ^^"); + assert_eq!(stderr_lines.next().unwrap(), " ~~~~~"); assert_contains!(stderr_lines.next().unwrap(), "Bundle failed"); // the target file hasn't been created yet assert!(!target_file.is_file()); @@ -929,6 +932,9 @@ mod watcher { write(&another_test, "syntax error ^^").unwrap(); assert_contains!(stderr_lines.next().unwrap(), "Restarting"); assert_contains!(stderr_lines.next().unwrap(), "error:"); + assert_eq!(stderr_lines.next().unwrap(), ""); + assert_eq!(stderr_lines.next().unwrap(), " syntax error ^^"); + assert_eq!(stderr_lines.next().unwrap(), " ~~~~~"); assert_contains!(stderr_lines.next().unwrap(), "Test failed"); // Then restore the file diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 3cfec9019..d146c958e 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -327,7 +327,20 @@ async fn check_source_files( not_formatted_files_count.fetch_add(1, Ordering::Relaxed); let _g = output_lock.lock(); warn!("Error checking: {}", file_path.to_string_lossy()); - warn!(" {}", e); + warn!( + "{}", + format!("{}", e) + .split('\n') + .map(|l| { + if l.trim().is_empty() { + String::new() + } else { + format!(" {}", l) + } + }) + .collect::<Vec<_>>() + .join("\n") + ); } } Ok(()) diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index fbdda3f5c..a40b6fcd1 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -2,8 +2,10 @@ use crate::colors; use deno_ast::swc::parser::error::SyntaxError; +use deno_ast::swc::parser::token::BinOpToken; use deno_ast::swc::parser::token::Token; use deno_ast::swc::parser::token::Word; +use deno_ast::view::AssignOp; use deno_core::anyhow::Context as _; use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; @@ -235,6 +237,12 @@ impl Validator for EditorHelper { for item in deno_ast::lex(ctx.input(), deno_ast::MediaType::TypeScript) { if let deno_ast::TokenOrComment::Token(token) = item.inner { match token { + Token::BinOp(BinOpToken::Div) + | Token::AssignOp(AssignOp::DivAssign) => { + // it's too complicated to write code to detect regular expression literals + // which are no longer tokenized, so if a `/` or `/=` happens, then we bail + return Ok(ValidationResult::Valid(None)); + } Token::BackQuote => in_template = !in_template, Token::LParen | Token::LBracket diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 0c0563ab8..f6bbf9b9c 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -193,12 +193,13 @@ impl ReplSession { line: &str, ) -> EvaluationOutput { fn format_diagnostic(diagnostic: &deno_ast::Diagnostic) -> String { + let display_position = diagnostic.display_position(); format!( "{}: {} at {}:{}", colors::red("parse error"), diagnostic.message(), - diagnostic.display_position.line_number, - diagnostic.display_position.column_number, + display_position.line_number, + display_position.column_number, ) } |