MCPcopy Create free account
hub / github.com/angular/angular / parseR3

Function parseR3

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

Source from the content-addressed store, hash-verified

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