mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1149015 - Part 4: Remove some use of expression closure from jstests js1_8_5/reflect-parse/. r=luke
This commit is contained in:
parent
c9908ee8be
commit
3ddb3cd146
@ -36,7 +36,7 @@ var Match =
|
||||
}
|
||||
},
|
||||
|
||||
toString: function() "[object Pattern]"
|
||||
toString: () => "[object Pattern]"
|
||||
};
|
||||
|
||||
Pattern.ANY = new Pattern;
|
||||
|
@ -2,10 +2,18 @@
|
||||
|
||||
loadRelativeToScript('PatternBuilders.js');
|
||||
|
||||
function localSrc(src) "(function(){ " + src + " })"
|
||||
function localPatt(patt) program([exprStmt(funExpr(null, [], blockStmt([patt])))])
|
||||
function blockSrc(src) "(function(){ { " + src + " } })"
|
||||
function blockPatt(patt) program([exprStmt(funExpr(null, [], blockStmt([blockStmt([patt])])))])
|
||||
function localSrc(src) {
|
||||
return "(function(){ " + src + " })";
|
||||
}
|
||||
function localPatt(patt) {
|
||||
return program([exprStmt(funExpr(null, [], blockStmt([patt])))]);
|
||||
}
|
||||
function blockSrc(src) {
|
||||
return "(function(){ { " + src + " } })";
|
||||
}
|
||||
function blockPatt(patt) {
|
||||
return program([exprStmt(funExpr(null, [], blockStmt([blockStmt([patt])])))]);
|
||||
}
|
||||
|
||||
function assertBlockStmt(src, patt) {
|
||||
blockPatt(patt).assert(Reflect.parse(blockSrc(src)));
|
||||
|
@ -4,128 +4,259 @@ loadRelativeToScript('Match.js');
|
||||
|
||||
var { Pattern, MatchError } = Match;
|
||||
|
||||
function program(elts) Pattern({ type: "Program", body: elts })
|
||||
function exprStmt(expr) Pattern({ type: "ExpressionStatement", expression: expr })
|
||||
function throwStmt(expr) Pattern({ type: "ThrowStatement", argument: expr })
|
||||
function returnStmt(expr) Pattern({ type: "ReturnStatement", argument: expr })
|
||||
function yieldExpr(expr) Pattern({ type: "YieldExpression", argument: expr })
|
||||
function lit(val) Pattern({ type: "Literal", value: val })
|
||||
function comp(name) Pattern({ type: "ComputedName", name: name })
|
||||
function spread(val) Pattern({ type: "SpreadExpression", expression: val})
|
||||
function program(elts) {
|
||||
return Pattern({ type: "Program", body: elts });
|
||||
}
|
||||
function exprStmt(expr) {
|
||||
return Pattern({ type: "ExpressionStatement", expression: expr });
|
||||
}
|
||||
function throwStmt(expr) {
|
||||
return Pattern({ type: "ThrowStatement", argument: expr });
|
||||
}
|
||||
function returnStmt(expr) {
|
||||
return Pattern({ type: "ReturnStatement", argument: expr });
|
||||
}
|
||||
function yieldExpr(expr) {
|
||||
return Pattern({ type: "YieldExpression", argument: expr });
|
||||
}
|
||||
function lit(val) {
|
||||
return Pattern({ type: "Literal", value: val });
|
||||
}
|
||||
function comp(name) {
|
||||
return Pattern({ type: "ComputedName", name: name });
|
||||
}
|
||||
function spread(val) {
|
||||
return Pattern({ type: "SpreadExpression", expression: val});
|
||||
}
|
||||
var thisExpr = Pattern({ type: "ThisExpression" });
|
||||
function funDecl(id, params, body, defaults=[], rest=null) Pattern(
|
||||
{ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: defaults,
|
||||
body: body,
|
||||
rest: rest,
|
||||
generator: false })
|
||||
function genFunDecl(id, params, body) Pattern({ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: [],
|
||||
body: body,
|
||||
generator: true })
|
||||
function varDecl(decls) Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" })
|
||||
function letDecl(decls) Pattern({ type: "VariableDeclaration", declarations: decls, kind: "let" })
|
||||
function constDecl(decls) Pattern({ type: "VariableDeclaration", declarations: decls, kind: "const" })
|
||||
function ident(name) Pattern({ type: "Identifier", name: name })
|
||||
function dotExpr(obj, id) Pattern({ type: "MemberExpression", computed: false, object: obj, property: id })
|
||||
function memExpr(obj, id) Pattern({ type: "MemberExpression", computed: true, object: obj, property: id })
|
||||
function forStmt(init, test, update, body) Pattern({ type: "ForStatement", init: init, test: test, update: update, body: body })
|
||||
function forOfStmt(lhs, rhs, body) Pattern({ type: "ForOfStatement", left: lhs, right: rhs, body: body })
|
||||
function forInStmt(lhs, rhs, body) Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: false })
|
||||
function forEachInStmt(lhs, rhs, body) Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: true })
|
||||
function breakStmt(lab) Pattern({ type: "BreakStatement", label: lab })
|
||||
function continueStmt(lab) Pattern({ type: "ContinueStatement", label: lab })
|
||||
function blockStmt(body) Pattern({ type: "BlockStatement", body: body })
|
||||
function literal(val) Pattern({ type: "Literal", value: val })
|
||||
var emptyStmt = Pattern({ type: "EmptyStatement" })
|
||||
function ifStmt(test, cons, alt) Pattern({ type: "IfStatement", test: test, alternate: alt, consequent: cons })
|
||||
function labStmt(lab, stmt) Pattern({ type: "LabeledStatement", label: lab, body: stmt })
|
||||
function withStmt(obj, stmt) Pattern({ type: "WithStatement", object: obj, body: stmt })
|
||||
function whileStmt(test, stmt) Pattern({ type: "WhileStatement", test: test, body: stmt })
|
||||
function doStmt(stmt, test) Pattern({ type: "DoWhileStatement", test: test, body: stmt })
|
||||
function switchStmt(disc, cases) Pattern({ type: "SwitchStatement", discriminant: disc, cases: cases })
|
||||
function caseClause(test, stmts) Pattern({ type: "SwitchCase", test: test, consequent: stmts })
|
||||
function defaultClause(stmts) Pattern({ type: "SwitchCase", test: null, consequent: stmts })
|
||||
function catchClause(id, guard, body) Pattern({ type: "CatchClause", param: id, guard: guard, body: body })
|
||||
function tryStmt(body, guarded, unguarded, fin) Pattern({ type: "TryStatement", block: body, guardedHandlers: guarded, handler: unguarded, finalizer: fin })
|
||||
function letStmt(head, body) Pattern({ type: "LetStatement", head: head, body: body })
|
||||
function funDecl(id, params, body, defaults=[], rest=null) {
|
||||
return Pattern({ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: defaults,
|
||||
body: body,
|
||||
rest: rest,
|
||||
generator: false });
|
||||
}
|
||||
function genFunDecl(id, params, body) {
|
||||
return Pattern({ type: "FunctionDeclaration",
|
||||
id: id,
|
||||
params: params,
|
||||
defaults: [],
|
||||
body: body,
|
||||
generator: true });
|
||||
}
|
||||
function varDecl(decls) {
|
||||
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" });
|
||||
}
|
||||
function letDecl(decls) {
|
||||
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "let" });
|
||||
}
|
||||
function constDecl(decls) {
|
||||
return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "const" });
|
||||
}
|
||||
function ident(name) {
|
||||
return Pattern({ type: "Identifier", name: name });
|
||||
}
|
||||
function dotExpr(obj, id) {
|
||||
return Pattern({ type: "MemberExpression", computed: false, object: obj, property: id });
|
||||
}
|
||||
function memExpr(obj, id) {
|
||||
return Pattern({ type: "MemberExpression", computed: true, object: obj, property: id });
|
||||
}
|
||||
function forStmt(init, test, update, body) {
|
||||
return Pattern({ type: "ForStatement", init: init, test: test, update: update, body: body });
|
||||
}
|
||||
function forOfStmt(lhs, rhs, body) {
|
||||
return Pattern({ type: "ForOfStatement", left: lhs, right: rhs, body: body });
|
||||
}
|
||||
function forInStmt(lhs, rhs, body) {
|
||||
return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: false });
|
||||
}
|
||||
function forEachInStmt(lhs, rhs, body) {
|
||||
return Pattern({ type: "ForInStatement", left: lhs, right: rhs, body: body, each: true });
|
||||
}
|
||||
function breakStmt(lab) {
|
||||
return Pattern({ type: "BreakStatement", label: lab });
|
||||
}
|
||||
function continueStmt(lab) {
|
||||
return Pattern({ type: "ContinueStatement", label: lab });
|
||||
}
|
||||
function blockStmt(body) {
|
||||
return Pattern({ type: "BlockStatement", body: body });
|
||||
}
|
||||
function literal(val) {
|
||||
return Pattern({ type: "Literal", value: val });
|
||||
}
|
||||
var emptyStmt = Pattern({ type: "EmptyStatement" });
|
||||
function ifStmt(test, cons, alt) {
|
||||
return Pattern({ type: "IfStatement", test: test, alternate: alt, consequent: cons });
|
||||
}
|
||||
function labStmt(lab, stmt) {
|
||||
return Pattern({ type: "LabeledStatement", label: lab, body: stmt });
|
||||
}
|
||||
function withStmt(obj, stmt) {
|
||||
return Pattern({ type: "WithStatement", object: obj, body: stmt });
|
||||
}
|
||||
function whileStmt(test, stmt) {
|
||||
return Pattern({ type: "WhileStatement", test: test, body: stmt });
|
||||
}
|
||||
function doStmt(stmt, test) {
|
||||
return Pattern({ type: "DoWhileStatement", test: test, body: stmt });
|
||||
}
|
||||
function switchStmt(disc, cases) {
|
||||
return Pattern({ type: "SwitchStatement", discriminant: disc, cases: cases });
|
||||
}
|
||||
function caseClause(test, stmts) {
|
||||
return Pattern({ type: "SwitchCase", test: test, consequent: stmts });
|
||||
}
|
||||
function defaultClause(stmts) {
|
||||
return Pattern({ type: "SwitchCase", test: null, consequent: stmts });
|
||||
}
|
||||
function catchClause(id, guard, body) {
|
||||
return Pattern({ type: "CatchClause", param: id, guard: guard, body: body });
|
||||
}
|
||||
function tryStmt(body, guarded, unguarded, fin) {
|
||||
return Pattern({ type: "TryStatement", block: body, guardedHandlers: guarded, handler: unguarded, finalizer: fin });
|
||||
}
|
||||
function letStmt(head, body) {
|
||||
return Pattern({ type: "LetStatement", head: head, body: body });
|
||||
}
|
||||
|
||||
function classStmt(id, heritage, body) Pattern({ type: "ClassStatement",
|
||||
name: id,
|
||||
heritage: heritage,
|
||||
body: body})
|
||||
function classExpr(id, heritage, body) Pattern({ type: "ClassExpression",
|
||||
name: id,
|
||||
heritage: heritage,
|
||||
body: body})
|
||||
function classMethod(id, body, kind, static) Pattern({ type: "ClassMethod",
|
||||
name: id,
|
||||
body: body,
|
||||
kind: kind,
|
||||
static: static })
|
||||
function classStmt(id, heritage, body) {
|
||||
return Pattern({ type: "ClassStatement",
|
||||
name: id,
|
||||
heritage: heritage,
|
||||
body: body});
|
||||
}
|
||||
function classExpr(id, heritage, body) {
|
||||
return Pattern({ type: "ClassExpression",
|
||||
name: id,
|
||||
heritage: heritage,
|
||||
body: body});
|
||||
}
|
||||
function classMethod(id, body, kind, static) {
|
||||
return Pattern({ type: "ClassMethod",
|
||||
name: id,
|
||||
body: body,
|
||||
kind: kind,
|
||||
static: static });
|
||||
}
|
||||
|
||||
function funExpr(id, args, body, gen) {
|
||||
return Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
body: body,
|
||||
generator: false });
|
||||
}
|
||||
function genFunExpr(id, args, body) {
|
||||
return Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
body: body,
|
||||
generator: true });
|
||||
}
|
||||
function arrowExpr(args, body) {
|
||||
return Pattern({ type: "ArrowFunctionExpression",
|
||||
params: args,
|
||||
body: body });
|
||||
}
|
||||
|
||||
function funExpr(id, args, body, gen) Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
body: body,
|
||||
generator: false })
|
||||
function genFunExpr(id, args, body) Pattern({ type: "FunctionExpression",
|
||||
id: id,
|
||||
params: args,
|
||||
body: body,
|
||||
generator: true })
|
||||
function arrowExpr(args, body) Pattern({ type: "ArrowFunctionExpression",
|
||||
params: args,
|
||||
body: body })
|
||||
function unExpr(op, arg) {
|
||||
return Pattern({ type: "UnaryExpression", operator: op, argument: arg });
|
||||
}
|
||||
function binExpr(op, left, right) {
|
||||
return Pattern({ type: "BinaryExpression", operator: op, left: left, right: right });
|
||||
}
|
||||
function aExpr(op, left, right) {
|
||||
return Pattern({ type: "AssignmentExpression", operator: op, left: left, right: right });
|
||||
}
|
||||
function updExpr(op, arg, prefix) {
|
||||
return Pattern({ type: "UpdateExpression", operator: op, argument: arg, prefix: prefix });
|
||||
}
|
||||
function logExpr(op, left, right) {
|
||||
return Pattern({ type: "LogicalExpression", operator: op, left: left, right: right });
|
||||
}
|
||||
|
||||
function unExpr(op, arg) Pattern({ type: "UnaryExpression", operator: op, argument: arg })
|
||||
function binExpr(op, left, right) Pattern({ type: "BinaryExpression", operator: op, left: left, right: right })
|
||||
function aExpr(op, left, right) Pattern({ type: "AssignmentExpression", operator: op, left: left, right: right })
|
||||
function updExpr(op, arg, prefix) Pattern({ type: "UpdateExpression", operator: op, argument: arg, prefix: prefix })
|
||||
function logExpr(op, left, right) Pattern({ type: "LogicalExpression", operator: op, left: left, right: right })
|
||||
function condExpr(test, cons, alt) {
|
||||
return Pattern({ type: "ConditionalExpression", test: test, consequent: cons, alternate: alt });
|
||||
}
|
||||
function seqExpr(exprs) {
|
||||
return Pattern({ type: "SequenceExpression", expressions: exprs });
|
||||
}
|
||||
function newExpr(callee, args) {
|
||||
return Pattern({ type: "NewExpression", callee: callee, arguments: args });
|
||||
}
|
||||
function callExpr(callee, args) {
|
||||
return Pattern({ type: "CallExpression", callee: callee, arguments: args });
|
||||
}
|
||||
function arrExpr(elts) {
|
||||
return Pattern({ type: "ArrayExpression", elements: elts });
|
||||
}
|
||||
function objExpr(elts) {
|
||||
return Pattern({ type: "ObjectExpression", properties: elts });
|
||||
}
|
||||
function computedName(elts) {
|
||||
return Pattern({ type: "ComputedName", name: elts });
|
||||
}
|
||||
function templateLit(elts) {
|
||||
return Pattern({ type: "TemplateLiteral", elements: elts });
|
||||
}
|
||||
function taggedTemplate(tagPart, templatePart) {
|
||||
return Pattern({ type: "TaggedTemplate", callee: tagPart, arguments : templatePart });
|
||||
}
|
||||
function template(raw, cooked, ...args) {
|
||||
return Pattern([{ type: "CallSiteObject", raw: raw, cooked: cooked}, ...args]);
|
||||
}
|
||||
|
||||
function condExpr(test, cons, alt) Pattern({ type: "ConditionalExpression", test: test, consequent: cons, alternate: alt })
|
||||
function seqExpr(exprs) Pattern({ type: "SequenceExpression", expressions: exprs })
|
||||
function newExpr(callee, args) Pattern({ type: "NewExpression", callee: callee, arguments: args })
|
||||
function callExpr(callee, args) Pattern({ type: "CallExpression", callee: callee, arguments: args })
|
||||
function arrExpr(elts) Pattern({ type: "ArrayExpression", elements: elts })
|
||||
function objExpr(elts) Pattern({ type: "ObjectExpression", properties: elts })
|
||||
function computedName(elts) Pattern({ type: "ComputedName", name: elts })
|
||||
function templateLit(elts) Pattern({ type: "TemplateLiteral", elements: elts })
|
||||
function taggedTemplate(tagPart, templatePart) Pattern({ type: "TaggedTemplate", callee: tagPart,
|
||||
arguments : templatePart })
|
||||
function template(raw, cooked, ...args) Pattern([{ type: "CallSiteObject", raw: raw, cooked:
|
||||
cooked}, ...args])
|
||||
function compExpr(body, blocks, filter, style) {
|
||||
if (style == "legacy" || !filter)
|
||||
return Pattern({ type: "ComprehensionExpression", body, blocks, filter, style });
|
||||
else
|
||||
return Pattern({ type: "ComprehensionExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
|
||||
if (style == "legacy" || !filter)
|
||||
return Pattern({ type: "ComprehensionExpression", body, blocks, filter, style });
|
||||
else
|
||||
return Pattern({ type: "ComprehensionExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
|
||||
}
|
||||
function genExpr(body, blocks, filter, style) {
|
||||
if (style == "legacy" || !filter)
|
||||
return Pattern({ type: "GeneratorExpression", body, blocks, filter, style });
|
||||
else
|
||||
return Pattern({ type: "GeneratorExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
|
||||
if (style == "legacy" || !filter)
|
||||
return Pattern({ type: "GeneratorExpression", body, blocks, filter, style });
|
||||
else
|
||||
return Pattern({ type: "GeneratorExpression", body, blocks: blocks.concat(compIf(filter)), filter: null, style });
|
||||
}
|
||||
function graphExpr(idx, body) {
|
||||
return Pattern({ type: "GraphExpression", index: idx, expression: body });
|
||||
}
|
||||
function letExpr(head, body) {
|
||||
return Pattern({ type: "LetExpression", head: head, body: body });
|
||||
}
|
||||
function idxExpr(idx) {
|
||||
return Pattern({ type: "GraphIndexExpression", index: idx });
|
||||
}
|
||||
function graphExpr(idx, body) Pattern({ type: "GraphExpression", index: idx, expression: body })
|
||||
function letExpr(head, body) Pattern({ type: "LetExpression", head: head, body: body })
|
||||
function idxExpr(idx) Pattern({ type: "GraphIndexExpression", index: idx })
|
||||
|
||||
function compBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: false })
|
||||
function compEachBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: true, of: false })
|
||||
function compOfBlock(left, right) Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: true })
|
||||
function compIf(test) Pattern({ type: "ComprehensionIf", test: test })
|
||||
function compBlock(left, right) {
|
||||
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: false });
|
||||
}
|
||||
function compEachBlock(left, right) {
|
||||
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: true, of: false });
|
||||
}
|
||||
function compOfBlock(left, right) {
|
||||
return Pattern({ type: "ComprehensionBlock", left: left, right: right, each: false, of: true });
|
||||
}
|
||||
function compIf(test) {
|
||||
return Pattern({ type: "ComprehensionIf", test: test });
|
||||
}
|
||||
|
||||
function arrPatt(elts) Pattern({ type: "ArrayPattern", elements: elts })
|
||||
function objPatt(elts) Pattern({ type: "ObjectPattern", properties: elts })
|
||||
function arrPatt(elts) {
|
||||
return Pattern({ type: "ArrayPattern", elements: elts });
|
||||
}
|
||||
function objPatt(elts) {
|
||||
return Pattern({ type: "ObjectPattern", properties: elts });
|
||||
}
|
||||
|
||||
function assignElem(target, defaultExpr = null, targetIdent = typeof target == 'string' ? ident(target) : target) defaultExpr ? aExpr('=', targetIdent, defaultExpr) : targetIdent
|
||||
function assignProp(property, target, defaultExpr = null, shorthand = !target, targetProp = target || ident(property)) Pattern({
|
||||
type: "Property", key: ident(property), shorthand,
|
||||
value: defaultExpr ? aExpr('=', targetProp, defaultExpr) : targetProp })
|
||||
function assignElem(target, defaultExpr = null, targetIdent = typeof target == 'string' ? ident(target) : target) {
|
||||
return defaultExpr ? aExpr('=', targetIdent, defaultExpr) : targetIdent;
|
||||
}
|
||||
function assignProp(property, target, defaultExpr = null, shorthand = !target, targetProp = target || ident(property)) {
|
||||
return Pattern({
|
||||
type: "Property", key: ident(property), shorthand,
|
||||
value: defaultExpr ? aExpr('=', targetProp, defaultExpr) : targetProp });
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ return {
|
||||
literal: function(val) {
|
||||
return ["LiteralExpr", { value: val }];
|
||||
},
|
||||
expressionStatement: function(expr) expr,
|
||||
expressionStatement: expr => expr,
|
||||
conditionalExpression: function(test, cons, alt) {
|
||||
return ["ConditionalExpr", {}, test, cons, alt];
|
||||
},
|
||||
@ -140,7 +140,7 @@ return {
|
||||
yieldExpression: reject,
|
||||
letExpression: reject,
|
||||
|
||||
emptyStatement: function() ["EmptyStmt", {}],
|
||||
emptyStatement: () => ["EmptyStmt", {}],
|
||||
blockStatement: function(stmts) {
|
||||
stmts.unshift("BlockStmt", {});
|
||||
return stmts;
|
||||
@ -190,7 +190,7 @@ return {
|
||||
throwStatement: function(expr) {
|
||||
return ["ThrowStmt", {}, expr];
|
||||
},
|
||||
debuggerStatement: function() ["DebuggerStmt", {}],
|
||||
debuggerStatement: () => ["DebuggerStmt", {}],
|
||||
letStatement: reject,
|
||||
switchCase: function(expr, stmts) {
|
||||
if (expr)
|
||||
|
@ -2,62 +2,62 @@
|
||||
function test() {
|
||||
// Builder tests
|
||||
|
||||
Pattern("program").match(Reflect.parse("42", {builder:{program:function()"program"}}));
|
||||
Pattern("program").match(Reflect.parse("42", {builder:{program:() => "program"}}));
|
||||
|
||||
assertGlobalStmt("throw 42", 1, { throwStatement: function() 1 });
|
||||
assertGlobalStmt("for (;;);", 2, { forStatement: function() 2 });
|
||||
assertGlobalStmt("for (x in y);", 3, { forInStatement: function() 3 });
|
||||
assertGlobalStmt("{ }", 4, { blockStatement: function() 4 });
|
||||
assertGlobalStmt("foo: { }", 5, { labeledStatement: function() 5 });
|
||||
assertGlobalStmt("with (o) { }", 6, { withStatement: function() 6 });
|
||||
assertGlobalStmt("while (x) { }", 7, { whileStatement: function() 7 });
|
||||
assertGlobalStmt("do { } while(false);", 8, { doWhileStatement: function() 8 });
|
||||
assertGlobalStmt("switch (x) { }", 9, { switchStatement: function() 9 });
|
||||
assertGlobalStmt("try { } catch(e) { }", 10, { tryStatement: function() 10 });
|
||||
assertGlobalStmt(";", 11, { emptyStatement: function() 11 });
|
||||
assertGlobalStmt("debugger;", 12, { debuggerStatement: function() 12 });
|
||||
assertGlobalStmt("42;", 13, { expressionStatement: function() 13 });
|
||||
assertGlobalStmt("for (;;) break", forStmt(null, null, null, 14), { breakStatement: function() 14 });
|
||||
assertGlobalStmt("for (;;) continue", forStmt(null, null, null, 15), { continueStatement: function() 15 });
|
||||
assertGlobalStmt("throw 42", 1, { throwStatement: () => 1 });
|
||||
assertGlobalStmt("for (;;);", 2, { forStatement: () => 2 });
|
||||
assertGlobalStmt("for (x in y);", 3, { forInStatement: () => 3 });
|
||||
assertGlobalStmt("{ }", 4, { blockStatement: () => 4 });
|
||||
assertGlobalStmt("foo: { }", 5, { labeledStatement: () => 5 });
|
||||
assertGlobalStmt("with (o) { }", 6, { withStatement: () => 6 });
|
||||
assertGlobalStmt("while (x) { }", 7, { whileStatement: () => 7 });
|
||||
assertGlobalStmt("do { } while(false);", 8, { doWhileStatement: () => 8 });
|
||||
assertGlobalStmt("switch (x) { }", 9, { switchStatement: () => 9 });
|
||||
assertGlobalStmt("try { } catch(e) { }", 10, { tryStatement: () => 10 });
|
||||
assertGlobalStmt(";", 11, { emptyStatement: () => 11 });
|
||||
assertGlobalStmt("debugger;", 12, { debuggerStatement: () => 12 });
|
||||
assertGlobalStmt("42;", 13, { expressionStatement: () => 13 });
|
||||
assertGlobalStmt("for (;;) break", forStmt(null, null, null, 14), { breakStatement: () => 14 });
|
||||
assertGlobalStmt("for (;;) continue", forStmt(null, null, null, 15), { continueStatement: () => 15 });
|
||||
|
||||
assertBlockDecl("var x", "var", { variableDeclaration: function(kind) kind });
|
||||
assertBlockDecl("let x", "let", { variableDeclaration: function(kind) kind });
|
||||
assertBlockDecl("const x = undefined", "const", { variableDeclaration: function(kind) kind });
|
||||
assertBlockDecl("function f() { }", "function", { functionDeclaration: function() "function" });
|
||||
assertBlockDecl("var x", "var", { variableDeclaration: kind => kind });
|
||||
assertBlockDecl("let x", "let", { variableDeclaration: kind => kind });
|
||||
assertBlockDecl("const x = undefined", "const", { variableDeclaration: kind => kind });
|
||||
assertBlockDecl("function f() { }", "function", { functionDeclaration: () => "function" });
|
||||
|
||||
assertGlobalExpr("(x,y,z)", 1, { sequenceExpression: function() 1 });
|
||||
assertGlobalExpr("(x ? y : z)", 2, { conditionalExpression: function() 2 });
|
||||
assertGlobalExpr("x + y", 3, { binaryExpression: function() 3 });
|
||||
assertGlobalExpr("delete x", 4, { unaryExpression: function() 4 });
|
||||
assertGlobalExpr("x = y", 5, { assignmentExpression: function() 5 });
|
||||
assertGlobalExpr("x || y", 6, { logicalExpression: function() 6 });
|
||||
assertGlobalExpr("x++", 7, { updateExpression: function() 7 });
|
||||
assertGlobalExpr("new x", 8, { newExpression: function() 8 });
|
||||
assertGlobalExpr("x()", 9, { callExpression: function() 9 });
|
||||
assertGlobalExpr("x.y", 10, { memberExpression: function() 10 });
|
||||
assertGlobalExpr("(function() { })", 11, { functionExpression: function() 11 });
|
||||
assertGlobalExpr("[1,2,3]", 12, { arrayExpression: function() 12 });
|
||||
assertGlobalExpr("({ x: y })", 13, { objectExpression: function() 13 });
|
||||
assertGlobalExpr("this", 14, { thisExpression: function() 14 });
|
||||
assertGlobalExpr("[x for (x in y)]", 17, { comprehensionExpression: function() 17 });
|
||||
assertGlobalExpr("(x for (x in y))", 18, { generatorExpression: function() 18 });
|
||||
assertGlobalExpr("(function() { yield 42 })", genFunExpr(null, [], blockStmt([exprStmt(19)])), { yieldExpression: function() 19 });
|
||||
assertGlobalExpr("(let (x) x)", 20, { letExpression: function() 20 });
|
||||
assertGlobalExpr("(x,y,z)", 1, { sequenceExpression: () => 1 });
|
||||
assertGlobalExpr("(x ? y : z)", 2, { conditionalExpression: () => 2 });
|
||||
assertGlobalExpr("x + y", 3, { binaryExpression: () => 3 });
|
||||
assertGlobalExpr("delete x", 4, { unaryExpression: () => 4 });
|
||||
assertGlobalExpr("x = y", 5, { assignmentExpression: () => 5 });
|
||||
assertGlobalExpr("x || y", 6, { logicalExpression: () => 6 });
|
||||
assertGlobalExpr("x++", 7, { updateExpression: () => 7 });
|
||||
assertGlobalExpr("new x", 8, { newExpression: () => 8 });
|
||||
assertGlobalExpr("x()", 9, { callExpression: () => 9 });
|
||||
assertGlobalExpr("x.y", 10, { memberExpression: () => 10 });
|
||||
assertGlobalExpr("(function() { })", 11, { functionExpression: () => 11 });
|
||||
assertGlobalExpr("[1,2,3]", 12, { arrayExpression: () => 12 });
|
||||
assertGlobalExpr("({ x: y })", 13, { objectExpression: () => 13 });
|
||||
assertGlobalExpr("this", 14, { thisExpression: () => 14 });
|
||||
assertGlobalExpr("[x for (x in y)]", 17, { comprehensionExpression: () => 17 });
|
||||
assertGlobalExpr("(x for (x in y))", 18, { generatorExpression: () => 18 });
|
||||
assertGlobalExpr("(function() { yield 42 })", genFunExpr(null, [], blockStmt([exprStmt(19)])), { yieldExpression: () => 19 });
|
||||
assertGlobalExpr("(let (x) x)", 20, { letExpression: () => 20 });
|
||||
|
||||
assertGlobalStmt("switch (x) { case y: }", switchStmt(ident("x"), [1]), { switchCase: function() 1 });
|
||||
assertGlobalStmt("try { } catch (e) { }", 2, { tryStatement: (function(b, g, u, f) u), catchClause: function() 2 });
|
||||
assertGlobalStmt("try { } catch (e if e instanceof A) { } catch (e if e instanceof B) { }", [2, 2], { tryStatement: (function(b, g, u, f) g), catchClause: function() 2 });
|
||||
assertGlobalStmt("try { } catch (e) { }", tryStmt(blockStmt([]), [], 2, null), { catchClause: function() 2 });
|
||||
assertGlobalStmt("switch (x) { case y: }", switchStmt(ident("x"), [1]), { switchCase: () => 1 });
|
||||
assertGlobalStmt("try { } catch (e) { }", 2, { tryStatement: (b, g, u, f) => u, catchClause: () => 2 });
|
||||
assertGlobalStmt("try { } catch (e if e instanceof A) { } catch (e if e instanceof B) { }", [2, 2], { tryStatement: (b, g, u, f) => g, catchClause: () => 2 });
|
||||
assertGlobalStmt("try { } catch (e) { }", tryStmt(blockStmt([]), [], 2, null), { catchClause: () => 2 });
|
||||
assertGlobalStmt("try { } catch (e if e instanceof A) { } catch (e if e instanceof B) { }",
|
||||
tryStmt(blockStmt([]), [2, 2], null, null),
|
||||
{ catchClause: function() 2 });
|
||||
{ catchClause: () => 2 });
|
||||
assertGlobalExpr("[x for (y in z) for (x in y)]",
|
||||
compExpr(ident("x"), [3, 3], null, "legacy"),
|
||||
{ comprehensionBlock: function() 3 });
|
||||
{ comprehensionBlock: () => 3 });
|
||||
|
||||
assertGlobalExpr("({ x: y } = z)", aExpr("=", 1, ident("z")), { objectPattern: function() 1 });
|
||||
assertGlobalExpr("({ x: y } = z)", aExpr("=", objPatt([2]), ident("z")), { propertyPattern: function() 2 });
|
||||
assertGlobalExpr("[ x ] = y", aExpr("=", 3, ident("y")), { arrayPattern: function() 3 });
|
||||
assertGlobalExpr("({ x: y } = z)", aExpr("=", 1, ident("z")), { objectPattern: () => 1 });
|
||||
assertGlobalExpr("({ x: y } = z)", aExpr("=", objPatt([2]), ident("z")), { propertyPattern: () => 2 });
|
||||
assertGlobalExpr("[ x ] = y", aExpr("=", 3, ident("y")), { arrayPattern: () => 3 });
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,8 @@ function test() {
|
||||
// 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(n => ("x" + n + " = 0"), makePattSrc);
|
||||
var pattPatts = makePatternCombinations(n => (aExpr("=", ident("x" + n), lit(0))), makePattPatt);
|
||||
|
||||
for (var i = 0; i < pattSrcs.length; i++) {
|
||||
var src = pattSrcs[i].join(",");
|
||||
@ -20,12 +20,12 @@ function testAssignmentCombinations(makePattSrc, makePattPatt) {
|
||||
}
|
||||
}
|
||||
|
||||
testAssignmentCombinations(function (n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
|
||||
function (n) (aExpr("=",
|
||||
objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))]),
|
||||
lit(0))));
|
||||
testAssignmentCombinations(n => ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
|
||||
n => (aExpr("=",
|
||||
objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))]),
|
||||
lit(0))));
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,45 +1,53 @@
|
||||
// |reftest| skip-if(!xulRuntime.shell)
|
||||
function test() {
|
||||
|
||||
var JS_HAS_EXPR_CLOSURES = true;
|
||||
|
||||
function testParamPatternCombinations(makePattSrc, makePattPatt) {
|
||||
var pattSrcs = makePatternCombinations(function(n) ("x" + n), makePattSrc);
|
||||
var pattPatts = makePatternCombinations(function(n) (ident("x" + n)), makePattPatt);
|
||||
var pattSrcs = makePatternCombinations(n => ("x" + n), makePattSrc);
|
||||
var pattPatts = makePatternCombinations(n => (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(",") + ") " + body + ")";
|
||||
}
|
||||
function makePatt(body) {
|
||||
return funExpr(null, pattPatts[i], body);
|
||||
}
|
||||
|
||||
// no upvars, block body
|
||||
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")]))])));
|
||||
// no upvars, expression body
|
||||
assertExpr(makeSrc("(0)"), makePatt(lit(0)));
|
||||
// upvars, expression body
|
||||
assertExpr(makeSrc("[x1,x2,x3,x4,x5]"),
|
||||
makePatt(arrExpr([ident("x1"), ident("x2"), ident("x3"), ident("x4"), ident("x5")])));
|
||||
if (JS_HAS_EXPR_CLOSURES) {
|
||||
// no upvars, expression body
|
||||
assertExpr(makeSrc("(0)"), makePatt(lit(0)));
|
||||
// upvars, expression body
|
||||
assertExpr(makeSrc("[x1,x2,x3,x4,x5]"),
|
||||
makePatt(arrExpr([ident("x1"), ident("x2"), ident("x3"), ident("x4"), ident("x5")])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testParamPatternCombinations(function(n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "}"),
|
||||
function(n) (objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))])));
|
||||
testParamPatternCombinations(n => ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "}"),
|
||||
n => (objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))])));
|
||||
|
||||
testParamPatternCombinations(function(n) ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10}"),
|
||||
function(n) (objPatt([assignProp("a" + n, ident("x" + n), lit(10)),
|
||||
assignProp("b" + n, ident("y" + n), lit(10)),
|
||||
assignProp("c" + n, ident("z" + n), lit(10))])));
|
||||
testParamPatternCombinations(n => ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10}"),
|
||||
n => (objPatt([assignProp("a" + n, ident("x" + n), lit(10)),
|
||||
assignProp("b" + n, ident("y" + n), lit(10)),
|
||||
assignProp("c" + n, ident("z" + n), lit(10))])));
|
||||
|
||||
testParamPatternCombinations(function(n) ("[x" + n + "," + "y" + n + "," + "z" + n + "]"),
|
||||
function(n) (arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)])));
|
||||
testParamPatternCombinations(n => ("[x" + n + "," + "y" + n + "," + "z" + n + "]"),
|
||||
n => (arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)])));
|
||||
|
||||
testParamPatternCombinations(function(n) ("[a" + n + ", ..." + "b" + n + "]"),
|
||||
function(n) (arrPatt([assignElem("a" + n), spread(ident("b" + n))])));
|
||||
testParamPatternCombinations(n => ("[a" + n + ", ..." + "b" + n + "]"),
|
||||
n => (arrPatt([assignElem("a" + n), spread(ident("b" + n))])));
|
||||
|
||||
testParamPatternCombinations(function(n) ("[a" + n + ", " + "b" + n + " = 10]"),
|
||||
function(n) (arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))])));
|
||||
testParamPatternCombinations(n => ("[a" + n + ", " + "b" + n + " = 10]"),
|
||||
n => (arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))])));
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,12 @@
|
||||
function test() {
|
||||
|
||||
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(n => ("x" + n), makePattSrc);
|
||||
var pattPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: null }), makePattPatt);
|
||||
// It's illegal to have uninitialized const declarations, so we need a
|
||||
// separate set of patterns and sources.
|
||||
var constSrcs = makePatternCombinations(function(n) ("x" + n + " = undefined"), makePattSrc);
|
||||
var constPatts = makePatternCombinations(function(n) ({ id: ident("x" + n), init: ident("undefined") }), makePattPatt);
|
||||
var constSrcs = makePatternCombinations(n => ("x" + n + " = undefined"), makePattSrc);
|
||||
var constPatts = makePatternCombinations(n => ({ id: ident("x" + n), init: ident("undefined") }), makePattPatt);
|
||||
|
||||
for (var i = 0; i < pattSrcs.length; i++) {
|
||||
// variable declarations in blocks
|
||||
@ -29,29 +29,29 @@ function testVarPatternCombinations(makePattSrc, makePattPatt) {
|
||||
}
|
||||
}
|
||||
|
||||
testVarPatternCombinations(function (n) ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
|
||||
function (n) ({ id: objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))]),
|
||||
init: lit(0) }));
|
||||
testVarPatternCombinations(n => ("{a" + n + ":x" + n + "," + "b" + n + ":y" + n + "," + "c" + n + ":z" + n + "} = 0"),
|
||||
n => ({ id: objPatt([assignProp("a" + n, ident("x" + n)),
|
||||
assignProp("b" + n, ident("y" + n)),
|
||||
assignProp("c" + n, ident("z" + n))]),
|
||||
init: lit(0) }));
|
||||
|
||||
testVarPatternCombinations(function (n) ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10} = 0"),
|
||||
function (n) ({ id: objPatt([assignProp("a" + n, ident("x" + n), lit(10)),
|
||||
assignProp("b" + n, ident("y" + n), lit(10)),
|
||||
assignProp("c" + n, ident("z" + n), lit(10))]),
|
||||
init: lit(0) }));
|
||||
testVarPatternCombinations(n => ("{a" + n + ":x" + n + " = 10," + "b" + n + ":y" + n + " = 10," + "c" + n + ":z" + n + " = 10} = 0"),
|
||||
n => ({ id: objPatt([assignProp("a" + n, ident("x" + n), lit(10)),
|
||||
assignProp("b" + n, ident("y" + n), lit(10)),
|
||||
assignProp("c" + n, ident("z" + n), lit(10))]),
|
||||
init: lit(0) }));
|
||||
|
||||
testVarPatternCombinations(function(n) ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0"),
|
||||
function(n) ({ id: arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)]),
|
||||
init: lit(0) }));
|
||||
testVarPatternCombinations(n => ("[x" + n + "," + "y" + n + "," + "z" + n + "] = 0"),
|
||||
n => ({ id: arrPatt([assignElem("x" + n), assignElem("y" + n), assignElem("z" + n)]),
|
||||
init: lit(0) }));
|
||||
|
||||
testVarPatternCombinations(function(n) ("[a" + n + ", ..." + "b" + n + "] = 0"),
|
||||
function(n) ({ id: arrPatt([assignElem("a" + n), spread(ident("b" + n))]),
|
||||
init: lit(0) }));
|
||||
testVarPatternCombinations(n => ("[a" + n + ", ..." + "b" + n + "] = 0"),
|
||||
n => ({ id: arrPatt([assignElem("a" + n), spread(ident("b" + n))]),
|
||||
init: lit(0) }));
|
||||
|
||||
testVarPatternCombinations(function(n) ("[a" + n + ", " + "b" + n + " = 10] = 0"),
|
||||
function(n) ({ id: arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))]),
|
||||
init: lit(0) }));
|
||||
testVarPatternCombinations(n => ("[a" + n + ", " + "b" + n + " = 10] = 0"),
|
||||
n => ({ id: arrPatt([assignElem("a" + n), assignElem("b" + n, lit(10))]),
|
||||
init: lit(0) }));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user