Skip to content

Commit

Permalink
Fixing JS not bug
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Jan 4, 2018
1 parent 291aeb8 commit 6f0294b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions spec/InspectorSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ spec = do
it "is True on direct usage in function" $ do
uses (named "m") (js "function f(x) { m }") `shouldBe` True

it "is True on direct call in function" $ do
uses (named "m") (js "function f(x) { m() }") `shouldBe` True

it "is True on negated call in function" $ do
uses (named "m") (js "function f(x) { !m() }") `shouldBe` True

it "is True on direct usage of something like it in function" $ do
uses (like "m") (js "function f(x) { m2 }") `shouldBe` True

Expand Down
8 changes: 7 additions & 1 deletion spec/JavaScriptSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec = do
js "var m = function(x) { return 1 }" `shouldBe` hs "m = \\x -> 1"

it "simple function declaration" $ do
js "function f(x) { return 1 }" `shouldBe` hs "f x = 1"
js "function f(x) { return 1 }" `shouldBe` hs "f x = 1"

it "simple procedure declaration" $ do
js "function f(x) { console.log('fruit') }" `shouldBe` (
Expand Down Expand Up @@ -83,6 +83,12 @@ spec = do
it "handles booleans" $ do
js "true" `shouldBe` MuTrue

it "handles negation" $ do
js "!true" `shouldBe` (Application (Reference "!") [MuTrue])

it "handles boolean binary operations" $ do
js "true || false " `shouldBe` (Application (Reference "||") [MuTrue, MuFalse])

it "handles lambdas" $ do
js "(function(x, y) { 1 })" `shouldBe` (Lambda [VariablePattern "x", VariablePattern "y"] (MuNumber 1))

Expand Down
2 changes: 1 addition & 1 deletion src/Language/Mulang/Parsers/JavaScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ muJSExpression (JSMemberNew _ (JSIdentifier _ name) _ args _) = New name (
--muJSExpression (JSMemberSquare JSExpression _ JSExpression _) -- ^firstpart, lb, expr, rb
muJSExpression (JSNewExpression _ (JSIdentifier _ name)) = New name []
muJSExpression (JSObjectLiteral _ propertyList _) = MuObject (compactMap id.map muJSObjectProperty.muJSCommaTrailingList $ propertyList)
muJSExpression (JSUnaryExpression (JSUnaryOpNot _) e) = Application (Reference "!") [muJSExpression e]
muJSExpression (JSUnaryExpression op (JSIdentifier _ name)) = Assignment name (muJSUnaryOp op name)
muJSExpression (JSVarInitExpression (JSIdentifier _ name) initial) = Variable name (muJSVarInitializer initial)
muJSExpression _ = Other
Expand Down Expand Up @@ -147,7 +148,6 @@ muJSUnaryOp (JSUnaryOpDecr _) r = (Application (Reference "-") [Reference r, MuN
--muJSUnaryOp (JSUnaryOpDelete _)
muJSUnaryOp (JSUnaryOpIncr _) r = (Application (Reference "+") [Reference r, MuNumber 1])
--muJSUnaryOp (JSUnaryOpMinus _)
--muJSUnaryOp (JSUnaryOpNot _)
--muJSUnaryOp (JSUnaryOpPlus _)
--muJSUnaryOp (JSUnaryOpTilde _)
--muJSUnaryOp (JSUnaryOpTypeof _)
Expand Down

0 comments on commit 6f0294b

Please sign in to comment.