jsaddle-wasm-0.1.2.1: Run JSaddle JSM with the GHC Wasm backend
Safe HaskellNone
LanguageGHC2021

Language.Javascript.JSaddle.Wasm.TH

Description

Utilities for evaluating (at runtime) JS code that is known at compile time via TemplateHaskell without relying on JS eval.

For niche use cases, generating JSaddle-based eval instead is possible by disabling the eval-via-jsffi Cabal flag.

For convenience, on non-Wasm GHCs, the semantics of having eval-via-jsffi disabled are used.

Synopsis

Documentation

eval :: String -> Q Exp Source #

Generate an expression that, when called, evaluates the given chunk of JS code. Additionally, a list of argument types can be specified.

For example,

$(eval "console.log('hi')") :: JSM ()

will print "hi" to the console when executed.

Internally, this generates the following code:

  • If the Cabal flag eval-via-jsffi is enabled (the default): An appropriate safe Wasm JSFFI import.
  • If eval-via-jsffi is disabled: Use JSaddle's eval.

evalFile :: FilePath -> Q Exp Source #

Like eval, but read the JS code to evaluate from a file.