Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.d/internal_accommodate-initial-digit-idents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Accommodate internally-generated identifiers that start with digits
7 changes: 5 additions & 2 deletions src/Language/PureScript/CodeGen/JS/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ moduleNameToJs (ModuleName mn) =
--
-- * Alphanumeric characters are kept unmodified.
--
-- * Reserved javascript identifiers are prefixed with '$$'.
-- * Reserved javascript identifiers and identifiers starting with digits are
-- prefixed with '$$'.
identToJs :: Ident -> Text
identToJs (Ident name) = anyNameToJs name
identToJs (Ident name)
| not (T.null name) && isDigit (T.head name) = "$$" <> T.concatMap identCharToText name
| otherwise = anyNameToJs name
identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
identToJs UnusedIdent = unusedIdent
identToJs (InternalIdent RuntimeLazyFactory) = "$runtime_lazy"
Expand Down
16 changes: 16 additions & 0 deletions tests/purs/passing/CSEInitialDigitSymbols.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Main where

import Data.Symbol (class IsSymbol, reflectSymbol)
import Effect.Console (log)
import Type.Proxy (Proxy(..))

reflectSymbol' :: forall s. IsSymbol s => Proxy s -> String
reflectSymbol' = reflectSymbol

two = reflectSymbol (Proxy :: _ "2")
two2 = reflectSymbol' (Proxy :: _ "2")

twoThirty = reflectSymbol (Proxy :: _ "2:30")
twoThirty2 = reflectSymbol' (Proxy :: _ "2:30")

main = log "Done"