refactor(transpiler): instanceof

This commit is contained in:
Vojta Jina 2014-10-09 14:04:25 -07:00
parent c7e9d10f0b
commit 2d19e7122b
1 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,9 @@
import {INSTANCEOF} from 'traceur/src/syntax/TokenType'; import {INSTANCEOF} from 'traceur/src/syntax/TokenType';
import {ParseTreeTransformer} from './ParseTreeTransformer'; import {ParseTreeTransformer} from './ParseTreeTransformer';
import {
createBinaryExpression,
createOperatorToken
} from 'traceur/src/codegeneration/ParseTreeFactory';
/** /**
* Transforms `a instanceof b` to `a is b`, * Transforms `a instanceof b` to `a is b`,
@ -11,13 +14,10 @@ export class InstanceOfTransformer extends ParseTreeTransformer {
* @return {ParseTree} * @return {ParseTree}
*/ */
transformBinaryExpression(tree) { transformBinaryExpression(tree) {
tree.left = this.transformAny(tree.left); tree = super(tree);
tree.right = this.transformAny(tree.right);
if (tree.operator.type === 'instanceof') { if (tree.operator.type === INSTANCEOF) {
// TODO(vojta): do this in a cleaner way. return createBinaryExpression(tree.left, createOperatorToken('is'), tree.right);
tree.operator.type = 'is';
return tree;
} }
return tree; return tree;