@@ -65,6 +65,16 @@ testExpressionParser = describe "Parse expressions:" $ do
6565 testExpr " {[x]() {}}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSMethodDefinition (JSPropertyComputed (JSIdentifier 'x')) () (JSBlock [])]))"
6666 testExpr " {*a(x,y) {yield y;}}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSGeneratorMethodDefinition (JSIdentifier 'a') (JSIdentifier 'x',JSIdentifier 'y') (JSBlock [JSYieldExpression (JSIdentifier 'y'),JSSemicolon])]))"
6767 testExpr " {*[x]({y},...z) {}}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSGeneratorMethodDefinition (JSPropertyComputed (JSIdentifier 'x')) (JSObjectLiteral [JSPropertyIdentRef 'y'],JSSpreadExpression (JSIdentifier 'z')) (JSBlock [])]))"
68+
69+ it " object spread" $ do
70+ testExpr " {...obj}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSObjectSpread (JSIdentifier 'obj')]))"
71+ testExpr " {a: 1, ...obj}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSPropertyNameandValue (JSIdentifier 'a') [JSDecimal '1'],JSObjectSpread (JSIdentifier 'obj')]))"
72+ testExpr " {...obj, b: 2}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSObjectSpread (JSIdentifier 'obj'),JSPropertyNameandValue (JSIdentifier 'b') [JSDecimal '2']]))"
73+ testExpr " {a: 1, ...obj, b: 2}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSPropertyNameandValue (JSIdentifier 'a') [JSDecimal '1'],JSObjectSpread (JSIdentifier 'obj'),JSPropertyNameandValue (JSIdentifier 'b') [JSDecimal '2']]))"
74+ testExpr " {...obj1, ...obj2}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSObjectSpread (JSIdentifier 'obj1'),JSObjectSpread (JSIdentifier 'obj2')]))"
75+ testExpr " {...getObject()}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSObjectSpread (JSMemberExpression (JSIdentifier 'getObject',JSArguments ()))]))"
76+ testExpr " {x, ...obj, y}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSPropertyIdentRef 'x',JSObjectSpread (JSIdentifier 'obj'),JSPropertyIdentRef 'y']))"
77+ testExpr " {...obj, method() {}}" `shouldBe` " Right (JSAstExpression (JSObjectLiteral [JSObjectSpread (JSIdentifier 'obj'),JSMethodDefinition (JSIdentifier 'method') () (JSBlock [])]))"
6878
6979 it " unary expression" $ do
7080 testExpr " delete y" `shouldBe` " Right (JSAstExpression (JSUnaryExpression ('delete',JSIdentifier 'y')))"
0 commit comments