fix(ivy): compile pipe in context of ternary operator (#28635)
Previously, it wasn't possible to compile template that contains pipe in context of ternary operator `{{ 1 ? 2 : 0 | myPipe }}` due to the error `Error: Illegal state: Pipes should have been converted into functions. Pipe: async`. This PR fixes a typo in expression parser so that pipes are correctly converted into functions. PR Close #28635
This commit is contained in:

committed by
Miško Hevery

parent
2ca77da4ca
commit
2bf0d1a56f
38
packages/core/test/acceptance/pipe_spec.ts
Normal file
38
packages/core/test/acceptance/pipe_spec.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Component, Pipe, PipeTransform} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
describe('pipe', () => {
|
||||
it('should support pipe in context of ternary operator', () => {
|
||||
@Pipe({name: 'pipe'})
|
||||
class MyPipe implements PipeTransform {
|
||||
transform(value: any): any { return value; }
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `{{ condition ? 'a' : 'b' | pipe }}`,
|
||||
})
|
||||
class MyApp {
|
||||
condition = false;
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [MyApp, MyPipe]});
|
||||
const fixture = TestBed.createComponent(MyApp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement).toHaveText('b');
|
||||
|
||||
fixture.componentInstance.condition = true;
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement).toHaveText('a');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user