test(compiler): check `fullStart` source-span (#42062)

The tests were checking that the source-span of parsed HTML nodes were
accurate, but they were not checking the span when it includes the
"leading trivia", which are given by the `fullStart` rather than `start`
location.

PR Close #42062
This commit is contained in:
Pete Bacon Darwin 2021-05-20 13:18:33 +01:00 committed by atscott
parent 8a54896a91
commit 973f9b8d19
2 changed files with 21 additions and 16 deletions

View File

@ -87,6 +87,10 @@ class _Humanizer implements html.Visitor {
private _appendContext(ast: html.Node, input: any[]): any[] { private _appendContext(ast: html.Node, input: any[]): any[] {
if (!this.includeSourceSpan) return input; if (!this.includeSourceSpan) return input;
input.push(ast.sourceSpan.toString()); input.push(ast.sourceSpan.toString());
if (ast.sourceSpan.fullStart.offset !== ast.sourceSpan.start.offset) {
input.push(ast.sourceSpan.fullStart.file.content.substring(
ast.sourceSpan.fullStart.offset, ast.sourceSpan.end.offset));
}
return input; return input;
} }
} }

View File

@ -798,7 +798,8 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
]); ]);
}); });
it('should set the end source span excluding trailing whitespace whitespace', () => { it('should not include leading trivia from the following node of an element in the end source',
() => {
expect(humanizeDomSourceSpans( expect(humanizeDomSourceSpans(
parser.parse('<input type="text" />\n\n\n <span>\n</span>', 'TestComp', { parser.parse('<input type="text" />\n\n\n <span>\n</span>', 'TestComp', {
leadingTriviaChars: [' ', '\n', '\r', '\t'], leadingTriviaChars: [' ', '\n', '\r', '\t'],
@ -809,9 +810,9 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
'<input type="text" />' '<input type="text" />'
], ],
[html.Attribute, 'type', 'text', ['text'], 'type="text"'], [html.Attribute, 'type', 'text', ['text'], 'type="text"'],
[html.Text, '\n\n\n ', 0, ['\n\n\n '], ''], [html.Text, '\n\n\n ', 0, ['\n\n\n '], '', '\n\n\n '],
[html.Element, 'span', 0, '<span>\n</span>', '<span>', '</span>'], [html.Element, 'span', 0, '<span>\n</span>', '<span>', '</span>'],
[html.Text, '\n', 1, ['\n'], ''], [html.Text, '\n', 1, ['\n'], '', '\n'],
]); ]);
}); });