Skip to content

Commit 6c54a0a

Browse files
petebacondarwinthePunderWoman
authored andcommitted
test(compiler): check fullStart source-span (#43132)
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 #43132
1 parent 8ed452b commit 6c54a0a

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎packages/compiler/test/ml_parser/ast_spec_utils.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class _Humanizer implements html.Visitor {
8787
private _appendContext(ast: html.Node, input: any[]): any[] {
8888
if (!this.includeSourceSpan) return input;
8989
input.push(ast.sourceSpan.toString());
90+
if (ast.sourceSpan.fullStart.offset !== ast.sourceSpan.start.offset) {
91+
input.push(ast.sourceSpan.fullStart.file.content.substring(
92+
ast.sourceSpan.fullStart.offset, ast.sourceSpan.end.offset));
93+
}
9094
return input;
9195
}
9296
}

‎packages/compiler/test/ml_parser/html_parser_spec.ts‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -852,22 +852,23 @@ import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn, humanizeNodes}
852852
]);
853853
});
854854

855-
it('should set the end source span excluding trailing whitespace whitespace', () => {
856-
expect(humanizeDomSourceSpans(
857-
parser.parse('<input type="text" />\n\n\n <span>\n</span>', 'TestComp', {
858-
leadingTriviaChars: [' ', '\n', '\r', '\t'],
859-
})))
860-
.toEqual([
861-
[
862-
html.Element, 'input', 0, '<input type="text" />', '<input type="text" />',
863-
'<input type="text" />'
864-
],
865-
[html.Attribute, 'type', 'text', ['text'], 'type="text"'],
866-
[html.Text, '\n\n\n ', 0, ['\n\n\n '], ''],
867-
[html.Element, 'span', 0, '<span>\n</span>', '<span>', '</span>'],
868-
[html.Text, '\n', 1, ['\n'], ''],
869-
]);
870-
});
855+
it('should not include leading trivia from the following node of an element in the end source',
856+
() => {
857+
expect(humanizeDomSourceSpans(
858+
parser.parse('<input type="text" />\n\n\n <span>\n</span>', 'TestComp', {
859+
leadingTriviaChars: [' ', '\n', '\r', '\t'],
860+
})))
861+
.toEqual([
862+
[
863+
html.Element, 'input', 0, '<input type="text" />', '<input type="text" />',
864+
'<input type="text" />'
865+
],
866+
[html.Attribute, 'type', 'text', ['text'], 'type="text"'],
867+
[html.Text, '\n\n\n ', 0, ['\n\n\n '], '', '\n\n\n '],
868+
[html.Element, 'span', 0, '<span>\n</span>', '<span>', '</span>'],
869+
[html.Text, '\n', 1, ['\n'], '', '\n'],
870+
]);
871+
});
871872

872873
it('should not set the end source span for elements that are implicitly closed', () => {
873874
expect(humanizeDomSourceSpans(parser.parse('<div><p></div>', 'TestComp'))).toEqual([

0 commit comments

Comments
 (0)