MCPcopy
hub / github.com/zh-lx/code-inspector / transformCode

Function transformCode

packages/core/src/server/transform/index.ts:27–75  ·  view source on GitHub ↗
(params: TransformCodeParams)

Source from the content-addressed store, hash-verified

25};
26
27export async function transformCode(params: TransformCodeParams) {
28 let {
29 content,
30 filePath,
31 fileType,
32 escapeTags = [],
33 pathType = 'relative',
34 mdx = false,
35 } = params;
36 if (!fs.existsSync(filePath) || isIgnoredFile({ content, fileType })) {
37 return content;
38 }
39 const finalEscapeTags = [...CodeInspectorEscapeTags, ...escapeTags];
40 const resolveFilePath = filePath;
41
42 filePath = getRelativeOrAbsolutePath(filePath, pathType);
43
44 try {
45 if (fileType === 'vue') {
46 return await transformVue(content, filePath, finalEscapeTags);
47 } else if (fileType === 'jsx') {
48 return transformJsx(content, filePath, finalEscapeTags);
49 } else if (fileType === 'svelte') {
50 return transformSvelte(content, filePath, finalEscapeTags);
51 } else if (fileType === 'astro') {
52 return transformAstro(
53 content,
54 filePath,
55 finalEscapeTags,
56 resolveFilePath,
57 );
58 } else if (fileType === 'mdx') {
59 if (!mdx) {
60 return content;
61 }
62
63 return await transformMdx(
64 content,
65 filePath,
66 finalEscapeTags,
67 resolveFilePath,
68 );
69 } else {
70 return content;
71 }
72 } catch (error) {
73 return content;
74 }
75}

Callers 6

MakoCodeInspectorPluginFunction · 0.90
setupFunction · 0.90
loadFunction · 0.90
transformFunction · 0.90
index.test.tsFile · 0.90

Calls 7

isIgnoredFileFunction · 0.90
transformVueFunction · 0.90
transformJsxFunction · 0.90
transformSvelteFunction · 0.90
transformAstroFunction · 0.90
transformMdxFunction · 0.90

Tested by

no test coverage detected