@@ -1,10 +1,10 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
33module Generate.JavaScript.Builder
4− ( Expr(..), Id(..), Prop(..), LValue(..)
4+ ( encodeUtf8
5+ , Expr(..), Id(..), Prop(..), LValue(..)
56 , Stmt(..), Case(..), VarDecl(..)
67 , InfixOp(..), PrefixOp(..)
7− , stmtsToText
88 )
99 where
1010
@@ -15,12 +15,10 @@ module Generate.JavaScript.Builder
1515
1616import Prelude hiding (lines)
1717import qualified Data.List as List
18+import Data.ByteString.Builder
1819import Data.Monoid ((<>))
1920import Data.Text (Text)
20−import Data.Text.Lazy.Builder
21−import Data.Text.Lazy.Builder.Int (decimal)
22−import Data.Text.Lazy.Builder.RealFloat (realFloat)
23−import qualified Data.Text.Lazy as LazyText
21+import qualified Data.Text.Encoding as Text
2422
2523
2624
@@ -129,12 +127,12 @@ data PrefixOp
129127
130128
131129
132−-- CONVERT TO LAZY TEXT
130+-- ENCODE
133131
134132
135−stmtsToText :: [Stmt] -> LazyText.Text
136−stmtsToText stmts =
137− toLazyText (fromStmtBlock "" stmts)
133+encodeUtf8 :: [Stmt] -> Builder
134+encodeUtf8 stmts =
135+ fromStmtBlock "" stmts
138136
139137
140138
@@ -277,6 +275,11 @@ fromId (Id name) =
277275 fromText name
278276
279277
278+fromText :: Text -> Builder
279+fromText txt =
280+ byteString (Text.encodeUtf8 txt)
281+
282+
280283
281284-- VAR DECLS
282285
@@ -334,10 +337,10 @@ fromExpr indent grouping expression =
334337 (One, quoted string)
335338
336339 Float n ->
337− (One, realFloat n)
340+ (One, doubleDec n)
338341
339342 Int n ->
340− (One, decimal n)
343+ (One, intDec n)
341344
342345 Bool bool ->
343346 (One, if bool then "true" else "false")
@@ -482,7 +485,7 @@ fromProp prop =
482485 quoted string
483486
484487 IntProp n ->
485− decimal n
488+ intDec n
486489
487490
488491