Skip to content

Commit 8181c4f

Browse files
authored
Accommodate internal initial-digit identifiers (purescript#4334)
The motivating example is the `xyzIsSymbol` style of variable name that can be created by `CoreFn.CSE`.
1 parent d721f48 commit 8181c4f

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Accommodate internally-generated identifiers that start with digits

src/Language/PureScript/CodeGen/JS/Common.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ moduleNameToJs (ModuleName mn) =
1919
--
2020
-- * Alphanumeric characters are kept unmodified.
2121
--
22-
-- * Reserved javascript identifiers are prefixed with '$$'.
22+
-- * Reserved javascript identifiers and identifiers starting with digits are
23+
-- prefixed with '$$'.
2324
identToJs :: Ident -> Text
24-
identToJs (Ident name) = anyNameToJs name
25+
identToJs (Ident name)
26+
| not (T.null name) && isDigit (T.head name) = "$$" <> T.concatMap identCharToText name
27+
| otherwise = anyNameToJs name
2528
identToJs (GenIdent _ _) = internalError "GenIdent in identToJs"
2629
identToJs UnusedIdent = unusedIdent
2730
identToJs (InternalIdent RuntimeLazyFactory) = "$runtime_lazy"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Main where
2+
3+
import Data.Symbol (class IsSymbol, reflectSymbol)
4+
import Effect.Console (log)
5+
import Type.Proxy (Proxy(..))
6+
7+
reflectSymbol' :: forall s. IsSymbol s => Proxy s -> String
8+
reflectSymbol' = reflectSymbol
9+
10+
two = reflectSymbol (Proxy :: _ "2")
11+
two2 = reflectSymbol' (Proxy :: _ "2")
12+
13+
twoThirty = reflectSymbol (Proxy :: _ "2:30")
14+
twoThirty2 = reflectSymbol' (Proxy :: _ "2:30")
15+
16+
main = log "Done"

0 commit comments

Comments
 (0)