Skip to content

Commit 2d19e71

Browse files
committed
refactor(transpiler): instanceof
1 parent c7e9d10 commit 2d19e71

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {INSTANCEOF} from 'traceur/src/syntax/TokenType';
2-
32
import {ParseTreeTransformer} from './ParseTreeTransformer';
3+
import {
4+
createBinaryExpression,
5+
createOperatorToken
6+
} from 'traceur/src/codegeneration/ParseTreeFactory';
47

58
/**
69
* Transforms `a instanceof b` to `a is b`,
@@ -11,15 +14,12 @@ export class InstanceOfTransformer extends ParseTreeTransformer {
1114
* @return {ParseTree}
1215
*/
1316
transformBinaryExpression(tree) {
14-
tree.left = this.transformAny(tree.left);
15-
tree.right = this.transformAny(tree.right);
17+
tree = super(tree);
1618

17-
if (tree.operator.type === 'instanceof') {
18-
// TODO(vojta): do this in a cleaner way.
19-
tree.operator.type = 'is';
20-
return tree;
19+
if (tree.operator.type === INSTANCEOF) {
20+
return createBinaryExpression(tree.left, createOperatorToken('is'), tree.right);
2121
}
2222

2323
return tree;
2424
}
25-
}
25+
}

0 commit comments

Comments
 (0)