Home / Function/ safeConvertToTSX() — astro Function Reference

safeConvertToTSX() — astro Function Reference

Architecture documentation for the safeConvertToTSX() function in astro2tsx.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  113ec72f_0497_ec7d_997c_ec2ef65c0af8["safeConvertToTSX()"]
  f004a067_f0ae_35cb_fc32_ccf4d7476223["astro2tsx.ts"]
  113ec72f_0497_ec7d_997c_ec2ef65c0af8 -->|defined in| f004a067_f0ae_35cb_fc32_ccf4d7476223
  3b0a8762_2dc4_2dd5_6c0b_507bb1bd0169["astro2tsx()"]
  3b0a8762_2dc4_2dd5_6c0b_507bb1bd0169 -->|calls| 113ec72f_0497_ec7d_997c_ec2ef65c0af8
  style 113ec72f_0497_ec7d_997c_ec2ef65c0af8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/language-server/src/core/astro2tsx.ts lines 21–66

export function safeConvertToTSX(content: string, options: ConvertToTSXOptions) {
	try {
		const tsx = convertToTSX(content, {
			filename: options.filename,
			includeScripts: false,
			includeStyles: false,
		});
		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 transform this file to TSX. 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,
				},
				scripts: [],
				styles: [],
			},
		} satisfies TSXResult;
	}
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does safeConvertToTSX() do?
safeConvertToTSX() is a function in the astro codebase, defined in packages/language-tools/language-server/src/core/astro2tsx.ts.
Where is safeConvertToTSX() defined?
safeConvertToTSX() is defined in packages/language-tools/language-server/src/core/astro2tsx.ts at line 21.
What calls safeConvertToTSX()?
safeConvertToTSX() is called by 1 function(s): astro2tsx.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free