purescript-0.12.5: PureScript Programming Language Compiler

Safe HaskellNone
LanguageHaskell2010

Language.PureScript.CodeGen.JS.Common

Description

Common code generation utility functions

Synopsis

Documentation

identToJs :: Ident -> Text Source #

Convert an Ident into a valid JavaScript identifier:

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

properToJs :: ProperName a -> Text Source #

Convert a ProperName into a valid JavaScript identifier:

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

anyNameToJs :: Text -> Text Source #

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 Source #

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 Source #

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

nameIsJsReserved :: Text -> Bool Source #

Checks whether an identifier name is reserved in JavaScript.

nameIsJsBuiltIn :: Text -> Bool Source #

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