From 0c8ec952eec0456a4372dab49f4abbcffbb42147 Mon Sep 17 00:00:00 2001 From: marxo126 Date: Sat, 21 Mar 2026 09:44:37 +0100 Subject: [PATCH] fix: handle trailing commas in tree-sitter-swift binding.gyp patch The patch script fails to parse tree-sitter-swift@0.6.0's binding.gyp because the file contains both Python-style # comments AND trailing commas in JSON arrays. The existing regex strips # comments but leaves trailing commas, causing JSON.parse() to fail with: "Unexpected token ']'" This silently prevents tree-sitter-swift from building, which means Swift files are skipped entirely during analysis. Fix: add a second regex pass to strip trailing commas before ] or } after comment removal. Fixes #386, #406 Co-Authored-By: Claude Opus 4.6 (1M context) --- gitnexus/scripts/patch-tree-sitter-swift.cjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gitnexus/scripts/patch-tree-sitter-swift.cjs b/gitnexus/scripts/patch-tree-sitter-swift.cjs index 3c3dcad50..2336e9952 100755 --- a/gitnexus/scripts/patch-tree-sitter-swift.cjs +++ b/gitnexus/scripts/patch-tree-sitter-swift.cjs @@ -41,8 +41,10 @@ try { let needsRebuild = false; if (content.includes('"actions"')) { - // Strip Python-style comments (#) before JSON parsing - const cleaned = content.replace(/#[^\n]*/g, ''); + // Strip Python-style comments (#) and trailing commas before JSON parsing + const cleaned = content + .replace(/#[^\n]*/g, '') // Remove # comments + .replace(/,(\s*[\]}])/g, '$1'); // Remove trailing commas before ] or } const gyp = JSON.parse(cleaned); if (gyp.targets && gyp.targets[0] && gyp.targets[0].actions) {