(template: string)
| 54 | * parses the template string into the Html AST |
| 55 | */ |
| 56 | export function parseTemplate(template: string): ParseResult { |
| 57 | let parsed: ParseTreeResult; |
| 58 | try { |
| 59 | // Note: we use the HtmlParser here, instead of the `parseTemplate` function, because the |
| 60 | // latter returns an Ivy AST, not an HTML AST. The HTML AST has the advantage of preserving |
| 61 | // interpolated text as text nodes containing a mixture of interpolation tokens and text tokens, |
| 62 | // rather than turning them into `BoundText` nodes like the Ivy AST does. This allows us to |
| 63 | // easily get the text-only ranges without having to reconstruct the original text. |
| 64 | parsed = new HtmlParser().parse(template, '', { |
| 65 | // Allows for ICUs to be parsed. |
| 66 | tokenizeExpansionForms: true, |
| 67 | // Explicitly disable blocks so that their characters are treated as plain text. |
| 68 | tokenizeBlocks: true, |
| 69 | preserveLineEndings: true, |
| 70 | }); |
| 71 | |
| 72 | // Don't migrate invalid templates. |
| 73 | if (parsed.errors && parsed.errors.length > 0) { |
| 74 | const errors = parsed.errors.map((e) => ({type: 'parse', error: e})); |
| 75 | return {tree: undefined, errors}; |
| 76 | } |
| 77 | } catch (e: any) { |
| 78 | return {tree: undefined, errors: [{type: 'parse', error: e}]}; |
| 79 | } |
| 80 | return {tree: parsed, errors: []}; |
| 81 | } |
| 82 | |
| 83 | function pipeMatchRegExpFor(name: string): RegExp { |
| 84 | return new RegExp(`\\|\\s*${name}`); |
no test coverage detected
searching dependent graphs…