Fix visitPreprocessedAst bug when ifdef directives followed by comments#59
Fix visitPreprocessedAst bug when ifdef directives followed by comments#59AndrewRayCode merged 1 commit intoShaderFrog:mainfrom
Conversation
| const res = visitNode(child, node, path, nodeKey, i - offset); | ||
| if (res?.removed) { | ||
| offset += 1; | ||
| } |
There was a problem hiding this comment.
I see that child here becomes [ '// test', null ] and then '// test' which it tries to dive into and causes the error.
At a glance I wonder if something is screwy with the parse tree. It's weird there's a null here. And I'm not sure the code should be getting here at all. What makes me think this, is this codepath is used for all visiting, and there are plenty of other cases where lines end with comments.
Either way this is a definite improvement, thank you!
There was a problem hiding this comment.
I found a different way to address this - the change I added here https://github.com/ShaderFrog/glsl-parser/pull/60/files#diff-b78ac5f8fa2dcd8ef492d5c8cb4837b1f3489873eb1e130b1be66e1bdc3eedaaR33
In the parse tree, most nodes have a "wsEnd" key, representing the whitespace at the end of the lexeme, which can include comments. The wsEnd value is always supposed to be a string. The bug in the grammar was that it was not properly producing the string // test - the convoluted array logic in the parser was leaving it as ['// test', null]. THe parser update linked above properly produces a string for the ending whitespace including the comment.
If the value of any node key is a string, it's not visited, so this code path isn't hit.
|
Released in @shaderfrog/glsl-parser@6.1.0 |
No description provided.