---
title: "SourceSpan: interface in IR, TypeShade API reference"
description: "SourceSpan, an interface in IR. Where an IR node came from in its authored source: the file, the exact UTF-16 offsets…"
url: https://typeshade.dev/api/sourcespan/
language: en
---

# `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'`
`import type { SourceSpan } from 'typeshade/core/ir'`

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

## Syntax

```ts
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`](https://typeshade.dev/api/stmt/) and [`FuncDecl`](https://typeshade.dev/api/funcdecl/) it lowers, for the outermost call node lowered from each `ts.CallExpression`, and for an assignment’s target. A workgroup-variable read also carries its span for stage diagnostics, without adding a debugger step. 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

**`file` read only `string`**

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

**`start` read only `number`**

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

**`length` read only `number`**

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

**`line` read only `number`**

Zero-based line of `start`.

**`character` read only `number`**

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

**`endLine` read only `number`**

Zero-based line of the exclusive end offset.

**`endCharacter` read only `number`**

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

## See also

- [`Stmt`](https://typeshade.dev/api/stmt/)
- [`FuncDecl`](https://typeshade.dev/api/funcdecl/)
- [`sourceSpanOf`](https://typeshade.dev/api/sourcespanof/)

## Source

[`src/core/ir/span.ts`, line 55](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/span.ts#L55), at commit af54ddad5
