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