refactor(compiler): allow parsing templates with custom leadingTriviaChars (#31136)

Move the definition leadingTriviaChars included in parsing a template
to the parameters of parseTemplate. This allows overriding of the
default leadingTriviaChars, which is needed by some pipelines like the
indexing pipeline because leadingTriviaChars may throw off the recorded
span of selectors.

PR Close #31136
This commit is contained in:
Ayaz Hafiz 2019-06-19 08:38:40 -07:00 committed by Kara Erickson
parent 70ad91ed8b
commit f2219081e3
1 changed files with 7 additions and 1 deletions

View File

@ -1940,6 +1940,12 @@ export interface ParseTemplateOptions {
* but the new line should increment the current line for source mapping. * but the new line should increment the current line for source mapping.
*/ */
escapedString?: boolean; escapedString?: boolean;
/**
* An array of characters that should be considered as leading trivia.
* Leading trivia are characters that are not important to the developer, and so should not be
* included in source-map segments. A common example is whitespace.
*/
leadingTriviaChars?: string[];
} }
/** /**
@ -1957,7 +1963,7 @@ export function parseTemplate(
const htmlParser = new HtmlParser(); const htmlParser = new HtmlParser();
const parseResult = htmlParser.parse( const parseResult = htmlParser.parse(
template, templateUrl, template, templateUrl,
{...options, tokenizeExpansionForms: true, leadingTriviaChars: LEADING_TRIVIA_CHARS}); {leadingTriviaChars: LEADING_TRIVIA_CHARS, ...options, tokenizeExpansionForms: true});
if (parseResult.errors && parseResult.errors.length > 0) { if (parseResult.errors && parseResult.errors.length > 0) {
return {errors: parseResult.errors, nodes: [], styleUrls: [], styles: []}; return {errors: parseResult.errors, nodes: [], styleUrls: [], styles: []};