Skip to content

Commit b0476f3

Browse files
marclavalmatsko
authored andcommitted
feat(ivy): support providers and viewProviders (angular#25803)
PR Close angular#25803
1 parent 9dc52d9 commit b0476f3

File tree

76 files changed

+4088
-1635
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4088
-1635
lines changed

packages/compiler-cli/src/ngcc/test/rendering/renderer_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Renderer', () => {
128128
}));
129129
expect(addDefinitionsSpy.calls.first().args[2])
130130
.toEqual(
131-
`A.ngDirectiveDef = ɵngcc0.ɵdefineDirective({ type: A, selectors: [["", "a", ""]], factory: function A_Factory(t) { return new (t || A)(); }, features: [ɵngcc0.ɵPublicFeature] });`);
131+
`A.ngDirectiveDef = ɵngcc0.ɵdefineDirective({ type: A, selectors: [["", "a", ""]], factory: function A_Factory(t) { return new (t || A)(); } });`);
132132
});
133133

134134
it('should call removeDecorators with the source code, a map of class decorators that have been analyzed',

packages/compiler-cli/src/ngtsc/annotations/src/component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export class ComponentDecoratorHandler implements
118118
preserveWhitespaces = value;
119119
}
120120

121+
const viewProviders: Expression|null = component.has('viewProviders') ?
122+
new WrappedNodeExpr(component.get('viewProviders') !) :
123+
null;
124+
121125
// Go through the root directories for this project, and select the one with the smallest
122126
// relative path representation.
123127
const filePath = node.getSourceFile().fileName;
@@ -202,6 +206,7 @@ export class ComponentDecoratorHandler implements
202206
directives: EMPTY_MAP,
203207
wrapDirectivesInClosure: false, //
204208
animations,
209+
viewProviders
205210
},
206211
parsedTemplate: template.nodes,
207212
},

packages/compiler-cli/src/ngtsc/annotations/src/directive.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export function extractDirectiveMetadata(
146146

147147
const host = extractHostBindings(directive, decoratedElements, reflector, checker, coreModule);
148148

149+
const providers: Expression|null =
150+
directive.has('providers') ? new WrappedNodeExpr(directive.get('providers') !) : null;
151+
149152
// Determine if `ngOnChanges` is a lifecycle hook defined on the component.
150153
const usesOnChanges = members.some(
151154
member => !member.isStatic && member.kind === ClassMemberKind.Method &&
@@ -176,7 +179,7 @@ export function extractDirectiveMetadata(
176179
outputs: {...outputsFromMeta, ...outputsFromFields}, queries, selector,
177180
type: new WrappedNodeExpr(clazz.name !),
178181
typeArgumentCount: reflector.getGenericArityOfClass(clazz) || 0,
179-
typeSourceSpan: null !, usesInheritance, exportAs,
182+
typeSourceSpan: null !, usesInheritance, exportAs, providers
180183
};
181184
return {decoratedElements, decorator: directive, metadata};
182185
}

packages/compiler-cli/test/compliance/r3_compiler_compliance_spec.ts

Lines changed: 19 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ describe('compiler compliance', () => {
415415
factory: function MyComponent_Factory(t){
416416
return new (t || MyComponent)();
417417
},
418-
features: [$r3$.ɵPublicFeature],
419418
consts: 1,
420419
vars: 0,
421420
template: function MyComponent_Template(rf,ctx){
@@ -470,7 +469,6 @@ describe('compiler compliance', () => {
470469
type: ChildComponent,
471470
selectors: [["child"]],
472471
factory: function ChildComponent_Factory(t) { return new (t || ChildComponent)(); },
473-
features: [$r3$.ɵPublicFeature],
474472
consts: 1,
475473
vars: 0,
476474
template: function ChildComponent_Template(rf, ctx) {
@@ -485,8 +483,7 @@ describe('compiler compliance', () => {
485483
SomeDirective.ngDirectiveDef = $r3$.ɵdefineDirective({
486484
type: SomeDirective,
487485
selectors: [["", "some-directive", ""]],
488-
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); },
489-
features: [$r3$.ɵPublicFeature]
486+
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); }
490487
});
491488
`;
492489

@@ -498,7 +495,6 @@ describe('compiler compliance', () => {
498495
type: MyComponent,
499496
selectors: [["my-component"]],
500497
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
501-
features: [$r3$.ɵPublicFeature],
502498
consts: 2,
503499
vars: 0,
504500
template: function MyComponent_Template(rf, ctx) {
@@ -543,8 +539,7 @@ describe('compiler compliance', () => {
543539
SomeDirective.ngDirectiveDef = $r3$.ɵdefineDirective({
544540
type: SomeDirective,
545541
selectors: [["div", "some-directive", "", 8, "foo", 3, "title", "", 9, "baz"]],
546-
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); },
547-
features: [$r3$.ɵPublicFeature]
542+
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); }
548543
});
549544
`;
550545

@@ -553,8 +548,7 @@ describe('compiler compliance', () => {
553548
OtherDirective.ngDirectiveDef = $r3$.ɵdefineDirective({
554549
type: OtherDirective,
555550
selectors: [["", 5, "span", "title", "", 9, "baz"]],
556-
factory: function OtherDirective_Factory(t) {return new (t || OtherDirective)(); },
557-
features: [$r3$.ɵPublicFeature]
551+
factory: function OtherDirective_Factory(t) {return new (t || OtherDirective)(); }
558552
});
559553
`;
560554

@@ -590,8 +584,7 @@ describe('compiler compliance', () => {
590584
hostBindings: function HostBindingDir_HostBindings(dirIndex, elIndex) {
591585
$r3$.ɵelementProperty(elIndex, "id", $r3$.ɵbind($r3$.ɵload(dirIndex).dirId));
592586
},
593-
hostVars: 1,
594-
features: [$r3$.ɵPublicFeature]
587+
hostVars: 1
595588
});
596589
`;
597590

@@ -635,7 +628,6 @@ describe('compiler compliance', () => {
635628
$r3$.ɵelementProperty(elIndex, "id", $r3$.ɵbind($r3$.ɵpureFunction1(1, $ff$, $r3$.ɵload(dirIndex).id)));
636629
},
637630
hostVars: 3,
638-
features: [$r3$.ɵPublicFeature],
639631
consts: 0,
640632
vars: 0,
641633
template: function HostBindingComp_Template(rf, ctx) {}
@@ -679,7 +671,6 @@ describe('compiler compliance', () => {
679671
$r3$.ɵdirectiveInject(ElementRef), $r3$.ɵdirectiveInject(ViewContainerRef),
680672
$r3$.ɵdirectiveInject(ChangeDetectorRef));
681673
},
682-
features: [$r3$.ɵPublicFeature],
683674
consts: 0,
684675
vars: 0,
685676
template: function MyComponent_Template(rf, ctx) {}
@@ -720,8 +711,7 @@ describe('compiler compliance', () => {
720711
IfDirective.ngDirectiveDef = $r3$.ɵdefineDirective({
721712
type: IfDirective,
722713
selectors: [["", "if", ""]],
723-
factory: function IfDirective_Factory(t) { return new (t || IfDirective)($r3$.ɵdirectiveInject(TemplateRef)); },
724-
features: [$r3$.ɵPublicFeature]
714+
factory: function IfDirective_Factory(t) { return new (t || IfDirective)($r3$.ɵdirectiveInject(TemplateRef)); }
725715
});`;
726716
const MyComponentDefinition = `
727717
const $c1$ = ["foo", ""];
@@ -743,7 +733,6 @@ describe('compiler compliance', () => {
743733
type: MyComponent,
744734
selectors: [["my-component"]],
745735
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
746-
features: [$r3$.ɵPublicFeature],
747736
consts: 3,
748737
vars: 0,
749738
template: function MyComponent_Template(rf, ctx) {
@@ -806,7 +795,6 @@ describe('compiler compliance', () => {
806795
type: MyApp,
807796
selectors: [["my-app"]],
808797
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
809-
features: [$r3$.ɵPublicFeature],
810798
consts: 1,
811799
vars: 3,
812800
template: function MyApp_Template(rf, ctx) {
@@ -888,7 +876,6 @@ describe('compiler compliance', () => {
888876
type: MyApp,
889877
selectors: [["my-app"]],
890878
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
891-
features: [$r3$.ɵPublicFeature],
892879
consts: 1,
893880
vars: 11,
894881
template: function MyApp_Template(rf, ctx) {
@@ -952,7 +939,6 @@ describe('compiler compliance', () => {
952939
type: MyApp,
953940
selectors: [["my-app"]],
954941
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
955-
features: [$r3$.ɵPublicFeature],
956942
consts: 1,
957943
vars: 3,
958944
template: function MyApp_Template(rf, ctx) {
@@ -1020,7 +1006,6 @@ describe('compiler compliance', () => {
10201006
type: MyApp,
10211007
selectors: [["my-app"]],
10221008
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
1023-
features: [$r3$.ɵPublicFeature],
10241009
consts: 1,
10251010
vars: 8,
10261011
template: function MyApp_Template(rf, ctx) {
@@ -1079,7 +1064,6 @@ describe('compiler compliance', () => {
10791064
type: SimpleComponent,
10801065
selectors: [["simple"]],
10811066
factory: function SimpleComponent_Factory(t) { return new (t || SimpleComponent)(); },
1082-
features: [$r3$.ɵPublicFeature],
10831067
consts: 2,
10841068
vars: 0,
10851069
template: function SimpleComponent_Template(rf, ctx) {
@@ -1102,7 +1086,6 @@ describe('compiler compliance', () => {
11021086
type: ComplexComponent,
11031087
selectors: [["complex"]],
11041088
factory: function ComplexComponent_Factory(t) { return new (t || ComplexComponent)(); },
1105-
features: [$r3$.ɵPublicFeature],
11061089
consts: 4,
11071090
vars: 0,
11081091
template: function ComplexComponent_Template(rf, ctx) {
@@ -1171,7 +1154,6 @@ describe('compiler compliance', () => {
11711154
type: ViewQueryComponent,
11721155
selectors: [["view-query-component"]],
11731156
factory: function ViewQueryComponent_Factory(t) { return new (t || ViewQueryComponent)(); },
1174-
features: [$r3$.ɵPublicFeature],
11751157
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
11761158
if (rf & 1) {
11771159
$r3$.ɵquery(0, SomeDirective, true);
@@ -1348,17 +1330,16 @@ describe('compiler compliance', () => {
13481330
factory: function ContentQueryComponent_Factory(t) {
13491331
return new (t || ContentQueryComponent)();
13501332
},
1351-
contentQueries: function ContentQueryComponent_ContentQueries() {
1352-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, true));
1353-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, false));
1333+
contentQueries: function ContentQueryComponent_ContentQueries(dirIndex) {
1334+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, true), dirIndex);
1335+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, false), dirIndex);
13541336
},
13551337
contentQueriesRefresh: function ContentQueryComponent_ContentQueriesRefresh(dirIndex, queryStartIndex) {
13561338
const instance = $r3$.ɵload(dirIndex);
13571339
var $tmp$;
13581340
($r3$.ɵqueryRefresh(($tmp$ = $r3$.ɵloadQueryList(queryStartIndex))) && ($instance$.someDir = $tmp$.first));
13591341
($r3$.ɵqueryRefresh(($tmp$ = $r3$.ɵloadQueryList((queryStartIndex + 1)))) && ($instance$.someDirList = $tmp$));
13601342
},
1361-
features: [$r3$.ɵPublicFeature],
13621343
consts: 2,
13631344
vars: 0,
13641345
template: function ContentQueryComponent_Template(rf, ctx) {
@@ -1406,9 +1387,9 @@ describe('compiler compliance', () => {
14061387
14071388
ContentQueryComponent.ngComponentDef = $r3$.ɵdefineComponent({
14081389
1409-
contentQueries: function ContentQueryComponent_ContentQueries() {
1410-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e0_attrs$, true));
1411-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e1_attrs$, false));
1390+
contentQueries: function ContentQueryComponent_ContentQueries(dirIndex) {
1391+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e0_attrs$, true), dirIndex);
1392+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e1_attrs$, false), dirIndex);
14121393
},
14131394
contentQueriesRefresh: function ContentQueryComponent_ContentQueriesRefresh(dirIndex, queryStartIndex) {
14141395
const instance = $r3$.ɵload(dirIndex);
@@ -1459,11 +1440,11 @@ describe('compiler compliance', () => {
14591440
14601441
ContentQueryComponent.ngComponentDef = $r3$.ɵdefineComponent({
14611442
1462-
contentQueries: function ContentQueryComponent_ContentQueries() {
1463-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e0_attrs$ , true, TemplateRef));
1464-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, true, ElementRef));
1465-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e1_attrs$, false, ElementRef));
1466-
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, false, TemplateRef));
1443+
contentQueries: function ContentQueryComponent_ContentQueries(dirIndex) {
1444+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e0_attrs$ , true, TemplateRef), dirIndex);
1445+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, true, ElementRef), dirIndex);
1446+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, $e1_attrs$, false, ElementRef), dirIndex);
1447+
$r3$.ɵregisterContentQuery($r3$.ɵquery(null, SomeDirective, false, TemplateRef), dirIndex);
14671448
},
14681449
contentQueriesRefresh: function ContentQueryComponent_ContentQueriesRefresh(dirIndex, queryStartIndex) {
14691450
const instance = $r3$.ɵload(dirIndex);
@@ -1552,7 +1533,6 @@ describe('compiler compliance', () => {
15521533
type: MyApp,
15531534
selectors: [["my-app"]],
15541535
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
1555-
features: [$r3$.ɵPublicFeature],
15561536
consts: 6,
15571537
vars: 17,
15581538
template: function MyApp_Template(rf, ctx) {
@@ -1616,7 +1596,6 @@ describe('compiler compliance', () => {
16161596
type: MyApp,
16171597
selectors: [["my-app"]],
16181598
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
1619-
features: [$r3$.ɵPublicFeature],
16201599
consts: 6,
16211600
vars: 27,
16221601
template: function MyApp_Template(rf, ctx) {
@@ -1671,7 +1650,6 @@ describe('compiler compliance', () => {
16711650
type: MyComponent,
16721651
selectors: [["my-component"]],
16731652
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
1674-
features: [$r3$.ɵPublicFeature],
16751653
consts: 3,
16761654
vars: 1,
16771655
template: function MyComponent_Template(rf, ctx) {
@@ -1765,7 +1743,6 @@ describe('compiler compliance', () => {
17651743
type: MyComponent,
17661744
selectors: [["my-component"]],
17671745
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
1768-
features: [$r3$.ɵPublicFeature],
17691746
consts: 6,
17701747
vars: 1,
17711748
template: function MyComponent_Template(rf, ctx) {
@@ -1911,7 +1888,7 @@ describe('compiler compliance', () => {
19111888
selectors: [["lifecycle-comp"]],
19121889
factory: function LifecycleComp_Factory(t) { return new (t || LifecycleComp)(); },
19131890
inputs: {nameMin: "name"},
1914-
features: [$r3$.ɵPublicFeature, $r3$.ɵNgOnChangesFeature],
1891+
features: [$r3$.ɵNgOnChangesFeature],
19151892
consts: 0,
19161893
vars: 0,
19171894
template: function LifecycleComp_Template(rf, ctx) {}
@@ -1922,7 +1899,6 @@ describe('compiler compliance', () => {
19221899
type: SimpleLayout,
19231900
selectors: [["simple-layout"]],
19241901
factory: function SimpleLayout_Factory(t) { return new (t || SimpleLayout)(); },
1925-
features: [$r3$.ɵPublicFeature],
19261902
consts: 2,
19271903
vars: 2,
19281904
template: function SimpleLayout_Template(rf, ctx) {
@@ -2032,7 +2008,7 @@ describe('compiler compliance', () => {
20322008
factory: function ForOfDirective_Factory(t) {
20332009
return new (t || ForOfDirective)($r3$.ɵdirectiveInject(ViewContainerRef), $r3$.ɵdirectiveInject(TemplateRef));
20342010
},
2035-
features: [$r3$.ɵPublicFeature, $r3$.ɵNgOnChangesFeature],
2011+
features: [$r3$.ɵNgOnChangesFeature],
20362012
inputs: {forOf: "forOf"}
20372013
});
20382014
`;
@@ -2052,7 +2028,6 @@ describe('compiler compliance', () => {
20522028
type: MyComponent,
20532029
selectors: [["my-component"]],
20542030
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
2055-
features: [$r3$.ɵPublicFeature],
20562031
consts: 2,
20572032
vars: 1,
20582033
template: function MyComponent_Template(rf, ctx){
@@ -2108,7 +2083,7 @@ describe('compiler compliance', () => {
21082083
factory: function ForOfDirective_Factory(t) {
21092084
return new (t || ForOfDirective)($r3$.ɵdirectiveInject(ViewContainerRef), $r3$.ɵdirectiveInject(TemplateRef));
21102085
},
2111-
features: [$r3$.ɵPublicFeature, $r3$.ɵNgOnChangesFeature],
2086+
features: [$r3$.ɵNgOnChangesFeature],
21122087
inputs: {forOf: "forOf"}
21132088
});
21142089
`;
@@ -2131,7 +2106,6 @@ describe('compiler compliance', () => {
21312106
type: MyComponent,
21322107
selectors: [["my-component"]],
21332108
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
2134-
features: [$r3$.ɵPublicFeature],
21352109
consts: 2,
21362110
vars: 1,
21372111
template: function MyComponent_Template(rf, ctx) {
@@ -2231,7 +2205,6 @@ describe('compiler compliance', () => {
22312205
type: MyComponent,
22322206
selectors: [["my-component"]],
22332207
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
2234-
features: [$r3$.ɵPublicFeature],
22352208
consts: 2,
22362209
vars: 1,
22372210
template: function MyComponent_Template(rf, ctx) {

packages/compiler-cli/test/compliance/r3_view_compiler_directives_spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('compiler compliance: directives', () => {
4242
type: MyComponent,
4343
selectors: [["my-component"]],
4444
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
45-
features: [$r3$.ɵPublicFeature],
4645
consts: 1,
4746
vars: 0,
4847
template: function MyComponent_Template(rf, ctx) {
@@ -88,7 +87,6 @@ describe('compiler compliance: directives', () => {
8887
type: MyComponent,
8988
selectors: [["my-component"]],
9089
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
91-
features: [$r3$.ɵPublicFeature],
9290
consts: 1,
9391
vars: 0,
9492
template: function MyComponent_Template(rf, ctx) {

packages/compiler-cli/test/compliance/r3_view_compiler_listener_spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ describe('compiler compliance: listen()', () => {
202202
type: MyComponent,
203203
selectors: [["my-component"]],
204204
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
205-
features: [$r3$.ɵPublicFeature],
206205
consts: 4,
207206
vars: 0,
208207
template: function MyComponent_Template(rf, ctx) {

0 commit comments

Comments
 (0)