From eb5763c23f081dd48c68c53009f8d787e9d3d5c0 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Mon, 11 Jul 2016 17:19:38 -0700 Subject: [PATCH] fix(compiler): Generates function expressions as returning any (#9980) Function expressions are used in an expression context so untyped function expressions should have any as the result type. Fixes: #9877 --- .../integrationtest/src/queries.ts | 20 ++++++++++++++++++- .../compiler/src/output/ts_emitter.ts | 2 +- .../compiler/test/output/ts_emitter_spec.ts | 4 ++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/@angular/compiler-cli/integrationtest/src/queries.ts b/modules/@angular/compiler-cli/integrationtest/src/queries.ts index cb3677e8e7..76a92d93cd 100644 --- a/modules/@angular/compiler-cli/integrationtest/src/queries.ts +++ b/modules/@angular/compiler-cli/integrationtest/src/queries.ts @@ -6,7 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ -import {Component, QueryList, ViewChild, ViewChildren} from '@angular/core'; +import {NgFor} from '@angular/common'; +import {Component, Directive, QueryList, ViewChild, ViewChildren} from '@angular/core'; @Component({selector: 'comp-for-child-query', template: 'child'}) export class CompForChildQuery { @@ -21,3 +22,20 @@ export class CompWithChildQuery { @ViewChild(CompForChildQuery) child: CompForChildQuery; @ViewChildren(CompForChildQuery) children: QueryList; } + +@Directive({selector: '[directive-for-query]'}) +export class DirectiveForQuery { +} + +@Component({ + selector: 'comp-with-directive-child', + directives: [DirectiveForQuery, NgFor], + template: `
+
{{data}}
+
` +}) +export class CompWithDirectiveChild { + @ViewChildren(DirectiveForQuery) children: QueryList; + + divData: string[]; +} diff --git a/modules/@angular/compiler/src/output/ts_emitter.ts b/modules/@angular/compiler/src/output/ts_emitter.ts index 5604796603..cbfa2cbd82 100644 --- a/modules/@angular/compiler/src/output/ts_emitter.ts +++ b/modules/@angular/compiler/src/output/ts_emitter.ts @@ -170,7 +170,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor ctx.print(`(`); this._visitParams(ast.params, ctx); ctx.print(`):`); - this.visitType(ast.type, ctx, 'void'); + this.visitType(ast.type, ctx); ctx.println(` => {`); ctx.incIndent(); this.visitAllStatements(ast.statements, ctx); diff --git a/modules/@angular/compiler/test/output/ts_emitter_spec.ts b/modules/@angular/compiler/test/output/ts_emitter_spec.ts index 7d9203763e..43fcc22ea0 100644 --- a/modules/@angular/compiler/test/output/ts_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/ts_emitter_spec.ts @@ -143,11 +143,11 @@ export function main() { }); it('should support function expressions', () => { - expect(emitStmt(o.fn([], []).toStmt())).toEqual(['():void => {', '};'].join('\n')); + expect(emitStmt(o.fn([], []).toStmt())).toEqual(['():any => {', '};'].join('\n')); expect(emitStmt(o.fn([], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE).toStmt())) .toEqual(['():number => {', ' return 1;\n};'].join('\n')); expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt())).toEqual([ - '(param1:number):void => {', '};' + '(param1:number):any => {', '};' ].join('\n')); });