Skip to content

Commit e2337f4

Browse files
flbulgarellierikd
authored andcommitted
Adding support for for..of and friends
1 parent 754aa45 commit e2337f4

File tree

10 files changed

+68
-3
lines changed

10 files changed

+68
-3
lines changed

src/Language/JavaScript/Parser/AST.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ data JSStatement
127127
| JSForIn !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,expr,in,expr,rb,stmt
128128
| JSForVar !JSAnnot !JSAnnot !JSAnnot !(JSCommaList JSExpression) !JSAnnot !(JSCommaList JSExpression) !JSAnnot !(JSCommaList JSExpression) !JSAnnot !JSStatement -- ^for,lb,var,vardecl,semi,expr,semi,expr,rb,stmt
129129
| JSForVarIn !JSAnnot !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,var,vardecl,in,expr,rb,stmt
130+
| JSForLet !JSAnnot !JSAnnot !JSAnnot !(JSCommaList JSExpression) !JSAnnot !(JSCommaList JSExpression) !JSAnnot !(JSCommaList JSExpression) !JSAnnot !JSStatement -- ^for,lb,var,vardecl,semi,expr,semi,expr,rb,stmt
131+
| JSForLetIn !JSAnnot !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,var,vardecl,in,expr,rb,stmt
132+
| JSForLetOf !JSAnnot !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,var,vardecl,in,expr,rb,stmt
133+
| JSForOf !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,expr,in,expr,rb,stmt
134+
| JSForVarOf !JSAnnot !JSAnnot !JSAnnot !JSExpression !JSBinOp !JSExpression !JSAnnot !JSStatement -- ^for,lb,var,vardecl,in,expr,rb,stmt
130135
| JSFunction !JSAnnot !JSIdent !JSAnnot !(JSCommaList JSIdent) !JSAnnot !JSBlock !JSSemi -- ^fn,name, lb,parameter list,rb,block,autosemi
131136
| JSIf !JSAnnot !JSAnnot !JSExpression !JSAnnot !JSStatement -- ^if,(,expr,),stmt
132137
| JSIfElse !JSAnnot !JSAnnot !JSExpression !JSAnnot !JSStatement !JSAnnot !JSStatement -- ^if,(,expr,),stmt,else,rest
@@ -196,6 +201,7 @@ data JSBinOp
196201
| JSBinOpMinus !JSAnnot
197202
| JSBinOpMod !JSAnnot
198203
| JSBinOpNeq !JSAnnot
204+
| JSBinOpOf !JSAnnot
199205
| JSBinOpOr !JSAnnot
200206
| JSBinOpPlus !JSAnnot
201207
| JSBinOpRsh !JSAnnot
@@ -328,6 +334,11 @@ instance ShowStripped JSStatement where
328334
ss (JSForIn _ _lb x1s _i x2 _rb x3) = "JSForIn " ++ ss x1s ++ " (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
329335
ss (JSForVar _ _lb _v x1s _s1 x2s _s2 x3s _rb x4) = "JSForVar " ++ ss x1s ++ " " ++ ss x2s ++ " " ++ ss x3s ++ " (" ++ ss x4 ++ ")"
330336
ss (JSForVarIn _ _lb _v x1 _i x2 _rb x3) = "JSForVarIn (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
337+
ss (JSForLet _ _lb _v x1s _s1 x2s _s2 x3s _rb x4) = "JSForLet " ++ ss x1s ++ " " ++ ss x2s ++ " " ++ ss x3s ++ " (" ++ ss x4 ++ ")"
338+
ss (JSForLetIn _ _lb _v x1 _i x2 _rb x3) = "JSForLetIn (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
339+
ss (JSForLetOf _ _lb _v x1 _i x2 _rb x3) = "JSForLetOf (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
340+
ss (JSForOf _ _lb x1s _i x2 _rb x3) = "JSForOf " ++ ss x1s ++ " (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
341+
ss (JSForVarOf _ _lb _v x1 _i x2 _rb x3) = "JSForVarOf (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
331342
ss (JSFunction _ n _lb pl _rb x3 _) = "JSFunction " ++ ssid n ++ " " ++ ss pl ++ " (" ++ ss x3 ++ ")"
332343
ss (JSIf _ _lb x1 _rb x2) = "JSIf (" ++ ss x1 ++ ") (" ++ ss x2 ++ ")"
333344
ss (JSIfElse _ _lb x1 _rb x2 _e x3) = "JSIfElse (" ++ ss x1 ++ ") (" ++ ss x2 ++ ") (" ++ ss x3 ++ ")"
@@ -463,6 +474,7 @@ instance ShowStripped JSBinOp where
463474
ss (JSBinOpMinus _) = "'-'"
464475
ss (JSBinOpMod _) = "'%'"
465476
ss (JSBinOpNeq _) = "'!='"
477+
ss (JSBinOpOf _) = "'of'"
466478
ss (JSBinOpOr _) = "'||'"
467479
ss (JSBinOpPlus _) = "'+'"
468480
ss (JSBinOpRsh _) = "'>>'"
@@ -559,6 +571,7 @@ deAnnot (JSBinOpLt _) = JSBinOpLt JSNoAnnot
559571
deAnnot (JSBinOpMinus _) = JSBinOpMinus JSNoAnnot
560572
deAnnot (JSBinOpMod _) = JSBinOpMod JSNoAnnot
561573
deAnnot (JSBinOpNeq _) = JSBinOpNeq JSNoAnnot
574+
deAnnot (JSBinOpOf _) = JSBinOpOf JSNoAnnot
562575
deAnnot (JSBinOpOr _) = JSBinOpOr JSNoAnnot
563576
deAnnot (JSBinOpPlus _) = JSBinOpPlus JSNoAnnot
564577
deAnnot (JSBinOpRsh _) = JSBinOpRsh JSNoAnnot

src/Language/JavaScript/Parser/Grammar7.y

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import qualified Language.JavaScript.Parser.AST as AST
110110
'let' { LetToken {} }
111111
'new' { NewToken {} }
112112
'null' { NullToken {} }
113+
'of' { OfToken {} }
113114
'return' { ReturnToken {} }
114115
'set' { SetToken {} }
115116
'switch' { SwitchToken {} }
@@ -271,6 +272,9 @@ StrictNe : '!==' { AST.JSBinOpStrictNeq (mkJSAnnot $1) }
271272
Ne :: { AST.JSBinOp }
272273
Ne : '!=' { AST.JSBinOpNeq (mkJSAnnot $1)}
273274

275+
Of :: { AST.JSBinOp }
276+
Of : 'of' { AST.JSBinOpOf (mkJSAnnot $1) }
277+
274278
Or :: { AST.JSBinOp }
275279
Or : '||' { AST.JSBinOpOr (mkJSAnnot $1) }
276280

@@ -470,6 +474,7 @@ IdentifierName : Identifier {$1}
470474
| 'let' { AST.JSIdentifier (mkJSAnnot $1) "let" }
471475
| 'new' { AST.JSIdentifier (mkJSAnnot $1) "new" }
472476
| 'null' { AST.JSIdentifier (mkJSAnnot $1) "null" }
477+
| 'of' { AST.JSIdentifier (mkJSAnnot $1) "of" }
473478
| 'return' { AST.JSIdentifier (mkJSAnnot $1) "return" }
474479
| 'set' { AST.JSIdentifier (mkJSAnnot $1) "set" }
475480
| 'switch' { AST.JSIdentifier (mkJSAnnot $1) "switch" }
@@ -1005,9 +1010,19 @@ IterationStatement : Do StatementNoEmpty While LParen Expression RParen MaybeSem
10051010
| For LParen Var VariableDeclarationListNoIn Semi ExpressionOpt Semi ExpressionOpt RParen Statement
10061011
{ AST.JSForVar $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 {- 'IterationStatement4' -} }
10071012
| For LParen LeftHandSideExpression In Expression RParen Statement
1008-
{ AST.JSForIn $1 $2 $3 $4 $5 $6 $7 {- 'IterationStatement 5-} }
1013+
{ AST.JSForIn $1 $2 $3 $4 $5 $6 $7 {- 'IterationStatement 5' -} }
10091014
| For LParen Var VariableDeclarationNoIn In Expression RParen Statement
10101015
{ AST.JSForVarIn $1 $2 $3 $4 $5 $6 $7 $8 {- 'IterationStatement6' -} }
1016+
| For LParen Let VariableDeclarationListNoIn Semi ExpressionOpt Semi ExpressionOpt RParen Statement
1017+
{ AST.JSForLet $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 {- 'IterationStatement 7' -} }
1018+
| For LParen Let VariableDeclarationNoIn In Expression RParen Statement
1019+
{ AST.JSForLetIn $1 $2 $3 $4 $5 $6 $7 $8 {- 'IterationStatement 8' -} }
1020+
| For LParen Let VariableDeclarationNoIn Of Expression RParen Statement
1021+
{ AST.JSForLetOf $1 $2 $3 $4 $5 $6 $7 $8 {- 'IterationStatement 9' -} }
1022+
| For LParen LeftHandSideExpression Of Expression RParen Statement
1023+
{ AST.JSForOf $1 $2 $3 $4 $5 $6 $7 {- 'IterationStatement 10'-} }
1024+
| For LParen Var VariableDeclarationNoIn Of Expression RParen Statement
1025+
{ AST.JSForVarOf $1 $2 $3 $4 $5 $6 $7 $8 {- 'IterationStatement 11' -} }
10111026

10121027
-- ContinueStatement : See 12.7
10131028
-- continue [no LineTerminator here] Identifieropt ;

src/Language/JavaScript/Parser/Lexer.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ keywordNames =
535535
536536
, ( "null", NullToken ) -- null literal
537537
538+
, ( "of", OfToken )
538539
, ( "return", ReturnToken )
539540
, ( "switch", SwitchToken )
540541
, ( "this", ThisToken )

src/Language/JavaScript/Parser/Token.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ data Token
7979
| InstanceofToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8080
| NewToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8181
| NullToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
82+
| OfToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8283
| ReturnToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8384
| SwitchToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }
8485
| ThisToken { tokenSpan :: !TokenPosn, tokenLiteral :: !String, tokenComment :: ![CommentAnnotation] }

src/Language/JavaScript/Pretty/Printer.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ instance RenderJS JSBinOp where
155155
(|>) pacc (JSBinOpMinus annot) = pacc |> annot |> "-"
156156
(|>) pacc (JSBinOpMod annot) = pacc |> annot |> "%"
157157
(|>) pacc (JSBinOpNeq annot) = pacc |> annot |> "!="
158+
(|>) pacc (JSBinOpOf annot) = pacc |> annot |> "of"
158159
(|>) pacc (JSBinOpOr annot) = pacc |> annot |> "||"
159160
(|>) pacc (JSBinOpPlus annot) = pacc |> annot |> "+"
160161
(|>) pacc (JSBinOpRsh annot) = pacc |> annot |> ">>"
@@ -225,6 +226,11 @@ instance RenderJS JSStatement where
225226
(|>) pacc (JSForIn af alb x1s i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> x1s |> i |> x2 |> arb |> ")" |> x3
226227
(|>) pacc (JSForVar af alb v x1s s1 x2s s2 x3s arb x4) = pacc |> af |> "for" |> alb |> "(" |> "var" |> v |> x1s |> s1 |> ";" |> x2s |> s2 |> ";" |> x3s |> arb |> ")" |> x4
227228
(|>) pacc (JSForVarIn af alb v x1 i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> "var" |> v |> x1 |> i |> x2 |> arb |> ")" |> x3
229+
(|>) pacc (JSForLet af alb v x1s s1 x2s s2 x3s arb x4) = pacc |> af |> "for" |> alb |> "(" |> "let" |> v |> x1s |> s1 |> ";" |> x2s |> s2 |> ";" |> x3s |> arb |> ")" |> x4
230+
(|>) pacc (JSForLetIn af alb v x1 i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> "let" |> v |> x1 |> i |> x2 |> arb |> ")" |> x3
231+
(|>) pacc (JSForLetOf af alb v x1 i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> "let" |> v |> x1 |> i |> x2 |> arb |> ")" |> x3
232+
(|>) pacc (JSForOf af alb x1s i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> x1s |> i |> x2 |> arb |> ")" |> x3
233+
(|>) pacc (JSForVarOf af alb v x1 i x2 arb x3) = pacc |> af |> "for" |> alb |> "(" |> "var" |> v |> x1 |> i |> x2 |> arb |> ")" |> x3
228234
(|>) pacc (JSFunction af n alb x2s arb x3 s) = pacc |> af |> "function" |> n |> alb |> "(" |> x2s |> arb |> ")" |> x3 |> s
229235
(|>) pacc (JSIf annot alb x1 arb x2s) = pacc |> annot |> "if" |> alb |> "(" |> x1 |> arb |> ")" |> x2s
230236
(|>) pacc (JSIfElse annot alb x1 arb x2s ea x3s) = pacc |> annot |> "if" |> alb |> "(" |> x1 |> arb |> ")" |> x2s |> ea |> "else" |> x3s

src/Language/JavaScript/Process/Minify.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ fixStmt a s (JSFor _ _ el1 _ el2 _ el3 _ st) = JSFor a emptyAnnot (fixEmpty el1)
4848
fixStmt a s (JSForIn _ _ e1 op e2 _ st) = JSForIn a emptyAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
4949
fixStmt a s (JSForVar _ _ _ el1 _ el2 _ el3 _ st) = JSForVar a emptyAnnot spaceAnnot (fixEmpty el1) emptyAnnot (fixEmpty el2) emptyAnnot (fixEmpty el3) emptyAnnot (fixStmtE s st)
5050
fixStmt a s (JSForVarIn _ _ _ e1 op e2 _ st) = JSForVarIn a emptyAnnot spaceAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
51+
fixStmt a s (JSForLet _ _ _ el1 _ el2 _ el3 _ st) = JSForLet a emptyAnnot spaceAnnot (fixEmpty el1) emptyAnnot (fixEmpty el2) emptyAnnot (fixEmpty el3) emptyAnnot (fixStmtE s st)
52+
fixStmt a s (JSForLetIn _ _ _ e1 op e2 _ st) = JSForLetIn a emptyAnnot spaceAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
53+
fixStmt a s (JSForLetOf _ _ _ e1 op e2 _ st) = JSForLetOf a emptyAnnot spaceAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
54+
fixStmt a s (JSForOf _ _ e1 op e2 _ st) = JSForOf a emptyAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
55+
fixStmt a s (JSForVarOf _ _ _ e1 op e2 _ st) = JSForVarOf a emptyAnnot spaceAnnot (fixEmpty e1) (fixSpace op) (fixSpace e2) emptyAnnot (fixStmtE s st)
5156
fixStmt a s (JSFunction _ n _ ps _ blk _) = JSFunction a (fixSpace n) emptyAnnot (fixEmpty ps) emptyAnnot (fixEmpty blk) s
5257
fixStmt a s (JSIf _ _ e _ st) = JSIf a emptyAnnot (fixEmpty e) emptyAnnot (fixIfElseBlock emptyAnnot s st)
5358
fixStmt a s (JSIfElse _ _ e _ (JSEmptyStatement _) _ sf) = JSIfElse a emptyAnnot (fixEmpty e) emptyAnnot (JSEmptyStatement emptyAnnot) emptyAnnot (fixStmt spaceAnnot s sf)
@@ -226,6 +231,7 @@ instance MinifyJS JSBinOp where
226231
fix _ (JSBinOpMinus _) = JSBinOpMinus emptyAnnot
227232
fix _ (JSBinOpMod _) = JSBinOpMod emptyAnnot
228233
fix _ (JSBinOpNeq _) = JSBinOpNeq emptyAnnot
234+
fix a (JSBinOpOf _) = JSBinOpOf a
229235
fix _ (JSBinOpOr _) = JSBinOpOr emptyAnnot
230236
fix _ (JSBinOpPlus _) = JSBinOpPlus emptyAnnot
231237
fix _ (JSBinOpRsh _) = JSBinOpRsh emptyAnnot

test/Test/Language/Javascript/Lexer.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ testLexer = describe "Lexer:" $ do
6161
testLex "continue\nx=1" `shouldBe` "[ContinueToken,WsToken,IdentifierToken 'x',SimpleAssignToken,DecimalToken 1]"
6262
testLex "return\nx=1" `shouldBe` "[ReturnToken,WsToken,IdentifierToken 'x',SimpleAssignToken,DecimalToken 1]"
6363

64+
it "var/let" $ do
65+
testLex "var\n" `shouldBe` "[VarToken,WsToken]"
66+
testLex "let\n" `shouldBe` "[LetToken,WsToken]"
67+
68+
it "in/of" $ do
69+
testLex "in\n" `shouldBe` "[InToken,WsToken]"
70+
testLex "of\n" `shouldBe` "[OfToken,WsToken]"
71+
6472

6573
testLex :: String -> String
6674
testLex str =

test/Test/Language/Javascript/Minify.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ testMinifyStmt = describe "Minify statements:" $ do
180180
minifyStmt " for (var x ; y ; z) { } " `shouldBe` "for(var x;y;z){}"
181181
minifyStmt " for ( x in 5 ) foo (x) ;" `shouldBe` "for(x in 5)foo(x)"
182182
minifyStmt " for ( var x in 5 ) { foo ( x++ ); y ++ ; } ;" `shouldBe` "for(var x in 5){foo(x++);y++}"
183-
183+
minifyStmt " for (let x ; y ; z) { } " `shouldBe` "for(let x;y;z){}"
184+
minifyStmt " for ( let x in 5 ) { foo ( x++ ); y ++ ; } ;" `shouldBe` "for(let x in 5){foo(x++);y++}"
185+
minifyStmt " for ( let x of 5 ) { foo ( x++ ); y ++ ; } ;" `shouldBe` "for(let x of 5){foo(x++);y++}"
186+
minifyStmt " for ( x of 5 ) { foo ( x++ ); y ++ ; } ;" `shouldBe` "for(x of 5){foo(x++);y++}"
187+
minifyStmt " for ( var x of 5 ) { foo ( x++ ); y ++ ; } ;" `shouldBe` "for(var x of 5){foo(x++);y++}"
184188
it "labelled" $ do
185189
minifyStmt " start : while ( true ) { if ( i ++ < 3 ) continue start ; break ; } ; " `shouldBe` "start:while(true){if(i++<3)continue start;break}"
186190
minifyStmt " { k ++ ; start : while ( true ) { if ( i ++ < 3 ) continue start ; break ; } ; } ; " `shouldBe` "{k++;start:while(true){if(i++<3)continue start;break}}"

test/Test/Language/Javascript/RoundTrip.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ testRoundTrip = describe "Roundtrip:" $ do
5959
testRT "/*a*/x/*b*/>/*c*/y"
6060
testRT "/*a*/x/*b*/<=/*c*/y"
6161
testRT "/*a*/x/*b*/>=/*c*/y"
62-
testRT "/*a*/x /*b*/instance of /*c*/y"
62+
testRT "/*a*/x /*b*/instanceof /*c*/y"
6363
testRT "/*a*/x/*b*/=/*c*/{/*d*/get/*e*/ foo/*f*/(/*g*/)/*h*/ {/*i*/return/*j*/ 1/*k*/}/*l*/,/*m*/set/*n*/ foo/*o*/(/*p*/a/*q*/) /*r*/{/*s*/x/*t*/=/*u*/a/*v*/}/*w*/}"
6464
testRT "... /*a*/ x"
6565

@@ -83,6 +83,11 @@ testRoundTrip = describe "Roundtrip:" $ do
8383
testRT "for(var x;y;z){}"
8484
testRT "for(x in 5){}"
8585
testRT "for(var x in 5){}"
86+
testRT "for(let x;y;z){}"
87+
testRT "for(let x in 5){}"
88+
testRT "for(let x of 5){}"
89+
testRT "for(x of 5){}"
90+
testRT "for(var x of 5){}"
8691
testRT "var x=1;"
8792
testRT "const x=1,y=2;"
8893
testRT "continue;"

test/Test/Language/Javascript/StatementParser.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ testStatementParser = describe "Parse statements:" $ do
5151

5252
testStmt "for(var x in 5){}" `shouldBe` "Right (JSAstStatement (JSForVarIn (JSVarInitExpression (JSIdentifier 'x') ) (JSDecimal '5') (JSStatementBlock [])))"
5353

54+
testStmt "for(let x;y;z){}" `shouldBe` "Right (JSAstStatement (JSForLet (JSVarInitExpression (JSIdentifier 'x') ) (JSIdentifier 'y') (JSIdentifier 'z') (JSStatementBlock [])))"
55+
testStmt "for(let x in 5){}" `shouldBe` "Right (JSAstStatement (JSForLetIn (JSVarInitExpression (JSIdentifier 'x') ) (JSDecimal '5') (JSStatementBlock [])))"
56+
testStmt "for(let x of 5){}" `shouldBe` "Right (JSAstStatement (JSForLetOf (JSVarInitExpression (JSIdentifier 'x') ) (JSDecimal '5') (JSStatementBlock [])))"
57+
testStmt "for(x of 5){}" `shouldBe` "Right (JSAstStatement (JSForOf JSIdentifier 'x' (JSDecimal '5') (JSStatementBlock [])))"
58+
testStmt "for(var x of 5){}" `shouldBe` "Right (JSAstStatement (JSForVarOf (JSVarInitExpression (JSIdentifier 'x') ) (JSDecimal '5') (JSStatementBlock [])))"
59+
5460
it "variable/constant/let declaration" $ do
5561
testStmt "var x=1;" `shouldBe` "Right (JSAstStatement (JSVariable (JSVarInitExpression (JSIdentifier 'x') [JSDecimal '1'])))"
5662
testStmt "const x=1,y=2;" `shouldBe` "Right (JSAstStatement (JSConstant (JSVarInitExpression (JSIdentifier 'x') [JSDecimal '1'],JSVarInitExpression (JSIdentifier 'y') [JSDecimal '2'])))"

0 commit comments

Comments
 (0)