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

Function parseTemplate

packages/compiler/src/render3/view/template.ts:140–276  ·  view source on GitHub ↗
(
  template: string,
  templateUrl: string,
  options: ParseTemplateOptions = {},
)

Source from the content-addressed store, hash-verified

138 * @param options options to modify how the template is parsed
139 */
140export function parseTemplate(
141 template: string,
142 templateUrl: string,
143 options: ParseTemplateOptions = {},
144): ParsedTemplate {
145 const {preserveWhitespaces, enableI18nLegacyMessageIdFormat} = options;
146 const selectorlessEnabled = options.enableSelectorless ?? false;
147 const bindingParser = makeBindingParser(selectorlessEnabled);
148 const htmlParser = new HtmlParser();
149 const parseResult = htmlParser.parse(template, templateUrl, {
150 leadingTriviaChars: LEADING_TRIVIA_CHARS,
151 ...options,
152 tokenizeExpansionForms: true,
153 tokenizeBlocks: options.enableBlockSyntax ?? true,
154 tokenizeLet: options.enableLetSyntax ?? true,
155 selectorlessEnabled,
156 });
157
158 if (
159 !options.alwaysAttemptHtmlToR3AstConversion &&
160 parseResult.errors &&
161 parseResult.errors.length > 0
162 ) {
163 const parsedTemplate: ParsedTemplate = {
164 preserveWhitespaces,
165 errors: parseResult.errors,
166 nodes: [],
167 styleUrls: [],
168 styles: [],
169 ngContentSelectors: [],
170 };
171 if (options.collectCommentNodes) {
172 parsedTemplate.commentNodes = [];
173 }
174 return parsedTemplate;
175 }
176
177 let rootNodes: html.Node[] = parseResult.rootNodes;
178
179 // We need to use the same `retainEmptyTokens` value for both parses to avoid
180 // causing a mismatch when reusing source spans, even if the
181 // `preserveSignificantWhitespace` behavior is different between the two
182 // parses.
183 const retainEmptyTokens = !(options.preserveSignificantWhitespace ?? true);
184
185 // process i18n meta information (scan attributes, generate ids)
186 // before we run whitespace removal process, because existing i18n
187 // extraction process (ng extract-i18n) relies on a raw content to generate
188 // message ids
189 const i18nMetaVisitor = new I18nMetaVisitor(
190 /* keepI18nAttrs */ !preserveWhitespaces,
191 enableI18nLegacyMessageIdFormat,
192 options.preserveSignificantWhitespace,
193 retainEmptyTokens,
194 );
195 const i18nMetaResult = i18nMetaVisitor.visitAllWithErrors(rootNodes);
196
197 if (

Callers 13

binding_spec.tsFile · 0.90
parseJitTemplateFunction · 0.90
analyzeMethod · 0.90
visitNodeFunction · 0.90
parseFunction · 0.90
toR3ComponentMetaMethod · 0.90
getBoundTemplateFunction · 0.90
tcbFunction · 0.90
setupFunction · 0.90
parseExtractedTemplateFunction · 0.90

Calls 6

parseMethod · 0.95
visitAllWithErrorsMethod · 0.95
htmlAstToRender3AstFunction · 0.90
makeBindingParserFunction · 0.85
visitAllMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…