SimonDanisch / Bonito.jl

Serving JS to the browser
MIT License
204 stars 29 forks source link

"syntax: { } vector syntax is discontinued" when interpolating template literals in Javascript #209

Closed topolarity closed 8 months ago

topolarity commented 8 months ago
app = App() do session, request
    width = 500; height = 500
    dom = DOM.div(width = width, height = height)
    Bonito.onload(session, dom, js"""
        function (container){
            var str = "Hello, world!";
            alert(`${str}`);
        }
    """)
    return dom
end

Gives an error:

ERROR: LoadError: syntax: { } vector syntax is discontinued around /home/topolarity/repos/julia/show_graph.jl:11
Stacktrace:
 [1] top-level scope
   @ ~/repos/julia/show_graph.jl:8
 [2] include(fname::String)
   @ Base.MainInclude ./client.jl:489
 [3] top-level scope
   @ REPL[9]:1
in expression starting at /home/topolarity/repos/julia/show_graph.jl:8

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

SimonDanisch commented 8 months ago

I dont think we can make this work. You can include the JS as a dependency via a .js file, or use any other string concatenation strategy ;)

topolarity commented 8 months ago

The warning seems to suggest that ${...} always represents the discontinued vector syntax in Julia.

$( ... ) and other variants are not used as a placeholder in Javascript, just the curly brace syntax (to my knowledge).

Is there a reason that can't be escaped from interpolation?