git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
fixes #2581: generate JS static member accesses whenever possible
5b3b759Michael Ficarra
src/Language/PureScript/Pretty/JS.hs+4−4
@@ -159,12 +159,12 @@ conditional = mkPattern match
159 match (JSConditional ss cond th el) = Just ((ss, th, el), cond)
159 match (JSConditional ss cond th el) = Just ((ss, th, el), cond)
160 match _ = Nothing
160 match _ = Nothing
161
161
162−accessor :: (Emit gen) => Pattern PrinterState JS (gen, JS)
162+accessor :: Pattern PrinterState JS (Text, JS)
163accessor = mkPattern match
163accessor = mkPattern match
164 where
164 where
165 match (JSIndexer _ (JSStringLiteral _ prop) val) =
165 match (JSIndexer _ (JSStringLiteral _ prop) val) =
166 case decodeString prop of
166 case decodeString prop of
167− Just s | not (identNeedsEscaping s) -> Just (emit s, val)
167+ Just s | not (identNeedsEscaping s) -> Just (s, val)
168 _ -> Nothing
168 _ -> Nothing
169 match _ = Nothing
169 match _ = Nothing
170
170
@@ -259,8 +259,8 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
259 matchValue = buildPrettyPrinter operators (literals <+> fmap parensPos matchValue)
259 matchValue = buildPrettyPrinter operators (literals <+> fmap parensPos matchValue)
260 operators :: (Emit gen) => OperatorTable PrinterState JS gen
260 operators :: (Emit gen) => OperatorTable PrinterState JS gen
261 operators =
261 operators =
262− OperatorTable [ [ Wrap accessor $ \prop val -> val <> emit "." <> prop ]
262+ OperatorTable [ [ Wrap indexer $ \index val -> val <> emit "[" <> index <> emit "]" ]
263− , [ Wrap indexer $ \index val -> val <> emit "[" <> index <> emit "]" ]
263+ , [ Wrap accessor $ \prop val -> val <> emit "." <> emit prop ]
264 , [ Wrap app $ \args val -> val <> emit "(" <> args <> emit ")" ]
264 , [ Wrap app $ \args val -> val <> emit "(" <> args <> emit ")" ]
265 , [ unary JSNew "new " ]
265 , [ unary JSNew "new " ]
266 , [ Wrap lam $ \(name, args, ss) ret -> addMapping' ss <>
266 , [ Wrap lam $ \(name, args, ss) ret -> addMapping' ss <>