Skip to content

Commit 6d2082d

Browse files
committed
1 parent abf7f9a commit 6d2082d

8 files changed

+73
-93
lines changed

demo/collector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function collectRegex() {
5858
}
5959

6060
timerId = window.setTimeout(function () {
61-
var code, result, occurrences, model, i, str;
61+
var code, result, occurrences, model, i;
6262

6363
if (typeof window.editor === 'undefined') {
6464
code = document.getElementById('code').value;

demo/functiontrace.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
(function (global) {
2929
'use strict';
3030

31-
var lookup;
32-
3331
function id(i) {
3432
return document.getElementById(i);
3533
}
3634

3735
function traceInstrument() {
38-
var tracer, code, i, functionList, signature, pos;
36+
var tracer, code, signature;
3937

4038
if (typeof window.editor === 'undefined') {
4139
code = document.getElementById('code').value;

demo/validate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function validate(delay) {
88
}
99

1010
validateId = window.setTimeout(function () {
11-
var code, result, syntax, errors, i, str;
11+
var code, result, syntax, errors, i;
1212

1313
if (typeof window.editor === 'undefined') {
1414
code = document.getElementById('editor').value;

esprima.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ parseStatement: true, parseSourceElement: true */
6767
PropertyKind,
6868
Messages,
6969
Regex,
70-
SyntaxTreeDelegate,
7170
source,
7271
strict,
7372
index,
7473
lineNumber,
7574
lineStart,
7675
length,
77-
delegate,
7876
lookahead,
7977
state,
8078
extra;
@@ -347,7 +345,7 @@ parseStatement: true, parseSourceElement: true */
347345
// 7.4 Comments
348346

349347
function addComment(type, value, start, end, loc) {
350-
var comment, attacher;
348+
var comment;
351349

352350
assert(typeof start === 'number', 'Comment must have valid position');
353351

@@ -1171,7 +1169,7 @@ parseStatement: true, parseSourceElement: true */
11711169
}
11721170

11731171
function scanRegExp() {
1174-
var start, body, flags, pattern, value;
1172+
var start, body, flags, value;
11751173

11761174
lookahead = null;
11771175
skipComment();
@@ -1366,7 +1364,7 @@ parseStatement: true, parseSourceElement: true */
13661364
}
13671365

13681366
function collectToken() {
1369-
var loc, token, range, value;
1367+
var loc, token, value;
13701368

13711369
skipComment();
13721370
loc = {
@@ -2715,7 +2713,7 @@ parseStatement: true, parseSourceElement: true */
27152713
// 11.13 Assignment Operators
27162714

27172715
function parseAssignmentExpression() {
2718-
var oldParenthesisCount, token, expr, right, params, list, startToken;
2716+
var oldParenthesisCount, token, expr, right, list, startToken;
27192717

27202718
oldParenthesisCount = state.parenthesisCount;
27212719

@@ -3773,15 +3771,13 @@ parseStatement: true, parseSourceElement: true */
37733771

37743772
function tokenize(code, options) {
37753773
var toString,
3776-
token,
37773774
tokens;
37783775

37793776
toString = String;
37803777
if (typeof code !== 'string' && !(code instanceof String)) {
37813778
code = toString(code);
37823779
}
37833780

3784-
delegate = SyntaxTreeDelegate;
37853781
source = code;
37863782
index = 0;
37873783
lineNumber = (source.length > 0) ? 1 : 0;
@@ -3826,12 +3822,11 @@ parseStatement: true, parseSourceElement: true */
38263822
return extra.tokens;
38273823
}
38283824

3829-
token = lex();
3825+
lex();
38303826
while (lookahead.type !== Token.EOF) {
38313827
try {
3832-
token = lex();
3828+
lex();
38333829
} catch (lexError) {
3834-
token = lookahead;
38353830
if (extra.errors) {
38363831
extra.errors.push(lexError);
38373832
// We have to break on the first error
@@ -3867,7 +3862,6 @@ parseStatement: true, parseSourceElement: true */
38673862
code = toString(code);
38683863
}
38693864

3870-
delegate = SyntaxTreeDelegate;
38713865
source = code;
38723866
index = 0;
38733867
lineNumber = (source.length > 0) ? 1 : 0;

test/benchmarks.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ if (typeof window !== 'undefined') {
201201
}
202202

203203
function run() {
204-
var el, test, source, benchmark;
204+
var test, source, benchmark;
205205

206206
if (index >= suite.length) {
207207
setText('total-time', (1000 * totalTime).toFixed(1) + ' ms \xb1 ' +
@@ -212,7 +212,6 @@ if (typeof window !== 'undefined') {
212212
}
213213

214214
test = slug(suite[index]);
215-
el = id(test);
216215
source = window.data[test];
217216
setText(test + '-time', 'Running...');
218217

@@ -305,8 +304,7 @@ if (typeof window !== 'undefined') {
305304
}
306305

307306
function runTests(tests) {
308-
var index,
309-
tree = [],
307+
var tree = [],
310308
totalTime = 0,
311309
totalSize = 0,
312310
totalRme = 0;

test/reflect.js

+59-59
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
function testReflect(Reflect, Pattern) {
2121

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 }); }
2828
var thisExpr = Pattern({ type: "ThisExpression" });
2929
function funDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
3030
id: id,
@@ -34,7 +34,7 @@ function funDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration
3434
rest: null,
3535
generator: false,
3636
expression: false
37-
}) }
37+
}); }
3838
function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration",
3939
id: id,
4040
params: params,
@@ -43,32 +43,32 @@ function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclarat
4343
rest: null,
4444
generator: false,
4545
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 }); }
6060
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 }); }
7272
function funExpr(id, args, body, gen) { return Pattern({ type: "FunctionExpression",
7373
id: id,
7474
params: args,
@@ -77,7 +77,7 @@ function funExpr(id, args, body, gen) { return Pattern({ type: "FunctionExpressi
7777
rest: null,
7878
generator: false,
7979
expression: false
80-
}) }
80+
}); }
8181
function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression",
8282
id: id,
8383
params: args,
@@ -86,29 +86,29 @@ function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression
8686
rest: null,
8787
generator: false,
8888
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])])))]); }
112112

113113
function assertBlockStmt(src, patt) {
114114
blockPatt(patt).assert(Reflect.parse(blockSrc(src)));
@@ -271,10 +271,10 @@ assertExpr("(x ^= y)", aExpr("^=", ident("x"), ident("y")));
271271
assertExpr("(x &= y)", aExpr("&=", ident("x"), ident("y")));
272272
assertExpr("(x || y)", logExpr("||", ident("x"), ident("y")));
273273
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")));
275275
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")]));
278278
assertExpr("(a,b,c,d,e,f,g)", seqExpr([ident("a"),ident("b"),ident("c"),ident("d"),ident("e"),ident("f"),ident("g")]));
279279
assertExpr("(new Object)", newExpr(ident("Object"), []));
280280
assertExpr("(new Object())", newExpr(ident("Object"), []));

test/runner.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function hasAttachedComment(syntax) {
114114

115115
function testParse(esprima, code, syntax) {
116116
'use strict';
117-
var expected, tree, actual, options, StringObject, i, len, err;
117+
var expected, tree, actual, options, StringObject, i, len;
118118

119119
// alias, so that JSLint does not complain.
120120
StringObject = String;
@@ -274,7 +274,7 @@ function testError(esprima, code, exception) {
274274

275275
try {
276276
if (tokenize) {
277-
esprima.tokenize(code, options[i])
277+
esprima.tokenize(code, options[i]);
278278
} else {
279279
esprima.parse(code, options[i]);
280280
}
@@ -342,9 +342,7 @@ if (typeof window !== 'undefined') {
342342
fixture,
343343
source,
344344
tick,
345-
expected,
346-
index,
347-
len;
345+
expected;
348346

349347
function setText(el, str) {
350348
if (typeof el.innerText === 'string') {

test/test.js

-8
Original file line numberDiff line numberDiff line change
@@ -21010,14 +21010,6 @@ var testFixture = {
2101021010
message: 'Error: Line 1: Parameter name eval or arguments is not allowed in strict mode'
2101121011
},
2101221012

21013-
// strict mode, using eval when IsSimpleParameterList is false
21014-
'"use strict"; (eval, a) => 42': {
21015-
index: 29,
21016-
lineNumber: 1,
21017-
column: 30,
21018-
message: 'Error: Line 1: Parameter name eval or arguments is not allowed in strict mode'
21019-
},
21020-
2102121013
'(a, a) => 42': {
2102221014
index: 6,
2102321015
lineNumber: 1,

0 commit comments

Comments
 (0)