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

80.55% Statements 29/36
85.71% Branches 6/7
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 856x 22x 22x 22x 11x 11x 11x 11x 11x 11x 11x 11x 22x               22x 845x 845x 845x  
/** @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();
}