git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
comment-styles: style comment types differently (#2597)
bc18c54Matthew Leon
CONTRIBUTORS.md+1
@@ -87,6 +87,7 @@ This file lists the contributors to the PureScript compiler project, and the ter
87- [@bbqbaron](https://github.com/bbqbaron) (Eric Loren) My existing contributions and all future contributions until further notice are Copyright Eric Loren, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
87- [@bbqbaron](https://github.com/bbqbaron) (Eric Loren) My existing contributions and all future contributions until further notice are Copyright Eric Loren, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
88- [@RyanGlScott](https://github.com/RyanGlScott) (Ryan Scott) My existing contributions and all future contributions until further notice are Copyright Ryan Scott, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
88- [@RyanGlScott](https://github.com/RyanGlScott) (Ryan Scott) My existing contributions and all future contributions until further notice are Copyright Ryan Scott, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
89- [@seungha-kim](https://github.com/seungha-kim) (Seungha Kim) My existing contributions and all future contributions until further notice are Copyright Seungha Kim, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
89- [@seungha-kim](https://github.com/seungha-kim) (Seungha Kim) My existing contributions and all future contributions until further notice are Copyright Seungha Kim, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
90+- [@matthewleon](https://github.com/matthewleon) (Matthew Leon) My existing contributions and all future contributions until further notice are Copyright Matthew Leon, and are licensed to the owners and users of the PureScript compiler project under the terms of the [MIT license](http://opensource.org/licenses/MIT).
90
91
91### Companies
92### Companies
92
93
src/Language/PureScript/Pretty/JS.hs+15−9
@@ -122,22 +122,30 @@ literals = mkPattern' match'
122 [ return $ emit $ lbl <> ": "
122 [ return $ emit $ lbl <> ": "
123 , prettyPrintJS' js
123 , prettyPrintJS' js
124 ]
124 ]
125− match (JSComment _ com js) = fmap mconcat $ sequence $
125+ match (JSComment _ com js) = mconcat <$> sequence
126+ [ mconcat <$> forM com comment
127+ , prettyPrintJS' js
128+ ]
129+ match (JSRaw _ js) = return $ emit js
130+ match _ = mzero
131+
132+ comment :: (Emit gen) => Comment -> StateT PrinterState Maybe gen
133+ comment (LineComment com) = fmap mconcat $ sequence $
134+ [ return $ emit "\n"
135+ , currentIndent
136+ , return $ emit "//" <> emit com <> emit "\n"
137+ ]
138+ comment (BlockComment com) = fmap mconcat $ sequence $
126 [ return $ emit "\n"
139 [ return $ emit "\n"
127 , currentIndent
140 , currentIndent
128 , return $ emit "/**\n"
141 , return $ emit "/**\n"
129 ] ++
142 ] ++
130− map asLine (concatMap commentLines com) ++
143+ map asLine (T.lines com) ++
131 [ currentIndent
144 [ currentIndent
132 , return $ emit " */\n"
145 , return $ emit " */\n"
133 , currentIndent
146 , currentIndent
134− , prettyPrintJS' js
135 ]
147 ]
136 where
148 where
137− commentLines :: Comment -> [Text]
138− commentLines (LineComment s) = [s]
139− commentLines (BlockComment s) = T.lines s
140−
141 asLine :: (Emit gen) => Text -> StateT PrinterState Maybe gen
149 asLine :: (Emit gen) => Text -> StateT PrinterState Maybe gen
142 asLine s = do
150 asLine s = do
143 i <- currentIndent
151 i <- currentIndent
@@ -150,8 +158,6 @@ literals = mkPattern' match'
150 Nothing -> case T.uncons t of
158 Nothing -> case T.uncons t of
151 Just (x, xs) -> x `T.cons` removeComments xs
159 Just (x, xs) -> x `T.cons` removeComments xs
152 Nothing -> ""
160 Nothing -> ""
153− match (JSRaw _ js) = return $ emit js
154− match _ = mzero
155
161
156conditional :: Pattern PrinterState JS ((Maybe SourceSpan, JS, JS), JS)
162conditional :: Pattern PrinterState JS ((Maybe SourceSpan, JS, JS), JS)
157conditional = mkPattern match
163conditional = mkPattern match