From 806671af3345f403d122911d8a3f09a2994bb8c0 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 12 Apr 2023 12:45:36 +0100 Subject: fix(core): preserve syntax error locations in dynamic imports (#18664) Fixes #6259. Adds the location for v8 syntax errors to the message (`message += " at {location}"`) when rethrowing them for dynamic imports. Discussing with @bartlomieju on discord I proposed just preserving v8's error and not reconstructing it, allowing the standard stack trace to just point to the syntax error instead of the dynamic import. But on further thought this way has parity with SWC's syntax errors + has the advantage of showing both the syntax error and dynamic import location. ```ts // temp.js await import("./temp2.js"); // temp2.js function foo() { await Promise.resolve(); } // Before: // error: Uncaught (in promise) SyntaxError: Unexpected reserved word // await import("./temp2.js"); // ^ // at async file:///.../temp.js:1:1 // After: // error: Uncaught (in promise) SyntaxError: Unexpected reserved word at file:///.../temp2.js:2:3 // await import("./temp2.js"); // ^ // at async file:///.../temp.js:1:1 ``` --- cli/tests/testdata/run/dynamic_import_syntax_error.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 cli/tests/testdata/run/dynamic_import_syntax_error.js (limited to 'cli/tests/testdata/run/dynamic_import_syntax_error.js') diff --git a/cli/tests/testdata/run/dynamic_import_syntax_error.js b/cli/tests/testdata/run/dynamic_import_syntax_error.js new file mode 100644 index 000000000..be8ec132f --- /dev/null +++ b/cli/tests/testdata/run/dynamic_import_syntax_error.js @@ -0,0 +1 @@ +await import("./dynamic_import_syntax_error_import.js"); -- cgit v1.2.3