@@ -30,8 +30,11 @@ export function handleRename(fromPos, oldName, newName, cm) {
3030function startRenaming ( cm , ast , fromPos , newName , oldName ) {
3131 const code = cm . getValue ( ) ;
3232 const fromIndex = cm . indexFromPos ( fromPos ) ;
33- const { scopeToDeclaredVarsMap = { } , userDefinedClassMetadata = { } } =
34- p5CodeAstAnalyzer ( cm ) || { } ;
33+ const {
34+ scopeToDeclaredVarsMap = { } ,
35+ userDefinedClassMetadata = { } ,
36+ userDefinedFunctionMetadata = { }
37+ } = p5CodeAstAnalyzer ( cm ) || { } ;
3538
3639 const baseContext = getContext (
3740 cm ,
@@ -40,23 +43,19 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
4043 scopeToDeclaredVarsMap ,
4144 userDefinedClassMetadata
4245 ) ;
43- const isInsideClassContext = baseContext in userDefinedClassMetadata ;
44-
45- const bc = getClassContext ( cm , ast , fromPos ) ;
4646
47+ const isInsideClassContext = baseContext in userDefinedClassMetadata ;
48+ const baseClassContext = getClassContext ( cm , ast , fromPos ) ;
4749 const isBaseThis = isThisReference ( cm , ast , fromPos , oldName ) ;
4850 const isGlobal = isGlobalReference (
4951 oldName ,
5052 baseContext ,
5153 scopeToDeclaredVarsMap ,
5254 userDefinedClassMetadata ,
53- bc ,
55+ baseClassContext ,
5456 isBaseThis
5557 ) ;
5658
57- console . log ( 'Clicked identifier isThisReference? →' , isBaseThis ) ;
58- console . log ( fromPos , isGlobal , 'iscc=' , isInsideClassContext ) ;
59-
6059 const replacements = [ ] ;
6160
6261 traverse ( ast , {
@@ -77,11 +76,8 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
7776 parent . type === 'ArrowFunctionExpression' ) &&
7877 parent . params . some ( ( p ) => p . type === 'Identifier' && p . name === oldName )
7978 ) {
80- // If the node *is* one of the parameters being declared, allow renaming
8179 if ( parent . params . includes ( node ) ) {
82- // parameter declaration → mark for renaming
8380 } else {
84- // usage inside param list → skip
8581 return ;
8682 }
8783 }
@@ -109,7 +105,6 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
109105 const isThis = isThisReference ( cm , ast , pos , oldName ) ;
110106
111107 if ( isInsideClassContext ) {
112- // Case: inside a class
113108 const classContext = getClassContext ( cm , ast , fromPos ) ;
114109 let baseMethodName = null ;
115110 if ( classContext && classContext . includes ( '.' ) ) {
@@ -130,31 +125,23 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
130125 }
131126 }
132127
133- // 1. Constructor parameter renaming
134- console . log ( baseMethodName , isThis , isBaseThis ) ;
135128 if (
136129 baseMethodName === 'constructor' &&
137130 classMeta . constructor_params . includes ( oldName ) &&
138131 isThis === isBaseThis &&
139132 baseContext === thisContext
140133 ) {
141- // Only rename inside the constructor body
142- console . log ( pos , 'constructor=' , thisContext , baseContext ) ;
143-
144134 for ( const [ methodName , vars ] of Object . entries (
145135 classMeta . methodVars || { }
146136 ) ) {
147- // console.log(pos, !vars.includes(oldName), thisContext, methodName);
148137 if ( ! vars . includes ( oldName ) && thisContext === methodName ) {
149138 shouldRenameMethodVar = true ;
150139 }
151140 }
152141 shouldRename =
153142 thisContext === baseContext &&
154143 ( currentMethodName == 'constructor' || shouldRenameGlobalVar ) ;
155- }
156- // 2. Local variable inside a method (methodVars)
157- else {
144+ } else {
158145 for ( const [ methodName , vars ] of Object . entries (
159146 classMeta . methodVars || { }
160147 ) ) {
@@ -192,6 +179,24 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
192179 ! isInBaseScope && thisScopeVars . hasOwnProperty ( oldName ) ;
193180 const isDeclaredInBaseScope = baseScopeVars . hasOwnProperty ( oldName ) ;
194181 const isDeclaredGlobally = globalScopeVars . hasOwnProperty ( oldName ) ;
182+ const isThisGlobal = isGlobalReference (
183+ oldName ,
184+ thisContext ,
185+ scopeToDeclaredVarsMap ,
186+ userDefinedClassMetadata ,
187+ baseClassContext ,
188+ isBaseThis
189+ ) ;
190+
191+ if (
192+ isThisGlobal &&
193+ thisContext in userDefinedFunctionMetadata &&
194+ userDefinedFunctionMetadata [ thisContext ] . params . some (
195+ ( param ) => param . p === oldName
196+ )
197+ ) {
198+ return ;
199+ }
195200
196201 const methodPath = path . findParent ( ( p ) => p . isClassMethod ( ) ) ;
197202 let currentMethodName = null ;
@@ -206,15 +211,14 @@ function startRenaming(cm, ast, fromPos, newName, oldName) {
206211 }
207212 }
208213
209- // ✅ NEW: If we're in a class constructor and "oldName" is a parameter, skip
210214 if (
211215 thisContext in userDefinedClassMetadata &&
212216 currentMethodName === 'constructor' &&
213217 userDefinedClassMetadata [ thisContext ] ?. constructor_params ?. includes (
214218 oldName
215219 )
216220 ) {
217- return ; //don’t rename constructor param or its usages
221+ return ;
218222 }
219223
220224 if (
0 commit comments