From 7035f225ad8d5a1fff018b5ab2d60952a4f40885 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Thu, 20 Jun 2019 18:42:44 -0700 Subject: [PATCH] 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 --- packages/compiler/src/render3/r3_ast.ts | 2 +- .../test/render3/r3_template_transform_spec.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/compiler/src/render3/r3_ast.ts b/packages/compiler/src/render3/r3_ast.ts index a5a3c17f6b..fbe1c7b72f 100644 --- a/packages/compiler/src/render3/r3_ast.ts +++ b/packages/compiler/src/render3/r3_ast.ts @@ -72,7 +72,7 @@ export class Element implements Node { public endSourceSpan: ParseSourceSpan|null, public i18n?: I18nAST) { // If the element is empty then the source span should include any closing tag if (children.length === 0 && startSourceSpan && endSourceSpan) { - this.sourceSpan = {...sourceSpan, end: endSourceSpan.end}; + this.sourceSpan = new ParseSourceSpan(sourceSpan.start, endSourceSpan.end); } } visit(visitor: Visitor): Result { return visitor.visitElement(this); } diff --git a/packages/compiler/test/render3/r3_template_transform_spec.ts b/packages/compiler/test/render3/r3_template_transform_spec.ts index 4b800f6153..eff0b5da3f 100644 --- a/packages/compiler/test/render3/r3_template_transform_spec.ts +++ b/packages/compiler/test/render3/r3_template_transform_spec.ts @@ -95,7 +95,17 @@ function expectFromR3Nodes(nodes: t.Node[]) { return expect(humanizer.result); } +function expectSpanFromHtml(html: string) { + const {nodes} = parse(html); + return expect(nodes[0] !.sourceSpan.toString()); +} + describe('R3 template transform', () => { + describe('ParseSpan on nodes toString', () => { + it('should create valid text span on Element with adjacent start and end tags', + () => { expectSpanFromHtml('
').toBe('
'); }); + }); + describe('Nodes without binding', () => { it('should parse text nodes', () => { expectFromHtml('a').toEqual([