From de4a115da78e518f927474512a2dcbe491985070 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sun, 3 Nov 2024 09:06:49 +0200 Subject: [PATCH 01/10] fix: adding a check to .mjs, and .mts files and skip the suggestions if one of them detected --- runtime/fmt_errors.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 7c6cf6d397..4ecea219b6 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -303,6 +303,13 @@ fn format_js_error_inner( } fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { + if let Some(frame) = e.frames.get(0) { + if let Some(file_name) = &frame.file_name { + if file_name.ends_with(".mjs") || file_name.ends_with(".mts") { + return vec![]; + } + } +} if let Some(msg) = &e.message { if msg.contains("module is not defined") || msg.contains("exports is not defined") From 81deb058a06823831c77d9b2405a0eae124b0ec3 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sun, 3 Nov 2024 09:35:49 +0200 Subject: [PATCH 02/10] Solving the issues related to the lint and format --- runtime/fmt_errors.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/fmt_errors.rs b/runtime/fmt_errors.rs index 4ecea219b6..00d1d385b3 100644 --- a/runtime/fmt_errors.rs +++ b/runtime/fmt_errors.rs @@ -303,13 +303,13 @@ fn format_js_error_inner( } fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { - if let Some(frame) = e.frames.get(0) { + if let Some(frame) = e.frames.first() { if let Some(file_name) = &frame.file_name { - if file_name.ends_with(".mjs") || file_name.ends_with(".mts") { - return vec![]; - } + if file_name.ends_with(".mjs") || file_name.ends_with(".mts") { + return vec![]; + } } -} + } if let Some(msg) = &e.message { if msg.contains("module is not defined") || msg.contains("exports is not defined") From 29546d8d99a42f0fbdbded4d713cb95c767cb730 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sun, 3 Nov 2024 10:14:36 +0200 Subject: [PATCH 03/10] Fixing the PR name From 95d7b43e652b3bfea2ff033733f5ed2e181f8c23 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Fri, 8 Nov 2024 19:11:20 +0200 Subject: [PATCH 04/10] Adding a test for the .mts and .cts --- tests/specs/fmt_errors/__test__.jsonc | 4 ++++ tests/specs/fmt_errors/a.cts | 4 ++++ tests/specs/fmt_errors/main.mts | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 tests/specs/fmt_errors/__test__.jsonc create mode 100644 tests/specs/fmt_errors/a.cts create mode 100644 tests/specs/fmt_errors/main.mts diff --git a/tests/specs/fmt_errors/__test__.jsonc b/tests/specs/fmt_errors/__test__.jsonc new file mode 100644 index 0000000000..05edd48cd1 --- /dev/null +++ b/tests/specs/fmt_errors/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run --allow-read main.mts", + "output": "3" +} \ No newline at end of file diff --git a/tests/specs/fmt_errors/a.cts b/tests/specs/fmt_errors/a.cts new file mode 100644 index 0000000000..5a92c93ea6 --- /dev/null +++ b/tests/specs/fmt_errors/a.cts @@ -0,0 +1,4 @@ +export function add(num1, num2) { + const result = num1 + num2; + console.log(result); +} diff --git a/tests/specs/fmt_errors/main.mts b/tests/specs/fmt_errors/main.mts new file mode 100644 index 0000000000..771bacf997 --- /dev/null +++ b/tests/specs/fmt_errors/main.mts @@ -0,0 +1,3 @@ +import * as a from "./a.cts"; + +console.log(a.add(1,2)); \ No newline at end of file From ca469ae97b20339919ea638bf26934db9a2a1d06 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Fri, 8 Nov 2024 19:33:54 +0200 Subject: [PATCH 05/10] Fixing th format issues --- tests/specs/fmt_errors/__test__.jsonc | 6 +++--- tests/specs/fmt_errors/a.cts | 4 ++-- tests/specs/fmt_errors/main.mts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/specs/fmt_errors/__test__.jsonc b/tests/specs/fmt_errors/__test__.jsonc index 05edd48cd1..74c0d3621d 100644 --- a/tests/specs/fmt_errors/__test__.jsonc +++ b/tests/specs/fmt_errors/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read main.mts", - "output": "3" -} \ No newline at end of file + "args": "run --allow-read main.mts", + "output": "3" +} diff --git a/tests/specs/fmt_errors/a.cts b/tests/specs/fmt_errors/a.cts index 5a92c93ea6..d5d6bfefcc 100644 --- a/tests/specs/fmt_errors/a.cts +++ b/tests/specs/fmt_errors/a.cts @@ -1,4 +1,4 @@ export function add(num1, num2) { - const result = num1 + num2; - console.log(result); + const result = num1 + num2; + console.log(result); } diff --git a/tests/specs/fmt_errors/main.mts b/tests/specs/fmt_errors/main.mts index 771bacf997..50da134249 100644 --- a/tests/specs/fmt_errors/main.mts +++ b/tests/specs/fmt_errors/main.mts @@ -1,3 +1,3 @@ import * as a from "./a.cts"; -console.log(a.add(1,2)); \ No newline at end of file +console.log(a.add(1, 2)); From 09c3cae9bfa5d9c718107354cc572ece5e6f9080 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Fri, 8 Nov 2024 20:14:59 +0200 Subject: [PATCH 06/10] Modify the test of .mts and .cts --- tests/specs/fmt_errors/__test__.jsonc | 2 +- tests/specs/fmt_errors/a.cts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/specs/fmt_errors/__test__.jsonc b/tests/specs/fmt_errors/__test__.jsonc index 74c0d3621d..374c07438a 100644 --- a/tests/specs/fmt_errors/__test__.jsonc +++ b/tests/specs/fmt_errors/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read main.mts", + "args": "run --unstable --allow-read main.mts", "output": "3" } diff --git a/tests/specs/fmt_errors/a.cts b/tests/specs/fmt_errors/a.cts index d5d6bfefcc..ff2beea9ed 100644 --- a/tests/specs/fmt_errors/a.cts +++ b/tests/specs/fmt_errors/a.cts @@ -1,4 +1,7 @@ -export function add(num1, num2) { +function add(num1, num2) { const result = num1 + num2; console.log(result); + return result; } + +module.exports = { add }; From 52d0cabd9b88ac5d6cf958b9ff5d54ffb8b32441 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Fri, 8 Nov 2024 20:31:48 +0200 Subject: [PATCH 07/10] Modify the output of the test to fit the expected --- tests/specs/fmt_errors/a.cts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/specs/fmt_errors/a.cts b/tests/specs/fmt_errors/a.cts index ff2beea9ed..636d99af3a 100644 --- a/tests/specs/fmt_errors/a.cts +++ b/tests/specs/fmt_errors/a.cts @@ -1,6 +1,5 @@ function add(num1, num2) { const result = num1 + num2; - console.log(result); return result; } From 5da2a52ec2ed86111383d37545774df9d1c172b2 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sat, 9 Nov 2024 17:58:20 +0200 Subject: [PATCH 08/10] Modify the printing statement to avoid the error --- tests/specs/fmt_errors/main.mts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/fmt_errors/main.mts b/tests/specs/fmt_errors/main.mts index 50da134249..c00df2e30f 100644 --- a/tests/specs/fmt_errors/main.mts +++ b/tests/specs/fmt_errors/main.mts @@ -1,3 +1,3 @@ import * as a from "./a.cts"; -console.log(a.add(1, 2)); +await Deno.stdout.write(new TextEncoder().encode(a.add(1, 2))); From a9b4bba3e47aad3517312e5440dd4137ef562bb3 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sat, 9 Nov 2024 18:26:37 +0200 Subject: [PATCH 09/10] Upgrade Canary From 8cca53b04454c9df56a37fd322c86f055d0ecf90 Mon Sep 17 00:00:00 2001 From: MohammadSu1 Date: Sun, 10 Nov 2024 08:54:51 +0200 Subject: [PATCH 10/10] Adding an output file to the test --- tests/specs/fmt_errors/__test__.jsonc | 2 +- tests/specs/fmt_errors/main.mts | 2 +- tests/specs/fmt_errors/main.out | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 tests/specs/fmt_errors/main.out diff --git a/tests/specs/fmt_errors/__test__.jsonc b/tests/specs/fmt_errors/__test__.jsonc index 374c07438a..4f7e7e2b02 100644 --- a/tests/specs/fmt_errors/__test__.jsonc +++ b/tests/specs/fmt_errors/__test__.jsonc @@ -1,4 +1,4 @@ { "args": "run --unstable --allow-read main.mts", - "output": "3" + "output": "main.out" } diff --git a/tests/specs/fmt_errors/main.mts b/tests/specs/fmt_errors/main.mts index c00df2e30f..50da134249 100644 --- a/tests/specs/fmt_errors/main.mts +++ b/tests/specs/fmt_errors/main.mts @@ -1,3 +1,3 @@ import * as a from "./a.cts"; -await Deno.stdout.write(new TextEncoder().encode(a.add(1, 2))); +console.log(a.add(1, 2)); diff --git a/tests/specs/fmt_errors/main.out b/tests/specs/fmt_errors/main.out new file mode 100644 index 0000000000..00750edc07 --- /dev/null +++ b/tests/specs/fmt_errors/main.out @@ -0,0 +1 @@ +3