es-check 9.7.1 → 9.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1609,16 +1609,49 @@ function getTypeofComparisonGuardBranch(comparison) {
1609
1609
 
1610
1610
  function getTypeofComparison(node) {
1611
1611
  if (node.type !== "BinaryExpression") return null;
1612
- if (!isTypeofComparisonOperator(node.operator)) return null;
1613
1612
 
1614
1613
  const leftComparison = getTypeofComparisonSide(node.left, node.right);
1615
1614
  if (leftComparison) {
1616
- return Object.assign({}, leftComparison, { operator: node.operator });
1615
+ return normalizeTypeofComparison(leftComparison, node.operator);
1617
1616
  }
1618
1617
 
1619
1618
  const rightComparison = getTypeofComparisonSide(node.right, node.left);
1620
- if (!rightComparison) return null;
1621
- return Object.assign({}, rightComparison, { operator: node.operator });
1619
+ if (rightComparison) {
1620
+ return normalizeTypeofComparison(rightComparison, node.operator, true);
1621
+ }
1622
+ return getBooleanTypeofComparison(node);
1623
+ }
1624
+
1625
+ function getBooleanTypeofComparison(node) {
1626
+ if (!isTypeofComparisonOperator(node.operator)) return null;
1627
+
1628
+ const isLeftBoolean = typeof node.left.value === "boolean";
1629
+ const valueNode = isLeftBoolean ? node.left : node.right;
1630
+ const expression = isLeftBoolean ? node.right : node.left;
1631
+ const isBoolean = valueNode.type === "Literal" && typeof valueNode.value === "boolean";
1632
+ if (!isBoolean) return null;
1633
+
1634
+ const comparison = getTypeofComparison(expression);
1635
+ if (!comparison) return null;
1636
+ const isEqual = node.operator === "===" || node.operator === "==";
1637
+ const preservesPolarity = isEqual === valueNode.value;
1638
+ const guardedBranch = getTypeofComparisonGuardBranch(comparison) === preservesPolarity;
1639
+ const operator = guardedBranch ? "!==" : "===";
1640
+ return { name: comparison.name, value: "undefined", operator };
1641
+ }
1642
+
1643
+ function normalizeTypeofComparison(comparison, operator, isReversed = false) {
1644
+ if (isTypeofComparisonOperator(operator)) {
1645
+ return Object.assign({}, comparison, { operator });
1646
+ }
1647
+
1648
+ const isRelational = operator === "<" || operator === ">";
1649
+ const isMinifiedGuard = isRelational && comparison.value === "u";
1650
+ if (!isMinifiedGuard) return null;
1651
+
1652
+ const isUndefined = (operator === ">") !== isReversed;
1653
+ const normalizedOperator = isUndefined ? "===" : "!==";
1654
+ return Object.assign({}, comparison, { value: "undefined", operator: normalizedOperator });
1622
1655
  }
1623
1656
 
1624
1657
  function isTypeofComparisonOperator(operator) {
@@ -1666,6 +1699,7 @@ function isFalseLiteral(node) {
1666
1699
  }
1667
1700
 
1668
1701
  function shouldSkipBranchGuard(node, branchValue) {
1702
+ if (node.type === "BinaryExpression") return true;
1669
1703
  const isLogical = node.type === "LogicalExpression";
1670
1704
  if (!isLogical) return false;
1671
1705
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-check",
3
- "version": "9.7.1",
3
+ "version": "9.7.2",
4
4
  "description": "Checks the ECMAScript version of .js glob against a specified version of ECMAScript with a shell command",
5
5
  "keywords": [
6
6
  "check for es6",