Skip to content

Commit

Permalink
fix: don't invert relational operators
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jun 3, 2024
1 parent 4b883a0 commit 67918d7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
11 changes: 0 additions & 11 deletions packages/webcrack/src/unminify/test/invert-boolean-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ test('not equal', () =>
test('not strict equal', () =>
expectJS('!(a !== b);').toMatchInlineSnapshot(`a === b;`));

test('greater than', () =>
expectJS('!(a > b);').toMatchInlineSnapshot(`a <= b;`));

test('less than', () => expectJS('!(a < b);').toMatchInlineSnapshot(`a >= b;`));

test('greater than or equal', () =>
expectJS('!(a >= b);').toMatchInlineSnapshot(`a < b;`));

test('less than or equal', () =>
expectJS('!(a <= b);').toMatchInlineSnapshot(`a > b;`));

test('logical or', () =>
expectJS('!(a || b || c);').toMatchInlineSnapshot(`!a && !b && !c;`));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import * as t from '@babel/types';
import * as m from '@codemod/matchers';
import type { Transform } from '../../ast-utils';

// >, >=, <, <= are not invertible because NaN <= 0 is false and NaN > 0 is false
// https://tc39.es/ecma262/multipage/abstract-operations.html#sec-islessthan

const INVERTED_BINARY_OPERATORS = {
'==': '!=',
'===': '!==',
'!=': '==',
'!==': '===',
'>': '<=',
'<': '>=',
'>=': '<',
'<=': '>',
} as const;

const INVERTED_LOGICAL_OPERATORS = {
Expand Down

0 comments on commit 67918d7

Please sign in to comment.