diff --git a/tools/mujs/lib/compiler/transform.ts b/tools/mujs/lib/compiler/transform.ts index 1ab059f41..e71cb75b0 100644 --- a/tools/mujs/lib/compiler/transform.ts +++ b/tools/mujs/lib/compiler/transform.ts @@ -216,6 +216,11 @@ export class Transformer { return this.withLocation(node, ident(node.text)); } + private transformTypeNode(node: ts.TypeNode | undefined): symbols.TypeToken { + // TODO[marapongo/mu#46]: emit strong typing information. + return "any"; + } + /** Modules **/ // This transforms top-level TypeScript module elements into their corresponding nodes. This transformation @@ -628,7 +633,7 @@ export class Transformer { name: name, parameters: parameters.map((p: VariableDeclaration) => p.variable), body: body, - returnType: "TODO", + returnType: this.transformTypeNode(node.type), }; } @@ -701,14 +706,21 @@ export class Transformer { variable: { kind: ast.localVariableKind, name: name, - type: "TODO", + type: this.transformTypeNode(node.type), }, initializer: initializer, }; } + // transformTypeAliasDeclaration emits a type whose base is the aliased type. The MuIL type system permits + // conversions between such types in a way that is roughly compatible with TypeScript's notion of type aliases. private transformTypeAliasDeclaration(node: ts.TypeAliasDeclaration, access: symbols.Accessibility): ast.Class { - return contract.fail("NYI"); + return this.withLocation(node, { + kind: ast.classKind, + name: this.transformIdentifier(node.name), + access: access, + extends: this.transformTypeNode(node.type), + }); } private makeVariableInitializer(decl: VariableDeclaration): ast.Statement { @@ -812,7 +824,7 @@ export class Transformer { } return { name: name, - type: "TODO", + type: this.transformTypeNode(node.type), initializer: initializer, }; } @@ -911,7 +923,7 @@ export class Transformer { access: this.getClassAccessibility(node), readonly: !!(mods & ts.ModifierFlags.Readonly), static: !!(mods & ts.ModifierFlags.Static), - type: "TODO", + type: this.transformTypeNode(node.type), }, false, initializer, diff --git a/tools/mujs/tests/output/modules/func_1/Mu.out.json b/tools/mujs/tests/output/modules/func_1/Mu.out.json index da6c716ab..e667fc8b6 100644 --- a/tools/mujs/tests/output/modules/func_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/func_1/Mu.out.json @@ -44,7 +44,7 @@ } } }, - "type": "TODO" + "type": "any" }, { "kind": "LocalVariable", @@ -63,7 +63,7 @@ } } }, - "type": "TODO" + "type": "any" } ], "body": { @@ -81,7 +81,7 @@ } } }, - "returnType": "TODO", + "returnType": "any", "loc": { "file": "index.ts", "start": { diff --git a/tools/mujs/tests/output/modules/func_exp_1/Mu.out.json b/tools/mujs/tests/output/modules/func_exp_1/Mu.out.json index 68cfc3276..9ae731393 100644 --- a/tools/mujs/tests/output/modules/func_exp_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/func_exp_1/Mu.out.json @@ -44,7 +44,7 @@ } } }, - "type": "TODO" + "type": "any" }, { "kind": "LocalVariable", @@ -63,7 +63,7 @@ } } }, - "type": "TODO" + "type": "any" } ], "body": { @@ -81,7 +81,7 @@ } } }, - "returnType": "TODO", + "returnType": "any", "loc": { "file": "index.ts", "start": { diff --git a/tools/mujs/tests/output/modules/func_exp_def_1/Mu.out.json b/tools/mujs/tests/output/modules/func_exp_def_1/Mu.out.json index f99435135..cd15210c1 100644 --- a/tools/mujs/tests/output/modules/func_exp_def_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/func_exp_def_1/Mu.out.json @@ -33,7 +33,7 @@ } } }, - "type": "TODO" + "type": "any" }, { "kind": "LocalVariable", @@ -52,7 +52,7 @@ } } }, - "type": "TODO" + "type": "any" } ], "body": { @@ -70,7 +70,7 @@ } } }, - "returnType": "TODO", + "returnType": "any", "loc": { "file": "index.ts", "start": { diff --git a/tools/mujs/tests/output/modules/var_1/Mu.out.json b/tools/mujs/tests/output/modules/var_1/Mu.out.json index ab4740fd4..7a8a5d83e 100644 --- a/tools/mujs/tests/output/modules/var_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/var_1/Mu.out.json @@ -26,7 +26,7 @@ } }, "access": "private", - "type": "TODO" + "type": "any" }, ".init": { "kind": "ModuleMethod", diff --git a/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json b/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json index 46dda09e9..aa5934880 100644 --- a/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json @@ -26,7 +26,7 @@ } }, "access": "public", - "type": "TODO" + "type": "any" }, ".init": { "kind": "ModuleMethod", diff --git a/tools/mujs/tests/output/scenarios/point/Mu.out.json b/tools/mujs/tests/output/scenarios/point/Mu.out.json index b2b2ce149..32ddf7f90 100644 --- a/tools/mujs/tests/output/scenarios/point/Mu.out.json +++ b/tools/mujs/tests/output/scenarios/point/Mu.out.json @@ -52,7 +52,7 @@ } } }, - "type": "TODO" + "type": "any" }, { "kind": "LocalVariable", @@ -71,7 +71,7 @@ } } }, - "type": "TODO" + "type": "any" } ], "body": { @@ -272,7 +272,7 @@ } } }, - "returnType": "TODO", + "returnType": "any", "static": false, "abstract": false, "loc": { @@ -323,7 +323,7 @@ } } }, - "type": "TODO" + "type": "any" } ], "body": { @@ -599,7 +599,7 @@ } } }, - "returnType": "TODO", + "returnType": "any", "static": false, "abstract": false, "loc": { @@ -634,7 +634,7 @@ "access": "public", "readonly": true, "static": false, - "type": "TODO" + "type": "any" }, "y": { "kind": "ClassProperty", @@ -656,7 +656,7 @@ "access": "public", "readonly": true, "static": false, - "type": "TODO" + "type": "any" } }, "abstract": false,