nit: move shiki highlighter consts to outer scope

This commit is contained in:
bholmesdev 2023-03-06 10:08:13 -05:00
parent aec7a0931f
commit 1de419034d

View file

@ -122,6 +122,10 @@ export interface AstroErrorPayload {
}; };
} }
// Shiki does not support `mjs` or `cjs` aliases by default.
// Map these to `.js` during error highlighting.
const ALTERNATIVE_JS_EXTS = ['cjs', 'mjs'];
/** /**
* Generate a payload for Vite's error overlay * Generate a payload for Vite's error overlay
*/ */
@ -151,9 +155,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): Promise<Astro
const highlighter = await getHighlighter({ theme: 'css-variables' }); const highlighter = await getHighlighter({ theme: 'css-variables' });
let highlighterLang = err.loc?.file?.split('.').pop(); let highlighterLang = err.loc?.file?.split('.').pop();
if (['cjs', 'mjs'].includes(highlighterLang ?? '')) { if (ALTERNATIVE_JS_EXTS.includes(highlighterLang ?? '')) {
// Shiki does not support `mjs` or `cjs` aliases by default.
// Map these to `js` instead.
highlighterLang = 'js'; highlighterLang = 'js';
} }
const highlightedCode = err.fullCode const highlightedCode = err.fullCode