@@ -1,10 +1,10 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Generate.JavaScript.Builder
3module Generate.JavaScript.Builder
4− ( Expr(..), Id(..), Prop(..), LValue(..)
5+ , Expr(..), Id(..), Prop(..), LValue(..)
5 , Stmt(..), Case(..), VarDecl(..)
6 , Stmt(..), Case(..), VarDecl(..)
6 , InfixOp(..), PrefixOp(..)
7 , InfixOp(..), PrefixOp(..)
@@ -15,12 +15,10 @@ module Generate.JavaScript.Builder
16import Prelude hiding (lines)
16import Prelude hiding (lines)
17import qualified Data.List as List
17import qualified Data.List as List
18+import Data.ByteString.Builder
18import Data.Monoid ((<>))
19import Data.Monoid ((<>))
19import Data.Text (Text)
20import 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
@@ -129,12 +127,12 @@ data PrefixOp
132−-- CONVERT TO LAZY TEXT
130+-- ENCODE
135−stmtsToText :: [Stmt] -> LazyText.Text
133+encodeUtf8 :: [Stmt] -> Builder
136−stmtsToText stmts =
134+encodeUtf8 stmts =
137− toLazyText (fromStmtBlock "" stmts)
135+ fromStmtBlock "" stmts
@@ -277,6 +275,11 @@ fromId (Id name) =
277 fromText name
275 fromText name
278+fromText :: Text -> Builder
280+ byteString (Text.encodeUtf8 txt)
281-- VAR DECLS
284-- VAR DECLS
@@ -334,10 +337,10 @@ fromExpr indent grouping expression =
334 (One, quoted string)
337 (One, quoted string)
336 Float n ->
339 Float n ->
337− (One, realFloat n)
340+ (One, doubleDec n)
340− (One, decimal n)
343+ (One, intDec n)
342 Bool bool ->
345 Bool bool ->
343 (One, if bool then "true" else "false")
346 (One, if bool then "true" else "false")
@@ -482,7 +485,7 @@ fromProp prop =
482 quoted string
485 quoted string
484 IntProp n ->
487 IntProp n ->
485− decimal n
488+ intDec n