Skip to content

Commit cd98149

Browse files
committed
Revert "feat(core): expose inputs, outputs and ngContentSelectors on ComponentFactory."
This reverts commit 1171f91.
1 parent c439742 commit cd98149

9 files changed

Lines changed: 11 additions & 134 deletions

File tree

modules/benchmarks/src/tree/ng2_next/tree.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ export class AppModule implements Injector, NgModuleRef<any> {
9797
this.renderer2 = new DomRendererFactory2(null, null);
9898
trustedEmptyColor = this.sanitizer.bypassSecurityTrustStyle('');
9999
trustedGreyColor = this.sanitizer.bypassSecurityTrustStyle('grey');
100-
this.componentFactory =
101-
createComponentFactory('#root', TreeComponent, TreeComponent_Host, {}, {}, []);
100+
this.componentFactory = createComponentFactory('#root', TreeComponent, TreeComponent_Host);
102101
}
103102

104103
get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND): any {

packages/compiler/src/aot/compiler.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,12 @@ export class AotCompiler {
162162
hostMeta, ngModule, [compMeta.type], null, fileSuffix, targetStatements)
163163
.viewClassVar;
164164
const compFactoryVar = componentFactoryName(compMeta.type.reference);
165-
const inputsExprs: o.LiteralMapEntry[] = [];
166-
for (let propName in compMeta.inputs) {
167-
const templateName = compMeta.inputs[propName];
168-
// Don't quote so that the key gets minified...
169-
inputsExprs.push(new o.LiteralMapEntry(propName, o.literal(templateName), false));
170-
}
171-
const outputsExprs: o.LiteralMapEntry[] = [];
172-
for (let propName in compMeta.outputs) {
173-
const templateName = compMeta.outputs[propName];
174-
// Don't quote so that the key gets minified...
175-
outputsExprs.push(new o.LiteralMapEntry(propName, o.literal(templateName), false));
176-
}
177-
178165
targetStatements.push(
179166
o.variable(compFactoryVar)
180167
.set(o.importExpr(createIdentifier(Identifiers.createComponentFactory)).callFn([
181-
o.literal(compMeta.selector), o.importExpr(compMeta.type),
182-
o.variable(hostViewFactoryVar), new o.LiteralMapExpr(inputsExprs),
183-
new o.LiteralMapExpr(outputsExprs),
184-
o.literalArr(
185-
compMeta.template.ngContentSelectors.map(selector => o.literal(selector)))
168+
o.literal(compMeta.selector),
169+
o.importExpr(compMeta.type),
170+
o.variable(hostViewFactoryVar),
186171
]))
187172
.toDeclStmt(
188173
o.importType(

packages/compiler/src/jit/compiler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵConsole as Console, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory, ɵstringify as stringify} from '@angular/core';
9+
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory, ɵstringify as stringify} from '@angular/core';
1010

1111
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompileStylesheetMetadata, ProviderMeta, ProxyClass, createHostComponentMeta, identifierName, ngModuleJitUrl, sharedStylesheetJitUrl, templateJitUrl, templateSourceUrl} from '../compile_metadata';
1212
import {CompilerConfig} from '../config';
@@ -44,7 +44,7 @@ export class JitCompiler implements Compiler {
4444
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
4545
private _templateParser: TemplateParser, private _styleCompiler: StyleCompiler,
4646
private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler,
47-
private _compilerConfig: CompilerConfig, private _console: Console) {}
47+
private _compilerConfig: CompilerConfig) {}
4848

4949
get injector(): Injector { return this._injector; }
5050

@@ -66,8 +66,6 @@ export class JitCompiler implements Compiler {
6666
}
6767

6868
getNgContentSelectors(component: Type<any>): string[] {
69-
this._console.warn(
70-
'Compiler.getNgContentSelectors is deprecated. Use ComponentFactory.ngContentSelectors instead!');
7169
const template = this._compiledTemplateCache.get(component);
7270
if (!template) {
7371
throw new Error(`The component ${stringify(component)} is not yet compiled!`);

packages/compiler/src/metadata_resolver.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,7 @@ export class CompileMetadataResolver {
142142
ngfactoryFilePath(dirType.filePath), cpl.componentFactoryName(dirType));
143143
} else {
144144
const hostView = this.getHostComponentViewClass(dirType);
145-
// Note: inputs / outputs / ngContentSelectors will be filled later once the template is
146-
// loaded.
147-
return createComponentFactory(selector, dirType, <any>hostView, {}, {}, []);
148-
}
149-
}
150-
151-
private initComponentFactory(
152-
factory: StaticSymbol|ComponentFactory<any>, inputs: {[key: string]: string},
153-
outputs: {[key: string]: string}, ngContentSelectors: string[]) {
154-
if (!(factory instanceof StaticSymbol)) {
155-
for (let propName in inputs) {
156-
const templateName = inputs[propName];
157-
factory.inputs.push({propName, templateName});
158-
}
159-
const outputsArr: {propName: string, templateName: string}[] = [];
160-
for (let propName in outputs) {
161-
const templateName = outputs[propName];
162-
factory.outputs.push({propName, templateName});
163-
}
164-
factory.ngContentSelectors.push(...ngContentSelectors);
145+
return createComponentFactory(selector, dirType, <any>hostView);
165146
}
166147
}
167148

@@ -205,11 +186,6 @@ export class CompileMetadataResolver {
205186
componentFactory: metadata.componentFactory,
206187
template: templateMetadata
207188
});
208-
if (templateMetadata) {
209-
this.initComponentFactory(
210-
metadata.componentFactory, metadata.inputs, metadata.outputs,
211-
templateMetadata.ngContentSelectors);
212-
}
213189
this._directiveCache.set(directiveType, normalizedDirMeta);
214190
this._summaryCache.set(directiveType, normalizedDirMeta.toSummary());
215191
return normalizedDirMeta;

packages/compiler/test/aot/compiler_spec.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -248,55 +248,6 @@ describe('compiler (unbundled Angular)', () => {
248248
`Warning: Can't resolve all parameters for MyService in /app/app.ts: (?). This will become an error in Angular v5.x`);
249249
}));
250250
});
251-
252-
describe('ComponentFactories', () => {
253-
it('should include inputs, outputs and ng-content selectors in the component factory',
254-
fakeAsync(() => {
255-
const FILES: MockData = {
256-
app: {
257-
'app.ts': `
258-
import {Component, NgModule, Input, Output} from '@angular/core';
259-
260-
@Component({
261-
selector: 'my-comp',
262-
template: '<ng-content></ng-content><ng-content select="child"></ng-content>'
263-
})
264-
export class MyComp {
265-
@Input('aInputName')
266-
aInputProp: string;
267-
268-
@Output('aOutputName')
269-
aOutputProp: any;
270-
}
271-
272-
@NgModule({
273-
declarations: [MyComp]
274-
})
275-
export class MyModule {}
276-
`
277-
}
278-
};
279-
const host = new MockCompilerHost(['/app/app.ts'], FILES, angularFiles);
280-
const aotHost = new MockAotCompilerHost(host);
281-
let generatedFiles: GeneratedFile[];
282-
const warnSpy = spyOn(console, 'warn');
283-
compile(host, aotHost, expectNoDiagnostics).then((f) => generatedFiles = f);
284-
285-
tick();
286-
287-
const genFile = generatedFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts');
288-
const createComponentFactoryCall =
289-
/ɵccf\([^)]*\)/m.exec(genFile.source)[0].replace(/\s*/g, '');
290-
// selector
291-
expect(createComponentFactoryCall).toContain('my-comp');
292-
// inputs
293-
expect(createComponentFactoryCall).toContain(`{aInputProp:'aInputName'}`);
294-
// outputs
295-
expect(createComponentFactoryCall).toContain(`{aOutputProp:'aOutputName'}`);
296-
// ngContentSelectors
297-
expect(createComponentFactoryCall).toContain(`['*','child']`);
298-
}));
299-
});
300251
});
301252

302253
describe('compiler (bundled Angular)', () => {

packages/core/src/linker/compiler.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ export class Compiler {
7373
* the template of the given component.
7474
* This is used by the `upgrade` library to compile the appropriate transclude content
7575
* in the AngularJS wrapper component.
76-
*
77-
* @deprecated since v4. Use ComponentFactory.ngContentSelectors instead.
7876
*/
7977
getNgContentSelectors(component: Type<any>): string[] { throw _throwError(); }
8078

packages/core/src/linker/component_factory.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,6 @@ export abstract class ComponentRef<C> {
7070
export abstract class ComponentFactory<C> {
7171
abstract get selector(): string;
7272
abstract get componentType(): Type<any>;
73-
/**
74-
* selector for all <ng-content> elements in the component.
75-
*/
76-
abstract get ngContentSelectors(): string[];
77-
/**
78-
* the inputs of the component.
79-
*/
80-
abstract get inputs(): {propName: string, templateName: string}[];
81-
/**
82-
* the outputs of the component.
83-
*/
84-
abstract get outputs(): {propName: string, templateName: string}[];
8573
/**
8674
* Creates a new component.
8775
*/

packages/core/src/linker/component_factory_resolver.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ export class ComponentFactoryBoundToModule<C> extends ComponentFactory<C> {
6565

6666
get selector() { return this.factory.selector; }
6767
get componentType() { return this.factory.componentType; }
68-
get ngContentSelectors() { return this.factory.ngContentSelectors; }
69-
get inputs() { return this.factory.inputs; }
70-
get outputs() { return this.factory.outputs; }
7168

7269
create(
7370
injector: Injector, projectableNodes?: any[][], rootSelectorOrNode?: string|any,

packages/core/src/view/refs.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,9 @@ import {attachEmbeddedView, detachEmbeddedView, moveEmbeddedView, renderDetachVi
2626
const EMPTY_CONTEXT = new Object();
2727

2828
export function createComponentFactory(
29-
selector: string, componentType: Type<any>, viewDefFactory: ViewDefinitionFactory,
30-
inputs: {[propName: string]: string}, outputs: {[propName: string]: string},
31-
ngContentSelectors: string[]): ComponentFactory<any> {
32-
const inputsArr: {propName: string, templateName: string}[] = [];
33-
for (let propName in inputs) {
34-
const templateName = inputs[propName];
35-
inputsArr.push({propName, templateName});
36-
}
37-
const outputsArr: {propName: string, templateName: string}[] = [];
38-
for (let propName in outputs) {
39-
const templateName = outputs[propName];
40-
outputsArr.push({propName, templateName});
41-
}
42-
return new ComponentFactory_(
43-
selector, componentType, viewDefFactory, inputsArr, outputsArr, ngContentSelectors);
29+
selector: string, componentType: Type<any>,
30+
viewDefFactory: ViewDefinitionFactory): ComponentFactory<any> {
31+
return new ComponentFactory_(selector, componentType, viewDefFactory);
4432
}
4533

4634
export function getComponentViewDefinitionFactory(componentFactory: ComponentFactory<any>):
@@ -56,10 +44,7 @@ class ComponentFactory_ extends ComponentFactory<any> {
5644

5745
constructor(
5846
public selector: string, public componentType: Type<any>,
59-
viewDefFactory: ViewDefinitionFactory,
60-
public inputs: {propName: string, templateName: string}[],
61-
public outputs: {propName: string, templateName: string}[],
62-
public ngContentSelectors: string[]) {
47+
viewDefFactory: ViewDefinitionFactory) {
6348
super();
6449
this.viewDefFactory = viewDefFactory;
6550
}

0 commit comments

Comments
 (0)