19
19
20
20
function testReflect ( Reflect , Pattern ) {
21
21
22
- function program ( elts ) { return Pattern ( { type : "Program" , body : elts } ) }
23
- function exprStmt ( expr ) { return Pattern ( { type : "ExpressionStatement" , expression : expr } ) }
24
- function throwStmt ( expr ) { return Pattern ( { type : "ThrowStatement" , argument : expr } ) }
25
- function returnStmt ( expr ) { return Pattern ( { type : "ReturnStatement" , argument : expr } ) }
26
- function yieldExpr ( expr ) { return Pattern ( { type : "YieldExpression" , argument : expr } ) }
27
- function lit ( val ) { return Pattern ( { type : "Literal" , value : val } ) }
22
+ function program ( elts ) { return Pattern ( { type : "Program" , body : elts } ) ; }
23
+ function exprStmt ( expr ) { return Pattern ( { type : "ExpressionStatement" , expression : expr } ) ; }
24
+ function throwStmt ( expr ) { return Pattern ( { type : "ThrowStatement" , argument : expr } ) ; }
25
+ function returnStmt ( expr ) { return Pattern ( { type : "ReturnStatement" , argument : expr } ) ; }
26
+ function yieldExpr ( expr ) { return Pattern ( { type : "YieldExpression" , argument : expr } ) ; }
27
+ function lit ( val ) { return Pattern ( { type : "Literal" , value : val } ) ; }
28
28
var thisExpr = Pattern ( { type : "ThisExpression" } ) ;
29
29
function funDecl ( id , params , body ) { return Pattern ( { type : "FunctionDeclaration" ,
30
30
id : id ,
@@ -34,7 +34,7 @@ function funDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration
34
34
rest : null ,
35
35
generator : false ,
36
36
expression : false
37
- } ) }
37
+ } ) ; }
38
38
function genFunDecl ( id , params , body ) { return Pattern ( { type : "FunctionDeclaration" ,
39
39
id : id ,
40
40
params : params ,
@@ -43,32 +43,32 @@ function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclarat
43
43
rest : null ,
44
44
generator : false ,
45
45
expression : false
46
- } ) }
47
- function declarator ( id , init ) { return Pattern ( { type : "VariableDeclarator" , id : id , init : init } ) }
48
- function varDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "var" } ) }
49
- function letDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "let" } ) }
50
- function constDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "const" } ) }
51
- function ident ( name ) { return Pattern ( { type : "Identifier" , name : name } ) }
52
- function dotExpr ( obj , id ) { return Pattern ( { type : "MemberExpression" , computed : false , object : obj , property : id } ) }
53
- function memExpr ( obj , id ) { return Pattern ( { type : "MemberExpression" , computed : true , object : obj , property : id } ) }
54
- function forStmt ( init , test , update , body ) { return Pattern ( { type : "ForStatement" , init : init , test : test , update : update , body : body } ) }
55
- function forInStmt ( lhs , rhs , body ) { return Pattern ( { type : "ForInStatement" , left : lhs , right : rhs , body : body , each : false } ) }
56
- function forEachInStmt ( lhs , rhs , body ) { return Pattern ( { type : "ForInStatement" , left : lhs , right : rhs , body : body , each : true } ) }
57
- function breakStmt ( lab ) { return Pattern ( { type : "BreakStatement" , label : lab } ) }
58
- function continueStmt ( lab ) { return Pattern ( { type : "ContinueStatement" , label : lab } ) }
59
- function blockStmt ( body ) { return Pattern ( { type : "BlockStatement" , body : body } ) }
46
+ } ) ; }
47
+ function declarator ( id , init ) { return Pattern ( { type : "VariableDeclarator" , id : id , init : init } ) ; }
48
+ function varDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "var" } ) ; }
49
+ function letDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "let" } ) ; }
50
+ function constDecl ( decls ) { return Pattern ( { type : "VariableDeclaration" , declarations : decls , kind : "const" } ) ; }
51
+ function ident ( name ) { return Pattern ( { type : "Identifier" , name : name } ) ; }
52
+ function dotExpr ( obj , id ) { return Pattern ( { type : "MemberExpression" , computed : false , object : obj , property : id } ) ; }
53
+ function memExpr ( obj , id ) { return Pattern ( { type : "MemberExpression" , computed : true , object : obj , property : id } ) ; }
54
+ function forStmt ( init , test , update , body ) { return Pattern ( { type : "ForStatement" , init : init , test : test , update : update , body : body } ) ; }
55
+ function forInStmt ( lhs , rhs , body ) { return Pattern ( { type : "ForInStatement" , left : lhs , right : rhs , body : body , each : false } ) ; }
56
+ function forEachInStmt ( lhs , rhs , body ) { return Pattern ( { type : "ForInStatement" , left : lhs , right : rhs , body : body , each : true } ) ; }
57
+ function breakStmt ( lab ) { return Pattern ( { type : "BreakStatement" , label : lab } ) ; }
58
+ function continueStmt ( lab ) { return Pattern ( { type : "ContinueStatement" , label : lab } ) ; }
59
+ function blockStmt ( body ) { return Pattern ( { type : "BlockStatement" , body : body } ) ; }
60
60
var emptyStmt = Pattern ( { type : "EmptyStatement" } ) ;
61
- function ifStmt ( test , cons , alt ) { return Pattern ( { type : "IfStatement" , test : test , alternate : alt , consequent : cons } ) }
62
- function labStmt ( lab , stmt ) { return Pattern ( { type : "LabeledStatement" , label : lab , body : stmt } ) }
63
- function withStmt ( obj , stmt ) { return Pattern ( { type : "WithStatement" , object : obj , body : stmt } ) }
64
- function whileStmt ( test , stmt ) { return Pattern ( { type : "WhileStatement" , test : test , body : stmt } ) }
65
- function doStmt ( stmt , test ) { return Pattern ( { type : "DoWhileStatement" , test : test , body : stmt } ) }
66
- function switchStmt ( disc , cases ) { return Pattern ( { type : "SwitchStatement" , discriminant : disc , cases : cases } ) }
67
- function caseClause ( test , stmts ) { return Pattern ( { type : "SwitchCase" , test : test , consequent : stmts } ) }
68
- function defaultClause ( stmts ) { return Pattern ( { type : "SwitchCase" , test : null , consequent : stmts } ) }
69
- function catchClause ( id , guard , body ) { if ( guard ) { return Pattern ( { type : "GuardedCatchClause" , param : id , guard : guard , body : body } ) } else { return Pattern ( { type : "CatchClause" , param : id , body : body } ) } }
70
- function tryStmt ( body , guarded , catches , fin ) { return Pattern ( { type : "TryStatement" , block : body , guardedHandlers : guarded , handlers : catches , finalizer : fin } ) }
71
- function letStmt ( head , body ) { return Pattern ( { type : "LetStatement" , head : head , body : body } ) }
61
+ function ifStmt ( test , cons , alt ) { return Pattern ( { type : "IfStatement" , test : test , alternate : alt , consequent : cons } ) ; }
62
+ function labStmt ( lab , stmt ) { return Pattern ( { type : "LabeledStatement" , label : lab , body : stmt } ) ; }
63
+ function withStmt ( obj , stmt ) { return Pattern ( { type : "WithStatement" , object : obj , body : stmt } ) ; }
64
+ function whileStmt ( test , stmt ) { return Pattern ( { type : "WhileStatement" , test : test , body : stmt } ) ; }
65
+ function doStmt ( stmt , test ) { return Pattern ( { type : "DoWhileStatement" , test : test , body : stmt } ) ; }
66
+ function switchStmt ( disc , cases ) { return Pattern ( { type : "SwitchStatement" , discriminant : disc , cases : cases } ) ; }
67
+ function caseClause ( test , stmts ) { return Pattern ( { type : "SwitchCase" , test : test , consequent : stmts } ) ; }
68
+ function defaultClause ( stmts ) { return Pattern ( { type : "SwitchCase" , test : null , consequent : stmts } ) ; }
69
+ function catchClause ( id , guard , body ) { if ( guard ) { return Pattern ( { type : "GuardedCatchClause" , param : id , guard : guard , body : body } ) } else { return Pattern ( { type : "CatchClause" , param : id , body : body } ) ; } }
70
+ function tryStmt ( body , guarded , catches , fin ) { return Pattern ( { type : "TryStatement" , block : body , guardedHandlers : guarded , handlers : catches , finalizer : fin } ) ; }
71
+ function letStmt ( head , body ) { return Pattern ( { type : "LetStatement" , head : head , body : body } ) ; }
72
72
function funExpr ( id , args , body , gen ) { return Pattern ( { type : "FunctionExpression" ,
73
73
id : id ,
74
74
params : args ,
@@ -77,7 +77,7 @@ function funExpr(id, args, body, gen) { return Pattern({ type: "FunctionExpressi
77
77
rest : null ,
78
78
generator : false ,
79
79
expression : false
80
- } ) }
80
+ } ) ; }
81
81
function genFunExpr ( id , args , body ) { return Pattern ( { type : "FunctionExpression" ,
82
82
id : id ,
83
83
params : args ,
@@ -86,29 +86,29 @@ function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression
86
86
rest : null ,
87
87
generator : false ,
88
88
expression : false
89
- } ) }
90
-
91
- function unExpr ( op , arg ) { return Pattern ( { type : "UnaryExpression" , operator : op , argument : arg , prefix : true } ) }
92
- function binExpr ( op , left , right ) { return Pattern ( { type : "BinaryExpression" , operator : op , left : left , right : right } ) }
93
- function aExpr ( op , left , right ) { return Pattern ( { type : "AssignmentExpression" , operator : op , left : left , right : right } ) }
94
- function updExpr ( op , arg , prefix ) { return Pattern ( { type : "UpdateExpression" , operator : op , argument : arg , prefix : prefix } ) }
95
- function logExpr ( op , left , right ) { return Pattern ( { type : "LogicalExpression" , operator : op , left : left , right : right } ) }
96
-
97
- function condExpr ( test , cons , alt ) { return Pattern ( { type : "ConditionalExpression" , test : test , consequent : cons , alternate : alt } ) }
98
- function seqExpr ( exprs ) { return Pattern ( { type : "SequenceExpression" , expressions : exprs } ) }
99
- function newExpr ( callee , args ) { return Pattern ( { type : "NewExpression" , callee : callee , arguments : args } ) }
100
- function callExpr ( callee , args ) { return Pattern ( { type : "CallExpression" , callee : callee , arguments : args } ) }
101
- function arrExpr ( elts ) { return Pattern ( { type : "ArrayExpression" , elements : elts } ) }
102
- function objExpr ( elts ) { return Pattern ( { type : "ObjectExpression" , properties : elts } ) }
103
- function objProp ( key , value , kind ) { return Pattern ( { type : "Property" , key : key , value : value , kind : kind } ) }
104
-
105
- function arrPatt ( elts ) { return Pattern ( { type : "ArrayPattern" , elements : elts } ) }
106
- function objPatt ( elts ) { return Pattern ( { type : "ObjectPattern" , properties : elts } ) }
107
-
108
- function localSrc ( src ) { return "(function(){ " + src + " })" }
109
- function localPatt ( patt ) { return program ( [ exprStmt ( funExpr ( null , [ ] , blockStmt ( [ patt ] ) ) ) ] ) }
110
- function blockSrc ( src ) { return "(function(){ { " + src + " } })" }
111
- function blockPatt ( patt ) { return program ( [ exprStmt ( funExpr ( null , [ ] , blockStmt ( [ blockStmt ( [ patt ] ) ] ) ) ) ] ) }
89
+ } ) ; }
90
+
91
+ function unExpr ( op , arg ) { return Pattern ( { type : "UnaryExpression" , operator : op , argument : arg , prefix : true } ) ; }
92
+ function binExpr ( op , left , right ) { return Pattern ( { type : "BinaryExpression" , operator : op , left : left , right : right } ) ; }
93
+ function aExpr ( op , left , right ) { return Pattern ( { type : "AssignmentExpression" , operator : op , left : left , right : right } ) ; }
94
+ function updExpr ( op , arg , prefix ) { return Pattern ( { type : "UpdateExpression" , operator : op , argument : arg , prefix : prefix } ) ; }
95
+ function logExpr ( op , left , right ) { return Pattern ( { type : "LogicalExpression" , operator : op , left : left , right : right } ) ; }
96
+
97
+ function condExpr ( test , cons , alt ) { return Pattern ( { type : "ConditionalExpression" , test : test , consequent : cons , alternate : alt } ) ; }
98
+ function seqExpr ( exprs ) { return Pattern ( { type : "SequenceExpression" , expressions : exprs } ) ; }
99
+ function newExpr ( callee , args ) { return Pattern ( { type : "NewExpression" , callee : callee , arguments : args } ) ; }
100
+ function callExpr ( callee , args ) { return Pattern ( { type : "CallExpression" , callee : callee , arguments : args } ) ; }
101
+ function arrExpr ( elts ) { return Pattern ( { type : "ArrayExpression" , elements : elts } ) ; }
102
+ function objExpr ( elts ) { return Pattern ( { type : "ObjectExpression" , properties : elts } ) ; }
103
+ function objProp ( key , value , kind ) { return Pattern ( { type : "Property" , key : key , value : value , kind : kind } ) ; }
104
+
105
+ function arrPatt ( elts ) { return Pattern ( { type : "ArrayPattern" , elements : elts } ) ; }
106
+ function objPatt ( elts ) { return Pattern ( { type : "ObjectPattern" , properties : elts } ) ; }
107
+
108
+ function localSrc ( src ) { return "(function(){ " + src + " })" ; }
109
+ function localPatt ( patt ) { return program ( [ exprStmt ( funExpr ( null , [ ] , blockStmt ( [ patt ] ) ) ) ] ) ; }
110
+ function blockSrc ( src ) { return "(function(){ { " + src + " } })" ; }
111
+ function blockPatt ( patt ) { return program ( [ exprStmt ( funExpr ( null , [ ] , blockStmt ( [ blockStmt ( [ patt ] ) ] ) ) ) ] ) ; }
112
112
113
113
function assertBlockStmt ( src , patt ) {
114
114
blockPatt ( patt ) . assert ( Reflect . parse ( blockSrc ( src ) ) ) ;
@@ -271,10 +271,10 @@ assertExpr("(x ^= y)", aExpr("^=", ident("x"), ident("y")));
271
271
assertExpr ( "(x &= y)" , aExpr ( "&=" , ident ( "x" ) , ident ( "y" ) ) ) ;
272
272
assertExpr ( "(x || y)" , logExpr ( "||" , ident ( "x" ) , ident ( "y" ) ) ) ;
273
273
assertExpr ( "(x && y)" , logExpr ( "&&" , ident ( "x" ) , ident ( "y" ) ) ) ;
274
- assertExpr ( "(w || x || y || z)" , logExpr ( "||" , logExpr ( "||" , logExpr ( "||" , ident ( "w" ) , ident ( "x" ) ) , ident ( "y" ) ) , ident ( "z" ) ) )
274
+ assertExpr ( "(w || x || y || z)" , logExpr ( "||" , logExpr ( "||" , logExpr ( "||" , ident ( "w" ) , ident ( "x" ) ) , ident ( "y" ) ) , ident ( "z" ) ) ) ;
275
275
assertExpr ( "(x ? y : z)" , condExpr ( ident ( "x" ) , ident ( "y" ) , ident ( "z" ) ) ) ;
276
- assertExpr ( "(x,y)" , seqExpr ( [ ident ( "x" ) , ident ( "y" ) ] ) )
277
- assertExpr ( "(x,y,z)" , seqExpr ( [ ident ( "x" ) , ident ( "y" ) , ident ( "z" ) ] ) )
276
+ assertExpr ( "(x,y)" , seqExpr ( [ ident ( "x" ) , ident ( "y" ) ] ) ) ;
277
+ assertExpr ( "(x,y,z)" , seqExpr ( [ ident ( "x" ) , ident ( "y" ) , ident ( "z" ) ] ) ) ;
278
278
assertExpr ( "(a,b,c,d,e,f,g)" , seqExpr ( [ ident ( "a" ) , ident ( "b" ) , ident ( "c" ) , ident ( "d" ) , ident ( "e" ) , ident ( "f" ) , ident ( "g" ) ] ) ) ;
279
279
assertExpr ( "(new Object)" , newExpr ( ident ( "Object" ) , [ ] ) ) ;
280
280
assertExpr ( "(new Object())" , newExpr ( ident ( "Object" ) , [ ] ) ) ;
0 commit comments