getVirtualFileTSX() — astro Function Reference
Architecture documentation for the getVirtualFileTSX() function in astro2tsx.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 840c0167_4b40_3f42_1c05_3306fbda825b["getVirtualFileTSX()"] b348b824_2985_3524_9b17_fd7579f42c1f["astro2tsx.ts"] 840c0167_4b40_3f42_1c05_3306fbda825b -->|defined in| b348b824_2985_3524_9b17_fd7579f42c1f acdd7f41_dc47_4c7c_d901_ea0356cddf50["astro2tsx()"] acdd7f41_dc47_4c7c_d901_ea0356cddf50 -->|calls| 840c0167_4b40_3f42_1c05_3306fbda825b 910094b7_f418_a70f_7f93_5f8146c51c66["patchTSX()"] 840c0167_4b40_3f42_1c05_3306fbda825b -->|calls| 910094b7_f418_a70f_7f93_5f8146c51c66 style 840c0167_4b40_3f42_1c05_3306fbda825b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/language-tools/ts-plugin/src/astro2tsx.ts lines 58–137
function getVirtualFileTSX(input: string, tsx: TSXResult, fileName: string): VirtualCode {
tsx.code = patchTSX(tsx.code, fileName);
const v3Mappings = decode(tsx.map.mappings);
const sourcedDoc = TextDocument.create(fileName, 'astro', 0, input);
const genDoc = TextDocument.create(fileName + '.tsx', 'typescriptreact', 0, tsx.code);
const mappings: CodeMapping[] = [];
let current:
| {
genOffset: number;
sourceOffset: number;
}
| undefined;
for (let genLine = 0; genLine < v3Mappings.length; genLine++) {
for (const segment of v3Mappings[genLine]) {
const genCharacter = segment[0];
const genOffset = genDoc.offsetAt({ line: genLine, character: genCharacter });
if (current) {
let length = genOffset - current.genOffset;
const sourceText = input.substring(current.sourceOffset, current.sourceOffset + length);
const genText = tsx.code.substring(current.genOffset, current.genOffset + length);
if (sourceText !== genText) {
length = 0;
for (let i = 0; i < genOffset - current.genOffset; i++) {
if (sourceText[i] === genText[i]) {
length = i + 1;
} else {
break;
}
}
}
if (length > 0) {
const lastMapping = mappings.length ? mappings[mappings.length - 1] : undefined;
if (
lastMapping &&
lastMapping.generatedOffsets[0] + lastMapping.lengths[0] === current.genOffset &&
lastMapping.sourceOffsets[0] + lastMapping.lengths[0] === current.sourceOffset
) {
lastMapping.lengths[0] += length;
} else {
mappings.push({
sourceOffsets: [current.sourceOffset],
generatedOffsets: [current.genOffset],
lengths: [length],
data: {
verification: true,
completion: true,
semantic: true,
navigation: true,
structure: true,
format: false,
},
});
}
}
current = undefined;
}
if (segment[2] !== undefined && segment[3] !== undefined) {
const sourceOffset = sourcedDoc.offsetAt({ line: segment[2], character: segment[3] });
current = {
genOffset,
sourceOffset,
};
}
}
}
return {
id: 'tsx',
languageId: 'typescriptreact',
snapshot: {
getText: (start, end) => tsx.code.substring(start, end),
getLength: () => tsx.code.length,
getChangeRange: () => undefined,
},
mappings: mappings,
embeddedCodes: [],
};
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does getVirtualFileTSX() do?
getVirtualFileTSX() is a function in the astro codebase, defined in packages/language-tools/ts-plugin/src/astro2tsx.ts.
Where is getVirtualFileTSX() defined?
getVirtualFileTSX() is defined in packages/language-tools/ts-plugin/src/astro2tsx.ts at line 58.
What does getVirtualFileTSX() call?
getVirtualFileTSX() calls 1 function(s): patchTSX.
What calls getVirtualFileTSX()?
getVirtualFileTSX() 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