( html: string, filePath: string, warn: Logger['warn'], visitor: (node: DefaultTreeAdapterMap['node']) => void, )
| 200 | type ParseWarnings = Partial<Record<ErrorCodes, string>> |
| 201 | |
| 202 | export 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 | |
| 225 | export function getScriptInfo(node: DefaultTreeAdapterMap['element']): { |
| 226 | src: Token.Attribute | undefined |
no test coverage detected