@@ -2,7 +2,8 @@ import type { SourceFile } from 'ts-morph';
22import { Node , SyntaxKind } from 'ts-morph' ;
33
44import type { Diagnostic , Transform , TransformContext , TransformResult } from '../../../types.js' ;
5- import { info , warning } from '../../../utils/diagnostics.js' ;
5+ import { isKeyPositionIdentifier } from '../../../utils/astUtils.js' ;
6+ import { actionRequired , info } from '../../../utils/diagnostics.js' ;
67import { hasMcpImports } from '../../../utils/importUtils.js' ;
78import { CONTEXT_PROPERTY_MAP , CTX_PARAM_NAME , EXTRA_PARAM_NAME } from '../mappings/contextPropertyMap.js' ;
89
@@ -32,9 +33,9 @@ function processCallback(
3233 const paramNameNode = extraParam . getNameNode ( ) ;
3334 if ( Node . isObjectBindingPattern ( paramNameNode ) ) {
3435 diagnostics . push (
35- warning (
36+ actionRequired (
3637 sourceFile . getFilePath ( ) ,
37- extraParam . getStartLineNumber ( ) ,
38+ extraParam ,
3839 `Destructuring of context parameter in signature: "${ paramNameNode . getText ( ) } ". ` +
3940 'Properties have been reorganized in v2 (e.g., signal is now ctx.mcpReq.signal). Manual refactoring required.'
4041 )
@@ -49,9 +50,9 @@ function processCallback(
4950 const otherParams = callbackNode . getParameters ( ) . filter ( p => p !== extraParam ) ;
5051 if ( otherParams . some ( p => p . getName ( ) === CTX_PARAM_NAME ) ) {
5152 diagnostics . push (
52- warning (
53+ actionRequired (
5354 sourceFile . getFilePath ( ) ,
54- extraParam . getStartLineNumber ( ) ,
55+ extraParam ,
5556 `Cannot rename '${ EXTRA_PARAM_NAME } ' to '${ CTX_PARAM_NAME } ': another parameter is already named '${ CTX_PARAM_NAME } '. Manual migration required.`
5657 )
5758 ) ;
@@ -74,9 +75,9 @@ function processCallback(
7475 } ) ;
7576 if ( ctxAlreadyInScope ) {
7677 diagnostics . push (
77- warning (
78+ actionRequired (
7879 sourceFile . getFilePath ( ) ,
79- extraParam . getStartLineNumber ( ) ,
80+ extraParam ,
8081 `Cannot rename '${ EXTRA_PARAM_NAME } ' to '${ CTX_PARAM_NAME } ': '${ CTX_PARAM_NAME } ' is already referenced in this scope. Manual migration required.`
8182 )
8283 ) ;
@@ -98,11 +99,7 @@ function processCallback(
9899 body . forEachDescendant ( node => {
99100 if ( ! Node . isIdentifier ( node ) || node . getText ( ) !== EXTRA_PARAM_NAME ) return ;
100101 const parent = node . getParent ( ) ;
101- // Skip property-name positions (e.g., meta.extra, { extra: value }, { extra }, { extra: x } = obj)
102- if ( parent && Node . isPropertyAccessExpression ( parent ) && parent . getNameNode ( ) === node ) return ;
103- if ( parent && Node . isPropertyAssignment ( parent ) && parent . getNameNode ( ) === node ) return ;
104- if ( parent && Node . isShorthandPropertyAssignment ( parent ) ) return ;
105- if ( parent && Node . isBindingElement ( parent ) && parent . getPropertyNameNode ( ) === node ) return ;
102+ if ( parent && isKeyPositionIdentifier ( node ) ) return ;
106103 identifiers . push ( node ) ;
107104 } ) ;
108105
@@ -131,6 +128,11 @@ function processCallback(
131128 }
132129 }
133130 }
131+ // Shorthand property assignment: { extra } → { extra: ctx }
132+ if ( parent && Node . isShorthandPropertyAssignment ( parent ) ) {
133+ replacements . push ( { node : parent , newText : `${ EXTRA_PARAM_NAME } : ${ CTX_PARAM_NAME } ` } ) ;
134+ continue ;
135+ }
134136 replacements . push ( { node : id , newText : CTX_PARAM_NAME } ) ;
135137 }
136138
@@ -163,9 +165,9 @@ function processCallback(
163165 const nameNode = node . getNameNode ( ) ;
164166 if ( ! Node . isObjectBindingPattern ( nameNode ) ) return ;
165167 diagnostics . push (
166- warning (
168+ actionRequired (
167169 sourceFile . getFilePath ( ) ,
168- node . getStartLineNumber ( ) ,
170+ node ,
169171 `Destructuring of context parameter detected: "const ${ nameNode . getText ( ) } = ${ CTX_PARAM_NAME } ". ` +
170172 'Properties have been reorganized in v2 (e.g., signal is now ctx.mcpReq.signal). Manual refactoring required.'
171173 )
0 commit comments