Map type aliases
TypeScript type aliases simply turn into MuIL classes with the base class being the aliased type. In theory, MuIL conversions will support the kind of conversions offered by aliases (or at least get sufficiently close). We will need to tackle this in part by marapongo/mu#46. In addition, while I was in there, I cleaned up the type token emission to emit "any" (rather than "TODO") and to use a single, central function for all ts.TypeNodes. This will also get cleaned up by marapongo/mu#46.
This commit is contained in:
parent
3c76092d46
commit
c28cd6305e
7 changed files with 35 additions and 23 deletions
|
@ -216,6 +216,11 @@ export class Transformer {
|
||||||
return this.withLocation(node, ident(node.text));
|
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 **/
|
/** Modules **/
|
||||||
|
|
||||||
// This transforms top-level TypeScript module elements into their corresponding nodes. This transformation
|
// This transforms top-level TypeScript module elements into their corresponding nodes. This transformation
|
||||||
|
@ -628,7 +633,7 @@ export class Transformer {
|
||||||
name: name,
|
name: name,
|
||||||
parameters: parameters.map((p: VariableDeclaration<ast.LocalVariable>) => p.variable),
|
parameters: parameters.map((p: VariableDeclaration<ast.LocalVariable>) => p.variable),
|
||||||
body: body,
|
body: body,
|
||||||
returnType: "TODO",
|
returnType: this.transformTypeNode(node.type),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,14 +706,21 @@ export class Transformer {
|
||||||
variable: {
|
variable: {
|
||||||
kind: ast.localVariableKind,
|
kind: ast.localVariableKind,
|
||||||
name: name,
|
name: name,
|
||||||
type: "TODO",
|
type: this.transformTypeNode(node.type),
|
||||||
},
|
},
|
||||||
initializer: initializer,
|
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 {
|
private transformTypeAliasDeclaration(node: ts.TypeAliasDeclaration, access: symbols.Accessibility): ast.Class {
|
||||||
return contract.fail("NYI");
|
return this.withLocation(node, <ast.Class>{
|
||||||
|
kind: ast.classKind,
|
||||||
|
name: this.transformIdentifier(node.name),
|
||||||
|
access: access,
|
||||||
|
extends: this.transformTypeNode(node.type),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private makeVariableInitializer(decl: VariableDeclaration<ast.Variable>): ast.Statement {
|
private makeVariableInitializer(decl: VariableDeclaration<ast.Variable>): ast.Statement {
|
||||||
|
@ -812,7 +824,7 @@ export class Transformer {
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: name,
|
name: name,
|
||||||
type: "TODO",
|
type: this.transformTypeNode(node.type),
|
||||||
initializer: initializer,
|
initializer: initializer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -911,7 +923,7 @@ export class Transformer {
|
||||||
access: this.getClassAccessibility(node),
|
access: this.getClassAccessibility(node),
|
||||||
readonly: !!(mods & ts.ModifierFlags.Readonly),
|
readonly: !!(mods & ts.ModifierFlags.Readonly),
|
||||||
static: !!(mods & ts.ModifierFlags.Static),
|
static: !!(mods & ts.ModifierFlags.Static),
|
||||||
type: "TODO",
|
type: this.transformTypeNode(node.type),
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
initializer,
|
initializer,
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "LocalVariable",
|
"kind": "LocalVariable",
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returnType": "TODO",
|
"returnType": "any",
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "LocalVariable",
|
"kind": "LocalVariable",
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
@ -81,7 +81,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returnType": "TODO",
|
"returnType": "any",
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "LocalVariable",
|
"kind": "LocalVariable",
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
@ -70,7 +70,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returnType": "TODO",
|
"returnType": "any",
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"access": "private",
|
"access": "private",
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
".init": {
|
".init": {
|
||||||
"kind": "ModuleMethod",
|
"kind": "ModuleMethod",
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
".init": {
|
".init": {
|
||||||
"kind": "ModuleMethod",
|
"kind": "ModuleMethod",
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"kind": "LocalVariable",
|
"kind": "LocalVariable",
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
@ -272,7 +272,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returnType": "TODO",
|
"returnType": "any",
|
||||||
"static": false,
|
"static": false,
|
||||||
"abstract": false,
|
"abstract": false,
|
||||||
"loc": {
|
"loc": {
|
||||||
|
@ -323,7 +323,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"body": {
|
"body": {
|
||||||
|
@ -599,7 +599,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"returnType": "TODO",
|
"returnType": "any",
|
||||||
"static": false,
|
"static": false,
|
||||||
"abstract": false,
|
"abstract": false,
|
||||||
"loc": {
|
"loc": {
|
||||||
|
@ -634,7 +634,7 @@
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"readonly": true,
|
"readonly": true,
|
||||||
"static": false,
|
"static": false,
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
},
|
},
|
||||||
"y": {
|
"y": {
|
||||||
"kind": "ClassProperty",
|
"kind": "ClassProperty",
|
||||||
|
@ -656,7 +656,7 @@
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"readonly": true,
|
"readonly": true,
|
||||||
"static": false,
|
"static": false,
|
||||||
"type": "TODO"
|
"type": "any"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abstract": false,
|
"abstract": false,
|
||||||
|
|
Loading…
Reference in a new issue