Skip to content

Keep p5.strands transpiler output valid for comma-joined expressions - #9193

Open
harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:fix-strands-comma-operator
Open

harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:fix-strands-comma-operator

Conversation

@harshiltewari2004

Copy link
Copy Markdown
Contributor

Resolves #9178

Changes

The transpiler assumed each call or assignment is its own statement. Comma-joined
code (as minifiers produce) breaks that assumption in three places, all in
src/strands/strands_transpiler.js:

1. Assignments were rewritten into statements. AssignmentExpression turned
the node into an ExpressionStatement for the bridge and bridgeSwizzle
paths, so escodegen emitted a ; mid-expression (;,) and the callback failed
to build. They are now rewritten as call expressions in place, via a new
replaceWithMethodCall() helper that the existing computed-member branch also
uses. This covers ternaries, call arguments and x++ (which routes through the
same handler). In ordinary statement position it also removes a stray empty
statement that was previously emitted.

2. .set() in control flow dropped sibling expressions. The rewrite replaced
the whole enclosing statement, so in a(), hook.set(v), b() the calls to a()
and b() disappeared from the output with no error. Only the .set() call is
replaced now.

3. .begin() / .end() were only found as standalone statements. With
hook.end(), b(); the generated hook.set(...) was inserted after .end(),
which produces a hook function that never assigns its result — a GLSL compile
error ('HOOK_getColor': Function does not return a value). A new
statementCallsHookMethod() helper, shared by both lookups, also looks inside
comma expressions.

Tests

Four tests in a new comma operator (#9178) suite in
test/unit/webgl/p5.Shader.js, one per failure mode. Verified by stashing the
source change: all four fail without it, each for its own reason, and pass with
it. The full WebGL and WebGPU shader suites pass.

PR Checklist

  • npm run lint passes
  • [Inline reference] is included / updated
  • [Unit tests] are included / updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: strands not handling comma operator (common in minified js)

1 participant