Revert "feat(core): expose inputs, outputs and ngContentSelectors on ComponentFactory."

This reverts commit 1171f91a80.
This commit is contained in:
Chuck Jazdzewski
2017-03-15 13:23:10 -07:00
parent c439742a54
commit cd981499f9
9 changed files with 11 additions and 134 deletions

View File

@ -162,27 +162,12 @@ export class AotCompiler {
hostMeta, ngModule, [compMeta.type], null, fileSuffix, targetStatements)
.viewClassVar;
const compFactoryVar = componentFactoryName(compMeta.type.reference);
const inputsExprs: o.LiteralMapEntry[] = [];
for (let propName in compMeta.inputs) {
const templateName = compMeta.inputs[propName];
// Don't quote so that the key gets minified...
inputsExprs.push(new o.LiteralMapEntry(propName, o.literal(templateName), false));
}
const outputsExprs: o.LiteralMapEntry[] = [];
for (let propName in compMeta.outputs) {
const templateName = compMeta.outputs[propName];
// Don't quote so that the key gets minified...
outputsExprs.push(new o.LiteralMapEntry(propName, o.literal(templateName), false));
}
targetStatements.push(
o.variable(compFactoryVar)
.set(o.importExpr(createIdentifier(Identifiers.createComponentFactory)).callFn([
o.literal(compMeta.selector), o.importExpr(compMeta.type),
o.variable(hostViewFactoryVar), new o.LiteralMapExpr(inputsExprs),
new o.LiteralMapExpr(outputsExprs),
o.literalArr(
compMeta.template.ngContentSelectors.map(selector => o.literal(selector)))
o.literal(compMeta.selector),
o.importExpr(compMeta.type),
o.variable(hostViewFactoryVar),
]))
.toDeclStmt(
o.importType(

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵConsole as Console, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory, ɵstringify as stringify} from '@angular/core';
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory, ɵstringify as stringify} from '@angular/core';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompileStylesheetMetadata, ProviderMeta, ProxyClass, createHostComponentMeta, identifierName, ngModuleJitUrl, sharedStylesheetJitUrl, templateJitUrl, templateSourceUrl} from '../compile_metadata';
import {CompilerConfig} from '../config';
@ -44,7 +44,7 @@ export class JitCompiler implements Compiler {
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
private _templateParser: TemplateParser, private _styleCompiler: StyleCompiler,
private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler,
private _compilerConfig: CompilerConfig, private _console: Console) {}
private _compilerConfig: CompilerConfig) {}
get injector(): Injector { return this._injector; }
@ -66,8 +66,6 @@ export class JitCompiler implements Compiler {
}
getNgContentSelectors(component: Type<any>): string[] {
this._console.warn(
'Compiler.getNgContentSelectors is deprecated. Use ComponentFactory.ngContentSelectors instead!');
const template = this._compiledTemplateCache.get(component);
if (!template) {
throw new Error(`The component ${stringify(component)} is not yet compiled!`);

View File

@ -142,26 +142,7 @@ export class CompileMetadataResolver {
ngfactoryFilePath(dirType.filePath), cpl.componentFactoryName(dirType));
} else {
const hostView = this.getHostComponentViewClass(dirType);
// Note: inputs / outputs / ngContentSelectors will be filled later once the template is
// loaded.
return createComponentFactory(selector, dirType, <any>hostView, {}, {}, []);
}
}
private initComponentFactory(
factory: StaticSymbol|ComponentFactory<any>, inputs: {[key: string]: string},
outputs: {[key: string]: string}, ngContentSelectors: string[]) {
if (!(factory instanceof StaticSymbol)) {
for (let propName in inputs) {
const templateName = inputs[propName];
factory.inputs.push({propName, templateName});
}
const outputsArr: {propName: string, templateName: string}[] = [];
for (let propName in outputs) {
const templateName = outputs[propName];
factory.outputs.push({propName, templateName});
}
factory.ngContentSelectors.push(...ngContentSelectors);
return createComponentFactory(selector, dirType, <any>hostView);
}
}
@ -205,11 +186,6 @@ export class CompileMetadataResolver {
componentFactory: metadata.componentFactory,
template: templateMetadata
});
if (templateMetadata) {
this.initComponentFactory(
metadata.componentFactory, metadata.inputs, metadata.outputs,
templateMetadata.ngContentSelectors);
}
this._directiveCache.set(directiveType, normalizedDirMeta);
this._summaryCache.set(directiveType, normalizedDirMeta.toSummary());
return normalizedDirMeta;

View File

@ -248,55 +248,6 @@ describe('compiler (unbundled Angular)', () => {
`Warning: Can't resolve all parameters for MyService in /app/app.ts: (?). This will become an error in Angular v5.x`);
}));
});
describe('ComponentFactories', () => {
it('should include inputs, outputs and ng-content selectors in the component factory',
fakeAsync(() => {
const FILES: MockData = {
app: {
'app.ts': `
import {Component, NgModule, Input, Output} from '@angular/core';
@Component({
selector: 'my-comp',
template: '<ng-content></ng-content><ng-content select="child"></ng-content>'
})
export class MyComp {
@Input('aInputName')
aInputProp: string;
@Output('aOutputName')
aOutputProp: any;
}
@NgModule({
declarations: [MyComp]
})
export class MyModule {}
`
}
};
const host = new MockCompilerHost(['/app/app.ts'], FILES, angularFiles);
const aotHost = new MockAotCompilerHost(host);
let generatedFiles: GeneratedFile[];
const warnSpy = spyOn(console, 'warn');
compile(host, aotHost, expectNoDiagnostics).then((f) => generatedFiles = f);
tick();
const genFile = generatedFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts');
const createComponentFactoryCall =
/ɵccf\([^)]*\)/m.exec(genFile.source)[0].replace(/\s*/g, '');
// selector
expect(createComponentFactoryCall).toContain('my-comp');
// inputs
expect(createComponentFactoryCall).toContain(`{aInputProp:'aInputName'}`);
// outputs
expect(createComponentFactoryCall).toContain(`{aOutputProp:'aOutputName'}`);
// ngContentSelectors
expect(createComponentFactoryCall).toContain(`['*','child']`);
}));
});
});
describe('compiler (bundled Angular)', () => {