|
| 1 | +{-# LANGUAGE OverloadedStrings #-} |
| 2 | + |
1 | 3 | -- | This module defines a basic AST for generating TypeScript |
2 | 4 | -- declaration files, and basic pretty-printing functionality. |
3 | 5 | -- |
@@ -31,10 +33,10 @@ printTypeScriptFile tsFile = do |
31 | 33 | buildMultilineComment :: Int -> [String] -> TLB.Builder |
32 | 34 | buildMultilineComment indentLevel commentLines = |
33 | 35 | let indentation = TLB.fromLazyText $ TL.replicate (fromIntegral indentLevel) " " |
34 | | - bodyIndentation = indentation <> TLB.fromString " * " |
35 | | - firstLine = indentation <> TLB.fromString "/**" |
| 36 | + bodyIndentation = indentation <> " * " |
| 37 | + firstLine = indentation <> "/**" |
36 | 38 | indentedCommentLines = map (\line -> (bodyIndentation <>) . TLB.fromString $ line <> "\n") commentLines |
37 | | - lastLine = indentation <> TLB.fromString " */" |
| 39 | + lastLine = indentation <> " */" |
38 | 40 | in mconcat [firstLine, "\n", mconcat indentedCommentLines, lastLine] |
39 | 41 |
|
40 | 42 | -- | Represents the top-level structure of a TypeScript declaration file. |
@@ -90,14 +92,14 @@ data DeclarationType |
90 | 92 | -- | Creates a builder for a TypeScript declaration type and content. |
91 | 93 | buildDeclarationType :: DeclarationType -> TLB.Builder |
92 | 94 | buildDeclarationType (ExportDec isDefault symbolName) = |
93 | | - TLB.fromString "export " |
94 | | - <> TLB.fromString (if isDefault then "default " else "") |
| 95 | + "export " |
| 96 | + <> (if isDefault then "default " else "") |
95 | 97 | <> TLB.fromString symbolName |
96 | | - <> TLB.fromString ";" |
| 98 | + <> ";" |
97 | 99 | buildDeclarationType (FunctionDec header) = |
98 | | - TLB.fromString "declare function " <> buildFunctionHeader header <> TLB.fromString ";" |
| 100 | + "declare function " <> buildFunctionHeader header <> ";" |
99 | 101 | buildDeclarationType (InterfaceDec name properties) = |
100 | | - TLB.fromString "declare interface " |
| 102 | + "declare interface " |
101 | 103 | <> TLB.fromString name |
102 | 104 | <> " {" |
103 | 105 | <> mconcat (map (\prop -> "\n" <> buildInterfaceContent prop <> "\n") properties) |
@@ -131,7 +133,7 @@ buildFunctionHeader :: FunctionHeader -> TLB.Builder |
131 | 133 | buildFunctionHeader (FunctionHeader name params returnType) = |
132 | 134 | TLB.fromString name |
133 | 135 | <> "(" |
134 | | - <> mconcatWith (TLB.fromString ", ") (map buildFunctionParam params) |
| 136 | + <> mconcatWith ", " (map buildFunctionParam params) |
135 | 137 | <> "): " |
136 | 138 | <> TLB.fromString returnType |
137 | 139 |
|
@@ -177,7 +179,7 @@ buildInterfaceContentType (InterfaceProperty name pType) = |
177 | 179 | buildInterfaceContentType (InterfaceMethod name params returnType) = |
178 | 180 | TLB.fromString name |
179 | 181 | <> "(" |
180 | | - <> mconcatWith (TLB.fromString ", ") (map buildFunctionParam params) |
| 182 | + <> mconcatWith ", " (map buildFunctionParam params) |
181 | 183 | <> "): " |
182 | 184 | <> TLB.fromString returnType |
183 | 185 | <> ";" |
|
0 commit comments