
committed by
Miško Hevery

parent
f11b2fb00b
commit
8baff1858b
@ -107,7 +107,7 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
|
||||
return null;
|
||||
}
|
||||
visitFunctionExpr(ast: o.FunctionExpr, ctx: EmitterVisitorContext): any {
|
||||
ctx.print(ast, `function(`);
|
||||
ctx.print(ast, `function${ast.name ? ' ' + ast.name : ''}(`);
|
||||
this._visitParams(ast.params, ctx);
|
||||
ctx.println(ast, `) {`);
|
||||
ctx.incIndent();
|
||||
|
@ -41,7 +41,7 @@ export class BuiltinType extends Type {
|
||||
super(modifiers);
|
||||
}
|
||||
visitType(visitor: TypeVisitor, context: any): any {
|
||||
return visitor.visitBuiltintType(this, context);
|
||||
return visitor.visitBuiltinType(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ export const STRING_TYPE = new BuiltinType(BuiltinTypeName.String);
|
||||
export const FUNCTION_TYPE = new BuiltinType(BuiltinTypeName.Function);
|
||||
|
||||
export interface TypeVisitor {
|
||||
visitBuiltintType(type: BuiltinType, context: any): any;
|
||||
visitBuiltinType(type: BuiltinType, context: any): any;
|
||||
visitExpressionType(type: ExpressionType, context: any): any;
|
||||
visitArrayType(type: ArrayType, context: any): any;
|
||||
visitMapType(type: MapType, context: any): any;
|
||||
@ -487,7 +487,7 @@ export class FnParam {
|
||||
export class FunctionExpr extends Expression {
|
||||
constructor(
|
||||
public params: FnParam[], public statements: Statement[], type?: Type|null,
|
||||
sourceSpan?: ParseSourceSpan|null) {
|
||||
sourceSpan?: ParseSourceSpan|null, public name?: string|null) {
|
||||
super(type, sourceSpan);
|
||||
}
|
||||
isEquivalent(e: Expression): boolean {
|
||||
@ -1088,7 +1088,7 @@ export class RecursiveAstVisitor implements StatementVisitor, ExpressionVisitor
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
visitBuiltintType(type: BuiltinType, context: any): any { return this.visitType(type, context); }
|
||||
visitBuiltinType(type: BuiltinType, context: any): any { return this.visitType(type, context); }
|
||||
visitExpressionType(type: ExpressionType, context: any): any {
|
||||
type.value.visitExpression(this, context);
|
||||
return this.visitType(type, context);
|
||||
@ -1369,9 +1369,9 @@ export function assertNotNull(
|
||||
}
|
||||
|
||||
export function fn(
|
||||
params: FnParam[], body: Statement[], type?: Type | null,
|
||||
sourceSpan?: ParseSourceSpan | null): FunctionExpr {
|
||||
return new FunctionExpr(params, body, type, sourceSpan);
|
||||
params: FnParam[], body: Statement[], type?: Type | null, sourceSpan?: ParseSourceSpan | null,
|
||||
name?: string | null): FunctionExpr {
|
||||
return new FunctionExpr(params, body, type, sourceSpan, name);
|
||||
}
|
||||
|
||||
export function ifStmt(condition: Expression, thenClause: Statement[], elseClause?: Statement[]) {
|
||||
|
@ -269,15 +269,23 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
}
|
||||
|
||||
visitFunctionExpr(ast: o.FunctionExpr, ctx: EmitterVisitorContext): any {
|
||||
if (ast.name) {
|
||||
ctx.print(ast, 'function ');
|
||||
ctx.print(ast, ast.name);
|
||||
}
|
||||
ctx.print(ast, `(`);
|
||||
this._visitParams(ast.params, ctx);
|
||||
ctx.print(ast, `)`);
|
||||
this._printColonType(ast.type, ctx, 'void');
|
||||
ctx.println(ast, ` => {`);
|
||||
if (!ast.name) {
|
||||
ctx.print(ast, ` => `);
|
||||
}
|
||||
ctx.println(ast, '{');
|
||||
ctx.incIndent();
|
||||
this.visitAllStatements(ast.statements, ctx);
|
||||
ctx.decIndent();
|
||||
ctx.print(ast, `}`);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -314,7 +322,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
return null;
|
||||
}
|
||||
|
||||
visitBuiltintType(type: o.BuiltinType, ctx: EmitterVisitorContext): any {
|
||||
visitBuiltinType(type: o.BuiltinType, ctx: EmitterVisitorContext): any {
|
||||
let typeStr: string;
|
||||
switch (type.name) {
|
||||
case o.BuiltinTypeName.Bool:
|
||||
|
Reference in New Issue
Block a user