Most appropriate sub-area of p5.js?
p5.js version
2.3.2
Web browser and version
All
Operating system
All
Steps to reproduce this
A common thing you'll see in some JavaScript minifiers is to collapse multiple statements (things separated by semicolons generally) into one expression (something that evaluates to a single value) via the comma operator. E.g. something like this:
let a
if (something) {
someThingIsTrue();
a = 1;
} else {
somethingElse();
a = 2;
}
...might get compressed into this:
let a = something ? (somethingIsTrue(), 1) : (somethingElse(), 2);
Anyway it seems p5.strands does not handle comma operators well. In the example below, simulating something a minifier produced while using strands at work, transpiles to invalid javascript:
let gradientShader
function setup() {
createCanvas(400, 400, WEBGL)
gradientShader = buildMaterialShader(() => {
let pos = sharedVec4()
worldInputs.begin(), pos = [worldInputs.position/200, 1], worldInputs.end()
pixelInputs.begin(), pixelInputs.color = pos, pixelInputs.end()
})
}
function draw() {
clear()
shader(gradientShader)
noStroke()
plane(width, height)
}
Live: https://editor.p5js.org/davepagurek/sketches/zNjhdJCGO
This transpiles to:
let pos = sharedVec4('pos');
worldInputs.begin(), pos.bridge(__p5.strandsNode([
__p5.strandsNode(worldInputs.position).div(200),
1
]));, worldInputs.end();
pixelInputs.begin(), pixelInputs.color = pos.getValue(), pixelInputs.end();
Note that there's a ;, in there. I think a few spots in our transpiler code have the assumption that each line is its own statement and is emitting semicolons where it shouldn't. We should do a little audit for those and create some test cases and fixes.
Most appropriate sub-area of p5.js?
p5.js version
2.3.2
Web browser and version
All
Operating system
All
Steps to reproduce this
A common thing you'll see in some JavaScript minifiers is to collapse multiple statements (things separated by semicolons generally) into one expression (something that evaluates to a single value) via the comma operator. E.g. something like this:
...might get compressed into this:
Anyway it seems p5.strands does not handle comma operators well. In the example below, simulating something a minifier produced while using strands at work, transpiles to invalid javascript:
Live: https://editor.p5js.org/davepagurek/sketches/zNjhdJCGO
This transpiles to:
Note that there's a
;,in there. I think a few spots in our transpiler code have the assumption that each line is its own statement and is emitting semicolons where it shouldn't. We should do a little audit for those and create some test cases and fixes.