git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #958 from purescript/js-op-precedence

Fix JS operator precedence

commit08b38fd4f25c200aebe2365bc040d16810cbb6e3 authorGary Burgess <gary.burgess@gmail.com> dateTue 17 Mar 2015, 23:46 (12 years ago) parenta60f34a738b03c
2 files changed+30−14
examples/passing/OperatorAssociativity.purs+16 src/Language/PureScript/Pretty/JS.hs+14−14
examples/passing/OperatorAssociativity.purs+16
@@ -40,3 +40,19 @@ main = do
4040
4141 assert (4 % (9 / 3) == 1) "4 % (9 / 3) == 1"
4242 assert ((4 % 9) / 2 == 2) "(4 % 9) / 2 == 2"
43+
44+ assert (not (1 < 0) == true) "not (1 < 0) == true"
45+ assert (not (complement (1 + 10) == 8) == true) "not (complement (1 + 10) == 8) == true"
46+ assert (not ((negate 1) < 0) == false) "not ((negate 1) < 0) == false"
47+
48+ assert (negate (1 + 10) == -11) "negate (1 + 10) == -11"
49+
50+ assert (2 * 3 / 4 == 1.5) "2 * 3 / 4 == 1.5"
51+ assert (1 * 2 * 3 * 4 * 5 / 6 == 20) "1 * 2 * 3 * 4 * 5 / 6 == 20"
52+ assert (complement (2 / 3 * 4) == -3) "complement (2 / 3 * 4) == -3"
53+
54+ assert (1 + 10 - 5 == 6) "1 + 10 - 5 == 6"
55+ assert (1 + 10 * 5 == 51) "1 + 10 * 5 == 51"
56+ assert (10 * 5 - 1 == 49) "10 * 5 - 1 == 49"
57+
58+ trace "Success!"
src/Language/PureScript/Pretty/JS.hs+14−14
@@ -272,26 +272,26 @@ prettyPrintJS' = A.runKleisli $ runPattern matchValue
272272 ++ fromMaybe "" name
273273 ++ "(" ++ intercalate ", " args ++ ") "
274274 ++ ret ]
275− , [ binary LessThan "<" ]
276− , [ binary LessThanOrEqualTo "<=" ]
277− , [ binary GreaterThan ">" ]
278− , [ binary GreaterThanOrEqualTo ">=" ]
279275 , [ Wrap typeOf $ \_ s -> "typeof " ++ s ]
280− , [ AssocR instanceOf $ \v1 v2 -> v1 ++ " instanceof " ++ v2 ]
281− , [ unary Not "!" ]
282− , [ unary BitwiseNot "~" ]
283− , [ negateOperator ]
284− , [ unary Positive "+" ]
276+ , [ unary Not "!"
277+ , unary BitwiseNot "~"
278+ , unary Positive "+"
279+ , negateOperator ]
285280 , [ binary Multiply "*"
286281 , binary Divide "/"
287282 , binary Modulus "%" ]
288283 , [ binary Add "+"
289284 , binary Subtract "-" ]
290− , [ binary ShiftLeft "<<" ]
291− , [ binary ShiftRight ">>" ]
292− , [ binary ZeroFillShiftRight ">>>" ]
293− , [ binary EqualTo "===" ]
294− , [ binary NotEqualTo "!==" ]
285+ , [ binary ShiftLeft "<<"
286+ , binary ShiftRight ">>"
287+ , binary ZeroFillShiftRight ">>>" ]
288+ , [ binary LessThan "<"
289+ , binary LessThanOrEqualTo "<="
290+ , binary GreaterThan ">"
291+ , binary GreaterThanOrEqualTo ">="
292+ , AssocR instanceOf $ \v1 v2 -> v1 ++ " instanceof " ++ v2 ]
293+ , [ binary EqualTo "==="
294+ , binary NotEqualTo "!==" ]
295295 , [ binary BitwiseAnd "&" ]
296296 , [ binary BitwiseXor "^" ]
297297 , [ binary BitwiseOr "|" ]