diff --git a/tools/transpiler/src/codegeneration/InstanceOfTransformer.js b/tools/transpiler/src/codegeneration/InstanceOfTransformer.js index b5d0204aa0..0b3b299bc2 100644 --- a/tools/transpiler/src/codegeneration/InstanceOfTransformer.js +++ b/tools/transpiler/src/codegeneration/InstanceOfTransformer.js @@ -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,15 +14,12 @@ 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; } -} \ No newline at end of file +}