From a1b56f14dd78c68c4cfc4e2470ba4d6a47adc670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=A4llberg?= Date: Mon, 29 Apr 2024 04:54:21 +0200 Subject: [PATCH] fix: make isIIFE match what it claims to match More specifically !function(){...}() wasn't matched, only !function(){...} which isn't an IIFE --- packages/ast-utils/src/matchers/isIIFE.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ast-utils/src/matchers/isIIFE.ts b/packages/ast-utils/src/matchers/isIIFE.ts index 48fbe631..940e3224 100644 --- a/packages/ast-utils/src/matchers/isIIFE.ts +++ b/packages/ast-utils/src/matchers/isIIFE.ts @@ -33,15 +33,15 @@ export function isStatementIIFE(j: JSCodeshift, node: Statement): node is Expres * ``` */ export function isIIFE(j: JSCodeshift, node: ASTNode): node is ExpressionStatement { + if (j.UnaryExpression.check(node) && node.operator === '!') { + node = node.argument + } + if (j.CallExpression.check(node)) { return j.FunctionExpression.check(node.callee) || j.ArrowFunctionExpression.check(node.callee) } - if (j.UnaryExpression.check(node) && node.operator === '!') { - return j.FunctionExpression.check(node.argument) - } - return false }