Skip to content

Commit a087313

Browse files
test: add comprehensive object spread syntax test coverage
Add extensive test cases for object spread expressions to validate parsing, pretty printing, and minification of all spread syntax patterns. Expression parser tests: - Basic spread: {...obj} - Mixed with properties: {a: 1, ...obj}, {...obj, b: 2} - Multiple spreads: {...obj1, ...obj2} - Function call spreads: {...getObject()} - Complex combinations with methods and identifiers Minifier tests: - Whitespace removal for object spread syntax - Proper formatting preservation in minified output Validates complete ECMAScript compliance for object spread expressions including edge cases and complex object literal combinations.
1 parent eb46655 commit a087313

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

test/Test/Language/Javascript/ExpressionParser.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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')))"

test/Test/Language/Javascript/Minify.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ testMinifyExpr = describe "Minify expressions:" $ do
4646
minifyExpr " { a ( x, y ) { } } " `shouldBe` "{a(x,y){}}"
4747
minifyExpr " { [ x + y ] ( ) { } } " `shouldBe` "{[x+y](){}}"
4848
minifyExpr " { * a ( x, y ) { } } " `shouldBe` "{*a(x,y){}}"
49+
minifyExpr " { ... obj } " `shouldBe` "{...obj}"
50+
minifyExpr " { a : 1 , ... obj } " `shouldBe` "{a:1,...obj}"
51+
minifyExpr " { ... obj , b : 2 } " `shouldBe` "{...obj,b:2}"
52+
minifyExpr " { ... obj1 , ... obj2 } " `shouldBe` "{...obj1,...obj2}"
4953

5054
it "parentheses" $ do
5155
minifyExpr " ( 'hello' ) " `shouldBe` "('hello')"

0 commit comments

Comments
 (0)