Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Language.PureScript.CodeGen.JS.Common
Description
Common code generation utility functions
Synopsis
- moduleNameToJs :: ModuleName -> Text
- identToJs :: Ident -> Text
- properToJs :: 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 Source #
identToJs :: Ident -> Text Source #
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 :: 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.
jsAnyReserved :: [Text] Source #
jsKeywords :: [Text] Source #
jsSometimesReserved :: [Text] Source #
jsFutureReserved :: [Text] Source #
jsOldReserved :: [Text] Source #
jsLiterals :: [Text] Source #