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

Function parseR3

packages/compiler/test/render3/view/util.ts:146–193  ·  view source on GitHub ↗
(
  input: string,
  options: {
    preserveWhitespaces?: boolean;
    leadingTriviaChars?: string[];
    ignoreError?: boolean;
    selectorlessEnabled?: boolean;
  } = {},
)

Source from the content-addressed store, hash-verified

144
145// Parse an html string to IVY specific info
146export function parseR3(
147 input: string,
148 options: {
149 preserveWhitespaces?: boolean;
150 leadingTriviaChars?: string[];
151 ignoreError?: boolean;
152 selectorlessEnabled?: boolean;
153 } = {},
154): Render3ParseResult {
155 const htmlParser = new HtmlParser();
156 const parseResult = htmlParser.parse(input, 'path:://to/template', {
157 tokenizeExpansionForms: true,
158 leadingTriviaChars: options.leadingTriviaChars ?? LEADING_TRIVIA_CHARS,
159 selectorlessEnabled: options.selectorlessEnabled,
160 });
161
162 if (parseResult.errors.length > 0 && !options.ignoreError) {
163 const msg = parseResult.errors.map((e) => e.toString()).join('\n');
164 throw new Error(msg);
165 }
166
167 let htmlNodes = processI18nMeta(parseResult).rootNodes;
168
169 if (!options.preserveWhitespaces) {
170 htmlNodes = visitAllWithSiblings(
171 new WhitespaceVisitor(true /* preserveSignificantWhitespace */),
172 htmlNodes,
173 );
174 }
175
176 const expressionParser = new Parser(new Lexer());
177 const schemaRegistry = new MockSchemaRegistry(
178 {'invalidProp': false},
179 {'mappedAttr': 'mappedProp'},
180 {'unknown': false, 'un-known': false},
181 ['onEvent'],
182 ['onEvent'],
183 );
184 const bindingParser = new BindingParser(expressionParser, schemaRegistry, []);
185 const r3Result = htmlAstToRender3Ast(htmlNodes, bindingParser, {collectCommentNodes: false});
186
187 if (r3Result.errors.length > 0 && !options.ignoreError) {
188 const msg = r3Result.errors.map((e) => e.toString()).join('\n');
189 throw new Error(msg);
190 }
191
192 return r3Result;
193}
194
195export function processI18nMeta(htmlAstWithErrors: ParseTreeResult): ParseTreeResult {
196 return new ParseTreeResult(

Callers

nothing calls this directly

Calls 7

parseMethod · 0.95
visitAllWithSiblingsFunction · 0.90
htmlAstToRender3AstFunction · 0.90
processI18nMetaFunction · 0.85
mapMethod · 0.80
joinMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…