astro2tsx.ts — astro Source File
Architecture documentation for astro2tsx.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b348b824_2985_3524_9b17_fd7579f42c1f["astro2tsx.ts"] c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] b348b824_2985_3524_9b17_fd7579f42c1f --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 881bedca_8bf1_6c82_1d1d_caae9da803fd["sync"] b348b824_2985_3524_9b17_fd7579f42c1f --> 881bedca_8bf1_6c82_1d1d_caae9da803fd 81a20ac1_6143_16be_33ec_872bb8d3a54b["types"] b348b824_2985_3524_9b17_fd7579f42c1f --> 81a20ac1_6143_16be_33ec_872bb8d3a54b d4ac305a_acbb_9af4_f554_8b9cd20cb784["sourcemap-codec"] b348b824_2985_3524_9b17_fd7579f42c1f --> d4ac305a_acbb_9af4_f554_8b9cd20cb784 040ca79b_dadf_4383_efd2_c0b13744e9f1["language-core"] b348b824_2985_3524_9b17_fd7579f42c1f --> 040ca79b_dadf_4383_efd2_c0b13744e9f1 2accdca4_fb80_ff68_515c_f646abc72243["vscode-languageserver-textdocument"] b348b824_2985_3524_9b17_fd7579f42c1f --> 2accdca4_fb80_ff68_515c_f646abc72243 style b348b824_2985_3524_9b17_fd7579f42c1f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import path from 'node:path';
import { convertToTSX } from '@astrojs/compiler/sync';
import type { ConvertToTSXOptions, TSXResult } from '@astrojs/compiler/types';
import { decode } from '@jridgewell/sourcemap-codec';
import type { CodeMapping, VirtualCode } from '@volar/language-core';
import { TextDocument } from 'vscode-languageserver-textdocument';
function safeConvertToTSX(content: string, options: ConvertToTSXOptions) {
try {
const tsx = convertToTSX(content, { filename: options.filename });
return tsx;
} catch (e) {
console.error(
`There was an error transforming ${options.filename} to TSX. An empty file will be returned instead. Please create an issue: https://github.com/withastro/astro/issues\nError: ${e}.`,
);
return {
code: '',
map: {
file: options.filename ?? '',
sources: [],
sourcesContent: [],
names: [],
mappings: '',
version: 0,
},
diagnostics: [
{
code: 1000,
location: { file: options.filename!, line: 1, column: 1, length: content.length },
severity: 1,
text: `The Astro compiler encountered an unknown error while parsing this file. Please create an issue with your code and the error shown in the server's logs: https://github.com/withastro/astro/issues`,
},
],
metaRanges: {
frontmatter: {
start: 0,
end: 0,
},
body: {
start: 0,
end: 0,
},
},
} satisfies TSXResult;
}
}
export function astro2tsx(input: string, fileName: string) {
const tsx = safeConvertToTSX(input, { filename: fileName });
return {
virtualFile: getVirtualFileTSX(input, tsx, fileName),
diagnostics: tsx.diagnostics,
};
}
function getVirtualFileTSX(input: string, tsx: TSXResult, fileName: string): VirtualCode {
tsx.code = patchTSX(tsx.code, fileName);
const v3Mappings = decode(tsx.map.mappings);
// ... (92 more lines)
Domain
Subdomains
Dependencies
- language-core
- node:path
- sourcemap-codec
- sync
- types
- vscode-languageserver-textdocument
Source
Frequently Asked Questions
What does astro2tsx.ts do?
astro2tsx.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, CoreMiddleware subdomain.
What functions are defined in astro2tsx.ts?
astro2tsx.ts defines 4 function(s): astro2tsx, getVirtualFileTSX, patchTSX, safeConvertToTSX.
What does astro2tsx.ts depend on?
astro2tsx.ts imports 6 module(s): language-core, node:path, sourcemap-codec, sync, types, vscode-languageserver-textdocument.
Where is astro2tsx.ts in the architecture?
astro2tsx.ts is located at packages/language-tools/ts-plugin/src/astro2tsx.ts (domain: CoreAstro, subdomain: CoreMiddleware, directory: packages/language-tools/ts-plugin/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free