From 6209b65a36b42c65e57e6af024339bf7cd5d9944 Mon Sep 17 00:00:00 2001 From: joeduffy Date: Sat, 21 Jan 2017 12:14:25 -0800 Subject: [PATCH] Serialize return types as proper AST tokens --- tools/mujs/lib/compiler/transform.ts | 12 +++++++++--- tools/mujs/tests/output/scenarios/point/Mu.out.json | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/mujs/lib/compiler/transform.ts b/tools/mujs/lib/compiler/transform.ts index 85ea89a1d..edfb31502 100644 --- a/tools/mujs/lib/compiler/transform.ts +++ b/tools/mujs/lib/compiler/transform.ts @@ -121,7 +121,7 @@ interface FunctionLikeDeclaration { name: ast.Identifier; parameters: ast.LocalVariable[]; body?: ast.Block; - returnType?: symbols.TypeToken; + returnType?: ast.TypeToken; } // TypeLike is any interface that has a possible TypeNode attached to it and can be queried for binding information. @@ -1035,10 +1035,16 @@ export class Transformer { } // Get the signature so that we can fetch the return type. - let returnType: symbols.TypeToken | undefined; + let returnType: ast.TypeToken | undefined; if (node.kind !== ts.SyntaxKind.Constructor) { let signature: ts.Signature = this.checker().getSignatureFromDeclaration(node); - returnType = this.resolveTypeToken(signature.getReturnType()); + let typeToken: symbols.TypeToken | undefined = this.resolveTypeToken(signature.getReturnType()); + if (typeToken) { + returnType = { + kind: ast.typeTokenKind, + tok: typeToken, + }; + } } // Delegate to the factory method to turn this into a real function object. diff --git a/tools/mujs/tests/output/scenarios/point/Mu.out.json b/tools/mujs/tests/output/scenarios/point/Mu.out.json index e95c193f9..d0054941a 100644 --- a/tools/mujs/tests/output/scenarios/point/Mu.out.json +++ b/tools/mujs/tests/output/scenarios/point/Mu.out.json @@ -697,7 +697,10 @@ } } }, - "returnType": "Point", + "returnType": { + "kind": "TypeToken", + "tok": "Point" + }, "static": false, "abstract": false, "loc": {