Skip to content

Commit

Permalink
feat(compiler): Propagate value span of ExpressionBinding to ParsedPr…
Browse files Browse the repository at this point in the history
…operty

This commit propagates the correct value span in an ExpressionBinding of
a microsyntax expression to ParsedProperty, which in turn porpagates the
span to the template ASTs (both VE and Ivy).
  • Loading branch information
kyliau committed Mar 18, 2020
1 parent c1a0f06 commit 15c9736
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/compiler/src/template_parser/binding_parser.ts
Expand Up @@ -145,8 +145,9 @@ export class BindingParser {
binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined;
targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan));
} else if (binding.value) {
const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan);
this._parsePropertyAst(
key, binding.value, sourceSpan, undefined, targetMatchableAttrs, targetProps);
key, binding.value, sourceSpan, valueSpan, targetMatchableAttrs, targetProps);
} else {
targetMatchableAttrs.push([key, '']);
this.parseLiteralAttr(
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler/test/render3/r3_ast_spans_spec.ts
Expand Up @@ -232,8 +232,8 @@ describe('R3 AST source spans', () => {
expectFromHtml('<div *ngFor="let item of items"></div>').toEqual([
['Template', '0:32', '0:32', '32:38'],
['TextAttribute', '5:31', '<empty>'],
['BoundAttribute', '5:31', '<empty>'],
['Variable', '13:22', '<empty>'], // let item
['BoundAttribute', '5:31', '25:30'], // *ngFor="let item of items" -> items
['Variable', '13:22', '<empty>'], // let item
['Element', '0:38', '0:32', '32:38'],
]);

Expand All @@ -245,8 +245,8 @@ describe('R3 AST source spans', () => {
// </ng-template>
expectFromHtml('<div *ngFor="item of items"></div>').toEqual([
['Template', '0:28', '0:28', '28:34'],
['BoundAttribute', '5:27', '<empty>'],
['BoundAttribute', '5:27', '<empty>'],
['BoundAttribute', '5:27', '13:18'], // ngFor="item of items" -> item
['BoundAttribute', '5:27', '21:26'], // ngFor="item of items" -> items
['Element', '0:34', '0:28', '28:34'],
]);
});
Expand All @@ -263,8 +263,8 @@ describe('R3 AST source spans', () => {
it('is correct for variables via as ...', () => {
expectFromHtml('<div *ngIf="expr as local"></div>').toEqual([
['Template', '0:27', '0:27', '27:33'],
['BoundAttribute', '5:26', '<empty>'],
['Variable', '6:25', '6:10'], // ngIf="expr as local -> ngIf
['BoundAttribute', '5:26', '12:17'], // ngIf="expr as local" -> expr
['Variable', '6:25', '6:10'], // ngIf="expr as local -> ngIf
['Element', '0:33', '0:27', '27:33'],
]);
});
Expand Down

0 comments on commit 15c9736

Please sign in to comment.