@sun-asterisk/impact-analyzer 1.0.1 → 1.0.2

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.
@@ -448,89 +448,64 @@ export class MethodCallGraph {
448
448
 
449
449
  /**
450
450
  * Get changed methods from git diff
451
- * Detects both:
452
- * 1. Methods that contain changed lines
453
- * 2. Method calls that were added/removed
451
+ * Uses ts-morph AST to detect which specific methods contain changes
454
452
  */
455
453
  getChangedMethods(diff, filePath) {
456
- const changedMethods = new Set();
457
- const changedMethodCalls = new Set();
458
-
459
454
  if (!diff || !filePath) return [];
460
455
 
461
456
  const sourceFile = this.project.getSourceFile(filePath);
462
457
  if (!sourceFile) return [];
463
458
 
464
- const classes = sourceFile.getClasses();
465
- if (classes.length === 0) return [];
466
-
467
- // Parse diff to extract changed line numbers
459
+ // Extract changed line numbers from diff
468
460
  const changedLines = this.extractChangedLineNumbers(diff);
469
-
470
461
  if (changedLines.length === 0) return [];
471
462
 
472
- // 1. Find methods that contain the changed lines
463
+ const changedMethods = [];
464
+
465
+ // Get all classes in the file
466
+ const classes = sourceFile.getClasses();
467
+
473
468
  for (const classDecl of classes) {
474
469
  const className = classDecl.getName();
470
+ if (!className) continue;
471
+
475
472
  const methods = classDecl.getMethods();
476
-
473
+
477
474
  for (const method of methods) {
478
475
  const methodName = method.getName();
479
- const startLine = method.getStartLineNumber();
480
- const endLine = method.getEndLineNumber();
481
-
482
- // Check if any changed line falls within this method's range
483
- const hasChangedLine = changedLines.some(
484
- lineNum => lineNum >= startLine && lineNum <= endLine
485
- );
486
-
487
- if (hasChangedLine) {
488
- const fullName = `${className}.${methodName}`;
489
- changedMethods.add(fullName);
490
- }
491
- }
492
- }
493
-
494
- // 2. Detect method calls that were modified in the diff
495
- const diffLines = diff.split('\n');
496
-
497
- for (const line of diffLines) {
498
- // Only look at added/removed lines
499
- if (!line.startsWith('+') && !line.startsWith('-')) continue;
500
-
501
- const codeLine = line.substring(1).trim();
502
-
503
- // Pattern: object.methodName(...) or await object.methodName(...)
504
- const methodCallPattern = /(?:await\s+)?(\w+)\.(\w+)\s*\(/g;
505
- let match;
506
-
507
- while ((match = methodCallPattern.exec(codeLine)) !== null) {
508
- const objectName = match[1];
509
- const methodName = match[2];
510
476
 
511
- // Try to resolve the type of the object
512
- const resolvedType = this.resolveObjectType(objectName, sourceFile, classes);
513
-
514
- if (resolvedType) {
515
- const fullName = `${resolvedType}.${methodName}`;
516
- changedMethodCalls.add(fullName);
477
+ // Check if this specific method contains changes
478
+ if (this.methodContainsChanges(method, changedLines)) {
479
+ changedMethods.push({
480
+ className: className,
481
+ methodName: methodName,
482
+ file: filePath,
483
+ fullName: `${className}.${methodName}`
484
+ });
517
485
  }
518
486
  }
519
487
  }
520
-
521
- // Combine both: methods containing changes + method calls that changed
522
- const allChangedMethods = [...changedMethods, ...changedMethodCalls];
523
488
 
524
- // Convert to objects with metadata
525
- return [...new Set(allChangedMethods)].map(fullName => {
526
- const parts = fullName.split('.');
527
- return {
528
- className: parts[0],
529
- methodName: parts[1],
530
- file: filePath,
531
- fullName: fullName
532
- };
533
- });
489
+ return changedMethods;
490
+ }
491
+
492
+ /**
493
+ * Check if a method contains actual code changes using ts-morph AST
494
+ */
495
+ methodContainsChanges(method, changedLines) {
496
+ const body = method.getBody();
497
+ if (!body) return false;
498
+
499
+ // Get the method body block (excluding signature and decorators)
500
+ const bodyStartLine = body.getStartLineNumber();
501
+ const bodyEndLine = body.getEndLineNumber();
502
+
503
+ // Check if any changed line is within the method body
504
+ const hasChangesInBody = changedLines.some(
505
+ line => line >= bodyStartLine && line <= bodyEndLine
506
+ );
507
+
508
+ return hasChangesInBody;
534
509
  }
535
510
 
536
511
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sun-asterisk/impact-analyzer",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Automated impact analysis for TypeScript/JavaScript projects",
5
5
  "main": "index.js",
6
6
  "type": "module",