From f2219081e3fa439e8d353e897dbe370c1da63c3b Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Wed, 19 Jun 2019 08:38:40 -0700 Subject: [PATCH] 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 --- packages/compiler/src/render3/view/template.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/compiler/src/render3/view/template.ts b/packages/compiler/src/render3/view/template.ts index 96bb460792..e7f3a40752 100644 --- a/packages/compiler/src/render3/view/template.ts +++ b/packages/compiler/src/render3/view/template.ts @@ -1940,6 +1940,12 @@ export interface ParseTemplateOptions { * but the new line should increment the current line for source mapping. */ 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 parseResult = htmlParser.parse( template, templateUrl, - {...options, tokenizeExpansionForms: true, leadingTriviaChars: LEADING_TRIVIA_CHARS}); + {leadingTriviaChars: LEADING_TRIVIA_CHARS, ...options, tokenizeExpansionForms: true}); if (parseResult.errors && parseResult.errors.length > 0) { return {errors: parseResult.errors, nodes: [], styleUrls: [], styles: []};