Skip to content

Commit 8459346

Browse files
committed
fix: restructure isReactHook condition to prevent Babel from mangling operator precedence
Extracting to a const variable prevents Babel from stripping the parentheses around the && group within the || chain in isFetchCallProperlyHandled, which would have caused any line containing 'const' to incorrectly match as a function start.
1 parent 5aadb9d commit 8459346

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

ai-slop-detector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,11 @@ class AISlopDetector {
536536
// Look backwards to find the start of the function
537537
for (let i = fetchLineIndex; i >= Math.max(0, fetchLineIndex - 20); i--) {
538538
const line = lines[i];
539+
const isReactHook = line.includes('const') && (line.includes('useState') || line.includes('useEffect') || line.includes('useCallback') || line.includes('useMemo'));
539540
if (line.includes('async function') ||
540541
line.includes('function') ||
541542
line.includes('=>') ||
542-
(line.includes('const') && (line.includes('useState') || line.includes('useEffect') || line.includes('useCallback') || line.includes('useMemo'))) ||
543+
isReactHook ||
543544
line.includes('export default function')) {
544545
// Check if this looks like the start of our function
545546
if (line.includes('{') || line.includes('=>')) {

karpeslop-bin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ class AISlopDetector {
434434
// Look backwards to find the start of the function
435435
for (let i = fetchLineIndex; i >= Math.max(0, fetchLineIndex - 20); i--) {
436436
const line = lines[i];
437-
if (line.includes('async function') || line.includes('function') || line.includes('=>') || line.includes('const') && (line.includes('useState') || line.includes('useEffect') || line.includes('useCallback') || line.includes('useMemo')) || line.includes('export default function')) {
437+
const isReactHook = line.includes('const') && (line.includes('useState') || line.includes('useEffect') || line.includes('useCallback') || line.includes('useMemo'));
438+
if (line.includes('async function') || line.includes('function') || line.includes('=>') || isReactHook || line.includes('export default function')) {
438439
// Check if this looks like the start of our function
439440
if (line.includes('{') || line.includes('=>')) {
440441
functionStart = i;

0 commit comments

Comments
 (0)