@@ -155,7 +155,7 @@ export function doTree(
155155 }
156156
157157 // The arguments are the last child
158- const argsNode = node . lastChild ;
158+ const argsNode = node . childForFieldName ( "arguments" ) ;
159159 if (
160160 argsNode === null ||
161161 argsNode . childCount === 0 ||
@@ -164,12 +164,8 @@ export function doTree(
164164 return ;
165165 }
166166
167- // Get the whole gettext translation string
168- // eslint-disable-next-line @typescript-eslint/no-unused-vars
169- const [ _fn , raw ] = node . children ;
170-
171167 // Safety check: verify we actually have an arguments node
172- if ( ! raw ) return ;
168+ if ( ! argsNode ) return ;
173169
174170 const translation : Partial < {
175171 msgctxt : string ;
@@ -186,12 +182,15 @@ export function doTree(
186182 const translationKeys =
187183 i18nFunctions [ functionName as keyof typeof i18nFunctions ] ;
188184
189- // Slice the children to skip the opening and closing parentheses/brackets
190- const children = raw . children . slice ( 1 , - 1 ) ;
185+ // Filter children to find only arguments, ignoring comments etc.
186+ const argumentNodes = argsNode . children . filter (
187+ ( child ) => child . type === "argument" ,
188+ ) ;
189+
191190 let translationKeyIndex = 0 ;
192191
193192 // Get the translation from the arguments
194- for ( const child of children ) {
193+ for ( const child of argumentNodes ) {
195194 let node = child ;
196195
197196 // unwrap the argument node, which is used in PHP.
@@ -213,7 +212,7 @@ export function doTree(
213212 // the translation key (eg. msgid)
214213 const currentKey = translationKeys [
215214 translationKeyIndex
216- ] as keyof typeof translation ;
215+ ] as keyof typeof translation ;
217216
218217 // Resolve the value using our new function (handles quotes and escapes)
219218 let nodeValue : string = resolveStringValue ( node ) ;
0 commit comments