File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ function shadergenerator(p5, fn) {
2020 if ( shaderModifier instanceof Function ) {
2121 let generatorFunction ;
2222 if ( options . parser ) {
23- const sourceString = shaderModifier . toString ( )
23+ // #7955 Wrap function declaration code in brackets so anonymous functions are not top level statements, which causes an error in acorn when parsing
24+ // https://github.com/acornjs/acorn/issues/1385
25+ const sourceString = `(${ shaderModifier . toString ( ) } )` ;
2426 const ast = parse ( sourceString , {
2527 ecmaVersion : 2021 ,
2628 locations : options . srcLocations
Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ suite('p5.Shader', function() {
324324 expect ( modified . fragSrc ( ) ) . not . to . match ( / # d e f i n e A U G M E N T E D _ H O O K _ g e t V e r t e x C o l o r / ) ;
325325 } ) ;
326326
327+ test ( 'anonymous function shaderModifier does not throw when parsed' , function ( ) {
328+ const callModify = ( ) => myShader . modify ( function ( ) { } ) ;
329+ expect ( callModify ) . not . toThrowError ( ) ;
330+ } ) ;
331+
327332 test ( 'filled hooks do have an AUGMENTED_HOOK define' , function ( ) {
328333 const modified = myShader . modify ( {
329334 'vec4 getVertexColor' : `(vec4 c) {
You can’t perform that action at this time.
0 commit comments