Skip to content

Feature Suggestion: Static Indexing Format for Compiler #504

Open
@HerringtonDarkholme

Description

@HerringtonDarkholme

Hi TypeScript team! Congratulations for the new TypeScript-Go release!

I understand that the new Compiler API is currently under design and development. However, I want to discuss the possibility of introducing a static indexing format from the TypeScript compiler that creates a snapshot of the codebase for external tools to consume.

Intriguing Example

We already have fast TypeScript linters in Rust, but they cannot handle type-aware linting. Even if TypeScript-Go is fast and provides Go API, the community needs to repay the effort to rewrite a new linter in Go. Or JS-based tools need to talk to Go using FFI.

Alternatively, a language agnostic language server indexing can help external tools utilize type information.

Design Consideration

This is not a new idea. LSIF from Microsoft and SCIP from Sourcegraph are two prominent examples for type indexing.

While it is less flexible than the Compiler API, it opens up new opportunities for various use cases. LSP/copmiler API are dynamic and interactive. APIs can even read/write/transform code on the fly (e.g. like Vue/Svelte/Angular language tools).

In contrast language indexing provides an offline and static alternative for code analysis and manipulation.

Of course, if TS-go can provide a compiler API in JS/Go, implementing indexing can be done in userland. But if it is hard to ship a JS-Go FFI, the indexing format can be a good workaround.

Usage

  1. Offline code browsing like GitHub/SourceGraph
  2. Non-JS/non-Go linter integration, e.g. biome, ast-grep
  3. Code auditing for compliance and quality checks
  4. Automated code rewriting based on types

Prior Art

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions