Implement TypeOf expressions
This commit is contained in:
parent
bd8faf313f
commit
2af011d6ab
3 changed files with 16 additions and 6 deletions
|
@ -622,8 +622,8 @@ func (a *astBinder) checkCastExpression(node *ast.CastExpression) {
|
|||
}
|
||||
|
||||
func (a *astBinder) checkTypeOfExpression(node *ast.TypeOfExpression) {
|
||||
// TODO: not sure; a string?
|
||||
contract.Failf("Binding of %v nodes not yet implemented", node.GetKind())
|
||||
// A typeof produces a string representation of the expression's type.
|
||||
a.b.ctx.RegisterType(node, types.String)
|
||||
}
|
||||
|
||||
func (a *astBinder) checkConditionalExpression(node *ast.ConditionalExpression) {
|
||||
|
|
|
@ -1637,8 +1637,15 @@ func (e *evaluator) evalIsInstExpression(node *ast.IsInstExpression) (*rt.Object
|
|||
}
|
||||
|
||||
func (e *evaluator) evalTypeOfExpression(node *ast.TypeOfExpression) (*rt.Object, *rt.Unwind) {
|
||||
contract.Failf("Evaluation of %v nodes not yet implemented", reflect.TypeOf(node))
|
||||
return nil, nil
|
||||
// Evaluate the underlying expression.
|
||||
obj, uw := e.evalExpression(node.Expression)
|
||||
if uw != nil {
|
||||
return nil, uw
|
||||
}
|
||||
|
||||
// Now just return the underlying type token for the object as a string.
|
||||
tok := obj.Type().Token()
|
||||
return e.alloc.NewString(string(tok)), nil
|
||||
}
|
||||
|
||||
func (e *evaluator) evalConditionalExpression(node *ast.ConditionalExpression) (*rt.Object, *rt.Unwind) {
|
||||
|
|
|
@ -2830,8 +2830,11 @@ export class Transformer {
|
|||
});
|
||||
}
|
||||
|
||||
private transformTypeOfExpression(node: ts.TypeOfExpression): ast.Expression {
|
||||
return notYetImplemented(node);
|
||||
private async transformTypeOfExpression(node: ts.TypeOfExpression): Promise<ast.Expression> {
|
||||
return this.withLocation(node, <ast.TypeOfExpression>{
|
||||
kind: ast.typeOfExpressionKind,
|
||||
expression: await this.transformExpression(node.expression),
|
||||
});
|
||||
}
|
||||
|
||||
private transformVoidExpression(node: ts.VoidExpression): ast.Expression {
|
||||
|
|
Loading…
Reference in a new issue