refactor(core): remove ViewResolver
and ViewResolverMock
The methods on `ViewResolverMock` have been merged into `DirectiveResolver`. BREAKING CHANGE: - ES5 users can no longer use the `View(…)` function to provide `ViewMetadata`. This mirrors the removal of the `@View` decorator a while ago.
This commit is contained in:
@ -406,7 +406,8 @@ export class CompileTemplateMetadata {
|
||||
export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
static create(
|
||||
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host,
|
||||
lifecycleHooks, providers, viewProviders, queries, viewQueries, entryComponents, template}: {
|
||||
lifecycleHooks, providers, viewProviders, queries, viewQueries, entryComponents,
|
||||
viewDirectives, viewPipes, template}: {
|
||||
type?: CompileTypeMetadata,
|
||||
isComponent?: boolean,
|
||||
selector?: string,
|
||||
@ -423,6 +424,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
queries?: CompileQueryMetadata[],
|
||||
viewQueries?: CompileQueryMetadata[],
|
||||
entryComponents?: CompileTypeMetadata[],
|
||||
viewDirectives?: CompileTypeMetadata[],
|
||||
viewPipes?: CompileTypeMetadata[],
|
||||
template?: CompileTemplateMetadata
|
||||
} = {}): CompileDirectiveMetadata {
|
||||
var hostListeners: {[key: string]: string} = {};
|
||||
@ -472,6 +475,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
queries,
|
||||
viewQueries,
|
||||
entryComponents,
|
||||
viewDirectives,
|
||||
viewPipes,
|
||||
template,
|
||||
});
|
||||
}
|
||||
@ -492,12 +497,17 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
viewQueries: CompileQueryMetadata[];
|
||||
// Note: Need to keep types here to prevent cycles!
|
||||
entryComponents: CompileTypeMetadata[];
|
||||
// Note: Need to keep types here to prevent cycles!
|
||||
viewDirectives: CompileTypeMetadata[];
|
||||
// Note: Need to keep types here to prevent cycles!
|
||||
viewPipes: CompileTypeMetadata[];
|
||||
|
||||
template: CompileTemplateMetadata;
|
||||
|
||||
constructor(
|
||||
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners,
|
||||
hostProperties, hostAttributes, lifecycleHooks, providers, viewProviders, queries,
|
||||
viewQueries, entryComponents, template}: {
|
||||
viewQueries, entryComponents, viewDirectives, viewPipes, template}: {
|
||||
type?: CompileTypeMetadata,
|
||||
isComponent?: boolean,
|
||||
selector?: string,
|
||||
@ -516,6 +526,8 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
queries?: CompileQueryMetadata[],
|
||||
viewQueries?: CompileQueryMetadata[],
|
||||
entryComponents?: CompileTypeMetadata[],
|
||||
viewDirectives?: CompileTypeMetadata[],
|
||||
viewPipes?: CompileTypeMetadata[],
|
||||
template?: CompileTemplateMetadata,
|
||||
} = {}) {
|
||||
this.type = type;
|
||||
@ -534,6 +546,9 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
this.queries = _normalizeArray(queries);
|
||||
this.viewQueries = _normalizeArray(viewQueries);
|
||||
this.entryComponents = _normalizeArray(entryComponents);
|
||||
this.viewDirectives = _normalizeArray(viewDirectives);
|
||||
this.viewPipes = _normalizeArray(viewPipes);
|
||||
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ export {RuntimeCompiler} from './runtime_compiler';
|
||||
export * from './url_resolver';
|
||||
export * from './xhr';
|
||||
|
||||
export {ViewResolver} from './view_resolver';
|
||||
export {DirectiveResolver} from './directive_resolver';
|
||||
export {PipeResolver} from './pipe_resolver';
|
||||
export {NgModuleResolver} from './ng_module_resolver';
|
||||
@ -38,7 +37,6 @@ import {DomElementSchemaRegistry} from './schema/dom_element_schema_registry';
|
||||
import {UrlResolver, DEFAULT_PACKAGE_URL_PROVIDER} from './url_resolver';
|
||||
import {Parser} from './expression_parser/parser';
|
||||
import {Lexer} from './expression_parser/lexer';
|
||||
import {ViewResolver} from './view_resolver';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
import {NgModuleResolver} from './ng_module_resolver';
|
||||
@ -76,7 +74,6 @@ export const COMPILER_PROVIDERS: Array<any|Type|{[k: string]: any}|any[]> =
|
||||
DomElementSchemaRegistry,
|
||||
/*@ts2dart_Provider*/ {provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry},
|
||||
UrlResolver,
|
||||
ViewResolver,
|
||||
DirectiveResolver,
|
||||
PipeResolver,
|
||||
NgModuleResolver
|
||||
|
@ -143,7 +143,16 @@ export class DirectiveResolver {
|
||||
changeDetection: dm.changeDetection,
|
||||
providers: dm.providers,
|
||||
viewProviders: dm.viewProviders,
|
||||
entryComponents: dm.entryComponents
|
||||
entryComponents: dm.entryComponents,
|
||||
directives: dm.directives,
|
||||
pipes: dm.pipes,
|
||||
template: dm.template,
|
||||
templateUrl: dm.templateUrl,
|
||||
styles: dm.styles,
|
||||
styleUrls: dm.styleUrls,
|
||||
encapsulation: dm.encapsulation,
|
||||
animations: dm.animations,
|
||||
interpolation: dm.interpolation
|
||||
});
|
||||
|
||||
} else {
|
||||
|
@ -24,7 +24,6 @@ import {PipeResolver} from './pipe_resolver';
|
||||
import {ElementSchemaRegistry} from './schema/element_schema_registry';
|
||||
import {getUrlScheme} from './url_resolver';
|
||||
import {MODULE_SUFFIX, ValueTransformer, sanitizeIdentifier, visitValue} from './util';
|
||||
import {ViewResolver} from './view_resolver';
|
||||
|
||||
@Injectable()
|
||||
export class CompileMetadataResolver {
|
||||
@ -37,10 +36,8 @@ export class CompileMetadataResolver {
|
||||
|
||||
constructor(
|
||||
private _ngModuleResolver: NgModuleResolver, private _directiveResolver: DirectiveResolver,
|
||||
private _pipeResolver: PipeResolver, private _viewResolver: ViewResolver,
|
||||
private _config: CompilerConfig, private _console: Console,
|
||||
private _schemaRegistry: ElementSchemaRegistry,
|
||||
private _reflector: ReflectorReader = reflector) {}
|
||||
private _pipeResolver: PipeResolver, private _config: CompilerConfig,
|
||||
private _console: Console, private _schemaRegistry: ElementSchemaRegistry, private _reflector: ReflectorReader = reflector) {}
|
||||
|
||||
private sanitizeTokenName(token: any): string {
|
||||
let identifier = stringify(token);
|
||||
@ -125,27 +122,28 @@ export class CompileMetadataResolver {
|
||||
var changeDetectionStrategy: ChangeDetectionStrategy = null;
|
||||
var viewProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
|
||||
var moduleUrl = staticTypeModuleUrl(directiveType);
|
||||
var viewDirectiveTypes: cpl.CompileTypeMetadata[] = [];
|
||||
var viewPipeTypes: cpl.CompileTypeMetadata[] = [];
|
||||
var entryComponentTypes: cpl.CompileTypeMetadata[] = [];
|
||||
let selector = dirMeta.selector;
|
||||
if (dirMeta instanceof ComponentMetadata) {
|
||||
var cmpMeta = <ComponentMetadata>dirMeta;
|
||||
var viewMeta = this._viewResolver.resolve(directiveType);
|
||||
assertArrayOfStrings('styles', viewMeta.styles);
|
||||
assertInterpolationSymbols('interpolation', viewMeta.interpolation);
|
||||
var animations = isPresent(viewMeta.animations) ?
|
||||
viewMeta.animations.map(e => this.getAnimationEntryMetadata(e)) :
|
||||
assertArrayOfStrings('styles', cmpMeta.styles);
|
||||
assertInterpolationSymbols('interpolation', cmpMeta.interpolation);
|
||||
var animations = isPresent(cmpMeta.animations) ?
|
||||
cmpMeta.animations.map(e => this.getAnimationEntryMetadata(e)) :
|
||||
null;
|
||||
assertArrayOfStrings('styles', viewMeta.styles);
|
||||
assertArrayOfStrings('styleUrls', viewMeta.styleUrls);
|
||||
assertArrayOfStrings('styles', cmpMeta.styles);
|
||||
assertArrayOfStrings('styleUrls', cmpMeta.styleUrls);
|
||||
|
||||
templateMeta = new cpl.CompileTemplateMetadata({
|
||||
encapsulation: viewMeta.encapsulation,
|
||||
template: viewMeta.template,
|
||||
templateUrl: viewMeta.templateUrl,
|
||||
styles: viewMeta.styles,
|
||||
styleUrls: viewMeta.styleUrls,
|
||||
encapsulation: cmpMeta.encapsulation,
|
||||
template: cmpMeta.template,
|
||||
templateUrl: cmpMeta.templateUrl,
|
||||
styles: cmpMeta.styles,
|
||||
styleUrls: cmpMeta.styleUrls,
|
||||
animations: animations,
|
||||
interpolation: viewMeta.interpolation
|
||||
interpolation: cmpMeta.interpolation
|
||||
});
|
||||
changeDetectionStrategy = cmpMeta.changeDetection;
|
||||
if (isPresent(dirMeta.viewProviders)) {
|
||||
@ -156,7 +154,26 @@ export class CompileMetadataResolver {
|
||||
if (cmpMeta.entryComponents) {
|
||||
entryComponentTypes =
|
||||
flattenArray(cmpMeta.entryComponents)
|
||||
.map((cmp) => this.getTypeMetadata(cmp, staticTypeModuleUrl(cmp)));
|
||||
.map((type) => this.getTypeMetadata(type, staticTypeModuleUrl(type)));
|
||||
}
|
||||
if (cmpMeta.directives) {
|
||||
viewDirectiveTypes = flattenArray(cmpMeta.directives).map((type) => {
|
||||
if (!type) {
|
||||
throw new BaseException(
|
||||
`Unexpected directive value '${type}' on the View of component '${stringify(directiveType)}'`);
|
||||
}
|
||||
|
||||
return this.getTypeMetadata(type, staticTypeModuleUrl(type));
|
||||
});
|
||||
}
|
||||
if (cmpMeta.pipes) {
|
||||
viewPipeTypes = flattenArray(cmpMeta.pipes).map((type) => {
|
||||
if (!type) {
|
||||
throw new BaseException(
|
||||
`Unexpected pipe value '${type}' on the View of component '${stringify(directiveType)}'`);
|
||||
}
|
||||
return this.getTypeMetadata(type, staticTypeModuleUrl(type));
|
||||
});
|
||||
}
|
||||
if (!selector) {
|
||||
selector = this._schemaRegistry.getDefaultComponentElementName();
|
||||
@ -196,6 +213,8 @@ export class CompileMetadataResolver {
|
||||
viewProviders: viewProviders,
|
||||
queries: queries,
|
||||
viewQueries: viewQueries,
|
||||
viewDirectives: viewDirectiveTypes,
|
||||
viewPipes: viewPipeTypes,
|
||||
entryComponents: entryComponentTypes
|
||||
});
|
||||
this._directiveCache.set(directiveType, meta);
|
||||
@ -386,20 +405,12 @@ export class CompileMetadataResolver {
|
||||
return;
|
||||
}
|
||||
const addPipe = (pipeType: Type) => {
|
||||
if (!pipeType) {
|
||||
throw new BaseException(
|
||||
`Unexpected pipe value '${pipeType}' on the View of component '${stringify(compMeta.type.runtime)}'`);
|
||||
}
|
||||
const pipeMeta = this.getPipeMetadata(pipeType);
|
||||
this._addPipeToModule(
|
||||
pipeMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule, moduleMeta.declaredPipes);
|
||||
};
|
||||
|
||||
const addDirective = (dirType: Type) => {
|
||||
if (!dirType) {
|
||||
throw new BaseException(
|
||||
`Unexpected directive value '${dirType}' on the View of component '${stringify(compMeta.type.runtime)}'`);
|
||||
}
|
||||
const dirMeta = this.getDirectiveMetadata(dirType);
|
||||
if (this._addDirectiveToModule(
|
||||
dirMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
|
||||
@ -407,12 +418,11 @@ export class CompileMetadataResolver {
|
||||
this._getTransitiveViewDirectivesAndPipes(dirMeta, moduleMeta);
|
||||
}
|
||||
};
|
||||
const view = this._viewResolver.resolve(compMeta.type.runtime);
|
||||
if (view.pipes) {
|
||||
flattenArray(view.pipes).forEach(addPipe);
|
||||
if (compMeta.viewPipes) {
|
||||
compMeta.viewPipes.forEach((cplType) => addPipe(cplType.runtime));
|
||||
}
|
||||
if (view.directives) {
|
||||
flattenArray(view.directives).forEach(addDirective);
|
||||
if (compMeta.viewDirectives) {
|
||||
compMeta.viewDirectives.forEach((cplType) => addDirective(cplType.runtime));
|
||||
}
|
||||
compMeta.entryComponents.forEach((entryComponentType) => {
|
||||
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
|
||||
|
@ -1,55 +0,0 @@
|
||||
/**
|
||||
* @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 {Injectable, ViewMetadata, ComponentMetadata,} from '@angular/core';
|
||||
import {ReflectorReader, reflector} from '../core_private';
|
||||
import {Type, stringify, isBlank, isPresent} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
|
||||
function _isComponentMetadata(obj: any): obj is ComponentMetadata {
|
||||
return obj instanceof ComponentMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves types to {@link ViewMetadata}.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ViewResolver {
|
||||
constructor(private _reflector: ReflectorReader = reflector) {}
|
||||
|
||||
resolve(component: Type, throwIfNotFound = true): ViewMetadata {
|
||||
const compMeta: ComponentMetadata =
|
||||
this._reflector.annotations(component).find(_isComponentMetadata);
|
||||
|
||||
if (isPresent(compMeta)) {
|
||||
if (isBlank(compMeta.template) && isBlank(compMeta.templateUrl)) {
|
||||
throw new BaseException(
|
||||
`Component '${stringify(component)}' must have either 'template' or 'templateUrl' set.`);
|
||||
|
||||
} else {
|
||||
return new ViewMetadata({
|
||||
templateUrl: compMeta.templateUrl,
|
||||
template: compMeta.template,
|
||||
directives: compMeta.directives,
|
||||
pipes: compMeta.pipes,
|
||||
encapsulation: compMeta.encapsulation,
|
||||
styles: compMeta.styles,
|
||||
styleUrls: compMeta.styleUrls,
|
||||
animations: compMeta.animations,
|
||||
interpolation: compMeta.interpolation
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (throwIfNotFound) {
|
||||
throw new BaseException(
|
||||
`Could not compile '${stringify(component)}' because it is not a component.`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user