X Tutup
Skip to content

Commit 0ed6fc4

Browse files
committed
fix(compiler): minor cleanups and fixes
Part of angular#3605
1 parent 9c97690 commit 0ed6fc4

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

modules/angular2/src/compiler/change_detector_compiler.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ export class ChangeDetectionCompiler {
4141
}
4242

4343
private _createChangeDetectorFactory(definition: ChangeDetectorDefinition): Function {
44-
if (IS_DART) {
44+
if (IS_DART || !this._genConfig.useJit) {
4545
var proto = new DynamicProtoChangeDetector(definition);
4646
return (dispatcher) => proto.instantiate(dispatcher);
4747
} else {
48-
// TODO(tbosch): provide a flag in _genConfig whether to allow eval or fall back to dynamic
49-
// change detection as well!
5048
return new ChangeDetectorJITGenerator(definition, UTIL, ABSTRACT_CHANGE_DETECTOR).generate();
5149
}
5250
}

modules/angular2/src/compiler/template_compiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export class TemplateCompiler {
3535

3636
normalizeDirectiveMetadata(directive:
3737
CompileDirectiveMetadata): Promise<CompileDirectiveMetadata> {
38+
if (!directive.isComponent) {
39+
// For non components there is nothing to be normalized yet.
40+
return PromiseWrapper.resolve(directive);
41+
}
3842
var normalizedTemplatePromise;
3943
if (directive.isComponent) {
4044
normalizedTemplatePromise =

modules/angular2/src/core/compiler/template_commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import {
1515
*/
1616
@CONST()
1717
export class CompiledTemplate {
18+
static getChangeDetectorFromData(data: any[]): Function { return data[0]; }
19+
static getCommandsFromData(data: any[]): TemplateCmd[] { return data[1]; }
20+
static getSylesFromData(data: any[]): string[] { return data[2]; }
21+
1822
// Note: paramGetter is a function so that we can have cycles between templates!
1923
// paramGetter returns a tuple with:
2024
// - ChangeDetector factory function
@@ -91,13 +95,11 @@ export function endElement(): TemplateCmd {
9195
export class BeginComponentCmd implements TemplateCmd, IBeginElementCmd, RenderBeginComponentCmd {
9296
isBound: boolean = true;
9397
templateId: number;
94-
component: Type;
9598
constructor(public name: string, public attrNameAndValues: string[],
9699
public eventTargetAndNames: string[],
97100
public variableNameAndValues: Array<string | number>, public directives: Type[],
98101
public nativeShadow: boolean, public ngContentIndex: number,
99102
public template: CompiledTemplate) {
100-
this.component = directives[0];
101103
this.templateId = template.id;
102104
}
103105
visit(visitor: RenderCommandVisitor, context: any): any {

modules/angular2/test/compiler/template_compiler_spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ export function main() {
212212
});
213213

214214
describe('normalizeDirectiveMetadata', () => {
215+
it('should return the given DirectiveMetadata for non components',
216+
inject([AsyncTestCompleter], (async) => {
217+
var meta = runtimeMetadataResolver.getMetadata(NonComponent);
218+
compiler.normalizeDirectiveMetadata(meta).then(normMeta => {
219+
expect(normMeta).toBe(meta);
220+
async.done();
221+
});
222+
}));
223+
215224
it('should normalize the template',
216225
inject([AsyncTestCompleter, XHR], (async, xhr: MockXHR) => {
217226
xhr.expect('angular2/test/compiler/compUrl.html', 'loadedTemplate');
@@ -323,10 +332,14 @@ export function humanizeTemplate(template: CompiledTemplate,
323332
}
324333
var commands = [];
325334
var templateData = template.dataGetter();
326-
result =
327-
{'styles': templateData[2], 'commands': commands, 'cd': testChangeDetector(templateData[0])};
335+
result = {
336+
'styles': CompiledTemplate.getSylesFromData(templateData),
337+
'commands': commands,
338+
'cd': testChangeDetector(CompiledTemplate.getChangeDetectorFromData(templateData))
339+
};
328340
humanizedTemplates.set(template.id, result);
329-
visitAllCommands(new CommandHumanizer(commands, humanizedTemplates), templateData[1]);
341+
visitAllCommands(new CommandHumanizer(commands, humanizedTemplates),
342+
CompiledTemplate.getCommandsFromData(templateData));
330343
return result;
331344
}
332345

0 commit comments

Comments
 (0)
X Tutup