fix: address Copilot review — private(set) export, for-loop tuple pattern

1. Export detection: exclude private(set)/fileprivate(set) from
   unexported check. Only the setter is restricted — the symbol
   itself is still readable cross-file.

2. For-loop binding: use extractVarName() instead of raw .text
   to avoid polluting scopeEnv with non-identifier keys from
   tuple destructuring patterns (e.g. `for (a, b) in ...`).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
marxo126 2026-03-22 11:37:02 +01:00
parent 16b1a63134
commit 0a3cdce00e
2 changed files with 8 additions and 3 deletions

View file

@ -205,7 +205,9 @@ const swiftExportChecker: ExportChecker = (node, _name) => {
while (current) {
if (current.type === 'modifiers' || current.type === 'visibility_modifier') {
const text = current.text || '';
if (/\bprivate\b|\bfileprivate\b/.test(text)) return false;
// Exclude private(set)/fileprivate(set) — only the setter is restricted,
// the symbol itself is still readable cross-file.
if (/\b(private|fileprivate)\b(?!\s*\()/.test(text)) return false;
}
current = current.parent;
}

View file

@ -340,8 +340,11 @@ const extractForLoopBinding: ForLoopExtractor = (node, { scopeEnv, declarationTy
if (!child) continue;
if (child.type === 'pattern' || child.type === 'simple_identifier') {
if (!loopVarName) {
// The loop variable - may be inside a pattern node or a direct simple_identifier
loopVarName = child.type === 'pattern' ? child.text : child.text;
// Extract a simple identifier from the pattern. Skip non-trivial patterns
// (e.g. tuple destructuring `for (a, b) in ...`) to avoid polluting scopeEnv.
const varName = extractVarName(child) ?? (child.type === 'simple_identifier' ? child.text : undefined);
if (!varName) return; // Non-simple pattern — bail out
loopVarName = varName;
continue;
}
}