token

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package token defines source positions for the TypeScript AST.

Synthesized nodes carry NoPos, so a tree may mix parsed and generated subtrees freely.

Index

Constants

This section is empty.

Variables

View Source
var NoSpan = Span{}

NoSpan is the span of a synthesized node.

Functions

This section is empty.

Types

type File

type File struct {
	Name string
	Size int
	// contains filtered or unexported fields
}

File maps byte offsets to line and column pairs. It is safe for concurrent reads once built.

func NewFile

func NewFile(name string, src []byte) *File

NewFile records line offsets for src and returns the resulting File.

func (*File) Position

func (f *File) Position(p Pos) Location

Position converts a byte offset to a Location.

type Location

type Location struct {
	File   string
	Line   int
	Column int
}

Location is a human-readable source position. Line and Column are 1-based, and Column counts bytes.

func (Location) String

func (l Location) String() string

type Pos

type Pos int

Pos is a 1-based byte offset into a source file, so that the zero value can mean "synthesized".

const NoPos Pos = 0

NoPos is the zero Pos, reported by every synthesized node.

func (Pos) IsValid

func (p Pos) IsValid() bool

IsValid reports whether p refers to a real source location.

type Span

type Span struct {
	Start Pos
	End   Pos
}

Span is a half-open byte range [Start, End).

func Between

func Between(a, b Span) Span

Between returns the span covering both a and b, ignoring invalid endpoints.

func (Span) IsValid

func (s Span) IsValid() bool

IsValid reports whether the span refers to real source text.

func (Span) String

func (s Span) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL