Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError stack trace source maps #4

Open
legendecas opened this issue Aug 12, 2024 · 2 comments
Open

SyntaxError stack trace source maps #4

legendecas opened this issue Aug 12, 2024 · 2 comments

Comments

@legendecas
Copy link
Member

legendecas commented Aug 12, 2024

With nodejs/node#54283 (comment), when the source codes containing syntax errors (like yet to be supported ECMAScript syntaxes) are used with the flag --experimental-tranform-types, there is no time for --enable-source-maps to collect source maps and perform stack trace mapping, as it collect source maps information from V8 parse results.

const obj = {
  [Symbol.dispose]() {
    console.log('disposed')
  }
}

function foo() {
  using _ = obj;
}

For example, if the following snippet is been parsed as JS, the error would be:

file:///Users/cwu631/Developer/nodejs/node/a.mjs:8
  using _ = obj;
        ^

SyntaxError: Unexpected identifier '_'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at callTranslator (node:internal/modules/esm/loader:436:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:442:30)
    at async ModuleJob._link (node:internal/modules/esm/module_job:106:19)

Node.js v23.0.0-pre

However, if it is parsed as TS:

~/D/n/node (pr-54283)> ./node --experimental-transform-types a.mts
(node:11541) ExperimentalWarning: Type Stripping is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///Users/cwu631/Developer/nodejs/node/a.mts:7
    using _ = obj
          ^

SyntaxError: Unexpected identifier '_'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:166:18)
    at ModuleLoader.<anonymous> (node:internal/modules/esm/translators:540:10)
    at callTranslator (node:internal/modules/esm/loader:436:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:442:30)
    at async ModuleJob._link (node:internal/modules/esm/module_job:106:19)

Node.js v23.0.0-pre

Note that the reported syntax error line number is 7, not 8 as expected.

@marco-ippolito
Copy link
Member

Is it an issue with the typescript loader implementation or with sourcemaps?

@legendecas
Copy link
Member Author

The problem is with the source map support, but it is only outstanding with an internal loader because the transpiled sources are not visible to users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants