Skip to content

Parser confuses variable 'x' and component 'myVec.x' #11

Open
@heidemn

Description

@heidemn

Currently, the minifier glsl-min-stream does not work correctly when a shader contains both the variables x and the vector subscript myVec.x.
The reason is that glsl-parser seems to re-use the node of the AST for both occurences of 'x'. -> The minifier first gets the node with node.type == 'ident', node.token.type == 'ident' (for the variable x). Then, the minifier gets the same node (equal by reference) with node.type == 'literal', node.token.type == 'ident'.
The minifier will minify the occurence as a variable. As a side effect, the occurence as a vector subscript will also be minified! This breaks the shader.
I think that glsl-min-stream is correctly implemented, but glsl-parser should not re-use the same node for different types of AST nodes.

Example: Because of this parser bug, following code...

float w = abs(projPosition.w);
if (projPosition.z > -w && projPosition.z < w) { /*... */ }

...is minified to:

float i = abs(h.i);
if(h.z > -i && h.z < i) { /* ... */ }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions