Home / Function/ patchTSX() — astro Function Reference

patchTSX() — astro Function Reference

Architecture documentation for the patchTSX() function in utils.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  5f6a40f0_a897_8297_c98a_2c0e5e90c306["patchTSX()"]
  6db4d7db_edbb_c18d_7ff5_decb13f1c284["utils.ts"]
  5f6a40f0_a897_8297_c98a_2c0e5e90c306 -->|defined in| 6db4d7db_edbb_c18d_7ff5_decb13f1c284
  15e8cb4e_2c8b_a58f_7a91_50841c8f74d1["framework2tsx()"]
  15e8cb4e_2c8b_a58f_7a91_50841c8f74d1 -->|calls| 5f6a40f0_a897_8297_c98a_2c0e5e90c306
  style 5f6a40f0_a897_8297_c98a_2c0e5e90c306 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/language-tools/language-server/src/core/utils.ts lines 75–87

export function patchTSX(code: string, filePath: string) {
	const basename = filePath.split('/').pop()!;
	const isDynamic = basename.startsWith('[') && basename.endsWith(']');

	return code.replace(/\b(\S*)__AstroComponent_/g, (fullMatch, m1: string) => {
		// If we don't have a match here, it usually means the file has a weird name that couldn't be expressed with valid identifier characters
		if (!m1) {
			if (basename === '404') return 'FourOhFour';
			return fullMatch;
		}
		return isDynamic ? `_${m1}_` : m1[0].toUpperCase() + m1.slice(1);
	});
}

Domain

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free