You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve traverse logic and error handling for safer translation parsing
- Add safety check for missing argument nodes to prevent runtime errors
- Conditionally log unexpected node types based on debug flag
- Minor cleanup and consistency improvements
// Safety check: verify we actually have an arguments node
171
+
if(!raw)return;
172
+
168
173
consttranslation: Partial<{
169
174
msgctxt: string;
170
175
msgid: string;
@@ -187,7 +192,6 @@ export function doTree(
187
192
// Get the translation from the arguments
188
193
for(constchildofchildren){
189
194
letnode=child;
190
-
letnodeValue: string|string[]=node.text;
191
195
192
196
// unwrap the argument node, which is used in PHP.
193
197
if(child.type==="argument"){
@@ -221,10 +225,12 @@ export function doTree(
221
225
nodeValue=node.text;
222
226
}else{
223
227
// Whenever we get an unexpected node type this string is not translatable and should be skipped
224
-
console.error(
225
-
`Unexpected node type ${node?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node.startPosition.row+1} pos ${node.startPosition.column+1}`,
226
-
);
227
-
return;// Parse error, skip this translation.
228
+
if(debugEnabled){
229
+
console.error(
230
+
`Unexpected node type ${node?.type} identified as ${translationKeys[translationKeyIndex]} with value ${nodeValue} in ${filepath} at ${node.startPosition.row+1} pos ${node.startPosition.column+1}`,
0 commit comments