From 4920d55f0b5206c43cc96a51cc0074c23c3cdaff Mon Sep 17 00:00:00 2001 From: Du Nong Date: Wed, 27 May 2026 16:37:19 +0700 Subject: [PATCH] fix: exclude strands shader-local variables from FES name conflict check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes false positive FES warning when declaring local variables inside p5.strands shader callbacks (arrow functions passed to .modify() or getWorldInputs()). These variables are shader-local and transpiled into GLSL — they have no relationship to the p5.js function namespace. Fix: add filterStrandsCallbacks() that strips arrow function body content before the codeToLines scan. Variables like 'red', 'green', 'blue' used inside strands callbacks will no longer trigger reserved name warnings. --- src/core/friendly_errors/sketch_reader.js | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/core/friendly_errors/sketch_reader.js b/src/core/friendly_errors/sketch_reader.js index 145f285958..a3308d9392 100644 --- a/src/core/friendly_errors/sketch_reader.js +++ b/src/core/friendly_errors/sketch_reader.js @@ -208,7 +208,57 @@ if (typeof IS_MINIFIED !== 'undefined') { * @private * @param {String} code code written by the user */ + // Filter out content inside strands arrow function callbacks + // These are transpiled into GLSL and run in a separate execution context + // e.g., .modify(() => { let red = 0.5; }) or getWorldInputs((inputs) => { ... }) + const filterStrandsCallbacks = code => { + let inStrandsCallback = false; + let braceDepth = 0; + let result = []; + let i = 0; + + while (i < code.length) { + const remaining = code.slice(i); + const arrowMatch = remaining.match(/^\s*=>\s*\{/); + if (arrowMatch && !inStrandsCallback) { + inStrandsCallback = true; + braceDepth = 1; + i += arrowMatch[0].length; + continue; + } + + if (inStrandsCallback) { + const openBrace = code.indexOf('{', i); + const closeBrace = code.indexOf('}', i); + + if (closeBrace !== -1 && (openBrace === -1 || closeBrace < openBrace)) { + braceDepth--; + if (braceDepth === 0) { + inStrandsCallback = false; + i = closeBrace + 1; + continue; + } + i = closeBrace + 1; + } else if (openBrace !== -1) { + braceDepth++; + i = openBrace + 1; + } else { + i++; + } + continue; + } + + result.push(code[i]); + i++; + } + + return result.join(''); + }; + const codeToLines = code => { + // Filter out strands callback bodies before scanning + code = filterStrandsCallbacks(code); + //convert code to array of code and filter out //unnecessary lines let arrayVariables = code