( importer: string, source: string, )
| 886 | } |
| 887 | |
| 888 | export 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 | |
| 920 | const interopHelper = (m: any, n: boolean) => |
| 921 | n || !m?.__esModule |
no test coverage detected