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

Function traverseHtml

packages/vite/src/node/plugins/html.ts:202–223  ·  view source on GitHub ↗
(
  html: string,
  filePath: string,
  warn: Logger['warn'],
  visitor: (node: DefaultTreeAdapterMap['node']) => void,
)

Source from the content-addressed store, hash-verified

200type ParseWarnings = Partial<Record<ErrorCodes, string>>
201
202export async function traverseHtml(
203 html: string,
204 filePath: string,
205 warn: Logger['warn'],
206 visitor: (node: DefaultTreeAdapterMap['node']) => void,
207): Promise<void> {
208 // lazy load compiler
209 const { parse, ErrorCodes } = await import('parse5')
210 const warnings: ParseWarnings = {}
211 const ast = parse(html, {
212 scriptingEnabled: false, // parse inside <noscript>
213 sourceCodeLocationInfo: true,
214 onParseError: (e: ParserError) => {
215 handleParseError(e, ErrorCodes, html, filePath, warnings)
216 },
217 })
218 traverseNodes(ast, visitor)
219
220 for (const message of Object.values(warnings)) {
221 warn(colors.yellow(`\n${message}`))
222 }
223}
224
225export function getScriptInfo(node: DefaultTreeAdapterMap['element']): {
226 src: Token.Attribute | undefined

Callers 3

devHtmlHookFunction · 0.90
handlerFunction · 0.85

Calls 3

handleParseErrorFunction · 0.85
traverseNodesFunction · 0.85
warnFunction · 0.50

Tested by

no test coverage detected