diff --git a/packages/webcrack/src/unminify/test/invert-boolean-logic.test.ts b/packages/webcrack/src/unminify/test/invert-boolean-logic.test.ts index 7f97cbcd..15052cf7 100644 --- a/packages/webcrack/src/unminify/test/invert-boolean-logic.test.ts +++ b/packages/webcrack/src/unminify/test/invert-boolean-logic.test.ts @@ -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;`)); diff --git a/packages/webcrack/src/unminify/transforms/invert-boolean-logic.ts b/packages/webcrack/src/unminify/transforms/invert-boolean-logic.ts index b6c2e913..9d70e553 100644 --- a/packages/webcrack/src/unminify/transforms/invert-boolean-logic.ts +++ b/packages/webcrack/src/unminify/transforms/invert-boolean-logic.ts @@ -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 = {