diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e2ddbf4..68642d1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -107,6 +107,13 @@ jobs: run: pnpm test working-directory: crates/astro_napi + - name: Build astro2tsx binding + run: pnpm --filter ./crates/astro2tsx run build-dev + + - name: Test astro2tsx binding + run: pnpm test + working-directory: crates/astro2tsx + - name: Build compiler package run: pnpm run build:compiler diff --git a/Cargo.toml b/Cargo.toml index 25b15391..97fc7cae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,17 @@ oxc_syntax = { git = "https://github.com/withastro/oxc", rev = "8bb526fc0c20beb4 oxc_transformer = { git = "https://github.com/withastro/oxc", rev = "8bb526fc0c20beb4649b223d3ac39851505caa5a" } oxc_sourcemap = "6.0.1" +# Biome dependencies via git, all pinned to the same fork revision +biome_diagnostics = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_html_parser = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_html_syntax = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_js_parser = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_parser = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_js_syntax = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_languages = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_rowan = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } +biome_string_case = { git = "https://github.com/Princesseuh/biome", rev = "e0a22c5f5b6fd09abe5e93ec0b5416f0ffbb73cb" } + # NAPI napi = { version = "3", features = ["tokio_rt"] } napi-build = "2" diff --git a/biome.jsonc b/biome.jsonc index 5b819f73..f16b0d56 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -11,7 +11,10 @@ "!crates/astro_napi/*.cjs", "!crates/astro_napi/*.mjs", "!crates/astro_napi/index.d.ts", - "!crates/astro_napi/npm" + "!crates/astro_napi/npm", + "!crates/astro2tsx/*.js", + "!crates/astro2tsx/index.d.ts", + "!crates/astro2tsx/npm" ] }, "vcs": { diff --git a/crates/astro2tsx/Cargo.toml b/crates/astro2tsx/Cargo.toml new file mode 100644 index 00000000..aff89d0f --- /dev/null +++ b/crates/astro2tsx/Cargo.toml @@ -0,0 +1,44 @@ +[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 + +[dependencies] +biome_diagnostics = { workspace = true } +biome_html_parser = { workspace = true } +biome_html_syntax = { workspace = true } +biome_js_parser = { workspace = true } +biome_parser = { workspace = true } +biome_js_syntax = { workspace = true } +biome_languages = { workspace = true } +biome_rowan = { workspace = true } +biome_string_case = { workspace = true } + +napi = { workspace = true } +napi-derive = { workspace = true } +oxc_sourcemap = { workspace = true } +oxc_syntax = { workspace = true } + +[dev-dependencies] +divan = { workspace = true } +insta = { workspace = true, features = ["glob", "serde"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" + +[build-dependencies] +napi-build = { workspace = true } + +[[bench]] +name = "convert" +harness = false diff --git a/crates/astro2tsx/__test__/astro2tsx.test.ts b/crates/astro2tsx/__test__/astro2tsx.test.ts new file mode 100644 index 00000000..f0166be9 --- /dev/null +++ b/crates/astro2tsx/__test__/astro2tsx.test.ts @@ -0,0 +1,209 @@ +import { readdirSync, readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { strict as assert } from 'node:assert'; +import ts from 'typescript'; +import { test } from 'node:test'; +import { convertToTsx } from '../index.js'; + +test('emits the TSX prefix and a Fragment-wrapped body', () => { + const result = convertToTsx('

Hello {value}

'); + assert.ok(result.code.startsWith('/* @jsxImportSource astro */')); + assert.match(result.code, /[\s\S]*

[\s\S]*<\/h1>[\s\S]*<\/Fragment>/); +}); + +test('rewrites top-level returns to throws', () => { + const result = convertToTsx("---\nif (cond) {\n\treturn Astro.redirect('/x');\n}\n---\n"); + assert.match(result.code, /throw\s+Astro\.redirect/); + assert.doesNotMatch(result.code, /return Astro\.redirect/); +}); + +test('detects `Props` interface and emits the Astro global declaration', () => { + const input = '---\ninterface Props {}\n---\n
'; + const result = convertToTsx(input, { filename: 'Index.astro' }); + assert.match(result.code, /_props: Props/); + assert.match( + result.code, + /declare const Astro: Readonly>/, + ); +}); + +test('reports parse errors but still produces output', () => { + const result = convertToTsx(' 0); +}); + +test('records frontmatter and body byte ranges', () => { + const result = convertToTsx('---\nlet x = 1;\n---\n

'); + assert.ok(result.frontmatter.end > result.frontmatter.start); + assert.ok(result.body.end > result.body.start); + const frontmatterSlice = result.code.slice(result.frontmatter.start, result.frontmatter.end); + assert.match(frontmatterSlice, /let x = 1;/); +}); + +test('mapped runs interpolate to exact source positions, Volar-style', () => { + const source = + '---\nconst x = 1;\n---\n
hello world
'; + const result = convertToTsx(source, { sourcemap: 'external' }); + const { generatedOffsets, sourceOffsets, lengths } = result; + + assert.ok(generatedOffsets instanceof Uint32Array); + assert.equal(generatedOffsets.length, sourceOffsets.length); + assert.equal(generatedOffsets.length, lengths.length); + assert.ok(generatedOffsets.length > 0); + for (let i = 0; i < generatedOffsets.length; i++) { + assert.ok(lengths[i] > 0, `run ${i} is empty`); + if (i > 0) { + assert.ok( + generatedOffsets[i] >= generatedOffsets[i - 1] + lengths[i - 1], + `run ${i} overlaps its predecessor`, + ); + } + } + + const originalAt = (generated) => { + for (let i = generatedOffsets.length - 1; i >= 0; i--) { + const delta = generated - generatedOffsets[i]; + if (delta >= 0 && delta < lengths[i]) return sourceOffsets[i] + delta; + } + return null; + }; + + // Hover-style probes, deliberately mid-run rather than at run starts. + for (const probe of ['id="main"', 'data-thing', 'hello', 'world', 'const x = 1;']) { + const generated = result.code.indexOf(probe); + assert.notEqual(generated, -1, `${probe} not in output`); + const original = originalAt(generated); + assert.notEqual(original, null, `${probe} is unmapped`); + assert.equal( + source.slice(original, original + probe.length), + probe, + `${probe} resolves to the wrong source text`, + ); + } + + // Synthetic output stays unmapped instead of resolving somewhere misleading. + assert.equal(originalAt(result.code.indexOf('')), null); + assert.equal(originalAt(result.code.indexOf('export default function')), null); +}); + +test('returns a self-contained source map v3', () => { + const input = '---\nlet x = 1;\n---\n

Hi

'; + const map = JSON.parse(convertToTsx(input).map!); + assert.equal(map.version, 3); + assert.deepEqual(map.sources, ['input.astro']); + assert.deepEqual(map.sourcesContent, [input]); + assert.deepEqual(map.names, []); + assert.ok(map.mappings.length > 0); +}); + +test('names the source after the filename option', () => { + const map = JSON.parse(convertToTsx('

', { filename: 'Index.astro' }).map!); + assert.deepEqual(map.sources, ['Index.astro']); +}); + +test('appends the inline source map comment by default', () => { + const { code, map } = convertToTsx('

Hi

'); + const marker = '\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,'; + assert.ok(code.includes(marker)); + const blob = code.slice(code.indexOf(marker) + marker.length); + assert.deepEqual(JSON.parse(Buffer.from(blob, 'base64').toString('utf8')), JSON.parse(map!)); +}); + +test("sourcemap: 'external' leaves the code without the comment", () => { + const inline = convertToTsx('

Hi

'); + const external = convertToTsx('

Hi

', { sourcemap: 'external' }); + assert.doesNotMatch(external.code, /sourceMappingURL/); + assert.ok(inline.code.startsWith(external.code)); +}); + +test('every clean-parse fixture emits syntactically valid TSX', async () => { + // Frontmatter is user JS emitted verbatim, so a fixture whose frontmatter is + // itself invalid TS legitimately produces invalid output. + const invalidUserCode = new Set(['props_generic_invalid']); + + const dir = join(import.meta.dirname, '../tests/fixtures'); + let checked = 0; + for (const file of readdirSync(dir)) { + if (!file.endsWith('.astro')) continue; + const name = file.slice(0, -'.astro'.length); + if (invalidUserCode.has(name)) continue; + + let source = readFileSync(join(dir, file), 'utf8'); + while (source.startsWith('// @config ')) { + source = source.slice(source.indexOf('\n') + 1); + } + + const result = convertToTsx(source, { filename: `${name}.astro` }); + if (result.hasParseErrors) continue; + + const sourceFile = ts.createSourceFile( + `${name}.tsx`, + result.code, + ts.ScriptTarget.Latest, + false, + ts.ScriptKind.TSX, + ); + const diagnostics = ( + sourceFile as unknown as { parseDiagnostics: { messageText: unknown; start: number }[] } + ).parseDiagnostics; + assert.deepEqual( + diagnostics.map((d) => `${name}: ${JSON.stringify(d.messageText)} at ${d.start}`), + [], + `invalid TSX emitted for ${name}:\n${result.code}`, + ); + checked++; + } + assert.ok(checked > 50, `expected to check most fixtures, checked ${checked}`); +}); + +test('offsets are UTF-16 code units, not bytes', () => { + const source = '---\nconst \u{1f984} = 1;\n---\n'; + const result = convertToTsx(source, { sourcemap: 'external' }); + + // The unicorn is four bytes but two UTF-16 units, so a byte offset would overshoot. + const style = result.styles[0]; + assert.equal(source.slice(style.position.start, style.position.end), '.a{color:red}'); + assert.equal( + source.slice(result.frontmatterSource.start, result.frontmatterSource.end).at(-1), + '-', + ); + + const { generatedOffsets, sourceOffsets, lengths } = result; + for (let i = 0; i < generatedOffsets.length; i++) { + assert.equal( + result.code.slice(generatedOffsets[i], generatedOffsets[i] + lengths[i]), + source.slice(sourceOffsets[i], sourceOffsets[i] + lengths[i]), + `run ${i} is not verbatim`, + ); + } +}); + +test('reports frontmatter status and positioned diagnostics', () => { + assert.equal(convertToTsx('---\nlet x = 1;\n---\n

').frontmatterStatus, 'closed'); + assert.equal(convertToTsx('---\nlet x = 1;\n').frontmatterStatus, 'open'); + assert.equal(convertToTsx('

').frontmatterStatus, 'doesnt-exist'); + + const broken = convertToTsx('

{x ==}
'); + assert.ok(broken.hasParseErrors); + assert.ok(broken.diagnostics.length > 0); + for (const diagnostic of broken.diagnostics) { + assert.ok(diagnostic.message.length > 0); + assert.equal(diagnostic.severity, 1); + assert.ok(diagnostic.position.end >= diagnostic.position.start); + } +}); + +test('sourcemap: false skips building the map', () => { + const source = '---\nconst x = 1;\n---\n

{x}

'; + const skipped = convertToTsx(source, { sourcemap: false }); + assert.equal(skipped.map, undefined); + assert.doesNotMatch(skipped.code, /sourceMappingURL/); + + // Opting out must not change the code or the offsets editors navigate by. + const external = convertToTsx(source, { sourcemap: 'external' }); + assert.equal(skipped.code, external.code); + assert.deepEqual(Array.from(skipped.generatedOffsets), Array.from(external.generatedOffsets)); + assert.deepEqual(Array.from(skipped.lengths), Array.from(external.lengths)); + assert.ok(external.map); +}); diff --git a/crates/astro2tsx/benches/convert.rs b/crates/astro2tsx/benches/convert.rs new file mode 100644 index 00000000..6702fba3 --- /dev/null +++ b/crates/astro2tsx/benches/convert.rs @@ -0,0 +1,114 @@ +use astro2tsx::{ConvertOptions, SourceMapMode, convert_to_tsx}; +use divan::counter::BytesCount; + +fn main() { + divan::main(); +} + +fn options() -> ConvertOptions { + ConvertOptions { + filename: Some("Component.astro".to_string()), + sourcemap: SourceMapMode::External, + } +} + +fn bench_convert(bencher: divan::Bencher<'_, '_>, source: &str) { + bencher + .counter(BytesCount::of_str(source)) + .bench_local(|| convert_to_tsx(divan::black_box(source), options())); +} + +mod components { + use super::*; + + #[divan::bench] + fn favicon(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/Favicon.astro")); + } + + #[divan::bench] + fn pill_link(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/PillLink.astro")); + } + + #[divan::bench] + fn social_links(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/SocialLinks.astro")); + } + + #[divan::bench] + fn header_drop_down(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/HeaderDropDown.astro")); + } + + #[divan::bench] + fn seo(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/SEO.astro")); + } + + #[divan::bench] + fn expression_heavy(bencher: divan::Bencher<'_, '_>) { + bench_convert(bencher, include_str!("fixtures/ExpressionHeavy.astro")); + } +} + +/// Repeats the section so the input grows without its shape changing. +fn build_page(sections: usize) -> String { + let fixture = include_str!("fixtures/ExpressionHeavy.astro"); + let (frontmatter, body) = fixture + .rsplit_once("---\n") + .expect("fixture has a frontmatter fence"); + let mut source = String::with_capacity(frontmatter.len() + 4 + body.len() * sections); + source.push_str(frontmatter); + source.push_str("---\n"); + for _ in 0..sections { + source.push_str(body); + } + source +} + +#[divan::bench(args = [8, 64, 256])] +fn large_page(bencher: divan::Bencher<'_, '_>, sections: usize) { + let source = build_page(sections); + bencher + .counter(BytesCount::of_str(&source)) + .bench_local(|| convert_to_tsx(divan::black_box(&source), options())); +} + +mod phases { + use super::*; + + #[divan::bench] + fn convert_only(bencher: divan::Bencher<'_, '_>) { + let source = build_page(64); + bencher + .counter(BytesCount::of_str(&source)) + .bench_local(|| convert_to_tsx(divan::black_box(&source), options())); + } + + #[divan::bench] + fn sourcemap_encode(bencher: divan::Bencher<'_, '_>) { + let source = build_page(64); + let result = convert_to_tsx(&source, options()); + bencher + .counter(BytesCount::of_str(&result.code)) + .bench_local(|| result.source_map(divan::black_box(&source), "Component.astro")); + } + + /// Inline is the napi binding's default, so this is the production path. + #[divan::bench] + fn convert_with_inline_map(bencher: divan::Bencher<'_, '_>) { + let source = build_page(64); + bencher + .counter(BytesCount::of_str(&source)) + .bench_local(|| { + convert_to_tsx( + divan::black_box(&source), + ConvertOptions { + filename: Some("Component.astro".to_string()), + sourcemap: SourceMapMode::Inline, + }, + ) + }); + } +} diff --git a/crates/astro2tsx/benches/fixtures/ExpressionHeavy.astro b/crates/astro2tsx/benches/fixtures/ExpressionHeavy.astro new file mode 100644 index 00000000..36402415 --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/ExpressionHeavy.astro @@ -0,0 +1,45 @@ +--- +interface Item { + href: string; + title: string; + tags: string[]; + draft?: boolean; +} + +interface Props { + items: Item[]; + heading?: string; +} + +const { items, heading = 'Latest posts' } = Astro.props; +const published = items.filter((item) => !item.draft); +--- + +
+

{heading}

+ {published.length === 0 &&

Nothing here yet.

} +
    + { + published.map((item, index) => ( +
  • + + {index === 0 ? ( + + {item.title} + + ) : ( + {item.title} + )} + {item.tags.length > 0 && ( + + {item.tags.map((tag) => ( + #{tag} + ))} + + )} +
  • + )) + } +
+ {published.length > 10 && See all {published.length} posts} +
diff --git a/crates/astro2tsx/benches/fixtures/Favicon.astro b/crates/astro2tsx/benches/fixtures/Favicon.astro new file mode 100644 index 00000000..db43d5dc --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/Favicon.astro @@ -0,0 +1,9 @@ + + + diff --git a/crates/astro2tsx/benches/fixtures/HeaderDropDown.astro b/crates/astro2tsx/benches/fixtures/HeaderDropDown.astro new file mode 100644 index 00000000..8fed5859 --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/HeaderDropDown.astro @@ -0,0 +1,86 @@ +--- +import { Icon } from 'astro-icon/components'; + +interface Props { + label: string; + items: Array<{ + href: string; + icon: string; + label: string; + prefetch?: boolean; + badge?: string; + }>; +} +--- + + +
+ + {Astro.props.label} + + +
+
+ + diff --git a/crates/astro2tsx/benches/fixtures/PillLink.astro b/crates/astro2tsx/benches/fixtures/PillLink.astro new file mode 100644 index 00000000..15e9d04b --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/PillLink.astro @@ -0,0 +1,35 @@ +--- +import { Icon } from 'astro-icon/components'; + +type Props = { + href: string; + title: string; + class?: string; + subtitle?: string; +}; + +const { title, subtitle, href, class: className } = Astro.props; +--- + + +
+ {title} +
+ { + subtitle && ( + + ) + } +
diff --git a/crates/astro2tsx/benches/fixtures/SEO.astro b/crates/astro2tsx/benches/fixtures/SEO.astro new file mode 100644 index 00000000..bf642f11 --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/SEO.astro @@ -0,0 +1,100 @@ +--- +export type Image = { + src: string; + alt: string; +}; +export type SEOMetadata = { + name: string; + title: string; + description: string; + image: Image; + canonicalURL?: URL | string | null; + locale?: string; +}; +export type OpenGraph = Partial & { + type?: string; +}; +export type Twitter = Partial & { + handle?: string; + card?: 'summary' | 'summary_large_image'; +}; +export type Props = SEOMetadata & { + og?: OpenGraph; + twitter?: Twitter; +}; +const { + name, + title, + description, + image, + locale = 'en', + canonicalURL = new URL(Astro.url.pathname, Astro.site), +} = Astro.props; + +const og = { + name, + title, + description, + canonicalURL, + image, + locale, + type: 'website', + ...Astro.props.og, +} satisfies OpenGraph; + +const twitter = { + name, + title, + description, + canonicalURL, + image, + locale, + card: 'summary_large_image', + ...Astro.props.twitter, +} satisfies Twitter; + +/** + * Enforce some standard canonical URL formatting across the site. + */ +function formatCanonicalURL(url: string | URL) { + const path = url.toString(); + const hasQueryParams = path.includes('?'); + // If there are query params, make sure the URL has no trailing slash + if (hasQueryParams) { + path.replace(/\/?$/, ''); + } + // otherwise, canonical URL always has a trailing slash + return path.replace(/\/?$/, hasQueryParams ? '' : '/'); +} +--- + +{/* Page Metadata */} +{canonicalURL && } + + +{/* OpenGraph Tags */} + + +{og.canonicalURL && } + + + +{og.image && } +{og.image && } + +{/* Twitter Tags */} +{twitter.card && } +{twitter.handle && } + + +{twitter.image && } +{twitter.image && } + +{ + /* + Robots meta tag for Google Search. + Enables a large image preview in Google search results, most pertinently in Chrome’s “Discover” view on mobile. + See: https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag#max-image-preview +*/ +} + diff --git a/crates/astro2tsx/benches/fixtures/SocialLinks.astro b/crates/astro2tsx/benches/fixtures/SocialLinks.astro new file mode 100644 index 00000000..02d94f0c --- /dev/null +++ b/crates/astro2tsx/benches/fixtures/SocialLinks.astro @@ -0,0 +1,21 @@ +--- +import { Icon } from 'astro-icon/components'; +import type { SocialLink } from '~/data/site-info.js'; + +export type Props = { + links: SocialLink[]; +}; + +const { links } = Astro.props; +--- + +
+ { + links.map((link) => ( + + {link.text} + + )) + } +
diff --git a/crates/astro2tsx/build.rs b/crates/astro2tsx/build.rs new file mode 100644 index 00000000..0f1b0100 --- /dev/null +++ b/crates/astro2tsx/build.rs @@ -0,0 +1,3 @@ +fn main() { + napi_build::setup(); +} diff --git a/crates/astro2tsx/index.d.ts b/crates/astro2tsx/index.d.ts new file mode 100644 index 00000000..afea9e76 --- /dev/null +++ b/crates/astro2tsx/index.d.ts @@ -0,0 +1,112 @@ +/* auto-generated by NAPI-RS */ +/* eslint-disable */ +export interface AstroDiagnostic { + message: string + severity: DiagnosticSeverity + position: Range +} + +export declare const enum AstroFrontmatterStatus { + DoesntExist = 'doesnt-exist', + Open = 'open', + Closed = 'closed' +} + +/** + * 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 + +export interface ConvertToTsxOptions { + /** + * Filename used to derive the default-exported component identifier + * (e.g. `MyPage.astro` produces `MyPage__AstroComponent_`). Optional. + */ + filename?: string + /** + * `false` skips building the map entirely, `"external"` returns it in + * `map` without touching `code`, and `true` / `"inline"` (the default) + * also appends a `//# sourceMappingURL=` comment. + */ + sourcemap?: boolean | string +} + +export interface ConvertToTsxResult { + code: string + /** + * Offsets into `code` where each mapped run starts, ascending. Positions + * inside a run resolve as `sourceOffsets[i] + (offset - + * generatedOffsets[i])` while within `lengths[i]` — the shape Volar + * mappings use. Output outside every run is synthetic. + */ + generatedOffsets: Uint32Array + sourceOffsets: Uint32Array + lengths: Uint32Array + /** Range of the frontmatter section within `code`. */ + frontmatter: Range + /** Range of the `` body within `code`. */ + body: Range + /** + * Source Map v3 JSON for `code`, with `sourcesContent` embedded. `None` + * when the caller opted out with `sourcemap: false`. + */ + map?: string + frontmatterStatus: AstroFrontmatterStatus + /** Range of the frontmatter in the original source, fences included. */ + frontmatterSource: Range + scripts: Array + styles: Array + diagnostics: Array + hasParseErrors: boolean +} + +export declare const enum DiagnosticSeverity { + Error = 1, + Warning = 2, + Information = 3, + Hint = 4 +} + +export interface ExtractedScript { + /** Range of `content` in the original source. */ + position: Range + content: string + type: ExtractedScriptType +} + +/** + * How a `"); + assert!(result.code.contains("")); + assert!(!result.code.contains("const a = 1;")); +} + +#[test] +fn json_script_text_is_excluded_but_the_tag_remains() { + let result = convert(""); + assert!(result.code.contains(""); + assert!(result.code.contains(""); + assert!(!script.code.contains("const a = 1;"), "{}", script.code); + + let style = convert(""); + assert!(!style.code.contains("color: red"), "{}", style.code); +} + +#[test] +fn excluded_bodies_are_still_reported_as_extracted_tags() { + let result = convert(""); + assert_eq!(result.scripts.len(), 1); + assert_eq!(result.scripts[0].content, "const a = 1;"); + assert_eq!(result.styles.len(), 1); + assert_eq!(result.styles[0].content, ".a{color:red}"); +} diff --git a/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.astro b/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.astro new file mode 100644 index 00000000..936cfebf --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.astro @@ -0,0 +1,2 @@ +a +b diff --git a/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.snap b/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.snap new file mode 100644 index 00000000..076fb930 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.snap @@ -0,0 +1,28 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 72 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/adjacent_siblings_top_level.astro +--- +/* @jsxImportSource astro */ + + +a +b + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHNwYW4+YTwvc3Bhbj5cbjxzcGFuPmI8L3NwYW4+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/attribute_event_and_style.astro b/crates/astro2tsx/tests/fixtures/attribute_event_and_style.astro new file mode 100644 index 00000000..73edca40 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_event_and_style.astro @@ -0,0 +1 @@ +
diff --git a/crates/astro2tsx/tests/fixtures/attribute_event_and_style.snap b/crates/astro2tsx/tests/fixtures/attribute_event_and_style.snap new file mode 100644 index 00000000..8bddee8f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_event_and_style.snap @@ -0,0 +1,45 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 87 + scripts: + - kind: EventAttribute + lang: event-attribute + generated: + start: 55 + end: 59 + source: + start: 14 + end: 18 + content: go() + styles: + - kind: StyleAttribute + lang: css + generated: + start: 68 + end: 77 + source: + start: 27 + end: 36 + content: "color:red" +input_file: crates/astro2tsx/tests/fixtures/attribute_event_and_style.astro +--- +/* @jsxImportSource astro */ + + +
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBvbmNsaWNrPVwiZ28oKVwiIHN0eWxlPVwiY29sb3I6cmVkXCI+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxJLENBQUssYyxDQUFlO0FBQ3BCO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.astro b/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.astro new file mode 100644 index 00000000..bf745e2d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.astro @@ -0,0 +1 @@ +
{i})} empty={}>
diff --git a/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.snap b/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.snap new file mode 100644 index 00000000..19a74226 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_expression_jsx.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 109 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_expression_jsx.astro +--- +/* @jsxImportSource astro */ + + +
{i})} empty={(void 0)}>
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBkYXRhLW91dD17aXRlbXMubWFwKGkgPT4gPGI+e2l9PC9iPil9IGVtcHR5PXt9PjwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsSSxDQUFLLFMsQ0FBVSwwQixFQUE0QixNLFVBQVE7QUFDbkQ7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/attribute_expression_value.astro b/crates/astro2tsx/tests/fixtures/attribute_expression_value.astro new file mode 100644 index 00000000..09db7ac0 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_expression_value.astro @@ -0,0 +1 @@ +
diff --git a/crates/astro2tsx/tests/fixtures/attribute_expression_value.snap b/crates/astro2tsx/tests/fixtures/attribute_expression_value.snap new file mode 100644 index 00000000..48109f56 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_expression_value.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 85 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_expression_value.astro +--- +/* @jsxImportSource astro */ + + +
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBjbGFzcz17Y2xzfSBhcmlhLWxhYmVsPXtsYWJlbH0+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxJLENBQUssTSxDQUFPLEcsRUFBSyxXLENBQVksSyxDQUFNO0FBQ25DO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/attribute_invalid_names.astro b/crates/astro2tsx/tests/fixtures/attribute_invalid_names.astro new file mode 100644 index 00000000..93b29638 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_invalid_names.astro @@ -0,0 +1 @@ +
diff --git a/crates/astro2tsx/tests/fixtures/attribute_invalid_names.snap b/crates/astro2tsx/tests/fixtures/attribute_invalid_names.snap new file mode 100644 index 00000000..054b2e4e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_invalid_names.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 103 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_invalid_names.astro +--- +/* @jsxImportSource astro */ + + +
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBAY2xpY2s9e2hhbmRsZXJ9IDpjbGFzcz1cInhcIiBuYW1lPVwib2tcIj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLEksQ0FBaUMsUyxPQUE1QixNLEdBQVEsTyxHQUFTLE0sT0FBb0I7QUFDMUM7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.astro b/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.astro new file mode 100644 index 00000000..0aca4fb7 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.snap b/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.snap new file mode 100644 index 00000000..270f1ae4 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_quoted_forms.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 99 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_quoted_forms.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBpZD0nc2luZ2xlJyBjbGFzcz1cImRvdWJsZVwiIGRhdGEtbj0zIGhpZGRlbj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLEksQ0FBSyxXLENBQVksYyxDQUFlLE8sQ0FBTyxDLEVBQUU7QUFDekM7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/attribute_shorthand.astro b/crates/astro2tsx/tests/fixtures/attribute_shorthand.astro new file mode 100644 index 00000000..d487c65d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_shorthand.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/attribute_shorthand.snap b/crates/astro2tsx/tests/fixtures/attribute_shorthand.snap new file mode 100644 index 00000000..e0aad1c6 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_shorthand.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 60 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_shorthand.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPEZvbyB7YmFyfSAvPlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsSSxDQUFNLEcsRUFBQSxHLENBQUk7QUFDVjtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/attribute_spread.astro b/crates/astro2tsx/tests/fixtures/attribute_spread.astro new file mode 100644 index 00000000..85ceb2ca --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_spread.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/attribute_spread.snap b/crates/astro2tsx/tests/fixtures/attribute_spread.snap new file mode 100644 index 00000000..d0e0feda --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_spread.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 69 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_spread.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPEZvbyB7Li4ucmVzdH0gbmFtZT1cInhcIiAvPlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsSSxLQUFTLEksRUFBTTtBQUNmO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/attribute_template_literal.astro b/crates/astro2tsx/tests/fixtures/attribute_template_literal.astro new file mode 100644 index 00000000..0a5e50f0 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_template_literal.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/attribute_template_literal.snap b/crates/astro2tsx/tests/fixtures/attribute_template_literal.snap new file mode 100644 index 00000000..264381b8 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/attribute_template_literal.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 68 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/attribute_template_literal.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPFRhZyBzcmM9e2BiYXIke2Zvb31gfSAvPlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsSSxDQUFLLEksQ0FBSyxXLENBQVk7QUFDdEI7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.astro b/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.astro new file mode 100644 index 00000000..8db6f50e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.astro @@ -0,0 +1,5 @@ +--- +const a = 1; +--- + +
x
diff --git a/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.snap b/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.snap new file mode 100644 index 00000000..e99a258d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.snap @@ -0,0 +1,32 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 20 + frontmatter: + start: 30 + end: 45 + body: + start: 59 + end: 91 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/comment_between_frontmatter_and_body.astro +--- +/* @jsxImportSource astro */ + + +const a = 1; + +{}; + +{/** between */} +
x
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5jb25zdCBhID0gMTtcbi0tLVxuPCEtLSBiZXR3ZWVuIC0tPlxuPGRpdj54PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QTs7QUFDRztBLElBQ0MsUyxHQUFZO0FBQ2hCO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/crlf_frontmatter.astro b/crates/astro2tsx/tests/fixtures/crlf_frontmatter.astro new file mode 100644 index 00000000..0063e8b2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/crlf_frontmatter.astro @@ -0,0 +1,6 @@ +--- +import { Meta } from './Meta.astro'; +--- +
+a +
diff --git a/crates/astro2tsx/tests/fixtures/crlf_frontmatter.snap b/crates/astro2tsx/tests/fixtures/crlf_frontmatter.snap new file mode 100644 index 00000000..a2cb1ddb --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/crlf_frontmatter.snap @@ -0,0 +1,33 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 46 + frontmatter: + start: 30 + end: 71 + body: + start: 85 + end: 119 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/crlf_frontmatter.astro +--- +/* @jsxImportSource astro */ + + +import { Meta } from './Meta.astro'; + +{}; + +
+a +
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXHJcbmltcG9ydCB7IE1ldGEgfSBmcm9tICcuL01ldGEuYXN0cm8nO1xyXG4tLS1cclxuPGRpdj5cclxuPHNwYW4+YTwvc3Bhbj5cclxuPC9kaXY+XHJcbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBOztBQUNHO0FBQ0g7QUFDQTtBQUNBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/directives.astro b/crates/astro2tsx/tests/fixtures/directives.astro new file mode 100644 index 00000000..b2fa1ef2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/directives.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/directives.snap b/crates/astro2tsx/tests/fixtures/directives.snap new file mode 100644 index 00000000..302fa354 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/directives.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 116 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/directives.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPENvbXAgY2xpZW50OmxvYWQgc2V0Omh0bWw9e2h0bWx9IGNsYXNzOmxpc3Q9e2Nsc30gdHJhbnNpdGlvbjpuYW1lPVwiblwiIC8+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxLLENBQU0sVyxDQUFZLGUsQ0FBZ0IsZ0IsQ0FBaUI7QUFDbkQ7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/escape_comment_bodies.astro b/crates/astro2tsx/tests/fixtures/escape_comment_bodies.astro new file mode 100644 index 00000000..7f0007b1 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/escape_comment_bodies.astro @@ -0,0 +1,2 @@ + +
diff --git a/crates/astro2tsx/tests/fixtures/escape_comment_bodies.snap b/crates/astro2tsx/tests/fixtures/escape_comment_bodies.snap new file mode 100644 index 00000000..c8b6e535 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/escape_comment_bodies.snap @@ -0,0 +1,28 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 116 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/escape_comment_bodies.astro +--- +/* @jsxImportSource astro */ + + +{/** outer \\{ braces \\} and *\/ star-slash */} +
{/** tight*/}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPCEtLSBvdXRlciB7IGJyYWNlcyB9IGFuZCAqLyBzdGFyLXNsYXNoIC0tPlxuPGRpdj48IS0tdGlnaHQtLT48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztJQUFJLFFBQU8sQ0FBQSxVQUFTLENBQUEsUUFBTyxhLEdBQWdCO0FBQzNDLEssS0FBUyxLLEdBQVE7QUFDakI7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.astro b/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.astro new file mode 100644 index 00000000..5890c788 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.astro @@ -0,0 +1 @@ +
{cond && a b}
diff --git a/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.snap b/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.snap new file mode 100644 index 00000000..21bc7dab --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 114 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_adjacent_siblings.astro +--- +/* @jsxImportSource astro */ + + +
{cond && a b}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57Y29uZCAmJiA8c3Bhbj5hPC9zcGFuPiA8c3Bhbj5iPC9zcGFuPn08L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLGMsVUFBYyw2QixXQUE2QjtBQUMzQztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_bare_gt.astro b/crates/astro2tsx/tests/fixtures/expression_bare_gt.astro new file mode 100644 index 00000000..a9742ca7 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_bare_gt.astro @@ -0,0 +1 @@ +{x &&
a > b
} diff --git a/crates/astro2tsx/tests/fixtures/expression_bare_gt.snap b/crates/astro2tsx/tests/fixtures/expression_bare_gt.snap new file mode 100644 index 00000000..9d09cdf8 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_bare_gt.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 70 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_bare_gt.astro +--- +/* @jsxImportSource astro */ + + +{x &&
a {`>`} b
} + +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie3ggJiYgPGRpdj5hID4gYjwvZGl2Pn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLGEsRUFBYSxDLEVBQUM7QUFDZDtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_comment_only.astro b/crates/astro2tsx/tests/fixtures/expression_comment_only.astro new file mode 100644 index 00000000..e0d83469 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_comment_only.astro @@ -0,0 +1 @@ +{} diff --git a/crates/astro2tsx/tests/fixtures/expression_comment_only.snap b/crates/astro2tsx/tests/fixtures/expression_comment_only.snap new file mode 100644 index 00000000..d27fc20f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_comment_only.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 63 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_comment_only.astro +--- +/* @jsxImportSource astro */ + + +{/** just a note */} + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiezwhLS0ganVzdCBhIG5vdGUgLS0+fVxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsQyxHQUFLLGEsRUFBZ0I7QUFDckI7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_comment_trailing.astro b/crates/astro2tsx/tests/fixtures/expression_comment_trailing.astro new file mode 100644 index 00000000..67864e6b --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_comment_trailing.astro @@ -0,0 +1 @@ +{x && hi } diff --git a/crates/astro2tsx/tests/fixtures/expression_comment_trailing.snap b/crates/astro2tsx/tests/fixtures/expression_comment_trailing.snap new file mode 100644 index 00000000..211f563e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_comment_trailing.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 80 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_comment_trailing.astro +--- +/* @jsxImportSource astro */ + + +{x && hi /** trailing note */} + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie3ggJiYgPGE+aGk8L2E+IDwhLS0gdHJhaWxpbmcgbm90ZSAtLT59XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxnQixHQUFvQixlLEVBQWtCO0FBQ3RDO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_empty.astro b/crates/astro2tsx/tests/fixtures/expression_empty.astro new file mode 100644 index 00000000..720338ff --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_empty.astro @@ -0,0 +1 @@ +
{}
diff --git a/crates/astro2tsx/tests/fixtures/expression_empty.snap b/crates/astro2tsx/tests/fixtures/expression_empty.snap new file mode 100644 index 00000000..3ace774a --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_empty.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 54 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_empty.astro +--- +/* @jsxImportSource astro */ + + +
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57fTwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsS0FBTztBQUNQO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_generics.astro b/crates/astro2tsx/tests/fixtures/expression_generics.astro new file mode 100644 index 00000000..a95c99f2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_generics.astro @@ -0,0 +1 @@ +
{foo(x)}
diff --git a/crates/astro2tsx/tests/fixtures/expression_generics.snap b/crates/astro2tsx/tests/fixtures/expression_generics.snap new file mode 100644 index 00000000..c952686a --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_generics.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 67 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_generics.astro +--- +/* @jsxImportSource astro */ + + +
{foo(x)}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57Zm9vPEJhcj4oeCl9PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_html_comment.astro b/crates/astro2tsx/tests/fixtures/expression_html_comment.astro new file mode 100644 index 00000000..e21b4261 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_html_comment.astro @@ -0,0 +1 @@ +{list.map(() => )} diff --git a/crates/astro2tsx/tests/fixtures/expression_html_comment.snap b/crates/astro2tsx/tests/fixtures/expression_html_comment.snap new file mode 100644 index 00000000..1fd160ea --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_html_comment.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 94 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_html_comment.astro +--- +/* @jsxImportSource astro */ + + +{list.map(() => {/** Hi*/})} + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2xpc3QubWFwKCgpID0+IDxDb21wb25lbnQ+PCEtLUhpLS0+PC9Db21wb25lbnQ+KX1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLDJCLEtBQStCLEUsR0FBSztBQUNwQztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_identifier.astro b/crates/astro2tsx/tests/fixtures/expression_identifier.astro new file mode 100644 index 00000000..5964bdac --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_identifier.astro @@ -0,0 +1 @@ +
{value}
diff --git a/crates/astro2tsx/tests/fixtures/expression_identifier.snap b/crates/astro2tsx/tests/fixtures/expression_identifier.snap new file mode 100644 index 00000000..2ec6d4bb --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_identifier.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 61 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_identifier.astro +--- +/* @jsxImportSource astro */ + + +
{value}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57dmFsdWV9PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_is_raw.astro b/crates/astro2tsx/tests/fixtures/expression_is_raw.astro new file mode 100644 index 00000000..e5f010bc --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_is_raw.astro @@ -0,0 +1 @@ +{cond &&
not {js} here
} diff --git a/crates/astro2tsx/tests/fixtures/expression_is_raw.snap b/crates/astro2tsx/tests/fixtures/expression_is_raw.snap new file mode 100644 index 00000000..51e6f344 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_is_raw.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 88 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_is_raw.astro +--- +/* @jsxImportSource astro */ + + +{cond &&
{`not {js} here`}
} + +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPGRpdiBpczpyYXc+bm90IHtqc30gaGVyZTwvZGl2Pn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLHFCLEVBQXFCLGEsRUFBYTtBQUNsQztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.astro b/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.astro new file mode 100644 index 00000000..ff454fa4 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.astro @@ -0,0 +1 @@ +{cond &&
if (a < b) { weird } text
} diff --git a/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.snap b/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.snap new file mode 100644 index 00000000..e1326acc --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 100 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_is_raw_unparseable.astro +--- +/* @jsxImportSource astro */ + + +{cond &&
{`if (a < b) { weird } text`}
} + +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPGRpdiBpczpyYXc+aWYgKGEgPCBiKSB7IHdlaXJkIH0gdGV4dDwvZGl2Pn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLHFCLEVBQXFCLHlCLEVBQXlCO0FBQzlDO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_map.astro b/crates/astro2tsx/tests/fixtures/expression_map.astro new file mode 100644 index 00000000..b8256a7b --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_map.astro @@ -0,0 +1 @@ +
    {items.map((i) =>
  • {i.name}
  • )}
diff --git a/crates/astro2tsx/tests/fixtures/expression_map.snap b/crates/astro2tsx/tests/fixtures/expression_map.snap new file mode 100644 index 00000000..47160969 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_map.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 89 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_map.astro +--- +/* @jsxImportSource astro */ + + +
    {items.map((i) =>
  • {i.name}
  • )}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHVsPntpdGVtcy5tYXAoKGkpID0+IDxsaT57aS5uYW1lfTwvbGk+KX08L3VsPlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUE7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_nested.astro b/crates/astro2tsx/tests/fixtures/expression_nested.astro new file mode 100644 index 00000000..ad216dc5 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_nested.astro @@ -0,0 +1 @@ +
{outer && {inner}}
diff --git a/crates/astro2tsx/tests/fixtures/expression_nested.snap b/crates/astro2tsx/tests/fixtures/expression_nested.snap new file mode 100644 index 00000000..fa9a27cd --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_nested.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 85 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_nested.astro +--- +/* @jsxImportSource astro */ + + +
{outer && {inner}}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57b3V0ZXIgJiYgPHNwYW4+e2lubmVyfTwvc3Bhbj59PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_object_literal.astro b/crates/astro2tsx/tests/fixtures/expression_object_literal.astro new file mode 100644 index 00000000..b3928a49 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_object_literal.astro @@ -0,0 +1 @@ +
{ { duration: 1 } }
diff --git a/crates/astro2tsx/tests/fixtures/expression_object_literal.snap b/crates/astro2tsx/tests/fixtures/expression_object_literal.snap new file mode 100644 index 00000000..a6913075 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_object_literal.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 73 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_object_literal.astro +--- +/* @jsxImportSource astro */ + + +
{ { duration: 1 } }
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57IHsgZHVyYXRpb246IDEgfSB9PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_script_exclusion.astro b/crates/astro2tsx/tests/fixtures/expression_script_exclusion.astro new file mode 100644 index 00000000..2b298810 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_script_exclusion.astro @@ -0,0 +1 @@ +{cond && } diff --git a/crates/astro2tsx/tests/fixtures/expression_script_exclusion.snap b/crates/astro2tsx/tests/fixtures/expression_script_exclusion.snap new file mode 100644 index 00000000..358b6055 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_script_exclusion.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 70 + scripts: + - kind: Script + lang: processed-module + generated: + start: 58 + end: 58 + source: + start: 17 + end: 37 + content: "if (a < b) { go(); }" + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_script_exclusion.astro +--- +/* @jsxImportSource astro */ + + +{cond && } + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPHNjcmlwdD5pZiAoYSA8IGIpIHsgZ28oKTsgfTwvc2NyaXB0Pn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLGlCQUFxQztBQUNyQztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.astro b/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.astro new file mode 100644 index 00000000..48d64935 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.astro @@ -0,0 +1 @@ +{cond && } diff --git a/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.snap b/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.snap new file mode 100644 index 00000000..a278bf66 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_shorthand_attr.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 74 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_shorthand_attr.astro +--- +/* @jsxImportSource astro */ + + +{cond && } + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPENhcmQge3RpdGxlfSAvPn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLGVBQWdCLEssRUFBQSxLLENBQU87QUFDdkI7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_single_element.astro b/crates/astro2tsx/tests/fixtures/expression_single_element.astro new file mode 100644 index 00000000..006de6d5 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_single_element.astro @@ -0,0 +1 @@ +
{cond && a}
diff --git a/crates/astro2tsx/tests/fixtures/expression_single_element.snap b/crates/astro2tsx/tests/fixtures/expression_single_element.snap new file mode 100644 index 00000000..f4c1410e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_single_element.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 78 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_single_element.astro +--- +/* @jsxImportSource astro */ + + +
{cond && a}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57Y29uZCAmJiA8c3Bhbj5hPC9zcGFuPn08L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_special_attr_names.astro b/crates/astro2tsx/tests/fixtures/expression_special_attr_names.astro new file mode 100644 index 00000000..30b84d94 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_special_attr_names.astro @@ -0,0 +1 @@ +{cond &&
} diff --git a/crates/astro2tsx/tests/fixtures/expression_special_attr_names.snap b/crates/astro2tsx/tests/fixtures/expression_special_attr_names.snap new file mode 100644 index 00000000..02a8029d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_special_attr_names.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 140 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_special_attr_names.astro +--- +/* @jsxImportSource astro */ + + +{cond &&
} + +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPGRpdiBAY2xpY2s9XCJ4XCIgY2xpZW50OmxvYWQuZm9vIHYtaWY9XCJ5XCIgeC1vbjprZXl1cC5lbnRlcj1cIndcIj48L2Rpdj59XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxjQUF5QyxTLE9BQTNCLE0sT0FBVyxlLFFBQXlCLGdCLE9BQW9CO0FBQ3RFO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/expression_spread_child.astro b/crates/astro2tsx/tests/fixtures/expression_spread_child.astro new file mode 100644 index 00000000..81a6d032 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_spread_child.astro @@ -0,0 +1 @@ +
{...rest}
diff --git a/crates/astro2tsx/tests/fixtures/expression_spread_child.snap b/crates/astro2tsx/tests/fixtures/expression_spread_child.snap new file mode 100644 index 00000000..8d962caf --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_spread_child.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: true + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 63 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_spread_child.astro +--- +/* @jsxImportSource astro */ + + +
{...rest}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57Li4ucmVzdH08L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_string_with_markup.astro b/crates/astro2tsx/tests/fixtures/expression_string_with_markup.astro new file mode 100644 index 00000000..d436622f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_string_with_markup.astro @@ -0,0 +1 @@ +
{"
"}
diff --git a/crates/astro2tsx/tests/fixtures/expression_string_with_markup.snap b/crates/astro2tsx/tests/fixtures/expression_string_with_markup.snap new file mode 100644 index 00000000..ed059e74 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_string_with_markup.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 63 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_string_with_markup.astro +--- +/* @jsxImportSource astro */ + + +
{"
"}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57XCI8YnIvPlwifTwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUE7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_style_exclusion.astro b/crates/astro2tsx/tests/fixtures/expression_style_exclusion.astro new file mode 100644 index 00000000..8cac4e65 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_style_exclusion.astro @@ -0,0 +1 @@ +{cond && } diff --git a/crates/astro2tsx/tests/fixtures/expression_style_exclusion.snap b/crates/astro2tsx/tests/fixtures/expression_style_exclusion.snap new file mode 100644 index 00000000..78abc0bd --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_style_exclusion.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 68 + scripts: [] + styles: + - kind: Style + lang: css + generated: + start: 57 + end: 57 + source: + start: 16 + end: 29 + content: ".a{color:red}" +input_file: crates/astro2tsx/tests/fixtures/expression_style_exclusion.astro +--- +/* @jsxImportSource astro */ + + +{cond && } + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPHN0eWxlPi5he2NvbG9yOnJlZH08L3N0eWxlPn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLGdCQUE2QjtBQUM3QjtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_template_attr.astro b/crates/astro2tsx/tests/fixtures/expression_template_attr.astro new file mode 100644 index 00000000..90d38fd8 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_template_attr.astro @@ -0,0 +1 @@ +{cond && } diff --git a/crates/astro2tsx/tests/fixtures/expression_template_attr.snap b/crates/astro2tsx/tests/fixtures/expression_template_attr.snap new file mode 100644 index 00000000..488c75e1 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_template_attr.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 77 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_template_attr.astro +--- +/* @jsxImportSource astro */ + + +{cond && } + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPFRhZyBkYXRhLXg9YHQke3h9YCAvPn1cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLHFCLENBQXFCLFEsQ0FBUTtBQUM3QjtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_template_with_markup.astro b/crates/astro2tsx/tests/fixtures/expression_template_with_markup.astro new file mode 100644 index 00000000..21df1cf1 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_template_with_markup.astro @@ -0,0 +1 @@ +
{`y`}
diff --git a/crates/astro2tsx/tests/fixtures/expression_template_with_markup.snap b/crates/astro2tsx/tests/fixtures/expression_template_with_markup.snap new file mode 100644 index 00000000..f410abc0 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_template_with_markup.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 66 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_template_with_markup.astro +--- +/* @jsxImportSource astro */ + + +
{`y`}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57YDxiPnk8L2I+YH08L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/expression_ternary_markup.astro b/crates/astro2tsx/tests/fixtures/expression_ternary_markup.astro new file mode 100644 index 00000000..43f9c290 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_ternary_markup.astro @@ -0,0 +1 @@ +
{cond ? yes : no}
diff --git a/crates/astro2tsx/tests/fixtures/expression_ternary_markup.snap b/crates/astro2tsx/tests/fixtures/expression_ternary_markup.snap new file mode 100644 index 00000000..d00a123d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_ternary_markup.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 95 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_ternary_markup.astro +--- +/* @jsxImportSource astro */ + + +
{cond ? yes : no}
+ +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj57Y29uZCA/IDxhIGhyZWY9Jy94Jz55ZXM8L2E+IDogPGI+bm88L2I+fTwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUE7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.astro b/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.astro new file mode 100644 index 00000000..fb40f106 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.astro @@ -0,0 +1 @@ +{cond &&
x
} diff --git a/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.snap b/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.snap new file mode 100644 index 00000000..27fba1eb --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_unquoted_attr.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 107 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_unquoted_attr.astro +--- +/* @jsxImportSource astro */ + + +{cond &&
x
} + +
+export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2NvbmQgJiYgPGRpdiBjbGFzcz1mb28gbWF4bGVuZ3RoPTI1NSBocmVmPS9hYm91dD54PC9kaXY+fVxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEscUJBQW9CLEcsQ0FBRyxZQUFXLEcsQ0FBRyxPQUFNLE0sQ0FBTTtBQUNqRDtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/expression_void_element.astro b/crates/astro2tsx/tests/fixtures/expression_void_element.astro new file mode 100644 index 00000000..a7da0caf --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_void_element.astro @@ -0,0 +1 @@ +{items.map(i =>
  • {i}
  • )} diff --git a/crates/astro2tsx/tests/fixtures/expression_void_element.snap b/crates/astro2tsx/tests/fixtures/expression_void_element.snap new file mode 100644 index 00000000..9e6ee504 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/expression_void_element.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 78 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/expression_void_element.astro +--- +/* @jsxImportSource astro */ + + +{items.map(i =>
  • {i}
  • )} + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsie2l0ZW1zLm1hcChpID0+IDxsaT57aX08YnI+PC9saT4pfVxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsMEIsQ0FBMEI7QUFDMUI7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/fragment_shorthand.astro b/crates/astro2tsx/tests/fixtures/fragment_shorthand.astro new file mode 100644 index 00000000..458e54fc --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/fragment_shorthand.astro @@ -0,0 +1,4 @@ +<> +
    a
    +
    b
    + diff --git a/crates/astro2tsx/tests/fixtures/fragment_shorthand.snap b/crates/astro2tsx/tests/fixtures/fragment_shorthand.snap new file mode 100644 index 00000000..d7186139 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/fragment_shorthand.snap @@ -0,0 +1,30 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 75 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/fragment_shorthand.astro +--- +/* @jsxImportSource astro */ + + +<> +
    a
    +
    b
    + + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPD5cbjxkaXY+YTwvZGl2PlxuPGRpdj5iPC9kaXY+XG48Lz5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_absent.astro b/crates/astro2tsx/tests/fixtures/frontmatter_absent.astro new file mode 100644 index 00000000..7c9a4a2c --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_absent.astro @@ -0,0 +1 @@ +
    plain
    diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_absent.snap b/crates/astro2tsx/tests/fixtures/frontmatter_absent.snap new file mode 100644 index 00000000..af038a99 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_absent.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 59 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_absent.astro +--- +/* @jsxImportSource astro */ + + +
    plain
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj5wbGFpbjwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUE7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_and_body.astro b/crates/astro2tsx/tests/fixtures/frontmatter_and_body.astro new file mode 100644 index 00000000..137d4c57 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_and_body.astro @@ -0,0 +1,5 @@ +--- +let value = 'world'; +--- + +

    Hello {value}

    diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_and_body.snap b/crates/astro2tsx/tests/fixtures/frontmatter_and_body.snap new file mode 100644 index 00000000..246ba47d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_and_body.snap @@ -0,0 +1,32 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 28 + frontmatter: + start: 30 + end: 53 + body: + start: 67 + end: 93 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_and_body.astro +--- +/* @jsxImportSource astro */ + + +let value = 'world'; + +{}; + + +

    Hello {value}

    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5sZXQgdmFsdWUgPSAnd29ybGQnO1xuLS0tXG5cbjxoMT5IZWxsbyB7dmFsdWV9PC9oMT5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBOztBQUNHO0FBQ0g7QUFDQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_empty.astro b/crates/astro2tsx/tests/fixtures/frontmatter_empty.astro new file mode 100644 index 00000000..666a3fff --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_empty.astro @@ -0,0 +1,3 @@ +--- +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_empty.snap b/crates/astro2tsx/tests/fixtures/frontmatter_empty.snap new file mode 100644 index 00000000..d9696db3 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_empty.snap @@ -0,0 +1,29 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 7 + frontmatter: + start: 30 + end: 31 + body: + start: 42 + end: 56 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_empty.astro +--- +/* @jsxImportSource astro */ + + + + +
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG4tLS1cbjxkaXY+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0E7QUFDQTtBQUNIO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_imports.astro b/crates/astro2tsx/tests/fixtures/frontmatter_imports.astro new file mode 100644 index 00000000..4801cfe4 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_imports.astro @@ -0,0 +1,5 @@ +--- +import Card from './Card.astro'; +import type { Foo } from './types'; +--- + diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_imports.snap b/crates/astro2tsx/tests/fixtures/frontmatter_imports.snap new file mode 100644 index 00000000..e55f0a99 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_imports.snap @@ -0,0 +1,32 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 76 + frontmatter: + start: 30 + end: 101 + body: + start: 115 + end: 126 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_imports.astro +--- +/* @jsxImportSource astro */ + + +import Card from './Card.astro'; +import type { Foo } from './types'; + +{}; + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbXBvcnQgQ2FyZCBmcm9tICcuL0NhcmQuYXN0cm8nO1xuaW1wb3J0IHR5cGUgeyBGb28gfSBmcm9tICcuL3R5cGVzJztcbi0tLVxuPENhcmQgLz5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBQUNBO0E7O0FBQ0c7QUFDSDtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_only.astro b/crates/astro2tsx/tests/fixtures/frontmatter_only.astro new file mode 100644 index 00000000..21217508 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_only.astro @@ -0,0 +1,3 @@ +--- +const a = 1; +--- diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_only.snap b/crates/astro2tsx/tests/fixtures/frontmatter_only.snap new file mode 100644 index 00000000..884b67ca --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_only.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 20 + frontmatter: + start: 30 + end: 45 + body: + start: 46 + end: 46 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_only.astro +--- +/* @jsxImportSource astro */ + + +const a = 1; + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5jb25zdCBhID0gMTtcbi0tLVxuIl0sIm1hcHBpbmdzIjoiQTs7QUFBRztBQUNIO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.astro b/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.astro new file mode 100644 index 00000000..c1d491cd --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.astro @@ -0,0 +1,6 @@ +--- +if (cond) { + return Astro.redirect('/x'); +} +--- +

    x

    diff --git a/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.snap b/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.snap new file mode 100644 index 00000000..209e0cf2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.snap @@ -0,0 +1,33 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 51 + frontmatter: + start: 30 + end: 76 + body: + start: 90 + end: 101 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/frontmatter_top_level_return.astro +--- +/* @jsxImportSource astro */ + + +if (cond) { + throw Astro.redirect('/x'); +} + +{}; + +

    x

    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pZiAoY29uZCkge1xuXHRyZXR1cm4gQXN0cm8ucmVkaXJlY3QoJy94Jyk7XG59XG4tLS1cbjxwPng8L3A+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QUFDQTtBQUNBO0E7O0FBQ0c7QUFDSDtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/get_static_paths_export.astro b/crates/astro2tsx/tests/fixtures/get_static_paths_export.astro new file mode 100644 index 00000000..7c2ac168 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/get_static_paths_export.astro @@ -0,0 +1,4 @@ +--- +export const getStaticPaths = async () => []; +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/get_static_paths_export.snap b/crates/astro2tsx/tests/fixtures/get_static_paths_export.snap new file mode 100644 index 00000000..3a6d9d89 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/get_static_paths_export.snap @@ -0,0 +1,41 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 53 + frontmatter: + start: 30 + end: 78 + body: + start: 92 + end: 106 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/get_static_paths_export.astro +--- +/* @jsxImportSource astro */ + + +export const getStaticPaths = async () => []; + +{}; + +
    + +
    +export default function __AstroComponent_(_props: ASTRO__MergeUnion>): any {} +type ASTRO__ArrayElement = ArrayType extends readonly (infer ElementType)[] ? ElementType : never; +type ASTRO__Flattened = T extends Array ? ASTRO__Flattened : T; +type ASTRO__InferredGetStaticPath = ASTRO__Flattened>>>; +type ASTRO__MergeUnion = T extends unknown ? T & { [P in Exclude]?: never } extends infer O ? { [P in keyof O]: O[P] } : never : never; +type ASTRO__Get = T extends undefined ? undefined : K extends keyof T ? T[K] : never; +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly>, typeof __AstroComponent_, ASTRO__Get>> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5leHBvcnQgY29uc3QgZ2V0U3RhdGljUGF0aHMgPSBhc3luYyAoKSA9PiBbXTtcbi0tLVxuPGRpdj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.astro b/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.astro new file mode 100644 index 00000000..ca1fad83 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.astro @@ -0,0 +1,5 @@ +--- +interface Props { slug: string } +export async function getStaticPaths() { return []; } +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.snap b/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.snap new file mode 100644 index 00000000..f4b8d3a1 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/get_static_paths_with_props.snap @@ -0,0 +1,42 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 94 + frontmatter: + start: 30 + end: 119 + body: + start: 133 + end: 147 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/get_static_paths_with_props.astro +--- +/* @jsxImportSource astro */ + + +interface Props { slug: string } +export async function getStaticPaths() { return []; } + +{}; + +
    + +
    +export default function __AstroComponent_(_props: Props): any {} +type ASTRO__ArrayElement = ArrayType extends readonly (infer ElementType)[] ? ElementType : never; +type ASTRO__Flattened = T extends Array ? ASTRO__Flattened : T; +type ASTRO__InferredGetStaticPath = ASTRO__Flattened>>>; +type ASTRO__MergeUnion = T extends unknown ? T & { [P in Exclude]?: never } extends infer O ? { [P in keyof O]: O[P] } : never : never; +type ASTRO__Get = T extends undefined ? undefined : K extends keyof T ? T[K] : never; +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly>> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgUHJvcHMgeyBzbHVnOiBzdHJpbmcgfVxuZXhwb3J0IGFzeW5jIGZ1bmN0aW9uIGdldFN0YXRpY1BhdGhzKCkgeyByZXR1cm4gW107IH1cbi0tLVxuPGRpdj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBQUNBO0E7O0FBQ0c7QUFDSDtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/html_comment_body.astro b/crates/astro2tsx/tests/fixtures/html_comment_body.astro new file mode 100644 index 00000000..31549ecb --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/html_comment_body.astro @@ -0,0 +1 @@ +

    x

    diff --git a/crates/astro2tsx/tests/fixtures/html_comment_body.snap b/crates/astro2tsx/tests/fixtures/html_comment_body.snap new file mode 100644 index 00000000..8d03fb77 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/html_comment_body.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 73 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/html_comment_body.astro +--- +/* @jsxImportSource astro */ + + +
    {/** hi */}

    x

    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj48IS0tIGhpIC0tPjxwPng8L3A+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxLLElBQVMsSSxHQUFPO0FBQ2hCO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/html_comment_top_level.astro b/crates/astro2tsx/tests/fixtures/html_comment_top_level.astro new file mode 100644 index 00000000..b667d4d3 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/html_comment_top_level.astro @@ -0,0 +1,2 @@ + +
    x
    diff --git a/crates/astro2tsx/tests/fixtures/html_comment_top_level.snap b/crates/astro2tsx/tests/fixtures/html_comment_top_level.snap new file mode 100644 index 00000000..9276933e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/html_comment_top_level.snap @@ -0,0 +1,28 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 72 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/html_comment_top_level.astro +--- +/* @jsxImportSource astro */ + + +{/** leading */} +
    x
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPCEtLSBsZWFkaW5nIC0tPlxuPGRpdj54PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOzs7SUFBSSxTLEdBQVk7QUFDaEI7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/multibyte.astro b/crates/astro2tsx/tests/fixtures/multibyte.astro new file mode 100644 index 00000000..7e92b23f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/multibyte.astro @@ -0,0 +1 @@ +

    foobar

    diff --git a/crates/astro2tsx/tests/fixtures/multibyte.snap b/crates/astro2tsx/tests/fixtures/multibyte.snap new file mode 100644 index 00000000..ea2e64f5 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/multibyte.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 68 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/multibyte.astro +--- +/* @jsxImportSource astro */ + + +

    foobar

    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGgxPuODhDwvaDE+PHA+Zm9vYmFyPC9wPlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUE7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/multibyte_astral.astro b/crates/astro2tsx/tests/fixtures/multibyte_astral.astro new file mode 100644 index 00000000..93f5ed04 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/multibyte_astral.astro @@ -0,0 +1,4 @@ +--- +const π = Math.PI; +--- +

    🦄 {π}

    diff --git a/crates/astro2tsx/tests/fixtures/multibyte_astral.snap b/crates/astro2tsx/tests/fixtures/multibyte_astral.snap new file mode 100644 index 00000000..e7c55cbe --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/multibyte_astral.snap @@ -0,0 +1,31 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 27 + frontmatter: + start: 30 + end: 52 + body: + start: 66 + end: 85 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/multibyte_astral.astro +--- +/* @jsxImportSource astro */ + + +const π = Math.PI; + +{}; + +

    🦄 {π}

    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5jb25zdCDPgCA9IE1hdGguUEk7XG4tLS1cbjxwPvCfpoQge8+AfTwvcD5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/named_component_export.astro b/crates/astro2tsx/tests/fixtures/named_component_export.astro new file mode 100644 index 00000000..876cfe39 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/named_component_export.astro @@ -0,0 +1,2 @@ +// @config filename=/src/pages/MyPage.astro +
    diff --git a/crates/astro2tsx/tests/fixtures/named_component_export.snap b/crates/astro2tsx/tests/fixtures/named_component_export.snap new file mode 100644 index 00000000..768f3aad --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/named_component_export.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 54 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/named_component_export.astro +--- +/* @jsxImportSource astro */ + + +
    + +
    +export default function MyPage__AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiL3NyYy9wYWdlcy9NeVBhZ2UuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/props_exported_alias_union.astro b/crates/astro2tsx/tests/fixtures/props_exported_alias_union.astro new file mode 100644 index 00000000..a43f6839 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_exported_alias_union.astro @@ -0,0 +1,6 @@ +--- +interface LocalProps { a: string } +interface RemoteProps { b: string } +export type Props = LocalProps | RemoteProps; +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_exported_alias_union.snap b/crates/astro2tsx/tests/fixtures/props_exported_alias_union.snap new file mode 100644 index 00000000..83bbc6ca --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_exported_alias_union.snap @@ -0,0 +1,38 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 124 + frontmatter: + start: 30 + end: 149 + body: + start: 163 + end: 172 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_exported_alias_union.astro +--- +/* @jsxImportSource astro */ + + +interface LocalProps { a: string } +interface RemoteProps { b: string } +export type Props = LocalProps | RemoteProps; + +{}; + +
    + + +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgTG9jYWxQcm9wcyB7IGE6IHN0cmluZyB9XG5pbnRlcmZhY2UgUmVtb3RlUHJvcHMgeyBiOiBzdHJpbmcgfVxuZXhwb3J0IHR5cGUgUHJvcHMgPSBMb2NhbFByb3BzIHwgUmVtb3RlUHJvcHM7XG4tLS1cbjxkaXYvPlxuIl0sIm1hcHBpbmdzIjoiQTs7QUFBRztBQUNIO0FBQ0E7QUFDQTtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/props_generic.astro b/crates/astro2tsx/tests/fixtures/props_generic.astro new file mode 100644 index 00000000..408930f2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_generic.astro @@ -0,0 +1,6 @@ +--- +interface Props { + item: T; +} +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_generic.snap b/crates/astro2tsx/tests/fixtures/props_generic.snap new file mode 100644 index 00000000..6a2ce28e --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_generic.snap @@ -0,0 +1,38 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 55 + frontmatter: + start: 30 + end: 80 + body: + start: 94 + end: 108 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_generic.astro +--- +/* @jsxImportSource astro */ + + +interface Props { + item: T; +} + +{}; + +
    + +
    +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgUHJvcHM8VCBleHRlbmRzIHN0cmluZz4ge1xuXHRpdGVtOiBUO1xufVxuLS0tXG48ZGl2PjwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7QUFBRztBQUNIO0FBQ0E7QUFDQTtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/props_generic_invalid.astro b/crates/astro2tsx/tests/fixtures/props_generic_invalid.astro new file mode 100644 index 00000000..87786888 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_generic_invalid.astro @@ -0,0 +1,4 @@ +--- +interface Props {} +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_generic_invalid.snap b/crates/astro2tsx/tests/fixtures/props_generic_invalid.snap new file mode 100644 index 00000000..3c8fa815 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_generic_invalid.snap @@ -0,0 +1,31 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 110 + frontmatter: + start: 30 + end: 135 + body: + start: 149 + end: 158 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_generic_invalid.astro +--- +/* @jsxImportSource astro */ + + +interface Props {} + +{}; + +
    + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgUHJvcHM8VCBleHRlbmRzIHsgW2tleTogc3RyaW5nXTogYW55IH0sIFAgZXh0ZW5kcyBzdHJpbmcgPyB7IFtrZXk6IHN0cmluZ106IGFueSB9OiBuZXZlcj4ge31cbi0tLVxuPGRpdi8+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QTs7QUFDRztBQUNIO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/props_imported.astro b/crates/astro2tsx/tests/fixtures/props_imported.astro new file mode 100644 index 00000000..cd1c2b52 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_imported.astro @@ -0,0 +1,4 @@ +--- +import type { Props } from './types'; +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_imported.snap b/crates/astro2tsx/tests/fixtures/props_imported.snap new file mode 100644 index 00000000..1527b755 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_imported.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 45 + frontmatter: + start: 30 + end: 70 + body: + start: 84 + end: 98 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_imported.astro +--- +/* @jsxImportSource astro */ + + +import type { Props } from './types'; + +{}; + +
    + +
    +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbXBvcnQgdHlwZSB7IFByb3BzIH0gZnJvbSAnLi90eXBlcyc7XG4tLS1cbjxkaXY+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QTs7QUFDRztBQUNIO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/props_interface.astro b/crates/astro2tsx/tests/fixtures/props_interface.astro new file mode 100644 index 00000000..1fbf8e55 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_interface.astro @@ -0,0 +1,7 @@ +--- +interface Props { + title: string; +} +const { title } = Astro.props; +--- +

    {title}

    diff --git a/crates/astro2tsx/tests/fixtures/props_interface.snap b/crates/astro2tsx/tests/fixtures/props_interface.snap new file mode 100644 index 00000000..c9972321 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_interface.snap @@ -0,0 +1,39 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 74 + frontmatter: + start: 30 + end: 99 + body: + start: 113 + end: 132 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_interface.astro +--- +/* @jsxImportSource astro */ + + +interface Props { + title: string; +} +const { title } = Astro.props; + +{}; + +

    {title}

    + +
    +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgUHJvcHMge1xuXHR0aXRsZTogc3RyaW5nO1xufVxuY29uc3QgeyB0aXRsZSB9ID0gQXN0cm8ucHJvcHM7XG4tLS1cbjxoMT57dGl0bGV9PC9oMT5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBQUNBO0FBQ0E7QUFDQTtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/props_polymorphic.astro b/crates/astro2tsx/tests/fixtures/props_polymorphic.astro new file mode 100644 index 00000000..69e03d70 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_polymorphic.astro @@ -0,0 +1,6 @@ +--- +interface Props extends HTMLAttributes { + as?: Tag; +} +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_polymorphic.snap b/crates/astro2tsx/tests/fixtures/props_polymorphic.snap new file mode 100644 index 00000000..8a5ea799 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_polymorphic.snap @@ -0,0 +1,38 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 108 + frontmatter: + start: 30 + end: 133 + body: + start: 147 + end: 156 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_polymorphic.astro +--- +/* @jsxImportSource astro */ + + +interface Props extends HTMLAttributes { + as?: Tag; +} + +{}; + +
    + + +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pbnRlcmZhY2UgUHJvcHM8VGFnIGV4dGVuZHMga2V5b2YgSlNYLkludHJpbnNpY0VsZW1lbnRzPiBleHRlbmRzIEhUTUxBdHRyaWJ1dGVzPFRhZz4ge1xuICBhcz86IFRhZztcbn1cbi0tLVxuPGRpdi8+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QUFDQTtBQUNBO0E7O0FBQ0c7QUFDSDtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/props_type_alias.astro b/crates/astro2tsx/tests/fixtures/props_type_alias.astro new file mode 100644 index 00000000..10982e01 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_type_alias.astro @@ -0,0 +1,4 @@ +--- +type Props = { title: string }; +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/props_type_alias.snap b/crates/astro2tsx/tests/fixtures/props_type_alias.snap new file mode 100644 index 00000000..e0195621 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/props_type_alias.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 39 + frontmatter: + start: 30 + end: 64 + body: + start: 78 + end: 92 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/props_type_alias.astro +--- +/* @jsxImportSource astro */ + + +type Props = { title: string }; + +{}; + +
    + +
    +export default function __AstroComponent_(_props: Props): any {} +/** + * Astro global available in all contexts in .astro files + * + * [Astro documentation](https://docs.astro.build/reference/api-reference/#astro-global) +*/ +declare const Astro: Readonly> +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG50eXBlIFByb3BzID0geyB0aXRsZTogc3RyaW5nIH07XG4tLS1cbjxkaXY+PC9kaXY+XG4iXSwibWFwcGluZ3MiOiJBOztBQUFHO0FBQ0g7QTs7QUFDRztBQUNIO0FBQ0E7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/raw_text_is_raw.astro b/crates/astro2tsx/tests/fixtures/raw_text_is_raw.astro new file mode 100644 index 00000000..9b670bf2 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_is_raw.astro @@ -0,0 +1 @@ +
    not markup
    diff --git a/crates/astro2tsx/tests/fixtures/raw_text_is_raw.snap b/crates/astro2tsx/tests/fixtures/raw_text_is_raw.snap new file mode 100644 index 00000000..38d4bff9 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_is_raw.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 82 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/raw_text_is_raw.astro +--- +/* @jsxImportSource astro */ + + +
    {`not markup`}
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiBpczpyYXc+PGI+bm90IG1hcmt1cDwvYj48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLEksQ0FBSyxPLEVBQU8saUIsRUFBaUI7QUFDN0I7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/raw_text_script_json.astro b/crates/astro2tsx/tests/fixtures/raw_text_script_json.astro new file mode 100644 index 00000000..67f04dfd --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_script_json.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/raw_text_script_json.snap b/crates/astro2tsx/tests/fixtures/raw_text_script_json.snap new file mode 100644 index 00000000..f32a985b --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_script_json.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 84 + scripts: + - kind: Script + lang: json + generated: + start: 73 + end: 73 + source: + start: 32 + end: 39 + content: "{\"a\":1}" + styles: [] +input_file: crates/astro2tsx/tests/fixtures/raw_text_script_json.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHNjcmlwdCB0eXBlPVwiYXBwbGljYXRpb24vanNvblwiPntcImFcIjoxfTwvc2NyaXB0PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsTyxDQUFRLHdCQUErQjtBQUN2QztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/raw_text_script_module.astro b/crates/astro2tsx/tests/fixtures/raw_text_script_module.astro new file mode 100644 index 00000000..7c249e20 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_script_module.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/raw_text_script_module.snap b/crates/astro2tsx/tests/fixtures/raw_text_script_module.snap new file mode 100644 index 00000000..75ae867d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_script_module.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 74 + scripts: + - kind: Script + lang: module + generated: + start: 63 + end: 63 + source: + start: 22 + end: 34 + content: const a = 1; + styles: [] +input_file: crates/astro2tsx/tests/fixtures/raw_text_script_module.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHNjcmlwdCB0eXBlPVwibW9kdWxlXCI+Y29uc3QgYSA9IDE7PC9zY3JpcHQ+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxPLENBQVEsY0FBMEI7QUFDbEM7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/raw_text_style.astro b/crates/astro2tsx/tests/fixtures/raw_text_style.astro new file mode 100644 index 00000000..a3f097f4 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_style.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/raw_text_style.snap b/crates/astro2tsx/tests/fixtures/raw_text_style.snap new file mode 100644 index 00000000..d281308f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/raw_text_style.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 58 + scripts: [] + styles: + - kind: Style + lang: css + generated: + start: 48 + end: 48 + source: + start: 7 + end: 25 + content: ".a { color: red; }" +input_file: crates/astro2tsx/tests/fixtures/raw_text_style.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHN0eWxlPi5hIHsgY29sb3I6IHJlZDsgfTwvc3R5bGU+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxPQUF5QjtBQUN6QjtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/script_type_labels.astro b/crates/astro2tsx/tests/fixtures/script_type_labels.astro new file mode 100644 index 00000000..4701dadb --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/script_type_labels.astro @@ -0,0 +1,3 @@ + + + diff --git a/crates/astro2tsx/tests/fixtures/script_type_labels.snap b/crates/astro2tsx/tests/fixtures/script_type_labels.snap new file mode 100644 index 00000000..2db37e80 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/script_type_labels.snap @@ -0,0 +1,56 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 174 + scripts: + - kind: Script + lang: inline + generated: + start: 71 + end: 71 + source: + start: 30 + end: 35 + content: go(); + - kind: Script + lang: json + generated: + start: 113 + end: 113 + source: + start: 77 + end: 84 + content: "{\"a\":1}" + - kind: Script + lang: unknown + generated: + start: 163 + end: 163 + source: + start: 134 + end: 137 + content: wat + styles: [] +input_file: crates/astro2tsx/tests/fixtures/script_type_labels.astro +--- +/* @jsxImportSource astro */ + + + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHNjcmlwdCB0eXBlPVwidGV4dC9wYXJ0eXRvd25cIj5nbygpOzwvc2NyaXB0PlxuPHNjcmlwdCB0eXBlPVwic3BlY3VsYXRpb25ydWxlc1wiPntcImFcIjoxfTwvc2NyaXB0PlxuPHNjcmlwdCBpczppbmxpbmUgdHlwZT1cInRleHQveC11bmtub3duXCI+d2F0PC9zY3JpcHQ+XG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQSxPLENBQVEsc0JBQTJCO0FBQ25DLE8sQ0FBUSx3QkFBK0I7QUFDdkMsTyxDQUFRLFMsQ0FBVSxzQkFBeUI7QUFDM0M7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/slot_element.astro b/crates/astro2tsx/tests/fixtures/slot_element.astro new file mode 100644 index 00000000..8042b69c --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/slot_element.astro @@ -0,0 +1 @@ +
    diff --git a/crates/astro2tsx/tests/fixtures/slot_element.snap b/crates/astro2tsx/tests/fixtures/slot_element.snap new file mode 100644 index 00000000..154d2ae0 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/slot_element.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 79 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/slot_element.astro +--- +/* @jsxImportSource astro */ + + +
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj48c2xvdCBuYW1lPVwiYVwiIC8+PHNsb3QgLz48L2Rpdj5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLFUsQ0FBVztBQUNYO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/slots.astro b/crates/astro2tsx/tests/fixtures/slots.astro new file mode 100644 index 00000000..4a0bf640 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/slots.astro @@ -0,0 +1,4 @@ + + H +

    body

    +
    diff --git a/crates/astro2tsx/tests/fixtures/slots.snap b/crates/astro2tsx/tests/fixtures/slots.snap new file mode 100644 index 00000000..0e74ed27 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/slots.snap @@ -0,0 +1,30 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 104 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/slots.astro +--- +/* @jsxImportSource astro */ + + + + H +

    body

    +
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPExheW91dD5cblx0PHNwYW4gc2xvdD1cImhlYWRlclwiPkg8L3NwYW4+XG5cdDxwPmJvZHk8L3A+XG48L0xheW91dD5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBO0FBQ0EsTSxDQUFPO0FBQ1A7QUFDQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/style_lang_label.astro b/crates/astro2tsx/tests/fixtures/style_lang_label.astro new file mode 100644 index 00000000..09f71f5a --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/style_lang_label.astro @@ -0,0 +1 @@ + diff --git a/crates/astro2tsx/tests/fixtures/style_lang_label.snap b/crates/astro2tsx/tests/fixtures/style_lang_label.snap new file mode 100644 index 00000000..c8916e10 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/style_lang_label.snap @@ -0,0 +1,36 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 70 + scripts: [] + styles: + - kind: Style + lang: scss + generated: + start: 60 + end: 60 + source: + start: 19 + end: 37 + content: ".a { color: red; }" +input_file: crates/astro2tsx/tests/fixtures/style_lang_label.astro +--- +/* @jsxImportSource astro */ + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPHN0eWxlIGxhbmc9XCJzY3NzXCI+LmEgeyBjb2xvcjogcmVkOyB9PC9zdHlsZT5cbiJdLCJtYXBwaW5ncyI6IkE7OztBQUFBLE0sQ0FBTyxZQUE4QjtBQUNyQztBIn0= diff --git a/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.astro b/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.astro new file mode 100644 index 00000000..bc87018d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.astro @@ -0,0 +1,2 @@ +
    spaced
    diff --git a/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.snap b/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.snap new file mode 100644 index 00000000..a34ce6ea --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 78 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/tag_whitespace_collapsing.astro +--- +/* @jsxImportSource astro */ + + +
    spaced
    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdiAgIGNsYXNzPVwiYVwiXG5cdGlkPVwiYlwiICAgPnNwYWNlZDwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsSSxDQUFPLFMsQ0FDTixPQUFTO0FBQ1Y7QSJ9 diff --git a/crates/astro2tsx/tests/fixtures/top_level_returns_nested.astro b/crates/astro2tsx/tests/fixtures/top_level_returns_nested.astro new file mode 100644 index 00000000..171373f7 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/top_level_returns_nested.astro @@ -0,0 +1,10 @@ +--- +if (broken) { + return Astro.redirect("/"); +} +const fn = () => { return 1; }; +function inner() { return 2; } +class C { method() { return 3; } } +return "top"; +--- +
    diff --git a/crates/astro2tsx/tests/fixtures/top_level_returns_nested.snap b/crates/astro2tsx/tests/fixtures/top_level_returns_nested.snap new file mode 100644 index 00000000..76dab655 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/top_level_returns_nested.snap @@ -0,0 +1,37 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: Closed + frontmatter_source: + start: 0 + end: 165 + frontmatter: + start: 30 + end: 190 + body: + start: 204 + end: 213 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/top_level_returns_nested.astro +--- +/* @jsxImportSource astro */ + + +if (broken) { + throw Astro.redirect("/"); +} +const fn = () => { return 1; }; +function inner() { return 2; } +class C { method() { return 3; } } +throw "top"; + +{}; + +
    + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5pZiAoYnJva2VuKSB7XG4gIHJldHVybiBBc3Ryby5yZWRpcmVjdChcIi9cIik7XG59XG5jb25zdCBmbiA9ICgpID0+IHsgcmV0dXJuIDE7IH07XG5mdW5jdGlvbiBpbm5lcigpIHsgcmV0dXJuIDI7IH1cbmNsYXNzIEMgeyBtZXRob2QoKSB7IHJldHVybiAzOyB9IH1cbnJldHVybiBcInRvcFwiO1xuLS0tXG48ZGl2Lz5cbiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/unclosed_member_tag.astro b/crates/astro2tsx/tests/fixtures/unclosed_member_tag.astro new file mode 100644 index 00000000..e1bc493d --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/unclosed_member_tag.astro @@ -0,0 +1,5 @@ +--- +const myMarkdown = await import("../content/post.md"); +--- + + + + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiLS0tXG5jb25zdCBteU1hcmtkb3duID0gYXdhaXQgaW1wb3J0KFwiLi4vY29udGVudC9wb3N0Lm1kXCIpO1xuLS0tXG5cbjxteU1hcmtkb3duLiJdLCJtYXBwaW5ncyI6IkE7O0FBQUc7QUFDSDtBOztBQUNHO0FBQ0g7QUFDQTtBIn0= diff --git a/crates/astro2tsx/tests/fixtures/unclosed_tag.astro b/crates/astro2tsx/tests/fixtures/unclosed_tag.astro new file mode 100644 index 00000000..bab0a1c9 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/unclosed_tag.astro @@ -0,0 +1 @@ + + +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGNvbXBvbmVudHMuXG4iXSwibWFwcGluZ3MiOiJBOzs7QUFBQTtBQUNBO0EifQ== diff --git a/crates/astro2tsx/tests/fixtures/void_elements.astro b/crates/astro2tsx/tests/fixtures/void_elements.astro new file mode 100644 index 00000000..73ce2a8f --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/void_elements.astro @@ -0,0 +1 @@ +


    diff --git a/crates/astro2tsx/tests/fixtures/void_elements.snap b/crates/astro2tsx/tests/fixtures/void_elements.snap new file mode 100644 index 00000000..c3e50f19 --- /dev/null +++ b/crates/astro2tsx/tests/fixtures/void_elements.snap @@ -0,0 +1,27 @@ +--- +source: crates/astro2tsx/tests/snapshots.rs +info: + has_parse_errors: false + frontmatter_status: DoesntExist + frontmatter_source: + start: 0 + end: 0 + frontmatter: + start: 30 + end: 30 + body: + start: 41 + end: 103 + scripts: [] + styles: [] +input_file: crates/astro2tsx/tests/fixtures/void_elements.astro +--- +/* @jsxImportSource astro */ + + +


    + +
    +export default function __AstroComponent_(_props: Record): any {} + +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiaW5wdXQuYXN0cm8iXSwic291cmNlc0NvbnRlbnQiOlsiPGRpdj48YnI+PGhyIC8+PGltZyBzcmM9XCJhLnBuZ1wiPjxpbnB1dCB0eXBlPVwidGV4dFwiPjwvZGl2PlxuIl0sIm1hcHBpbmdzIjoiQTs7O0FBQUEsUSxDQUFRLFcsQ0FBWSxXLENBQVcsTyxDQUFRLFcsQ0FBVztBQUNsRDtBIn0= diff --git a/crates/astro2tsx/tests/regressions.rs b/crates/astro2tsx/tests/regressions.rs new file mode 100644 index 00000000..8fa7dc9e --- /dev/null +++ b/crates/astro2tsx/tests/regressions.rs @@ -0,0 +1,475 @@ +//! Assertions over `convert_to_tsx` output for a spread of Astro inputs. + +use astro2tsx::{ConvertOptions, convert_to_tsx}; + +const PREFIX: &str = "/* @jsxImportSource astro */\n\n"; + +fn convert(source: &str) -> String { + convert_to_tsx(source, ConvertOptions::default()).code +} + +#[test] +fn frontmatter_range_is_recorded() { + let result = convert_to_tsx( + "---\nlet x = 1;\n---\n
    ", + ConvertOptions::default(), + ); + assert!(result.frontmatter_range.end > result.frontmatter_range.start); + let frontmatter_slice = &result.code + [result.frontmatter_range.start as usize..result.frontmatter_range.end as usize]; + assert!(frontmatter_slice.contains("let x = 1;")); +} + +#[test] +fn body_range_is_recorded() { + let result = convert_to_tsx("

    Hi

    ", ConvertOptions::default()); + assert!(result.body.end > result.body.start); + let body_slice = &result.code[result.body.start as usize..result.body.end as usize]; + assert!(body_slice.contains("

    ")); + assert!(body_slice.contains("

    ")); +} + +#[test] +fn unparseable_expression_bodies_are_not_silent() { + let broken = convert_to_tsx("
    {x ==}
    ", ConvertOptions::default()); + assert!(broken.has_parse_errors, "raw fallback must flag the result"); + + let empty = convert_to_tsx("
    {}
    ", ConvertOptions::default()); + assert!(!empty.has_parse_errors, "an empty expression is fine"); +} + +#[test] +fn parser_errors_surface_but_do_not_block_emission() { + // Unbalanced curly brace — bogus text expression recovery. + let result = convert_to_tsx( + "---\nconst items = [1];\n---\n{items.map(i =>
    {i}
    )", + ConvertOptions::default(), + ); + assert!(result.has_parse_errors); + assert!(result.code.starts_with(PREFIX)); +} + +/// Excluded bodies must stay reachable through the extracted arrays. +#[test] +fn unclosed_raw_text_element_still_accounts_for_its_content() { + let raw = convert("
    lost\n

    after

    "); + assert!( + raw.contains("lost") && raw.contains("after"), + "is:raw content should stay inline:\n{raw}" + ); + + let style = convert_to_tsx( + "", ConvertOptions::default()); + let range = tag.styles[0].range; + assert_eq!(range.start, range.end); + assert!(tag.code[..range.start as usize].ends_with("")); +} + +#[test] +fn props_binding_needs_a_local_name() { + for (input, has_props) in [ + ("---\nimport Foo from './Props';\nFoo;\n---\n
    ", false), + ( + "---\nimport { Props as Other } from './t';\n---\n
    ", + false, + ), + ("---\nexport { Props } from './t';\n---\n
    ", false), + ( + "---\n// mentions Props only in a comment\n---\n
    ", + false, + ), + ( + "---\nimport { Other as Props } from './t';\n---\n
    ", + true, + ), + ("---\nimport type { Props } from './t';\n---\n
    ", true), + ("---\nimport Props from './t';\n---\n
    ", true), + ( + "---\nexport interface Props { a: string }\n---\n
    ", + true, + ), + ] { + let actual = convert(input); + assert_eq!( + actual.contains("_props: Props"), + has_props, + "wrong Props detection for {input:?}:\n{actual}" + ); + } +} + +#[test] +fn frontmatter_is_terminated_even_when_a_comment_ends_with_a_semicolon() { + let actual = convert("---\nconst x = foo\n// note;\n---\n
    "); + assert!( + actual.contains("{};"), + "`` can continue the unterminated expression:\n{actual}" + ); +} + +#[test] +fn comments_before_the_first_element_survive() { + for input in [ + "\n
    x
    ", + "---\nconst a = 1;\n---\n\n
    x
    ", + ] { + let actual = convert(input); + assert!( + actual.contains("{/** leading */}") || actual.contains("{/** between */}"), + "a leading comment was dropped for {input:?}:\n{actual}" + ); + assert!(!actual.contains("