Skip to content

Adopt esrap 2.3.11+ sourcemaps: pass tokens, drop boundaryTokens and the bracket guess once esrap #212/#213 land #235

Open

Description

@leonidaz

esrap's sourcemap model changed in 2.3.10 and 2.3.11 (sveltejs/esrap#192, #198, #199), and two follow-up PRs are open (sveltejs/esrap#212 node starts printed inline, #213 tokens option). This tracks the @tsrx/core changes to adopt them and delete the mapping workarounds. octane uses createJsxTransform from @tsrx/core, so it is covered by the same changes.

Status on esrap 2.3.11 (verified by running compile_to_volar_mappings with esrap redirected)

Nothing crashes: the _ override in packages/tsrx/src/transform/jsx/helpers.js delegates to esrap's root visitor, so the per-node mappings from #198 come through. The only mappings lost versus 2.3.2 are the lexer function keyword tokens after async (esrap no longer maps a second keyword). boundaryTokens: true is ignored since 2.3.11.

Once sveltejs/esrap#213 ships (tokens option)

  • tsx_with_ts_locations in helpers.js: drop boundaryTokens, pass the parser's tokens as tokens. parse/index.js already collects onToken output for keywordTokens; keep the full token array (or the delimiters) for the volar print. Update types/parse.d.ts ESRapTSOptions, which declares neither boundaryTokens nor tokens.
  • segments.js set_bracket_computed_mapping: stop guessing [/] at key.loc ± 1 and stop skipping the mapping when the guess is absent (6c34d7d). With tokens both brackets have exact source positions and esrap maps them, so the mapping can be built from the real positions and computed-key diagnostics (TS2416, TS2464, TS1166, TS1170) are reported again, including [ key ], comments inside the brackets and multi-line keys.
  • segments.js IfStatement consequent/alternate {/} tokens (column ± 1): the braces are BlockStatement boundaries that esrap maps; use the node positions.
  • The shared source-mappings.js fixtures that say "skipped, not fatal" for computed keys and spans ending at a closing paren or bracket can assert exact mappings instead.

Once sveltejs/esrap#212 ships

  • LOCATION_WRAPPED_NODE_TYPES and TOOLING_LOCATION_WRAPPED_NODE_TYPES in helpers.js are mostly redundant with fix: resolve relative url() in style blocks and reject @import (#153) #198 (every visited node's start and end is mapped). Trim them to what esrap still cannot map: template-literal backticks are covered, JSX < > </ /> are not, generic-argument < > are not.
  • The import statement token and the trailing ; fudge in segments.js can be rechecked against the node mappings.
  • case/default, catch and for-head declarations are mapped by esrap; nothing to add on our side, but the fallthrough (TS7029) and modifier diagnostics can now be asserted in type-diagnostics.js.

Still open on the esrap side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions