Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Syntax } from 'esprima';
import * as estree from 'estree';
import NodeMutator from './NodeMutator';
import { IdentifiedNode } from './IdentifiedNode';
export default class BinaryOperatorMutator implements NodeMutator {
public name = 'BinaryOperator';
private readonly type = Syntax.BinaryExpression;
private readonly operators: { [targetedOperator: string]: estree.BinaryOperator | estree.BinaryOperator[] } = {
'!=': '==',
'!==': '===',
'%': '*',
'*': '/',
'+': '-',
'-': '+',
'/': '*',
'<': ['<=', '>='],
'<=': ['<', '>'],
'==': '!=',
'===': '!==',
'>': ['>=', '<='],
'>=': ['>', '<']
};
constructor() {
super('ConditionalBoundary', [Syntax.BinaryExpression], {
'<': '<=',
'<=': '<',
'>': '>=',
'>=': '>'
});
}
constructor () {
super('Math', [Syntax.BinaryExpression], {
'+': '-',
'-': '+',
'*': '/',
'/': '*',
'%': '*'});
}