@openrewrite/rewrite 8.67.0-20251112-160335 → 8.67.0-20251113-160321
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.
- package/dist/javascript/comparator.d.ts +64 -3
- package/dist/javascript/comparator.d.ts.map +1 -1
- package/dist/javascript/comparator.js +216 -155
- package/dist/javascript/comparator.js.map +1 -1
- package/dist/javascript/templating/comparator.d.ts +118 -9
- package/dist/javascript/templating/comparator.d.ts.map +1 -1
- package/dist/javascript/templating/comparator.js +821 -73
- package/dist/javascript/templating/comparator.js.map +1 -1
- package/dist/javascript/templating/index.d.ts +1 -1
- package/dist/javascript/templating/index.d.ts.map +1 -1
- package/dist/javascript/templating/index.js.map +1 -1
- package/dist/javascript/templating/pattern.d.ts +89 -5
- package/dist/javascript/templating/pattern.d.ts.map +1 -1
- package/dist/javascript/templating/pattern.js +442 -31
- package/dist/javascript/templating/pattern.js.map +1 -1
- package/dist/javascript/templating/types.d.ts +157 -1
- package/dist/javascript/templating/types.d.ts.map +1 -1
- package/dist/version.txt +1 -1
- package/package.json +1 -1
- package/src/javascript/comparator.ts +249 -169
- package/src/javascript/templating/comparator.ts +952 -87
- package/src/javascript/templating/index.ts +6 -1
- package/src/javascript/templating/pattern.ts +543 -23
- package/src/javascript/templating/types.ts +178 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import {Cursor, Tree} from '../..';
|
|
17
17
|
import {J, Type} from '../../java';
|
|
18
|
-
import type {
|
|
18
|
+
import type {Pattern} from "./pattern";
|
|
19
19
|
import type {Template} from "./template";
|
|
20
20
|
import type {CaptureValue, RawCode} from "./capture";
|
|
21
21
|
|
|
@@ -284,6 +284,49 @@ export interface PatternOptions {
|
|
|
284
284
|
* @default true (lenient matching enabled for backward compatibility)
|
|
285
285
|
*/
|
|
286
286
|
lenientTypeMatching?: boolean;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Enable debug logging for this pattern.
|
|
290
|
+
* When enabled, all match attempts will log detailed information to stderr,
|
|
291
|
+
* including the AST path traversed, mismatches encountered, and captured values.
|
|
292
|
+
*
|
|
293
|
+
* Can be overridden at the match() call level.
|
|
294
|
+
* Global debug can be enabled via PATTERN_DEBUG=true environment variable.
|
|
295
|
+
*
|
|
296
|
+
* Precedence: match() call > pattern configure() > PATTERN_DEBUG env var
|
|
297
|
+
*
|
|
298
|
+
* @default undefined (inherits from environment or match() call)
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* // Pattern-level debug
|
|
303
|
+
* const pat = pattern({ debug: true })`console.log(${value})`;
|
|
304
|
+
*
|
|
305
|
+
* // Disable debug for a noisy pattern when global debug is on
|
|
306
|
+
* const noisyPat = pattern({ debug: false })`import ${x} from ${y}`;
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
debug?: boolean;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Options for individual match() calls.
|
|
314
|
+
*/
|
|
315
|
+
export interface MatchOptions {
|
|
316
|
+
/**
|
|
317
|
+
* Enable debug logging for this specific match() call.
|
|
318
|
+
* Overrides pattern-level debug setting and global PATTERN_DEBUG env var.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* // Debug just this call
|
|
323
|
+
* const match = await pattern.match(node, cursor, { debug: true });
|
|
324
|
+
*
|
|
325
|
+
* // Disable debug for this call even if pattern or global debug is on
|
|
326
|
+
* const match = await pattern.match(node, cursor, { debug: false });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
debug?: boolean;
|
|
287
330
|
}
|
|
288
331
|
|
|
289
332
|
/**
|
|
@@ -495,3 +538,137 @@ export interface RewriteConfig {
|
|
|
495
538
|
*/
|
|
496
539
|
whereNot?: (node: J, cursor: Cursor) => boolean | Promise<boolean>;
|
|
497
540
|
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Options for debugging pattern matching.
|
|
544
|
+
* Used in Layer 1 (Core Instrumentation) to control debug output.
|
|
545
|
+
*/
|
|
546
|
+
export interface DebugOptions {
|
|
547
|
+
/**
|
|
548
|
+
* Enable detailed logging during pattern matching.
|
|
549
|
+
*/
|
|
550
|
+
enabled?: boolean;
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Log structural comparison steps.
|
|
554
|
+
*/
|
|
555
|
+
logComparison?: boolean;
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Log constraint evaluation.
|
|
559
|
+
*/
|
|
560
|
+
logConstraints?: boolean;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* A single debug log entry collected during pattern matching.
|
|
565
|
+
* Part of Layer 1 (Core Instrumentation).
|
|
566
|
+
*/
|
|
567
|
+
export interface DebugLogEntry {
|
|
568
|
+
/**
|
|
569
|
+
* Severity level of the log entry.
|
|
570
|
+
*/
|
|
571
|
+
level: 'trace' | 'debug' | 'info' | 'warn';
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* The scope/category of the log entry.
|
|
575
|
+
*/
|
|
576
|
+
scope: 'matching' | 'comparison' | 'constraint';
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Path in the AST where this log entry was generated.
|
|
580
|
+
*/
|
|
581
|
+
path: string[];
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Human-readable message.
|
|
585
|
+
*/
|
|
586
|
+
message: string;
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Optional data associated with this log entry.
|
|
590
|
+
*/
|
|
591
|
+
data?: any;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Detailed explanation of why a pattern failed to match.
|
|
596
|
+
* Built by Layer 1 (Core Instrumentation) and exposed by Layer 2 (API).
|
|
597
|
+
*/
|
|
598
|
+
export interface MatchExplanation {
|
|
599
|
+
/**
|
|
600
|
+
* The reason for the match failure.
|
|
601
|
+
*/
|
|
602
|
+
reason: 'structural-mismatch' | 'constraint-failed' | 'type-mismatch' | 'kind-mismatch' | 'value-mismatch' | 'array-length-mismatch';
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Path in the AST where the failure occurred (e.g., ['select', 'name']).
|
|
606
|
+
*/
|
|
607
|
+
path: string[];
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Human-readable description of what was expected.
|
|
611
|
+
*/
|
|
612
|
+
expected: string;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Human-readable description of what was actually found.
|
|
616
|
+
*/
|
|
617
|
+
actual: string;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* For constraint failures, details about which constraints failed.
|
|
621
|
+
*/
|
|
622
|
+
constraintFailures?: Array<{
|
|
623
|
+
captureName: string;
|
|
624
|
+
actualValue: any;
|
|
625
|
+
error?: string;
|
|
626
|
+
}>;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Additional context about the failure.
|
|
630
|
+
*/
|
|
631
|
+
details?: string;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Interface for accessing captured nodes from a successful pattern match.
|
|
636
|
+
* Part of the public API.
|
|
637
|
+
*/
|
|
638
|
+
export interface MatchResult {
|
|
639
|
+
/**
|
|
640
|
+
* Get a captured node by name or by Capture object.
|
|
641
|
+
*
|
|
642
|
+
* @param capture The capture name (string) or Capture object
|
|
643
|
+
* @returns The captured node(s), or undefined if not found
|
|
644
|
+
*/
|
|
645
|
+
get(capture: string): any;
|
|
646
|
+
get<T>(capture: Capture<T>): T | undefined;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Result of a pattern match attempt with debug information.
|
|
651
|
+
* Part of Layer 2 (Public API).
|
|
652
|
+
*/
|
|
653
|
+
export interface MatchAttemptResult {
|
|
654
|
+
/**
|
|
655
|
+
* Whether the pattern matched successfully.
|
|
656
|
+
*/
|
|
657
|
+
matched: boolean;
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* If matched, the match result with captured nodes. Undefined if not matched.
|
|
661
|
+
* Use `result.get('captureName')` or `result.get(captureObject)` to access captures.
|
|
662
|
+
*/
|
|
663
|
+
result?: MatchResult;
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* If not matched, explanation of why. Undefined if matched.
|
|
667
|
+
*/
|
|
668
|
+
explanation?: MatchExplanation;
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Debug log entries collected during matching (if debug was enabled).
|
|
672
|
+
*/
|
|
673
|
+
debugLog?: DebugLogEntry[];
|
|
674
|
+
}
|