From 0ed6fc4f6bc91141599efbde011191aaa159fe06 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 18 Sep 2015 10:33:23 -0700 Subject: [PATCH] fix(compiler): minor cleanups and fixes Part of #3605 --- .../src/compiler/change_detector_compiler.ts | 4 +--- .../src/compiler/template_compiler.ts | 4 ++++ .../src/core/compiler/template_commands.ts | 6 ++++-- .../test/compiler/template_compiler_spec.ts | 19 ++++++++++++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/modules/angular2/src/compiler/change_detector_compiler.ts b/modules/angular2/src/compiler/change_detector_compiler.ts index c85d565078..f30f87cdfe 100644 --- a/modules/angular2/src/compiler/change_detector_compiler.ts +++ b/modules/angular2/src/compiler/change_detector_compiler.ts @@ -41,12 +41,10 @@ export class ChangeDetectionCompiler { } private _createChangeDetectorFactory(definition: ChangeDetectorDefinition): Function { - if (IS_DART) { + if (IS_DART || !this._genConfig.useJit) { var proto = new DynamicProtoChangeDetector(definition); return (dispatcher) => proto.instantiate(dispatcher); } else { - // TODO(tbosch): provide a flag in _genConfig whether to allow eval or fall back to dynamic - // change detection as well! return new ChangeDetectorJITGenerator(definition, UTIL, ABSTRACT_CHANGE_DETECTOR).generate(); } } diff --git a/modules/angular2/src/compiler/template_compiler.ts b/modules/angular2/src/compiler/template_compiler.ts index 0f9f16d289..87d85ac22e 100644 --- a/modules/angular2/src/compiler/template_compiler.ts +++ b/modules/angular2/src/compiler/template_compiler.ts @@ -35,6 +35,10 @@ export class TemplateCompiler { normalizeDirectiveMetadata(directive: CompileDirectiveMetadata): Promise { + if (!directive.isComponent) { + // For non components there is nothing to be normalized yet. + return PromiseWrapper.resolve(directive); + } var normalizedTemplatePromise; if (directive.isComponent) { normalizedTemplatePromise = diff --git a/modules/angular2/src/core/compiler/template_commands.ts b/modules/angular2/src/core/compiler/template_commands.ts index dcd403baf3..44dfbbf690 100644 --- a/modules/angular2/src/core/compiler/template_commands.ts +++ b/modules/angular2/src/core/compiler/template_commands.ts @@ -15,6 +15,10 @@ import { */ @CONST() export class CompiledTemplate { + static getChangeDetectorFromData(data: any[]): Function { return data[0]; } + static getCommandsFromData(data: any[]): TemplateCmd[] { return data[1]; } + static getSylesFromData(data: any[]): string[] { return data[2]; } + // Note: paramGetter is a function so that we can have cycles between templates! // paramGetter returns a tuple with: // - ChangeDetector factory function @@ -91,13 +95,11 @@ export function endElement(): TemplateCmd { export class BeginComponentCmd implements TemplateCmd, IBeginElementCmd, RenderBeginComponentCmd { isBound: boolean = true; templateId: number; - component: Type; constructor(public name: string, public attrNameAndValues: string[], public eventTargetAndNames: string[], public variableNameAndValues: Array, public directives: Type[], public nativeShadow: boolean, public ngContentIndex: number, public template: CompiledTemplate) { - this.component = directives[0]; this.templateId = template.id; } visit(visitor: RenderCommandVisitor, context: any): any { diff --git a/modules/angular2/test/compiler/template_compiler_spec.ts b/modules/angular2/test/compiler/template_compiler_spec.ts index c1ba1e7895..b781822c89 100644 --- a/modules/angular2/test/compiler/template_compiler_spec.ts +++ b/modules/angular2/test/compiler/template_compiler_spec.ts @@ -212,6 +212,15 @@ export function main() { }); describe('normalizeDirectiveMetadata', () => { + it('should return the given DirectiveMetadata for non components', + inject([AsyncTestCompleter], (async) => { + var meta = runtimeMetadataResolver.getMetadata(NonComponent); + compiler.normalizeDirectiveMetadata(meta).then(normMeta => { + expect(normMeta).toBe(meta); + async.done(); + }); + })); + it('should normalize the template', inject([AsyncTestCompleter, XHR], (async, xhr: MockXHR) => { xhr.expect('angular2/test/compiler/compUrl.html', 'loadedTemplate'); @@ -323,10 +332,14 @@ export function humanizeTemplate(template: CompiledTemplate, } var commands = []; var templateData = template.dataGetter(); - result = - {'styles': templateData[2], 'commands': commands, 'cd': testChangeDetector(templateData[0])}; + result = { + 'styles': CompiledTemplate.getSylesFromData(templateData), + 'commands': commands, + 'cd': testChangeDetector(CompiledTemplate.getChangeDetectorFromData(templateData)) + }; humanizedTemplates.set(template.id, result); - visitAllCommands(new CommandHumanizer(commands, humanizedTemplates), templateData[1]); + visitAllCommands(new CommandHumanizer(commands, humanizedTemplates), + CompiledTemplate.getCommandsFromData(templateData)); return result; }