SourceSpan
인터페이스, 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'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface SourceSpan { readonly file: string; readonly start: number; readonly length: number; readonly line: number; readonly character: number; readonly endLine: number; readonly endCharacter: number;}설명
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.
인스턴스 속성
file읽기 전용stringThe compilation unit’s file name: the one the caller named, or the compiler’s own default when the caller named none.
start읽기 전용numberUTF-16 code-unit offset of the first character, into that file’s text.
length읽기 전용numberLength in UTF-16 code units.
start + lengthis the exclusive end offset.line읽기 전용numberZero-based line of
start.character읽기 전용numberZero-based UTF-16 character of
startwithin its line.endLine읽기 전용numberZero-based line of the exclusive end offset.
endCharacter읽기 전용numberZero-based UTF-16 character of the exclusive end offset within its line.
함께 보기
소스
src/core/ir/span.ts, 54행, 커밋 c66579bf 기준