refactor(transpiler): instanceof
This commit is contained in:
parent
c7e9d10f0b
commit
2d19e7122b
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue