Skip to content

SyntaxError stack trace source maps #4

@legendecas

Description

@legendecas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions