(params: TransformCodeParams)
| 25 | }; |
| 26 | |
| 27 | export 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 | } |
no test coverage detected