Skip to content
Browse files

Added patterns, let+const declarations, object shorthands

  • Loading branch information...
1 parent aab5940 commit 6f4df53e9bbf3ffc7c402a72a3eea21af5317f63 @zaach zaach committed
Showing with 282 additions and 66 deletions.
  1. +196 −21 lib/grammar.y
  2. +34 −0 lib/nodes.js
  3. +1 −1 lib/reflect.js
  4. +51 −44 test/reflect-parse.js
View
217 lib/grammar.y
@@ -5,9 +5,64 @@
%%
+Pattern
+ : OPENBRACE CLOSEBRACE
+ { $$ = yy.Node('ObjectPattern', [], yy.loc([@1,@2])); }
+ | OPENBRACE FieldList CLOSEBRACE
+ { $$ = yy.Node('ObjectPattern', $FieldList, yy.loc([@1,@3])); }
+ | OPENBRACE FieldList ',' CLOSEBRACE
+ { $$ = yy.Node('ObjectPattern', $FieldList, yy.loc([@1,@4])); }
+ | '[' ']'
+ { $$ = yy.Node('ArrayPattern', [], yy.loc([@1,@2])); }
+ /*| '[' '...' Element ']'*/
+ | '[' Elision ']'
+ { $$ = yy.Node('ArrayPattern', [,], yy.loc([@1,@3])); }
+ /*| '[' Elision '...' Element ']'*/
+ | '[' ArrayPatternList ']'
+ { $$ = yy.Node('ArrayPattern', $2, yy.loc([@1,@3])); }
+ /*| '[' ArrayPatternList '...' Element ']'*/
+ | '[' ArrayPatternList ',' ElisionOpt ']'
+ { $$ = yy.Node('ArrayPattern', $2.concat($4), yy.loc([@1,@5])); }
+ /*| '[' ArrayPatternList ',' ElisionOpt '...' Element ']'*/
+ ;
+
+ArrayPatternList
+ : Element
+ { $$ = [$1]; }
+ | Elision Element
+ { $$ = $1; $$.push($2); }
+ | ArrayPatternList ',' ElisionOpt Element
+ { $$ = $1.concat($3); $$.push($4); }
+ ;
+
+FieldList
+ : Field
+ { $$ = [$1]; }
+ | FieldList ',' Field
+ { $$ = $1; $$.push($3); }
+ ;
+
+Field
+ : IDENT
+ { $$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:yy.Node('Identifier', $1,yy.loc(@1)),kind: "init"}; }
+ | IDENT ':' Element
+ { yy.locComb(@$,@3);$$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:$3,kind: "init"}; }
+ ;
+
+Element
+ : Pattern
+ | IDENT
+ { $$ = yy.Node('Identifier', $1,yy.loc(@1)) }
+ ;
+
+ /* break up keywords to workaround some LALR(1) limitations */
IdentifierName
: IDENT
- | NULLTOKEN
+ | Keyword
+ ;
+
+Keyword
+ : NULLTOKEN
| TRUETOKEN
| FALSETOKEN
| BREAK
@@ -33,6 +88,7 @@ IdentifierName
| TRY
| TYPEOF
| VAR
+ | LET
| VOIDTOKEN
| WHILE
| WITH
@@ -67,7 +123,11 @@ RegularExpressionLiteralBegin
;
Property
- : IdentifierName ':' AssignmentExpr
+ : IDENT /* object shorthand strawman */
+ { $$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:yy.Node('Identifier', $1,yy.loc(@1)),kind: "init"}; }
+ | IDENT ':' AssignmentExpr
+ { yy.locComb(@$,@3);$$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:$3,kind: "init"}; }
+ | Keyword ':' AssignmentExpr
{ yy.locComb(@$,@3);$$ = {key:yy.Node('Identifier', $1,yy.loc(@1)),value:$3,kind: "init"}; }
| STRING ':' AssignmentExpr
{ yy.locComb(@$,@3);$$ = {key:yy.Node('Literal', String($1),yy.loc(@1)),value:$3,kind: "init"}; }
@@ -599,8 +659,7 @@ ExprNoBF
Statement
: Block
| VariableStatement
- | ConstStatement
- | FunctionDeclarationaration
+ | FunctionDeclaration
| EmptyStatement
| ExprStatement
| IfStatement
@@ -635,10 +694,29 @@ ConstDecralarionList
{ $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), null)]; }
| IDENT Initializer
{ yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern Initializer
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
| ConstDecralarionList ',' IDENT
{ yy.locComb(@$,@3);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
| ConstDecralarionList ',' IDENT Initializer
{ yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | ConstDecralarionList ',' Pattern Initializer
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
+ ;
+
+ConstDecralarionListNoIn
+ : IDENT
+ { $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), null)]; }
+ | IDENT InitializerNoIn
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern InitializerNoIn
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
+ | ConstDecralarionListNoIn ',' IDENT
+ { yy.locComb(@$,@3);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
+ | ConstDecralarionListNoIn ',' IDENT InitializerNoIn
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | ConstDecralarionListNoIn ',' Pattern InitializerNoIn
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
;
VariableStatement
@@ -653,10 +731,14 @@ VariableDeclarationList
{ $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), null)]; }
| IDENT Initializer
{ yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern Initializer
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
| VariableDeclarationList ',' IDENT
{ yy.locComb(@$,@3);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
| VariableDeclarationList ',' IDENT Initializer
{ yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | VariableDeclarationList ',' Pattern Initializer
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
;
VariableDeclarationListNoIn
@@ -665,12 +747,56 @@ VariableDeclarationListNoIn
| IDENT InitializerNoIn
{ yy.locComb(@$,@2);
$$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern InitializerNoIn
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
| VariableDeclarationListNoIn ',' IDENT
{ yy.locComb(@$,@3);
$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
| VariableDeclarationListNoIn ',' IDENT InitializerNoIn
{ yy.locComb(@$,@4);
$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | VariableDeclarationListNoIn ',' Pattern InitializerNoIn
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
+ ;
+
+LetStatement
+ : LET LetDeclarationList ';'
+ { $$ = yy.Node('VariableDeclaration',"let",$2,yy.loc([@$,@3])) }
+ | LET LetDeclarationList error
+ { $$ = yy.Node('VariableDeclaration',"let",$2,yy.loc([@$,@2])) }
+ ;
+
+LetDeclarationList
+ : IDENT
+ { $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), null)]; }
+ | IDENT Initializer
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern Initializer
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
+ | LetDeclarationList ',' IDENT
+ { yy.locComb(@$,@3);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
+ | LetDeclarationList ',' IDENT Initializer
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | LetDeclarationList ',' Pattern Initializer
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
+ ;
+
+LetDeclarationListNoIn
+ : IDENT
+ { $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), null)]; }
+ | IDENT InitializerNoIn
+ { yy.locComb(@$,@2);
+ $$ = [yy.Node('InitPatt', yy.Node('Identifier', $1,yy.loc(@1)), $2)]; }
+ | Pattern InitializerNoIn
+ { yy.locComb(@$,@2);$$ = [yy.Node('InitPatt', $1, $2)]; }
+ | LetDeclarationListNoIn ',' IDENT
+ { yy.locComb(@$,@3);
+ $$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), null)); }
+ | LetDeclarationListNoIn ',' IDENT InitializerNoIn
+ { yy.locComb(@$,@4);
+ $$ = $1; $1.push(yy.Node('InitPatt', yy.Node('Identifier', $3,yy.loc(@3)), $4)); }
+ | LetDeclarationListNoIn ',' Pattern InitializerNoIn
+ { yy.locComb(@$,@4);$$ = $1; $1.push(yy.Node('InitPatt', $3, $4)); }
;
Initializer
@@ -715,20 +841,60 @@ IterationStatement
{ $$ = yy.Node('ForStatement',
yy.Node('VariableDeclaration',"var", $4, yy.loc([@3,@4])),
$ExprOpt1, $ExprOpt2, $Statement, yy.loc([@$,@10])); }
+ | FOR '(' LET LetDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
+ { $$ = yy.Node('ForStatement',
+ yy.Node('VariableDeclaration',"let", $4, yy.loc([@3,@4])),
+ $ExprOpt1, $ExprOpt2, $Statement, yy.loc([@$,@10])); }
+ | FOR '(' CONSTTOKEN ConstDecralarionListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
+ { $$ = yy.Node('ForStatement',
+ yy.Node('VariableDeclaration',"const", $4, yy.loc([@3,@4])),
+ $ExprOpt1, $ExprOpt2, $Statement, yy.loc([@$,@10])); }
| FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
{ $$ = yy.Node('ForInStatement', $LeftHandSideExpr, $Expr, $Statement, false, yy.loc([@$,@7])); }
- | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
- { $$ = yy.Node('ForInStatement',
- yy.Node('VariableDeclaration',"var",
- [yy.Node('InitPatt',yy.Node('Identifier', $4,yy.loc(@4)),null)],
- yy.loc([@3,@4])),
- $Expr, $Statement, false, yy.loc([@$,@8])); }
- | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
- { $$ = yy.Node('ForInStatement',
- yy.Node('VariableDeclaration',"var",
- [yy.Node('InitPatt',yy.Node('Identifier', $4,yy.loc(@4)), $5)],
- yy.loc([@3,@5])),
- $Expr, $Statement, false, yy.loc([@$,@9])); }
+ | FOR '(' VarOrLet Expr ')' Statement
+ { $$ = yy.Node('ForInStatement', $3,
+ $Expr, $Statement, false, yy.loc([@$,@6])); }
+ | FOR '(' VarOrLetInitNoIn Expr ')' Statement
+ { $$ = yy.Node('ForInStatement', $3,
+ $Expr, $Statement, false, yy.loc([@$,@6])); }
+ ;
+
+VarOrLet
+ : VAR IDENT INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"var",
+ [yy.Node('InitPatt',yy.Node('Identifier', $2,yy.loc(@2)), null)],
+ yy.loc([@1,@2])) }
+ | VAR Pattern INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"var",
+ [yy.Node('InitPatt',$2, null)],
+ yy.loc([@1,@2])) }
+ | LET IDENT INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"let",
+ [yy.Node('InitPatt',yy.Node('Identifier', $2,yy.loc(@2)), null)],
+ yy.loc([@1,@2])) }
+ | LET Pattern INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"let",
+ [yy.Node('InitPatt',$2, null)],
+ yy.loc([@1,@2])) }
+ ;
+
+VarOrLetInitNoIn
+ : VAR IDENT InitializerNoIn INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"var",
+ [yy.Node('InitPatt',yy.Node('Identifier', $2,yy.loc(@2)), $3)],
+ yy.loc([@1,@3])) }
+ | VAR Pattern InitializerNoIn INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"var",
+ [yy.Node('InitPatt',$2, $3)],
+ yy.loc([@1,@3])) }
+ | LET IDENT InitializerNoIn INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"let",
+ [yy.Node('InitPatt',yy.Node('Identifier', $2,yy.loc(@2)), $3)],
+ yy.loc([@1,@3])) }
+ | LET Pattern InitializerNoIn INTOKEN
+ { $$ = yy.Node('VariableDeclaration',"let",
+ [yy.Node('InitPatt',$2, $3)],
+ yy.loc([@1,@3])) }
;
ExprOpt
@@ -767,9 +933,9 @@ BreakStatement
ReturnStatement
: RETURN ';'
- { $$ = yy.Node('ReturnStatement',null,yy.loc([@$,@3])); }
+ { $$ = yy.Node('ReturnStatement',null,yy.loc([@$,@2])); }
| RETURN error
- { $$ = yy.Node('ReturnStatement',null,yy.loc([@$,@3])); }
+ { $$ = yy.Node('ReturnStatement',null,yy.loc(@$)); }
| RETURN Expr ';'
{ $$ = yy.Node('ReturnStatement',$2,yy.loc([@$,@3])); }
| RETURN Expr error
@@ -851,7 +1017,7 @@ DebuggerStatement
{ $$ = yy.Node('DebuggerStatement', yy.loc(@1)); }
;
-FunctionDeclarationaration
+FunctionDeclaration
: FUNCTION IDENT '(' ')' Block
{ $$ = yy.Node('FunctionDeclaration',
yy.Node('Identifier', $2,yy.loc(@2)), [], $Block, false, false, yy.loc([@$,@5]))
@@ -883,8 +1049,12 @@ FunctionExpr
FormalParameterList
: IDENT
{ $$ = [yy.Node('Identifier', $1)]; }
+ | Pattern
+ { $$ = [$1]; }
| FormalParameterList ',' IDENT
{ $$ = $1; $$.push(yy.Node('Identifier', $3,yy.loc(@3))); }
+ | FormalParameterList ',' Pattern
+ { $$ = $1; $$.push($3); }
;
FunctionBody
@@ -901,10 +1071,15 @@ Program
;
SourceElements
- : Statement
+ : SourceElement
{ $$ = [$1]; }
- | SourceElements Statement
+ | SourceElements SourceElement
{ yy.locComb(@$,@2);
$$ = $1;$1.push($2); }
;
+SourceElement
+ : LetStatement
+ | ConstStatement
+ | Statement
+ ;
View
34 lib/nodes.js
@@ -18,10 +18,24 @@ var def = function def(name, ini) {
/* Nodes
*/
+// used in cases where object and array literals are valid expressions
+function convertExprToPattern (expr) {
+ if (expr.type == 'ObjectExpression') {
+ expr.type = 'ObjectPattern';
+ } else if (expr.type == 'ArrayExpression') {
+ expr.type = 'ArrayPattern';
+ }
+}
+
// Program node
def('Program', function (elements,loc) {
this.body = elements;
this.loc = loc;
+ this.body.forEach(function (el) {
+ if (el.type == "VariableDeclaration" && el.kind == "let") {
+ el.kind = "var";
+ }
+ });
});
def('ExpressionStatement', function (expression, loc) {
@@ -84,6 +98,13 @@ var funIni = function (ident, params, body, isGen, isExp, loc) {
this.generator = isGen;
this.expression = isExp;
this.loc = loc;
+ if (!this.expression) {
+ this.body.body.forEach(function (el) {
+ if (el.type == "VariableDeclaration" && el.kind == "let") {
+ el.kind = "var";
+ }
+ });
+ }
};
def('FunctionDeclaration', funIni);
@@ -176,6 +197,7 @@ def('AssignmentExpression', function (op, left, right, loc) {
this.left = left;
this.right = right;
this.loc = loc;
+ convertExprToPattern(left);
});
def('LogicalExpression', function (op, left, right, loc) {
@@ -246,6 +268,7 @@ def('ForStatement', function (init, test, update, body, loc) {
this.update = update;
this.body = body;
this.loc = loc;
+ if (init) convertExprToPattern(init);
});
def('ForInStatement', function (left, right, body, each, loc) {
@@ -254,6 +277,7 @@ def('ForInStatement', function (left, right, body, each, loc) {
this.body = body;
this.each = !!each;
this.loc = loc;
+ convertExprToPattern(left);
});
def('IfStatement', function (test, consequent, alternate, loc) {
@@ -263,6 +287,16 @@ def('IfStatement', function (test, consequent, alternate, loc) {
this.loc = loc;
});
+def('ObjectPattern', function (properties, loc) {
+ this.properties = properties;
+ this.loc = loc;
+});
+
+def('ArrayPattern', function (elements, loc) {
+ this.elements = elements;
+ this.loc = loc;
+});
+
return def;
}
View
2 lib/reflect.js
@@ -72,7 +72,7 @@ parser.yy.loc = function (loc) {
parser.yy.parseError = function (err, hash) {
// don't print error for missing semicolon
if (!(hash.expected.indexOf("';'") >= 0 && (hash.token === 'CLOSEBRACE' || parser.yy.lineBreak || parser.yy.lastLineBreak || hash.token === 1))) {
- throw new Error(err);
+ throw new SyntaxError(err);
}
};
View
95 test/reflect-parse.js
@@ -564,9 +564,14 @@ function assertStmt(src, patt) {
}
function assertExpr(src, patt) {
+try {
assertLocalExpr(src, patt);
assertGlobalExpr(src, patt);
assertBlockExpr(src, patt);
+} catch (e) {
+ console.log(src)
+ throw e;
+ }
}
function assertDecl(src, patt) {
@@ -582,8 +587,9 @@ function assertError(src, errorType) {
if (expected instanceof errorType) {
return;
}
+ console.log(expected)
}
- throw new Error("expected " + errorType.name + " for " + uneval(src));
+ throw new Error("expected " + errorType.name + " for " + String(src));
}
@@ -835,7 +841,6 @@ assertExpr("({ set x(v) { return 42 } })",
value: funExpr(null, [ident("v")], blockStmt([returnStmt(lit(42))])),
kind: "set" } ]));
-/*
// global let is var
assertGlobalDecl("let {x:y} = foo;", varDecl([{ id: objPatt([{ key: ident("x"), value: ident("y") }]),
init: ident("foo") }]));
@@ -851,8 +856,8 @@ assertDecl("const {x:y} = foo;", constDecl([{ id: objPatt([{ key: ident("x"), va
// various combinations of identifiers and destructuring patterns:
-function makePatternCombinations(id, destr)
- [
+function makePatternCombinations(id, destr) {
+ return [
[ id(1) ],
[ id(1), id(2) ],
[ id(1), id(2), id(3) ],
@@ -900,23 +905,24 @@ function makePatternCombinations(id, destr)
[ id(1), destr(2), destr(3), destr(4) ],
[ id(1), destr(2), destr(3), destr(4), id(5) ],
[ id(1), destr(2), destr(3), destr(4), destr(5) ]
- ]
+ ];
+}
// destructuring function parameters
function testParamPatternCombinations(makePattSrc, makePattPatt) {
- var pattSrcs = makePatternCombinations(function(n) ("x" + n), makePattSrc);
- var pattPatts = makePatternCombinations(function(n) (ident("x" + n)), makePattPatt);
+ var pattSrcs = makePatternCombinations(function(n){ return ("x" + n)}, makePattSrc);
+ var pattPatts = makePatternCombinations(function(n){ return (ident("x" + n))}, makePattPatt);
for (var i = 0; i < pattSrcs.length; i++) {
- function makeSrc(body) ("(function(" + pattSrcs[i].join(",") + ") " + body + ")")
- function makePatt(body) (funExpr(null, pattPatts[i], body))
+ function makeSrc(body){ return ("(function(" + pattSrcs[i].join(",") + ") {return " + body + "})")}
+ function makePatt(body){ return (funExpr(null, pattPatts[i], blockStmt([returnStmt(body)]))) }
// no upvars, block body
- assertExpr(makeSrc("{ }", makePatt(blockStmt([]))));
+ assertExpr(makeSrc(";", makePatt(blockStmt([]))));
// upvars, block body
- assertExpr(makeSrc("{ return [x1,x2,x3,x4,x5]; }"),
- makePatt(blockStmt([returnStmt(arrExpr([ident("x1"), ident("x2"), ident("x3"), ident("x4"), ident("x5")]))])));
+ assertExpr(makeSrc("[x1,x2,x3,x4,x5];"),
+ makePatt(arrExpr([ident("x1"), ident("x2"), ident("x3"), ident("x4"), ident("x5")])));
// no upvars, expression body
assertExpr(makeSrc("(0)"), makePatt(lit(0)));
// upvars, expression body
@@ -925,20 +931,20 @@ function testParamPatternCombinations(makePattSrc, makePattPatt) {
}
}
-testParamPatternCombinations(function(n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "}"),
- function(n) (objPatt([{ key: ident("a" + n), value: ident("x" + n) },
+testParamPatternCombinations(function(n) {return ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "}")},
+ function(n) {return (objPatt([{ key: ident("a" + n), value: ident("x" + n) },
{ key: ident("b" + n), value: ident("y" + n) },
- { key: ident("c" + n), value: ident("z" + n) }])));
+ { key: ident("c" + n), value: ident("z" + n) }]))});
-testParamPatternCombinations(function(n) ("[x" + n + "," + "y" + n + "," + "z" + n + "]"),
- function(n) (arrPatt([ident("x" + n), ident("y" + n), ident("z" + n)])));
+testParamPatternCombinations(function(n) {return ("[x" + n + "," + "y" + n + "," + "z" + n + "]")},
+ function(n) {return (arrPatt([ident("x" + n), ident("y" + n), ident("z" + n)]))});
// destructuring variable declarations
function testVarPatternCombinations(makePattSrc, makePattPatt) {
- var pattSrcs = makePatternCombinations(function(n) ("x" + n), makePattSrc);
- var pattPatts = makePatternCombinations(function(n) ({ id: ident("x" + n), init: null }), makePattPatt);
+ var pattSrcs = makePatternCombinations(function(n) {return ("x" + n)}, makePattSrc);
+ var pattPatts = makePatternCombinations(function(n) {return ({ id: ident("x" + n), init: null })}, makePattPatt);
for (var i = 0; i < pattSrcs.length; i++) {
// variable declarations in blocks
@@ -960,21 +966,21 @@ function testVarPatternCombinations(makePattSrc, makePattPatt) {
}
}
-testVarPatternCombinations(function (n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
- function (n) ({ id: objPatt([{ key: ident("a" + n), value: ident("x" + n) },
+testVarPatternCombinations(function (n) {return ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0")},
+ function (n) {return ({ id: objPatt([{ key: ident("a" + n), value: ident("x" + n) },
{ key: ident("b" + n), value: ident("y" + n) },
{ key: ident("c" + n), value: ident("z" + n) }]),
- init: lit(0) }));
+ init: lit(0) })});
-testVarPatternCombinations(function(n) ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0"),
- function(n) ({ id: arrPatt([ident("x" + n), ident("y" + n), ident("z" + n)]),
- init: lit(0) }));
+testVarPatternCombinations(function(n) {return ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0")},
+ function(n) {return ({ id: arrPatt([ident("x" + n), ident("y" + n), ident("z" + n)]),
+ init: lit(0) })});
// destructuring assignment
function testAssignmentCombinations(makePattSrc, makePattPatt) {
- var pattSrcs = makePatternCombinations(function(n) ("x" + n + " = 0"), makePattSrc);
- var pattPatts = makePatternCombinations(function(n) (aExpr("=", ident("x" + n), lit(0))), makePattPatt);
+ var pattSrcs = makePatternCombinations(function(n) {return ("x" + n + " = 0")}, makePattSrc);
+ var pattPatts = makePatternCombinations(function(n) {return (aExpr("=", ident("x" + n), lit(0)))}, makePattPatt);
for (var i = 0; i < pattSrcs.length; i++) {
var src = pattSrcs[i].join(",");
@@ -989,12 +995,12 @@ function testAssignmentCombinations(makePattSrc, makePattPatt) {
}
}
-testAssignmentCombinations(function (n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
- function (n) (aExpr("=",
+testAssignmentCombinations(function (n) {return ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0")},
+ function (n) {return (aExpr("=",
objPatt([{ key: ident("a" + n), value: ident("x" + n) },
{ key: ident("b" + n), value: ident("y" + n) },
{ key: ident("c" + n), value: ident("z" + n) }]),
- lit(0))));
+ lit(0)))});
// destructuring in for-in and for-each-in loop heads
@@ -1010,35 +1016,36 @@ assertStmt("for ({a:x,b:y,c:z} in foo);", forInStmt(axbycz, ident("foo"), emptyS
assertStmt("for (var [x,y,z] in foo);", forInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
assertStmt("for (let [x,y,z] in foo);", forInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
assertStmt("for ([x,y,z] in foo);", forInStmt(xyz, ident("foo"), emptyStmt));
-assertStmt("for each (var {a:x,b:y,c:z} in foo);", forEachInStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
-assertStmt("for each (let {a:x,b:y,c:z} in foo);", forEachInStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
-assertStmt("for each ({a:x,b:y,c:z} in foo);", forEachInStmt(axbycz, ident("foo"), emptyStmt));
-assertStmt("for each (var [x,y,z] in foo);", forEachInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
-assertStmt("for each (let [x,y,z] in foo);", forEachInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
-assertStmt("for each ([x,y,z] in foo);", forEachInStmt(xyz, ident("foo"), emptyStmt));
+//assertStmt("for each (var {a:x,b:y,c:z} in foo);", forEachInStmt(varDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+//assertStmt("for each (let {a:x,b:y,c:z} in foo);", forEachInStmt(letDecl([{ id: axbycz, init: null }]), ident("foo"), emptyStmt));
+//assertStmt("for each ({a:x,b:y,c:z} in foo);", forEachInStmt(axbycz, ident("foo"), emptyStmt));
+//assertStmt("for each (var [x,y,z] in foo);", forEachInStmt(varDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+//assertStmt("for each (let [x,y,z] in foo);", forEachInStmt(letDecl([{ id: xyz, init: null }]), ident("foo"), emptyStmt));
+//assertStmt("for each ([x,y,z] in foo);", forEachInStmt(xyz, ident("foo"), emptyStmt));
assertError("for (const x in foo);", SyntaxError);
assertError("for (const {a:x,b:y,c:z} in foo);", SyntaxError);
assertError("for (const [x,y,z] in foo);", SyntaxError);
-assertError("for each (const x in foo);", SyntaxError);
-assertError("for each (const {a:x,b:y,c:z} in foo);", SyntaxError);
-assertError("for each (const [x,y,z] in foo);", SyntaxError);
+//assertError("for each (const x in foo);", SyntaxError);
+//assertError("for each (const {a:x,b:y,c:z} in foo);", SyntaxError);
+//assertError("for each (const [x,y,z] in foo);", SyntaxError);
// destructuring in for-in and for-each-in loop heads with initializers
assertStmt("for (var {a:x,b:y,c:z} = 22 in foo);", forInStmt(varDecl([{ id: axbycz, init: lit(22) }]), ident("foo"), emptyStmt));
assertStmt("for (var [x,y,z] = 22 in foo);", forInStmt(varDecl([{ id: xyz, init: lit(22) }]), ident("foo"), emptyStmt));
-assertStmt("for each (var {a:x,b:y,c:z} = 22 in foo);", forEachInStmt(varDecl([{ id: axbycz, init: lit(22) }]), ident("foo"), emptyStmt));
-assertStmt("for each (var [x,y,z] = 22 in foo);", forEachInStmt(varDecl([{ id: xyz, init: lit(22) }]), ident("foo"), emptyStmt));
+//assertStmt("for each (var {a:x,b:y,c:z} = 22 in foo);", forEachInStmt(varDecl([{ id: axbycz, init: lit(22) }]), ident("foo"), emptyStmt));
+//assertStmt("for each (var [x,y,z] = 22 in foo);", forEachInStmt(varDecl([{ id: xyz, init: lit(22) }]), ident("foo"), emptyStmt));
assertError("for (x = 22 in foo);", SyntaxError);
assertError("for ({a:x,b:y,c:z} = 22 in foo);", SyntaxError);
assertError("for ([x,y,z] = 22 in foo);", SyntaxError);
assertError("for (const x = 22 in foo);", SyntaxError);
assertError("for (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
assertError("for (const [x,y,z] = 22 in foo);", SyntaxError);
-assertError("for each (const x = 22 in foo);", SyntaxError);
-assertError("for each (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
-assertError("for each (const [x,y,z] = 22 in foo);", SyntaxError);
+//assertError("for each (const x = 22 in foo);", SyntaxError);
+//assertError("for each (const {a:x,b:y,c:z} = 22 in foo);", SyntaxError);
+//assertError("for each (const [x,y,z] = 22 in foo);", SyntaxError);
+/*
// expression closures
assertDecl("function inc(x) (x + 1)", funDecl(ident("inc"), [ident("x")], binExpr("+", ident("x"), lit(1))));

0 comments on commit 6f4df53

Please sign in to comment.
Something went wrong with that request. Please try again.