Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/astro2tsx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "astro2tsx"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
publish = false
description = "Converts .astro files to .tsx for tsserver intellisense, using Biome's HTML CST"

[lib]
crate-type = ["cdylib", "lib"]
test = true
doctest = false

# Path deps into a sibling Biome checkout. Cargo follows the path into
# Biome's own workspace, so the `workspace = true` deps inside each
# Biome crate resolve from `../../../biome/Cargo.toml`. Switch to git
# deps once the Astro-specific lexer changes (template-literal attribute
# values) land in a published Biome version.
[dependencies]
biome_html_parser = { path = "../../../biome/crates/biome_html_parser" }
biome_html_syntax = { path = "../../../biome/crates/biome_html_syntax" }
biome_js_parser = { path = "../../../biome/crates/biome_js_parser" }
biome_js_syntax = { path = "../../../biome/crates/biome_js_syntax" }
biome_rowan = { path = "../../../biome/crates/biome_rowan" }

napi = { workspace = true }
napi-derive = { workspace = true }

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[build-dependencies]
napi-build = { workspace = true }
3 changes: 3 additions & 0 deletions crates/astro2tsx/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
68 changes: 68 additions & 0 deletions crates/astro2tsx/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */
/**
* Convert an Astro source file to TSX for tsserver intellisense.
*
* The conversion is error-tolerant: malformed input produces a
* best-effort TSX output rather than throwing, and `hasParseErrors` is
* set to `true` when the parser surfaced one or more diagnostics.
*/
export declare function convertToTsx(source: string, options?: ConvertToTsxOptions | undefined | null): ConvertToTsxResult

/** Options recognised by `convertToTsx`. */
export interface ConvertToTsxOptions {
/**
* Filename used to derive the default-exported component identifier
* (e.g. `MyPage.astro` produces `MyPage__AstroComponent_`). Optional.
*/
filename?: string
}

/** Result of converting an Astro source to TSX. */
export interface ConvertToTsxResult {
code: string
mappings: Array<Mapping>
frontmatter: GeneratedRange
body: GeneratedRange
scripts: Array<ExtractedTag>
styles: Array<ExtractedTag>
hasParseErrors: boolean
}

export interface ExtractedTag {
range: GeneratedRange
kind: ExtractedTagKind
content: string
lang?: string
}

export declare const enum ExtractedTagKind {
Script = 'Script',
Style = 'Style',
StyleAttribute = 'StyleAttribute',
EventAttribute = 'EventAttribute'
}

/**
* Byte range inside the generated TSX. Used to mark the frontmatter
* section, the body section, and each extracted script / style block.
*/
export interface GeneratedRange {
start: number
end: number
}

/**
* Per-byte source-position mapping. JS consumers can iterate this list
* to build a VLQ-encoded sourcemap or to translate offsets between the
* emitted TSX and the original `.astro` source.
*/
export interface Mapping {
/** Byte offset into the generated TSX. */
generated: number
/**
* Byte offset into the original `.astro` source. `None` for synthetic
* content (e.g. the `<Fragment>` wrapping or the prefix comment).
*/
original?: number
}
Loading
Loading