{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
module Text.TypeScript
(
tsc
, tscJSX
, typeScriptFile
, typeScriptJSXFile
, typeScriptFileReload
, typeScriptJSXFileReload
#ifdef TEST_EXPORT
, typeScriptSettings
, typeScriptJSXSettings
#endif
) where
import Language.Haskell.TH.Quote (QuasiQuoter (..))
import Language.Haskell.TH.Syntax
import Text.Shakespeare
import Text.Julius
typeScriptSettings :: Q ShakespeareSettings
typeScriptSettings :: Q ShakespeareSettings
typeScriptSettings = do
ShakespeareSettings
jsettings <- Q ShakespeareSettings
javascriptSettings
ShakespeareSettings -> Q ShakespeareSettings
forall (m :: * -> *) a. Monad m => a -> m a
return (ShakespeareSettings -> Q ShakespeareSettings)
-> ShakespeareSettings -> Q ShakespeareSettings
forall a b. (a -> b) -> a -> b
$ ShakespeareSettings
jsettings { varChar :: Char
varChar = Char
'#'
, preConversion :: Maybe PreConvert
preConversion = PreConvert -> Maybe PreConvert
forall a. a -> Maybe a
Just PreConvert :: PreConversion
-> [Char] -> [Char] -> Maybe WrapInsertion -> PreConvert
PreConvert {
preConvert :: PreConversion
preConvert = [Char] -> [[Char]] -> PreConversion
ReadProcess [Char]
"sh" [[Char]
"-c", [Char]
"TMP_IN=$(mktemp XXXXXXXXXX.ts); TMP_OUT=$(mktemp XXXXXXXXXX.js); cat /dev/stdin > ${TMP_IN} && tsc --out ${TMP_OUT} ${TMP_IN} && cat ${TMP_OUT}; rm ${TMP_IN} && rm ${TMP_OUT}"]
, preEscapeIgnoreBalanced :: [Char]
preEscapeIgnoreBalanced = [Char]
"'\""
, preEscapeIgnoreLine :: [Char]
preEscapeIgnoreLine = [Char]
"//"
, wrapInsertion :: Maybe WrapInsertion
wrapInsertion = WrapInsertion -> Maybe WrapInsertion
forall a. a -> Maybe a
Just WrapInsertion :: Maybe [Char]
-> [Char] -> [Char] -> [Char] -> [Char] -> Bool -> WrapInsertion
WrapInsertion {
wrapInsertionIndent :: Maybe [Char]
wrapInsertionIndent = Maybe [Char]
forall a. Maybe a
Nothing
, wrapInsertionStartBegin :: [Char]
wrapInsertionStartBegin = [Char]
";(function("
, wrapInsertionSeparator :: [Char]
wrapInsertionSeparator = [Char]
", "
, wrapInsertionStartClose :: [Char]
wrapInsertionStartClose = [Char]
"){"
, wrapInsertionEnd :: [Char]
wrapInsertionEnd = [Char]
"})"
, wrapInsertionAddParens :: Bool
wrapInsertionAddParens = Bool
False
}
}
}
typeScriptJSXSettings :: Q ShakespeareSettings
typeScriptJSXSettings :: Q ShakespeareSettings
typeScriptJSXSettings = do
ShakespeareSettings
tsSettings <- Q ShakespeareSettings
typeScriptSettings
let rp :: PreConversion
rp = [Char] -> [[Char]] -> PreConversion
ReadProcess [Char]
"sh" [[Char]
"-c", [Char]
"TMP_IN=$(mktemp XXXXXXXXXX.tsx); TMP_OUT=$(mktemp XXXXXXXXXX.js); cat /dev/stdin > ${TMP_IN} && tsc --module amd --jsx react --out ${TMP_OUT} ${TMP_IN} && cat ${TMP_OUT}; rm ${TMP_IN} && rm ${TMP_OUT}"]
ShakespeareSettings -> Q ShakespeareSettings
forall (m :: * -> *) a. Monad m => a -> m a
return (ShakespeareSettings -> Q ShakespeareSettings)
-> ShakespeareSettings -> Q ShakespeareSettings
forall a b. (a -> b) -> a -> b
$ ShakespeareSettings
tsSettings {
preConversion :: Maybe PreConvert
preConversion = (PreConvert -> PreConvert) -> Maybe PreConvert -> Maybe PreConvert
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\PreConvert
pc -> PreConvert
pc { preConvert :: PreConversion
preConvert = PreConversion
rp }) (ShakespeareSettings -> Maybe PreConvert
preConversion ShakespeareSettings
tsSettings)
}
tsc :: QuasiQuoter
tsc :: QuasiQuoter
tsc = QuasiQuoter :: ([Char] -> Q Exp)
-> ([Char] -> Q Pat)
-> ([Char] -> Q Type)
-> ([Char] -> Q [Dec])
-> QuasiQuoter
QuasiQuoter { quoteExp :: [Char] -> Q Exp
quoteExp = \[Char]
s -> do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
QuasiQuoter -> [Char] -> Q Exp
quoteExp (ShakespeareSettings -> QuasiQuoter
shakespeare ShakespeareSettings
rs) [Char]
s
}
tscJSX :: QuasiQuoter
tscJSX :: QuasiQuoter
tscJSX = QuasiQuoter :: ([Char] -> Q Exp)
-> ([Char] -> Q Pat)
-> ([Char] -> Q Type)
-> ([Char] -> Q [Dec])
-> QuasiQuoter
QuasiQuoter { quoteExp :: [Char] -> Q Exp
quoteExp = \[Char]
s -> do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
QuasiQuoter -> [Char] -> Q Exp
quoteExp (ShakespeareSettings -> QuasiQuoter
shakespeare ShakespeareSettings
rs) [Char]
s
}
typeScriptFile :: FilePath -> Q Exp
typeScriptFile :: [Char] -> Q Exp
typeScriptFile [Char]
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
ShakespeareSettings -> [Char] -> Q Exp
shakespeareFile ShakespeareSettings
rs [Char]
fp
typeScriptJSXFile :: FilePath -> Q Exp
typeScriptJSXFile :: [Char] -> Q Exp
typeScriptJSXFile [Char]
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
ShakespeareSettings -> [Char] -> Q Exp
shakespeareFile ShakespeareSettings
rs [Char]
fp
typeScriptFileReload :: FilePath -> Q Exp
typeScriptFileReload :: [Char] -> Q Exp
typeScriptFileReload [Char]
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptSettings
ShakespeareSettings -> [Char] -> Q Exp
shakespeareFileReload ShakespeareSettings
rs [Char]
fp
typeScriptJSXFileReload :: FilePath -> Q Exp
typeScriptJSXFileReload :: [Char] -> Q Exp
typeScriptJSXFileReload [Char]
fp = do
ShakespeareSettings
rs <- Q ShakespeareSettings
typeScriptJSXSettings
ShakespeareSettings -> [Char] -> Q Exp
shakespeareFileReload ShakespeareSettings
rs [Char]
fp