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) {
20
20
if ( shaderModifier instanceof Function ) {
21
21
let generatorFunction ;
22
22
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 ( ) } )` ;
24
26
const ast = parse ( sourceString , {
25
27
ecmaVersion : 2021 ,
26
28
locations : options . srcLocations
Original file line number Diff line number Diff line change @@ -324,6 +324,11 @@ suite('p5.Shader', function() {
324
324
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 / ) ;
325
325
} ) ;
326
326
327
+ test ( 'anonymous function shaderModifier does not throw when parsed' , function ( ) {
328
+ const callModify = ( ) => myShader . modify ( function ( ) { } ) ;
329
+ expect ( callModify ) . not . toThrowError ( ) ;
330
+ } ) ;
331
+
327
332
test ( 'filled hooks do have an AUGMENTED_HOOK define' , function ( ) {
328
333
const modified = myShader . modify ( {
329
334
'vec4 getVertexColor' : `(vec4 c) {
You can’t perform that action at this time.
0 commit comments