Skip to content

Commit 7035f22

Browse files
ayazhafizkara
authored andcommitted
fix(compiler): fix Elements not making a new ParseSourceSpan (#31190)
Change the Element constructor in r3_ast to create a new ParseSourceSpan when regenerating it rather than extending an object, which does not contain the overloaded toString(). PR Close #31190
1 parent 9c06af2 commit 7035f22

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎packages/compiler/src/render3/r3_ast.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Element implements Node {
7272
public endSourceSpan: ParseSourceSpan|null, public i18n?: I18nAST) {
7373
// If the element is empty then the source span should include any closing tag
7474
if (children.length === 0 && startSourceSpan && endSourceSpan) {
75-
this.sourceSpan = {...sourceSpan, end: endSourceSpan.end};
75+
this.sourceSpan = new ParseSourceSpan(sourceSpan.start, endSourceSpan.end);
7676
}
7777
}
7878
visit<Result>(visitor: Visitor<Result>): Result { return visitor.visitElement(this); }

‎packages/compiler/test/render3/r3_template_transform_spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,17 @@ function expectFromR3Nodes(nodes: t.Node[]) {
9595
return expect(humanizer.result);
9696
}
9797

98+
function expectSpanFromHtml(html: string) {
99+
const {nodes} = parse(html);
100+
return expect(nodes[0] !.sourceSpan.toString());
101+
}
102+
98103
describe('R3 template transform', () => {
104+
describe('ParseSpan on nodes toString', () => {
105+
it('should create valid text span on Element with adjacent start and end tags',
106+
() => { expectSpanFromHtml('<div></div>').toBe('<div></div>'); });
107+
});
108+
99109
describe('Nodes without binding', () => {
100110
it('should parse text nodes', () => {
101111
expectFromHtml('a').toEqual([

0 commit comments

Comments
 (0)