[Git][ghc/ghc][master] JS: avoid head/tail and unpackFS
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Wed Feb 8 02:25:33 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
c1670c6b by Sylvain Henry at 2023-02-07T21:25:18-05:00
JS: avoid head/tail and unpackFS
- - - - -
1 changed file:
- compiler/GHC/StgToJS/Printer.hs
Changes:
=====================================
compiler/GHC/StgToJS/Printer.hs
=====================================
@@ -108,19 +108,17 @@ ghcjsRenderJsV r (JHash m)
where
quoteIfRequired :: FastString -> Doc
quoteIfRequired x
- | isUnquotedKey x' = text x'
- | otherwise = PP.squotes (text x')
- where x' = unpackFS x
-
- isUnquotedKey :: String -> Bool
- isUnquotedKey x | null x = False
- | all isDigit x = True
- | otherwise = validFirstIdent (head x)
- && all validOtherIdent (tail x)
+ | isUnquotedKey x = ftext x
+ | otherwise = PP.squotes (ftext x)
+ isUnquotedKey :: FastString -> Bool
+ isUnquotedKey fs = case unpackFS fs of
+ [] -> False
+ s@(c:cs) -> all isDigit s || (validFirstIdent c && all validOtherIdent cs)
validFirstIdent c = c == '_' || c == '$' || isAlpha c
validOtherIdent c = isAlpha c || isDigit c
+
ghcjsRenderJsV r v = renderJsV defaultRenderJs r v
prettyBlock :: RenderJs -> [JStat] -> Doc
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c1670c6bb0be68942f1e469334f2004544da6635
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c1670c6bb0be68942f1e469334f2004544da6635
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230207/0493a757/attachment-0001.html>
More information about the ghc-commits
mailing list