Reworks the compiler to output the factories for directives, components and pipes under a new static field called `ngFactoryFn`, instead of the usual `factory` property in their respective defs. This should eventually allow us to inject any kind of decorated class (e.g. a pipe). **Note:** these changes are the first part of the refactor and they don't include injectables. I decided to leave injectables for a follow-up PR, because there's some more cases we need to handle when it comes to their factories. Furthermore, directives, components and pipes make up most of the compiler output tests that need to be refactored and it'll make follow-up PRs easier to review if the tests are cleaned up now. This is part of the larger refactor for FW-1468. PR Close #31953
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
/**
|
|
* @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 {getLContext} from '../../src/render3/context_discovery';
|
|
import {RenderFlags, ɵɵdefineComponent, ɵɵelementEnd, ɵɵelementStart, ɵɵtext} from '../../src/render3/index';
|
|
import {LViewDebug, toDebug} from '../../src/render3/instructions/lview_debug';
|
|
|
|
import {ComponentFixture} from './render_util';
|
|
|
|
describe('Debug Representation', () => {
|
|
it('should generate a human readable version', () => {
|
|
class MyComponent {
|
|
static ngFactoryDef = () => new MyComponent();
|
|
static ngComponentDef = ɵɵdefineComponent({
|
|
type: MyComponent,
|
|
selectors: [['my-comp']],
|
|
vars: 0,
|
|
consts: 2,
|
|
template: function(rf: RenderFlags, ctx: MyComponent) {
|
|
if (rf == RenderFlags.Create) {
|
|
ɵɵelementStart(0, 'div', ['id', '123']);
|
|
ɵɵtext(1, 'Hello World');
|
|
ɵɵelementEnd();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
const fixture = new ComponentFixture(MyComponent);
|
|
const hostView = toDebug(getLContext(fixture.component) !.lView);
|
|
expect(hostView.host).toEqual(null);
|
|
const myCompView = hostView.childViews[0] as LViewDebug;
|
|
expect(myCompView.host).toEqual('<div host="mark"><div id="123">Hello World</div></div>');
|
|
expect(myCompView.nodes ![0].html).toEqual('<div id="123">');
|
|
expect(myCompView.nodes ![0].nodes ![0].html).toEqual('Hello World');
|
|
});
|
|
});
|