Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
heidemn opened this issue Oct 8, 2015 · 1 comment
Open

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

heidemn opened this issue Oct 8, 2015 · 1 comment

Comments

@heidemn
Copy link

heidemn commented Oct 8, 2015

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) { /* ... */ }
@gre
Copy link
Member

gre commented Oct 8, 2015

👍

BTW this is a duplicate with stackgl/glsl-min-stream#2

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

No branches or pull requests

2 participants