diff --git a/src/strands/strands_transpiler.js b/src/strands/strands_transpiler.js index a42591787d..91a46d2597 100644 --- a/src/strands/strands_transpiler.js +++ b/src/strands/strands_transpiler.js @@ -1197,7 +1197,7 @@ const ASTCallbacks = { recursive(ast, { varyings: {}, inControlFlow: 0 }, postOrderControlFlowTransform); const transpiledSource = escodegen.generate(ast); const scopeKeys = Object.keys(scope); - const match = /\(?\s*(?:function)?\s*\(([^)]*)\)\s*(?:=>)?\s*{((?:.|\n)*)}\s*;?\s*\)?/ + const match = /\(?\s*(?:function)?\s*\w*\s*\(([^)]*)\)\s*(?:=>)?\s*{((?:.|\n)*)}\s*;?\s*\)?/ .exec(transpiledSource); if (!match) { console.log(transpiledSource); diff --git a/test/unit/webgl/p5.Shader.js b/test/unit/webgl/p5.Shader.js index 0f6ed8aef4..fecd4b6d6d 100644 --- a/test/unit/webgl/p5.Shader.js +++ b/test/unit/webgl/p5.Shader.js @@ -408,6 +408,26 @@ suite('p5.Shader', function() { }); }); suite('p5.strands', () => { + test('handles named function callbacks', () => { + myp5.createCanvas(5, 5, myp5.WEBGL); + function myMaterial() { + myp5.getPixelInputs(inputs => { + inputs.color = [ + 1, + 0, + 0, + 1 + ]; + return inputs; + }); + } + const myShader = myp5.baseMaterialShader().modify(myMaterial, { myp5 }); + expect(() => { + myp5.shader(myShader); + myp5.plane(myp5.width, myp5.height); + }).not.toThrowError(); + }); + test('does not break when arrays are in uniform callbacks', () => { myp5.createCanvas(5, 5, myp5.WEBGL); const myShader = myp5.baseMaterialShader().modify(() => {