Skip to content

Commit

Permalink
fix(compiler): Generates function expressions as returning any (#9980)
Browse files Browse the repository at this point in the history
Function expressions are used in an expression context so untyped
function expressions should have any as the result type.

Fixes: #9877
  • Loading branch information
chuckjaz committed Jul 12, 2016
1 parent d1a3e3a commit eb5763c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
20 changes: 19 additions & 1 deletion modules/@angular/compiler-cli/integrationtest/src/queries.ts
Expand Up @@ -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 {
Expand All @@ -21,3 +22,20 @@ export class CompWithChildQuery {
@ViewChild(CompForChildQuery) child: CompForChildQuery;
@ViewChildren(CompForChildQuery) children: QueryList<CompForChildQuery>;
}

@Directive({selector: '[directive-for-query]'})
export class DirectiveForQuery {
}

@Component({
selector: 'comp-with-directive-child',
directives: [DirectiveForQuery, NgFor],
template: `<div>
<div *ngFor="let data of divData" directive-for-query>{{data}}</div>
</div>`
})
export class CompWithDirectiveChild {
@ViewChildren(DirectiveForQuery) children: QueryList<DirectiveForQuery>;

divData: string[];
}
2 changes: 1 addition & 1 deletion modules/@angular/compiler/src/output/ts_emitter.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/compiler/test/output/ts_emitter_spec.ts
Expand Up @@ -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'));
});

Expand Down

0 comments on commit eb5763c

Please sign in to comment.