All files / src/compiler/phases/3-transform/client/visitors BinaryExpression.js

80.55% Statements 29/36
87.5% Branches 7/8
100% Functions 1/1
79.41% Lines 27/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 352x 2x 2x 2x 2x 2x 2x 2x 2x 2x 877x 17x 17x 17x 10x 10x 10x 10x 10x 10x 10x 7x 17x               17x 867x 867x 867x  
/** @import { Expression, BinaryExpression } from 'estree' */
/** @import { ComponentContext } from '../types' */
import { dev } from '../../../../state.js';
import * as b from '../../../../utils/builders.js';
 
/**
 * @param {BinaryExpression} node
 * @param {ComponentContext} context
 */
export function BinaryExpression(node, context) {
	if (dev) {
		const operator = node.operator;
 
		if (operator === '===' || operator === '!==') {
			return b.call(
				'$.strict_equals',
				/** @type {Expression} */ (context.visit(node.left)),
				/** @type {Expression} */ (context.visit(node.right)),
				operator === '!==' && b.literal(false)
			);
		}
 
		if (operator === '==' || operator === '!=') {
			return b.call(
				'$.equals',
				/** @type {Expression} */ (context.visit(node.left)),
				/** @type {Expression} */ (context.visit(node.right)),
				operator === '!=' && b.literal(false)
			);
		}
	}
 
	context.next();
}