SourceSpan
On this page

SourceSpan

Interface in IR

Where an IR node came from in its authored source: the file, the exact UTF-16 offsets, and the line and character of each end for display.

import type { SourceSpan } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

interface SourceSpan {
readonly file: string;
readonly start: number;
readonly length: number;
readonly line: number;
readonly character: number;
readonly endLine: number;
readonly endCharacter: number;
}

Description

The "use typeshade" source compiler fills one for every Stmt and FuncDecl it lowers, for the outermost call node lowered from each ts.CallExpression, and for an assignment’s target. A call the front end synthesises while expanding one carries none: random(seed) becomes a fract(sin(dot(…))) tree, the array higher-order functions expand into per-element calls, and Math.hypot becomes length(vec2(…)). None of those were written anywhere. A numeric cast is not in that list: f32(n) is a call node lowered from a ts.CallExpression the author wrote, and it carries the span of that text like any other. What has no span is f32(3), where the literal’s coercion folds to a lit — and a lit has no span field at all, so there is nothing to ask about. start and length are the authority; the four line and character fields are derived from them through the parsed ts.SourceFile’s own line map, so a consumer that holds only the span — a debug adapter, a source-map writer — does not have to re-read the file to display it.

Lines and characters are zero-based, matching the language service (docs/language-service-api.md §2) and LSP. TsCompilerDiagnostic’s own line and character are one-based; the two conventions already coexist and the language service already converts, so this type follows the editor-facing one rather than changing the diagnostic shape.

Instance properties

fileread only string

The compilation unit’s file name: the one the caller named, or the compiler’s own default when the caller named none.

startread only number

UTF-16 code-unit offset of the first character, into that file’s text.

lengthread only number

Length in UTF-16 code units. start + length is the exclusive end offset.

lineread only number

Zero-based line of start.

characterread only number

Zero-based UTF-16 character of start within its line.

endLineread only number

Zero-based line of the exclusive end offset.

endCharacterread only number

Zero-based UTF-16 character of the exclusive end offset within its line.

See also

Source

src/core/ir/span.ts, line 54, at commit 26de7be8

Edit this page Report a problem