feat(compiler): support skipping leading trivia in template source-maps (#30095)
Leading trivia, such as whitespace or comments, is confusing for developers looking at source-mapped templates, since they expect the source-map segment to start after the trivia. This commit adds skipping trivial characters to the lexer; and then implements that in the template parser. PR Close #30095
This commit is contained in:

committed by
Andrew Kushnir

parent
acaf1aa530
commit
304a12f027
@ -53,6 +53,8 @@ const NG_PROJECT_AS_ATTR_NAME = 'ngProjectAs';
|
||||
const GLOBAL_TARGET_RESOLVERS = new Map<string, o.ExternalReference>(
|
||||
[['window', R3.resolveWindow], ['document', R3.resolveDocument], ['body', R3.resolveBody]]);
|
||||
|
||||
const LEADING_TRIVIA_CHARS = [' ', '\n', '\r', '\t'];
|
||||
|
||||
// if (rf & flags) { .. }
|
||||
export function renderFlagCheckIfStmt(
|
||||
flags: core.RenderFlags, statements: o.Statement[]): o.IfStmt {
|
||||
@ -1733,8 +1735,9 @@ export function parseTemplate(
|
||||
const {interpolationConfig, preserveWhitespaces} = options;
|
||||
const bindingParser = makeBindingParser(interpolationConfig);
|
||||
const htmlParser = new HtmlParser();
|
||||
const parseResult =
|
||||
htmlParser.parse(template, templateUrl, {...options, tokenizeExpansionForms: true});
|
||||
const parseResult = htmlParser.parse(
|
||||
template, templateUrl,
|
||||
{...options, tokenizeExpansionForms: true, leadingTriviaChars: LEADING_TRIVIA_CHARS});
|
||||
|
||||
if (parseResult.errors && parseResult.errors.length > 0) {
|
||||
return {errors: parseResult.errors, nodes: [], styleUrls: [], styles: []};
|
||||
|
Reference in New Issue
Block a user