Language.PureScript.CodeGen.JS.Common

purescript-0.15.15: PureScript Programming Language Compiler

Safe Haskell | None
Language | Haskell2010

Language.PureScript.CodeGen.JS.Common

Description

Common code generation utility functions

Synopsis

- moduleNameToJs :: ModuleName -> Text
- identToJs :: Ident -> Text
- properToJs :: forall (a :: ProperNameType). ProperName a -> Text
- anyNameToJs :: Text -> Text
- isValidJsIdentifier :: Text -> Bool
- identCharToText :: Char -> Text
- nameIsJsReserved :: Text -> Bool
- nameIsJsBuiltIn :: Text -> Bool
- jsAnyReserved :: [Text]
- jsKeywords :: [Text]
- jsSometimesReserved :: [Text]
- jsFutureReserved :: [Text]
- jsFutureReservedStrict :: [Text]
- jsOldReserved :: [Text]
- jsLiterals :: [Text]

# Documentation

moduleNameToJs :: ModuleName -> Text #

identToJs :: Ident -> Text #

Convert an `Ident` into a valid JavaScript identifier:

- Alphanumeric characters are kept unmodified.
- Reserved javascript identifiers and identifiers starting with digits are prefixed with `$$`.

properToJs :: forall (a :: ProperNameType). ProperName a -> Text #

Convert a `ProperName` into a valid JavaScript identifier:

- Alphanumeric characters are kept unmodified.
- Reserved javascript identifiers are prefixed with `$$`.

anyNameToJs :: Text -> Text #

Convert any name into a valid JavaScript identifier.

Note that this function assumes that the argument is a valid PureScript identifier (either an `Ident` or a `ProperName`) to begin with; as such it will not produce valid JavaScript identifiers if the argument e.g. begins with a digit. Prefer `identToJs` or `properToJs` where possible.

isValidJsIdentifier :: Text -> Bool #

Test if a string is a valid JavaScript identifier as-is. Note that, while a return value of `True` guarantees that the string is a valid JS identifier, a return value of `False` does not guarantee that the string is not a valid JS identifier. That is, this check is more conservative than absolutely necessary.

identCharToText :: Char -> Text #

Attempts to find a human-readable name for a symbol, if none has been specified returns the ordinal value.

nameIsJsReserved :: Text -> Bool #

Checks whether an identifier name is reserved in JavaScript.

nameIsJsBuiltIn :: Text -> Bool #

Checks whether a name matches a built-in value in JavaScript.

jsAnyReserved :: [Text] #

jsKeywords :: [Text] #

jsSometimesReserved :: [Text] #

jsFutureReserved :: [Text] #

jsFutureReservedStrict :: [Text] #

jsOldReserved :: [Text] #

jsLiterals :: [Text] #