You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sourcemaps: the end of a typed name maps to the end of its type annotation #205
The mapping at the end of a typed identifier's name points past its type annotation:
functionf(id: string){}letx: number=1;
The code prints unchanged, but the segment at the end of id (generated column 13, the :) maps to source column 21, the ) after string. Likewise the end of x (column 5) maps to column 13, after number. A lookup on the generated : therefore resolves to the end of the annotation, and a consumer that builds a source range from the name's start and end mappings gets id: string rather than id.
Identifier writes the name with context.write(name, node), which adds mappings at node.loc.start and node.loc.end. For a typed binding, both Acorn (@sveltejs/acorn-typescript) and @typescript-eslint/typescript-estree give the Identifier a range covering the whole id: string (including ? or ! when present), so node.loc.end isn't the end of the name. Destructured parameters ({ a }: T, [b]: U) are not affected.
This persists on #198, where the generated : gets two segments: this one, then the type annotation's start.
The AST doesn't record where a typed name ends. For typed identifiers, one option is to derive the end from the name's length (which would be off only for names written with unicode escapes). The other is to skip the end mapping.
Reproduced on esrap 2.3.9 (main) with both parsers (typescript-estree 8.70).
Activity
fix: map the end of a typed identifier to the end of its name (svelte…