elm-explorations / webgl

Functional rendering with WebGL in Elm
https://package.elm-lang.org/packages/elm-explorations/webgl/latest/
BSD 3-Clause "New" or "Revised" License
117 stars 17 forks source link

GLSL with apostrophes breaks JS output #8

Closed declension closed 5 years ago

declension commented 5 years ago

Steps to replicate

A fragment shader like this:

fragmentShader : Shader {} Uniforms { vcoord : Vec2 }
fragmentShader =
    [glsl|
        uniform sampler2D texture;
        varying vec2 vcoord;

        // This ain't gonna work now

        void main () {
          gl_FragColor = texture2D(texture, vcoord);
        }
    |]

Expected

Actual

(The build uses Webpack, hence these messages)

ERROR in ./src/elm/Main.elm 12271:97
Module parse failed: Unexpected token (12271:97)
You may need an appropriate loader to handle this file type.
| };
| var author$project$GL$fragmentShader = {
>       src: '\n        uniform sampler2D texture;\n        varying vec2 vcoord;\n\n        // This ain't gonna compile now\n\n        void main () {\n          gl_FragColor = texture2D(texture, vcoord);\n        }\n    ',
|       attributes: {},
|       uniforms: {texture: 'texture'}
 @ ./src/index.js 4:0-37 132:8-11

Note the src of the author$project$GL$fragmentShader object is delimited by ', but the inline comment's ' is not escaped here thus breaking the JS (hence Webpack then failing).

w0rm commented 5 years ago

Hey, great find! This issue should be opened in the https://github.com/elm/compiler project somewhere around these lines https://github.com/elm/compiler/blob/d09b95aac107291d50e8ee391d3288fc18c3891a/compiler/src/Parse/Shader.hs#L33