Fix a problem with identifiers as expressions
MuIL doesn't support identifiers as expressions; instead, an explicit LoadLocationExpression is required. There was a problem in the current MuJS translation process -- masked by TypeScript silently duck typing from Identifier to Expression -- but our Mu decoding library discovered it. This fixes the problem by wrapping Identifiers used in Expression positions in a proper LoadLocationExpression node.
This commit is contained in:
parent
96c7f4fa52
commit
908522aa0f
2 changed files with 73 additions and 12 deletions
|
@ -379,7 +379,7 @@ export class Transformer {
|
||||||
return symbols.anyType;
|
return symbols.anyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transformIdentifier takes a TypeScript identifier node and yields a true MuIL identifier.
|
||||||
private transformIdentifier(node: ts.Identifier): ast.Identifier {
|
private transformIdentifier(node: ts.Identifier): ast.Identifier {
|
||||||
return this.withLocation(node, ident(node.text));
|
return this.withLocation(node, ident(node.text));
|
||||||
}
|
}
|
||||||
|
@ -872,7 +872,7 @@ export class Transformer {
|
||||||
private transformDeclarationIdentifier(node: ts.DeclarationName): ast.Identifier {
|
private transformDeclarationIdentifier(node: ts.DeclarationName): ast.Identifier {
|
||||||
switch (node.kind) {
|
switch (node.kind) {
|
||||||
case ts.SyntaxKind.Identifier:
|
case ts.SyntaxKind.Identifier:
|
||||||
return this.transformIdentifierExpression(node);
|
return this.transformIdentifier(node);
|
||||||
default:
|
default:
|
||||||
return contract.fail(`Unrecognized declaration identifier: ${ts.SyntaxKind[node.kind]}`);
|
return contract.fail(`Unrecognized declaration identifier: ${ts.SyntaxKind[node.kind]}`);
|
||||||
}
|
}
|
||||||
|
@ -1866,8 +1866,13 @@ export class Transformer {
|
||||||
return notYetImplemented(node);
|
return notYetImplemented(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
private transformIdentifierExpression(node: ts.Identifier): ast.Identifier {
|
// transformIdentifierExpression takes a TypeScript identifier node and yields a MuIL expression. This expression,
|
||||||
return this.withLocation(node, ident(node.text));
|
// when evaluated, will load the value of the target identifier, so that it's suitable as an expression node.
|
||||||
|
private transformIdentifierExpression(node: ts.Identifier): ast.Expression {
|
||||||
|
return this.withLocation(node, <ast.LoadLocationExpression>{
|
||||||
|
kind: ast.loadLocationExpressionKind,
|
||||||
|
name: this.transformIdentifier(node),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private transformObjectBindingPattern(node: ts.ObjectBindingPattern): ast.Expression {
|
private transformObjectBindingPattern(node: ts.ObjectBindingPattern): ast.Expression {
|
||||||
|
|
|
@ -130,8 +130,22 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"right": {
|
"right": {
|
||||||
"kind": "Identifier",
|
"kind": "LoadLocationExpression",
|
||||||
"ident": "x",
|
"name": {
|
||||||
|
"kind": "Identifier",
|
||||||
|
"ident": "x",
|
||||||
|
"loc": {
|
||||||
|
"file": "index.ts",
|
||||||
|
"start": {
|
||||||
|
"line": 9,
|
||||||
|
"column": 17
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 9,
|
||||||
|
"column": 18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
@ -221,8 +235,22 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"right": {
|
"right": {
|
||||||
"kind": "Identifier",
|
"kind": "LoadLocationExpression",
|
||||||
"ident": "y",
|
"name": {
|
||||||
|
"kind": "Identifier",
|
||||||
|
"ident": "y",
|
||||||
|
"loc": {
|
||||||
|
"file": "index.ts",
|
||||||
|
"start": {
|
||||||
|
"line": 10,
|
||||||
|
"column": 17
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 10,
|
||||||
|
"column": 18
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
@ -402,8 +430,22 @@
|
||||||
"right": {
|
"right": {
|
||||||
"kind": "LoadLocationExpression",
|
"kind": "LoadLocationExpression",
|
||||||
"object": {
|
"object": {
|
||||||
"kind": "Identifier",
|
"kind": "LoadLocationExpression",
|
||||||
"ident": "other",
|
"name": {
|
||||||
|
"kind": "Identifier",
|
||||||
|
"ident": "other",
|
||||||
|
"loc": {
|
||||||
|
"file": "index.ts",
|
||||||
|
"start": {
|
||||||
|
"line": 14,
|
||||||
|
"column": 34
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 14,
|
||||||
|
"column": 39
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
@ -508,8 +550,22 @@
|
||||||
"right": {
|
"right": {
|
||||||
"kind": "LoadLocationExpression",
|
"kind": "LoadLocationExpression",
|
||||||
"object": {
|
"object": {
|
||||||
"kind": "Identifier",
|
"kind": "LoadLocationExpression",
|
||||||
"ident": "other",
|
"name": {
|
||||||
|
"kind": "Identifier",
|
||||||
|
"ident": "other",
|
||||||
|
"loc": {
|
||||||
|
"file": "index.ts",
|
||||||
|
"start": {
|
||||||
|
"line": 14,
|
||||||
|
"column": 52
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 14,
|
||||||
|
"column": 57
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"loc": {
|
"loc": {
|
||||||
"file": "index.ts",
|
"file": "index.ts",
|
||||||
"start": {
|
"start": {
|
||||||
|
|
Loading…
Reference in a new issue