refactor(Compiler): misc minor updates

This commit is contained in:
Victor Berchet 2015-10-23 00:17:30 -07:00
parent dd2598ccd8
commit e1e52c098b
2 changed files with 18 additions and 22 deletions

View File

@ -56,28 +56,22 @@ export class TemplateCompiler {
// For non components there is nothing to be normalized yet. // For non components there is nothing to be normalized yet.
return PromiseWrapper.resolve(directive); return PromiseWrapper.resolve(directive);
} }
var normalizedTemplatePromise;
if (directive.isComponent) { return this._templateNormalizer.normalizeTemplate(directive.type, directive.template)
normalizedTemplatePromise = .then((normalizedTemplate: CompileTemplateMetadata) => new CompileDirectiveMetadata({
this._templateNormalizer.normalizeTemplate(directive.type, directive.template); type: directive.type,
} else { isComponent: directive.isComponent,
normalizedTemplatePromise = PromiseWrapper.resolve(null); dynamicLoadable: directive.dynamicLoadable,
} selector: directive.selector,
return normalizedTemplatePromise.then( exportAs: directive.exportAs,
(normalizedTemplate) => new CompileDirectiveMetadata({ changeDetection: directive.changeDetection,
type: directive.type, inputs: directive.inputs,
isComponent: directive.isComponent, outputs: directive.outputs,
dynamicLoadable: directive.dynamicLoadable, hostListeners: directive.hostListeners,
selector: directive.selector, hostProperties: directive.hostProperties,
exportAs: directive.exportAs, hostAttributes: directive.hostAttributes,
changeDetection: directive.changeDetection, lifecycleHooks: directive.lifecycleHooks, template: normalizedTemplate
inputs: directive.inputs, }));
outputs: directive.outputs,
hostListeners: directive.hostListeners,
hostProperties: directive.hostProperties,
hostAttributes: directive.hostAttributes,
lifecycleHooks: directive.lifecycleHooks, template: normalizedTemplate
}));
} }
compileHostComponentRuntime(type: Type): Promise<CompiledHostTemplate> { compileHostComponentRuntime(type: Type): Promise<CompiledHostTemplate> {

View File

@ -59,11 +59,13 @@ export class TemplateNormalizer {
.concat(templateMeta.styleUrls.map( .concat(templateMeta.styleUrls.map(
url => this._urlResolver.resolve(directiveType.moduleUrl, url))); url => this._urlResolver.resolve(directiveType.moduleUrl, url)));
allStyleAbsUrls = ListWrapper.filter(allStyleAbsUrls, isStyleUrlResolvable); allStyleAbsUrls = ListWrapper.filter(allStyleAbsUrls, isStyleUrlResolvable);
var allResolvedStyles = allStyles.map(style => { var allResolvedStyles = allStyles.map(style => {
var styleWithImports = extractStyleUrls(this._urlResolver, templateAbsUrl, style); var styleWithImports = extractStyleUrls(this._urlResolver, templateAbsUrl, style);
styleWithImports.styleUrls.forEach(styleUrl => allStyleAbsUrls.push(styleUrl)); styleWithImports.styleUrls.forEach(styleUrl => allStyleAbsUrls.push(styleUrl));
return styleWithImports.style; return styleWithImports.style;
}); });
var encapsulation = templateMeta.encapsulation; var encapsulation = templateMeta.encapsulation;
if (encapsulation === ViewEncapsulation.Emulated && allResolvedStyles.length === 0 && if (encapsulation === ViewEncapsulation.Emulated && allResolvedStyles.length === 0 &&
allStyleAbsUrls.length === 0) { allStyleAbsUrls.length === 0) {