Skip to content

Commit 4fe489f

Browse files
committedFeb 28, 2025
fix(compiler): exponentiation should be right-to-left associative (#60101)
For example, `a ** b ** c` should be equivalent to `a ** (b ** c)`, not `(a ** b) ** c` PR Close #60101
1 parent 265387a commit 4fe489f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
 

‎packages/compiler-cli/src/ngtsc/typecheck/test/type_check_block_spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('type check blocks', () => {
7979
expect(tcb('{{a * b ** c + d}}')).toContain(
8080
'(((((this).a)) * ((((this).b)) ** (((this).c)))) + (((this).d)))',
8181
);
82+
expect(tcb('{{a ** b ** c}}')).toContain('blah');
8283
});
8384

8485
it('should handle attribute values for directive inputs', () => {

‎packages/compiler/src/expression_parser/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ class _ParseAST {
960960
);
961961
}
962962
this.advance();
963-
const right = this.parsePrefix();
963+
const right = this.parseExponentiation();
964964
result = new Binary(this.span(start), this.sourceSpan(start), '**', result, right);
965965
}
966966
return result;

‎packages/core/test/acceptance/integration_spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -2787,6 +2787,16 @@ describe('acceptance integration tests', () => {
27872787
expect(fixture.nativeElement.textContent).toEqual('1.03 | 0.97');
27882788
});
27892789

2790+
it('should have right-to-left associativity for exponentiation', () => {
2791+
@Component({
2792+
template: '{{2 ** 2 ** 3}}',
2793+
})
2794+
class TestComponent {}
2795+
const fixture = TestBed.createComponent(TestComponent);
2796+
fixture.detectChanges();
2797+
expect(fixture.nativeElement.textContent).toEqual('256');
2798+
});
2799+
27902800
describe('tView.firstUpdatePass', () => {
27912801
function isFirstUpdatePass() {
27922802
const lView = getLView();

0 commit comments

Comments
 (0)