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

Fix print_script for 1.10 #36

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/script.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,28 @@ The fallback behavior of `print_script` is to show the object as
`"text/javascript"`. The `Javascript` wrapper will take any string
and let it be printed in this way.
"""
@static if VERSION > v"1.9.99"
# With the new JuliaSyntax parser, `hasmethod` appears to be invoked before
# other packages are loaded.
print_script(io::IO, value::Any) =
show(io, MIME"text/javascript"(), value)
else
@generated function print_script(io::IO, value)
# workaround for Julia#18221
if hasmethod(show, Tuple{IO, MIME{Symbol("text/javascript")}, value})
return :(show(io, MIME"text/javascript"(), value))
end
throw("$(value) is not showable as text/javascript")
end
end
print_script(io::IO, ::Nothing) =
print(io, "undefined")
print_script(io::IO, ::Missing) =
print(io, "null")
print_script(io::IO, value::Union{Bool, Symbol}) =
print(io, value)


function print_script(io::IO, value::Union{NamedTuple, AbstractDict})
print(io, '{')
first = true
Expand Down