deflake 1.2.38 → 1.2.39

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.
Files changed (2) hide show
  1. package/cli.js +38 -3
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -333,9 +333,44 @@ async function applyFix(res, loc, backups = new Map()) {
333
333
  lines.splice(p.line, 0, cleanLine);
334
334
  console.log(` ${C.GREEN}+ Line ${p.line + 1}: ${cleanLine.trim()}${C.RESET}`);
335
335
  } else {
336
- lines[idx] = cleanLine;
337
- console.log(` ${C.RED}- Line ${p.line}: ${originalLine.trim()}${C.RESET}`);
338
- console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
336
+ // REPLACE action
337
+ // SMART: Handle multi-line expression replacement
338
+ // If the original line starts a multi-line expression (has unclosed parens)
339
+ // and the replacement is a complete statement, remove continuation lines
340
+ const origOpen = (originalLine.match(/\(/g) || []).length;
341
+ const origClose = (originalLine.match(/\)/g) || []).length;
342
+ const replOpen = (cleanLine.match(/\(/g) || []).length;
343
+ const replClose = (cleanLine.match(/\)/g) || []).length;
344
+
345
+ if (origOpen > origClose && replOpen <= replClose) {
346
+ // Original has unclosed parens, replacement is complete
347
+ // Find the closing of the multi-line expression
348
+ let depth = origOpen - origClose;
349
+ let endIdx = idx;
350
+ for (let j = idx + 1; j < lines.length && depth > 0; j++) {
351
+ const lo = (lines[j].match(/\(/g) || []).length;
352
+ const lc = (lines[j].match(/\)/g) || []).length;
353
+ depth += lo - lc;
354
+ endIdx = j;
355
+ }
356
+ if (endIdx > idx) {
357
+ const removedLines = endIdx - idx;
358
+ console.log(` ${C.GRAY}🔧 Expanding REPLACE to cover ${removedLines + 1}-line expression (lines ${p.line}-${endIdx + 1})${C.RESET}`);
359
+ for (let j = idx; j <= endIdx; j++) {
360
+ console.log(` ${C.RED}- Line ${j + 1}: ${lines[j].trim()}${C.RESET}`);
361
+ }
362
+ lines.splice(idx, endIdx - idx + 1, cleanLine);
363
+ console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
364
+ } else {
365
+ lines[idx] = cleanLine;
366
+ console.log(` ${C.RED}- Line ${p.line}: ${originalLine.trim()}${C.RESET}`);
367
+ console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
368
+ }
369
+ } else {
370
+ lines[idx] = cleanLine;
371
+ console.log(` ${C.RED}- Line ${p.line}: ${originalLine.trim()}${C.RESET}`);
372
+ console.log(` ${C.GREEN}+ Line ${p.line}: ${cleanLine.trim()}${C.RESET}`);
373
+ }
339
374
  }
340
375
  content = lines.join('\n');
341
376
  appliedCount++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deflake",
3
- "version": "1.2.38",
3
+ "version": "1.2.39",
4
4
  "description": "AI-powered self-healing tool for Playwright, Cypress, and WebdriverIO tests.",
5
5
  "main": "client.js",
6
6
  "bin": {