MCPcopy
hub / github.com/vitejs/vite / createParseErrorInfo

Function createParseErrorInfo

packages/vite/src/node/plugins/importAnalysis.ts:888–918  ·  view source on GitHub ↗
(
  importer: string,
  source: string,
)

Source from the content-addressed store, hash-verified

886}
887
888export function createParseErrorInfo(
889 importer: string,
890 source: string,
891): { message: string; showCodeFrame: boolean } {
892 const isVue = importer.endsWith('.vue')
893 const isJsx = importer.endsWith('.jsx') || importer.endsWith('.tsx')
894 const maybeJSX = !isVue && isJSRequest(importer)
895 const probablyBinary = source.includes(
896 '\ufffd' /* unicode replacement character */,
897 )
898
899 const msg = isVue
900 ? `Install @vitejs/plugin-vue to handle .vue files.`
901 : maybeJSX
902 ? isJsx
903 ? `If you use tsconfig.json, make sure to not set jsx to preserve.`
904 : `If you are using JSX, make sure to name the file with the .jsx or .tsx extension.`
905 : `You may need to install appropriate plugins to handle the ${path.extname(
906 importer,
907 )} file format, or if it's an asset, add "**/*${path.extname(
908 importer,
909 )}" to \`assetsInclude\` in your configuration.`
910
911 return {
912 message:
913 `Failed to parse source for import analysis because the content ` +
914 `contains invalid JS syntax. ` +
915 msg,
916 showCodeFrame: !probablyBinary,
917 }
918}
919
920const interopHelper = (m: any, n: boolean) =>
921 n || !m?.__esModule

Callers 1

transformFunction · 0.85

Calls 1

isJSRequestFunction · 0.90

Tested by

no test coverage detected