|
6 | 6 | * found in the LICENSE file at https://angular.dev/license
|
7 | 7 | */
|
8 | 8 |
|
| 9 | +import {ASTWithSource} from '../../src/expression_parser/ast'; |
9 | 10 | import {ParseSourceSpan} from '../../src/parse_util';
|
10 | 11 | import * as t from '../../src/render3/r3_ast';
|
11 | 12 |
|
@@ -409,6 +410,24 @@ describe('R3 AST source spans', () => {
|
409 | 410 | ['BoundAttribute', '@animation', 'animation', '<empty>'],
|
410 | 411 | ]);
|
411 | 412 | });
|
| 413 | + |
| 414 | + it('should not throw off span of value in bound attribute when leading spaces are present', () => { |
| 415 | + const assertValueSpan = (template: string, start: number, end: number) => { |
| 416 | + const result = parse(template); |
| 417 | + const boundAttribute = (result.nodes[0] as t.Element).inputs[0]; |
| 418 | + const span = (boundAttribute.value as ASTWithSource).ast.sourceSpan; |
| 419 | + |
| 420 | + expect(span.start).toBe(start); |
| 421 | + expect(span.end).toBe(end); |
| 422 | + }; |
| 423 | + |
| 424 | + assertValueSpan('<a [b]="helloWorld"></a>', 8, 18); |
| 425 | + assertValueSpan('<a [b]=" helloWorld"></a>', 9, 19); |
| 426 | + assertValueSpan('<a [b]=" helloWorld"></a>', 10, 20); |
| 427 | + assertValueSpan('<a [b]=" helloWorld"></a>', 11, 21); |
| 428 | + assertValueSpan('<a [b]=" helloWorld"></a>', 12, 22); |
| 429 | + assertValueSpan('<a [b]=" helloWorld"></a>', 50, 60); |
| 430 | + }); |
412 | 431 | });
|
413 | 432 |
|
414 | 433 | describe('templates', () => {
|
|
0 commit comments