1
0
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-07-30 13:42:12 +00:00

Initial implementation of 'instanceof'

Works like an assignability check for now / does not yet honor nullables.
This commit is contained in:
dcodeIO
2018-06-07 17:04:41 +02:00
parent cea69a6de1
commit 7478c8a0d3
9 changed files with 472 additions and 4 deletions

@@ -3108,7 +3108,7 @@ export class Parser extends DiagnosticEmitter {
switch (token) {
// AssertionExpression
case Token.AS: {
let toType = this.parseType(tn);
let toType = this.parseType(tn); // reports
if (!toType) return null;
expr = Node.createAssertionExpression(
AssertionKind.AS,
@@ -3118,9 +3118,20 @@ export class Parser extends DiagnosticEmitter {
);
break;
}
// InstanceOfExpression
case Token.INSTANCEOF: {
let isType = this.parseType(tn); // reports
if (!isType) return null;
expr = Node.createInstanceOfExpression(
expr,
isType,
tn.range(startPos, tn.pos)
);
break;
}
// ElementAccessExpression
case Token.OPENBRACKET: {
next = this.parseExpression(tn);
next = this.parseExpression(tn); // reports
if (!next) return null;
if (!tn.skip(Token.CLOSEBRACKET)) {
this.error(