stef2nice
stef2nice

Reputation: 11

How to create an instanceof AST node using typescript compiler API

I would like to represent the typescript code "MyObj instanceOf MyClass" with the typescript compiler API.

I try to use the createBinary API as follow:

ts.createBinary(leftExpression,ts.SyntaxKind.InstanceOfKeyword, rightExpression);

How do I create the rightExpression?

Upvotes: 1

Views: 172

Answers (1)

David Sherret
David Sherret

Reputation: 106640

The left and right expressions are identifiers, so the createIdentifier method could be used:

const binaryExpression = ts.createBinary(ts.createIdentifier("MyObj"),
    ts.SyntaxKind.InstanceOfKeyword,
    ts.createIdentifier("MyClass"));

Upvotes: 1

Related Questions