MCPcopy Index your code
hub / github.com/angular/angular / parseTemplate

Function parseTemplate

packages/core/schematics/utils/parse_html.ts:56–81  ·  view source on GitHub ↗
(template: string)

Source from the content-addressed store, hash-verified

54 * parses the template string into the Html AST
55 */
56export 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
83function pipeMatchRegExpFor(name: string): RegExp {
84 return new RegExp(`\\|\\s*${name}`);

Callers 14

migrateNgClassBindingsFunction · 0.90
migrateCaseFunction · 0.90
validateMigratedTemplateFunction · 0.90
getTemplatesFunction · 0.90
getTemplateReferencesFunction · 0.90
canRemoveCommonModuleFunction · 0.90
generateI18nMarkersFunction · 0.90
migrateIfFunction · 0.90
migrateForFunction · 0.90
migrateSwitchFunction · 0.90

Calls 2

mapMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…