Skip to content

Commit 4fe489f

Browse files
committed
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy