HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-9.10.3GHC2021

GHC.JS.Syntax

  • Domain and Purpose

    GHC.JS.Syntax defines the Syntax for the JS backend in GHC. It comports with the ECMA-262 although not every production rule of the standard is represented. Code in this module is a fork of JMacro (BSD 3 Clause) by Gershom Bazerman, heavily modified to accomodate GHC's constraints.

  • Strategy

    Nothing fancy in this module, this is a classic deeply embedded AST for JS. We define numerous ADTs and pattern synonyms to make pattern matching and constructing ASTs easier.

  • Consumers

    The entire JS backend consumes this module, e.g., the modules in GHC.StgToJS.*. Please see GHC.JS.Make for a module which provides helper functions that use the deeply embedded DSL defined in this module to provide some of the benefits of a shallow embedding.

  • 9 types
  • 3 values
  • Packageghc-9.10.3
  • Exports33
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceSyntax.hs

Deeply embedded JS datatypes

8 declarations
datadata JStat
#

JavaScript statements, see the ECMA262 Reference for details

Constructors

Instances8Eq, Generic, Semigroup, Monoid, Binary, JsToDoc, …
datadata JExpr
#

JavaScript Expressions

Constructors

Instances7Eq, Generic, Outputable, Binary, JsToDoc, Rep, …
datadata JVal
#

JavaScript values

Constructors

Instances6Eq, Generic, Outputable, Binary, JsToDoc, Rep
datadata Op
#

JS Binary Operators. We do not deeply embed the comma operator and the assignment operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
datadata UOp
#

JS Unary Operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
datadata AOp
#

JS Unary Operators

Constructors

Instances9Enum, Eq, Data, Ord, Show, Generic, …
newtypenewtype Ident
#

A newtype wrapper around FastString for JS identifiers.

Constructors

Instances7Eq, Show, Uniquable, Binary, JVarMagic, ToJExpr, …

pattern synonyms over JS operators

21 declarations
patternpattern New :: JExpr -> JExpr
#

pattern synonym for a unary operator new

patternpattern Not :: JExpr -> JExpr
#

pattern synonym for logical not !

patternpattern BNot :: JExpr -> JExpr
#

pattern synonym for Bitwise Not ~

patternpattern Int :: Integer -> JExpr
#

pattern synonym to create integer values

patternpattern Var :: Ident -> JExpr
#

pattern synonym to create a local variable reference

patternpattern PreInc :: JExpr -> JExpr
#

pattern synonym for prefix increment ++x

patternpattern PreDec :: JExpr -> JExpr
#

pattern synonym for prefix decrement --x

Utility

4 declarations
newtypenewtype SaneDouble
#

A newtype wrapper around Double to ensure we never generate a Double that becomes a NaN, see instances for details on sanity.

Instances6Eq, Fractional, Num, Ord, Show, Binary