@@ -104,9 +104,9 @@ testSuite = testGroup "Parser"
104
104
, testCase " Statement28" (testStmt " y--" " Right (JSExpression [JSExpressionPostfix \" --\" [JSIdentifier \" y\" ]])" )
105
105
106
106
-- Member Expressions
107
- , testCase " MemberExpression1" (testStmt " function(){}" " Right (JSExpression [JSFunctionExpression [] (JSFunctionBody [])])" )
108
- , testCase " MemberExpression1" (testStmt " function(a){}" " Right (JSExpression [JSFunctionExpression [JSIdentifier \" a\" ] (JSFunctionBody [])])" )
109
- , testCase " MemberExpression1" (testStmt " function(a,b){}" " Right (JSExpression [JSFunctionExpression [JSIdentifier \" a\" ,JSIdentifier \" b\" ] (JSFunctionBody [])])" )
107
+ , testCase " MemberExpression1" (testStmt " function(){}" " Right (JSExpression [JSFunctionExpression [] [] (JSFunctionBody [])])" )
108
+ , testCase " MemberExpression1" (testStmt " function(a){}" " Right (JSExpression [JSFunctionExpression [] [ JSIdentifier \" a\" ] (JSFunctionBody [])])" )
109
+ , testCase " MemberExpression1" (testStmt " function(a,b){}" " Right (JSExpression [JSFunctionExpression [] [ JSIdentifier \" a\" ,JSIdentifier \" b\" ] (JSFunctionBody [])])" )
110
110
111
111
, testCase " MemberExpression1" (testStmt " x[y]" " Right (JSExpression [JSMemberSquare [JSIdentifier \" x\" ] (JSExpression [JSIdentifier \" y\" ])])" )
112
112
, testCase " MemberExpression1" (testStmt " x[y][z]" " Right (JSExpression [JSMemberSquare [JSMemberSquare [JSIdentifier \" x\" ] (JSExpression [JSIdentifier \" y\" ])] (JSExpression [JSIdentifier \" z\" ])])" )
@@ -201,9 +201,9 @@ testSuite = testGroup "Parser"
201
201
202
202
, testCase " Comment2" (testProg " /*x=1\n y=2\n */z=2;//foo\n a" " Right (JSSourceElementsTop [JSExpression [JSIdentifier \" z\" ,JSOperator \" =\" ,JSDecimal \" 2\" ],JSLiteral \" ;\" ,JSExpression [JSIdentifier \" a\" ]])" )
203
203
204
- , testCase "min_100_animals1" (testProg "function Animal(name){if(!name)throw new Error('Must specify an animal name');this.name=name};Animal.prototype.toString=function(){return this.name};o=new Animal(\"bob\");o.toString()==\"bob\"" "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Animal\") [JSIdentifier \"name\"] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSUnary \"!\",JSIdentifier \"name\"]) (JSBlock (JSStatementList [JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"Error\",JSArguments [[JSStringLiteral '\\'' \"Must specify an animal name\"]]])])),JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\"),JSOperator \"=\",JSIdentifier \"name\"]]]),JSLiteral \";\",JSExpression [JSMemberDot [JSMemberDot [JSIdentifier \"Animal\"] (JSIdentifier \"prototype\")] (JSIdentifier \"toString\"),JSOperator \"=\",JSFunctionExpression [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\")],JSLiteral \"\"]]])],JSLiteral \";\",JSExpression [JSIdentifier \"o\",JSOperator \"=\",JSLiteral \"new \",JSIdentifier \"Animal\",JSArguments [[JSStringLiteral '\"' \"bob\"]]],JSLiteral \";\",JSExpression [JSExpressionBinary \"==\" [JSMemberDot [JSIdentifier \"o\"] (JSIdentifier \"toString\"),JSArguments []] [JSStringLiteral '\"' \"bob\"]]])")
204
+ , testCase "min_100_animals1" (testProg "function Animal(name){if(!name)throw new Error('Must specify an animal name');this.name=name};Animal.prototype.toString=function(){return this.name};o=new Animal(\"bob\");o.toString()==\"bob\"" "Right (JSSourceElementsTop [JSFunction (JSIdentifier \"Animal\") [JSIdentifier \"name\"] (JSFunctionBody [JSSourceElements [JSIf (JSExpression [JSUnary \"!\",JSIdentifier \"name\"]) (JSBlock (JSStatementList [JSThrow (JSExpression [JSLiteral \"new \",JSIdentifier \"Error\",JSArguments [[JSStringLiteral '\\'' \"Must specify an animal name\"]]])])),JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\"),JSOperator \"=\",JSIdentifier \"name\"]]]),JSLiteral \";\",JSExpression [JSMemberDot [JSMemberDot [JSIdentifier \"Animal\"] (JSIdentifier \"prototype\")] (JSIdentifier \"toString\"),JSOperator \"=\",JSFunctionExpression [] [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \"this\"] (JSIdentifier \"name\")],JSLiteral \"\"]]])],JSLiteral \";\",JSExpression [JSIdentifier \"o\",JSOperator \"=\",JSLiteral \"new \",JSIdentifier \"Animal\",JSArguments [[JSStringLiteral '\"' \"bob\"]]],JSLiteral \";\",JSExpression [JSExpressionBinary \"==\" [JSMemberDot [JSIdentifier \"o\"] (JSIdentifier \"toString\"),JSArguments []] [JSStringLiteral '\"' \"bob\"]]])")
205
205
206
- , testCase " min_100_animals2" (testProg " Animal=function(){return this.name};" " Right (JSSourceElementsTop [JSExpression [JSIdentifier \" Animal\" ,JSOperator \" =\" ,JSFunctionExpression [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \" this\" ] (JSIdentifier \" name\" )],JSLiteral \"\" ]]])],JSLiteral \" ;\" ])" )
206
+ , testCase " min_100_animals2" (testProg " Animal=function(){return this.name};" " Right (JSSourceElementsTop [JSExpression [JSIdentifier \" Animal\" ,JSOperator \" =\" ,JSFunctionExpression [] [] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSMemberDot [JSLiteral \" this\" ] (JSIdentifier \" name\" )],JSLiteral \"\" ]]])],JSLiteral \" ;\" ])" )
207
207
208
208
, testCase " min_100_animals3" (testProg " if(a)x=1;y=2" " Right (JSSourceElementsTop [JSIf (JSExpression [JSIdentifier \" a\" ]) (JSBlock (JSStatementList [JSExpression [JSIdentifier \" x\" ,JSOperator \" =\" ,JSDecimal \" 1\" ]])),JSExpression [JSIdentifier \" y\" ,JSOperator \" =\" ,JSDecimal \" 2\" ]])" )
209
209
@@ -243,6 +243,10 @@ testSuite = testGroup "Parser"
243
243
244
244
, testCase " unicode5" (testFile " ./test/Unicode.js" " JSSourceElementsTop [JSExpression [JSIdentifier \"\\ 224\\ 225\\ 226\\ 227\\ 228\\ 229\" ,JSOperator \" =\" ,JSDecimal \" 1\" ],JSLiteral \" ;\" ]" )
245
245
246
+ , testCase " bug2.a" (testProg " function() {\n z = function /*z*/(o) {\n return r;\n };}" " Right (JSSourceElementsTop [JSExpression [JSFunctionExpression [] [] (JSFunctionBody [JSSourceElements [JSExpression [JSIdentifier \" z\" ,JSOperator \" =\" ,JSFunctionExpression [] [JSIdentifier \" o\" ] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSIdentifier \" r\" ],JSLiteral \" ;\" ]]])],JSLiteral \" ;\" ]])]])" )
247
+
248
+ , testCase " bug2.b" (testProg " function() {\n z = function z(o) {\n return r;\n };}" " Right (JSSourceElementsTop [JSExpression [JSFunctionExpression [] [] (JSFunctionBody [JSSourceElements [JSExpression [JSIdentifier \" z\" ,JSOperator \" =\" ,JSFunctionExpression [JSIdentifier \" z\" ] [JSIdentifier \" o\" ] (JSFunctionBody [JSSourceElements [JSReturn [JSExpression [JSIdentifier \" r\" ],JSLiteral \" ;\" ]]])],JSLiteral \" ;\" ]])]])" )
249
+
246
250
]
247
251
248
252
srcHelloWorld = " Hello"
0 commit comments