[Pkg-javascript-commits] [node-acorn-jsx] 294/484: Adjust start positions of parenthesized expressions to not include parentheses
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 3603f7d0b1d311f99a506549b9024f3e790e68e7
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Oct 8 11:52:40 2014 +0200
Adjust start positions of parenthesized expressions to not include parentheses
Issue #136
---
acorn.js | 88 ++++++++++++----------
test/driver.js | 9 +--
test/tests-harmony.js | 176 +++++++++++++++++++++----------------------
test/tests.js | 201 +++++++++-----------------------------------------
4 files changed, 174 insertions(+), 300 deletions(-)
diff --git a/acorn.js b/acorn.js
index 6ac1979..8b5cb15 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1236,19 +1236,24 @@
return node;
}
- // Start a node whose start offset information should be based on
- // the start of another node. For example, a binary operator node is
- // only started after its left-hand side has already been parsed.
+ // Sometimes, a node is only started *after* the token stream passed
+ // its start position. The functions below help storing a position
+ // and creating a node from a previous position.
- function startNodeFrom(other) {
- var node = new Node();
- node.start = other.start;
+ function storeCurrentPos() {
+ return options.locations ? [tokStart, tokStartLoc] : tokStart;
+ }
+
+ function startNodeAt(pos) {
+ var node = new Node(), start = pos;
if (options.locations) {
node.loc = new SourceLocation();
- node.loc.start = other.loc.start;
+ node.loc.start = start[1];
+ start = pos[0];
}
+ node.start = start;
if (options.ranges)
- node.range = [other.range[0], 0];
+ node.range = [start, 0];
return node;
}
@@ -1827,9 +1832,10 @@
// or the `in` operator (in for loops initalization expressions).
function parseExpression(noComma, noIn) {
+ var start = storeCurrentPos();
var expr = parseMaybeAssign(noIn);
if (!noComma && tokType === _comma) {
- var node = startNodeFrom(expr);
+ var node = startNodeAt(start);
node.expressions = [expr];
while (eat(_comma)) node.expressions.push(parseMaybeAssign(noIn));
return finishNode(node, "SequenceExpression");
@@ -1841,9 +1847,10 @@
// operators like `+=`.
function parseMaybeAssign(noIn) {
+ var start = storeCurrentPos();
var left = parseMaybeConditional(noIn);
if (tokType.isAssign) {
- var node = startNodeFrom(left);
+ var node = startNodeAt(start);
node.operator = tokVal;
node.left = tokType === _eq ? toAssignable(left) : left;
checkLVal(left);
@@ -1857,9 +1864,10 @@
// Parse a ternary conditional (`?:`) operator.
function parseMaybeConditional(noIn) {
+ var start = storeCurrentPos();
var expr = parseExprOps(noIn);
if (eat(_question)) {
- var node = startNodeFrom(expr);
+ var node = startNodeAt(start);
node.test = expr;
node.consequent = parseExpression(true);
expect(_colon);
@@ -1872,7 +1880,8 @@
// Start the precedence parser.
function parseExprOps(noIn) {
- return parseExprOp(parseMaybeUnary(), -1, noIn);
+ var start = storeCurrentPos();
+ return parseExprOp(parseMaybeUnary(), start, -1, noIn);
}
// Parse binary operators with the operator precedence parsing
@@ -1881,18 +1890,19 @@
// defer further parser to one of its callers when it encounters an
// operator that has a lower precedence than the set it is parsing.
- function parseExprOp(left, minPrec, noIn) {
+ function parseExprOp(left, leftStart, minPrec, noIn) {
var prec = tokType.binop;
if (prec != null && (!noIn || tokType !== _in)) {
if (prec > minPrec) {
- var node = startNodeFrom(left);
+ var node = startNodeAt(leftStart);
node.left = left;
node.operator = tokVal;
var op = tokType;
next();
- node.right = parseExprOp(parseMaybeUnary(), prec, noIn);
- var exprNode = finishNode(node, (op === _logicalOR || op === _logicalAND) ? "LogicalExpression" : "BinaryExpression");
- return parseExprOp(exprNode, minPrec, noIn);
+ var start = storeCurrentPos();
+ node.right = parseExprOp(parseMaybeUnary(), start, prec, noIn);
+ finishNode(node, (op === _logicalOR || op === _logicalAND) ? "LogicalExpression" : "BinaryExpression");
+ return parseExprOp(node, leftStart, minPrec, noIn);
}
}
return left;
@@ -1914,9 +1924,10 @@
raise(node.start, "Deleting local variable in strict mode");
return finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
}
+ var start = storeCurrentPos();
var expr = parseExprSubscripts();
while (tokType.postfix && !canInsertSemicolon()) {
- var node = startNodeFrom(expr);
+ var node = startNodeAt(start);
node.operator = tokVal;
node.prefix = false;
node.argument = expr;
@@ -1930,33 +1941,34 @@
// Parse call, dot, and `[]`-subscript expressions.
function parseExprSubscripts() {
- return parseSubscripts(parseExprAtom());
+ var start = storeCurrentPos();
+ return parseSubscripts(parseExprAtom(), start);
}
- function parseSubscripts(base, noCalls) {
+ function parseSubscripts(base, start, noCalls) {
if (eat(_dot)) {
- var node = startNodeFrom(base);
+ var node = startNodeAt(start);
node.object = base;
node.property = parseIdent(true);
node.computed = false;
- return parseSubscripts(finishNode(node, "MemberExpression"), noCalls);
+ return parseSubscripts(finishNode(node, "MemberExpression"), start, noCalls);
} else if (eat(_bracketL)) {
- var node = startNodeFrom(base);
+ var node = startNodeAt(start);
node.object = base;
node.property = parseExpression();
node.computed = true;
expect(_bracketR);
- return parseSubscripts(finishNode(node, "MemberExpression"), noCalls);
+ return parseSubscripts(finishNode(node, "MemberExpression"), start, noCalls);
} else if (!noCalls && eat(_parenL)) {
- var node = startNodeFrom(base);
+ var node = startNodeAt(start);
node.callee = base;
node.arguments = parseExprList(_parenR, false);
- return parseSubscripts(finishNode(node, "CallExpression"), noCalls);
+ return parseSubscripts(finishNode(node, "CallExpression"), start, noCalls);
} else if (tokType === _bquote) {
- var node = startNodeFrom(base);
+ var node = startNodeAt(start);
node.tag = base;
node.quasi = parseTemplate();
- return parseSubscripts(finishNode(node, "TaggedTemplateExpression"), noCalls);
+ return parseSubscripts(finishNode(node, "TaggedTemplateExpression"), start, noCalls);
} return base;
}
@@ -1976,9 +1988,10 @@
if (inGenerator) return parseYield();
case _name:
+ var start = storeCurrentPos();
var id = parseIdent(tokType !== _name);
if (eat(_arrow)) {
- return parseArrowExpression(startNodeFrom(id), [id]);
+ return parseArrowExpression(startNodeAt(start), [id]);
}
return id;
@@ -1997,11 +2010,12 @@
return finishNode(node, "Literal");
case _parenL:
+ var start = storeCurrentPos();
var tokStartLoc1 = tokStartLoc, tokStart1 = tokStart, val, exprList;
next();
// check whether this is generator comprehension or regular expression
if (options.ecmaVersion >= 6 && tokType === _for) {
- val = parseComprehension(startNode(), true);
+ val = parseComprehension(startNodeAt(start), true);
} else {
var oldParenL = ++metParenL;
if (tokType !== _parenR) {
@@ -2013,7 +2027,7 @@
expect(_parenR);
// if '=>' follows '(...)', convert contents to arguments
if (metParenL === oldParenL && eat(_arrow)) {
- val = parseArrowExpression(startNode(), exprList);
+ val = parseArrowExpression(startNodeAt(start), exprList);
} else {
// forbid '()' before everything but '=>'
if (!val) unexpected(lastStart);
@@ -2025,15 +2039,6 @@
}
}
}
- val.start = tokStart1;
- val.end = lastEnd;
- if (options.locations) {
- val.loc.start = tokStartLoc1;
- val.loc.end = lastEndLoc;
- }
- if (options.ranges) {
- val.range = [tokStart1, lastEnd];
- }
return val;
case _bracketL:
@@ -2078,7 +2083,8 @@
function parseNew() {
var node = startNode();
next();
- node.callee = parseSubscripts(parseExprAtom(), true);
+ var start = storeCurrentPos();
+ node.callee = parseSubscripts(parseExprAtom(), start, true);
if (eat(_parenL)) node.arguments = parseExprList(_parenR, false);
else node.arguments = empty;
return finishNode(node, "NewExpression");
diff --git a/test/driver.js b/test/driver.js
index 3b15510..a08bf6e 100644
--- a/test/driver.js
+++ b/test/driver.js
@@ -43,10 +43,9 @@
else callback("ok", test.code);
} else {
var mis = misMatch(test.ast, ast);
+ if (!mis && test.comments) mis = misMatch(test.comments, comments);
if (mis) callback("fail", test.code, mis);
- if (test.comments) mis = misMatch(test.comments, comments);
- if (!mis) callback("ok", test.code);
- else callback("fail", test.code, mis);
+ else callback("ok", test.code);
}
} catch(e) {
if (test.error && e instanceof SyntaxError) {
@@ -67,7 +66,7 @@
return str + " (" + pt + ")";
}
- function misMatch(exp, act) {
+ var misMatch = exports.misMatch = function(exp, act) {
if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
if (exp !== act) return ppJSON(exp) + " !== " + ppJSON(act);
} else if (exp.splice) {
@@ -83,7 +82,7 @@
if (mis) return addPath(mis, prop);
}
}
- }
+ };
function mangle(ast) {
if (typeof ast != "object" || !ast) return;
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index e0d3666..deeb049 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -1511,10 +1511,10 @@ test("e => ({ property: 42 })", {
end: {line: 1, column: 20}
}
}],
- range: [5, 23],
+ range: [6, 22],
loc: {
- start: {line: 1, column: 5},
- end: {line: 1, column: 23}
+ start: {line: 1, column: 6},
+ end: {line: 1, column: 22}
}
},
rest: null,
@@ -2330,10 +2330,10 @@ test("(x => x)", {
rest: null,
generator: false,
expression: true,
- range: [0, 8],
+ range: [1, 7],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 8}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 7}
}
},
range: [0, 8],
@@ -2500,19 +2500,19 @@ test("(x) => ((y, z) => (x, y, z))", {
}
}
],
- range: [18, 27],
+ range: [19, 26],
loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 27}
+ start: {line: 1, column: 19},
+ end: {line: 1, column: 26}
}
},
rest: null,
generator: false,
expression: true,
- range: [7, 28],
+ range: [8, 27],
loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 28}
+ start: {line: 1, column: 8},
+ end: {line: 1, column: 27}
}
},
rest: null,
@@ -4268,10 +4268,10 @@ test("({ responseText: text }) = res", {
end: {line: 1, column: 21}
}
}],
- range: [0, 24],
+ range: [1, 23],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 24}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 23}
}
},
right: {
@@ -6115,10 +6115,10 @@ test("(function* () { yield v })", {
rest: null,
generator: true,
expression: false,
- range: [0, 26],
+ range: [1, 25],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 26}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 25}
}
},
range: [0, 26],
@@ -6195,10 +6195,10 @@ test("(function* () { yield\nv })", {
rest: null,
generator: true,
expression: false,
- range: [0, 26],
+ range: [1, 25],
loc: {
- start: {line: 1, column: 0},
- end: {line: 2, column: 4}
+ start: {line: 1, column: 1},
+ end: {line: 2, column: 3}
}
},
range: [0, 26],
@@ -6264,10 +6264,10 @@ test("(function* () { yield *v })", {
rest: null,
generator: true,
expression: false,
- range: [0, 27],
+ range: [1, 26],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 27}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 26}
}
},
range: [0, 27],
@@ -6572,10 +6572,10 @@ test("(function* () { yield yield 10 })", {
rest: null,
generator: true,
expression: false,
- range: [0, 33],
+ range: [1, 32],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 33}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 32}
}
},
range: [0, 33],
@@ -8138,10 +8138,10 @@ test("\"use strict\"; (class A {constructor() { super() }})", {
end: {line: 1, column: 50}
}
},
- range: [14, 51],
+ range: [15, 50],
loc: {
- start: {line: 1, column: 14},
- end: {line: 1, column: 51}
+ start: {line: 1, column: 15},
+ end: {line: 1, column: 50}
}
},
range: [14, 51],
@@ -8482,10 +8482,10 @@ test("\"use strict\"; (class A { static constructor() { super() }})", {
end: {line: 1, column: 58}
}
},
- range: [14, 59],
+ range: [15, 58],
loc: {
- start: {line: 1, column: 14},
- end: {line: 1, column: 59}
+ start: {line: 1, column: 15},
+ end: {line: 1, column: 58}
}
},
range: [14, 59],
@@ -9437,10 +9437,10 @@ test("({[x]: 10})", {
end: {line: 1, column: 9}
}
}],
- range: [0, 11],
+ range: [1, 10],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 11}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 10}
}
},
range: [0, 11],
@@ -9517,10 +9517,10 @@ test("({[\"x\" + \"y\"]: 10})", {
end: {line: 1, column: 17}
}
}],
- range: [0, 19],
+ range: [1, 18],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 19}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 18}
}
},
range: [0, 19],
@@ -9590,10 +9590,10 @@ test("({[x]: function() {}})", {
end: {line: 1, column: 20}
}
}],
- range: [0, 22],
+ range: [1, 21],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 22}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 21}
}
},
range: [0, 22],
@@ -9683,10 +9683,10 @@ test("({[x]: 10, y: 20})", {
}
}
],
- range: [0, 18],
+ range: [1, 17],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 18}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 17}
}
},
range: [0, 18],
@@ -9810,10 +9810,10 @@ test("({get [x]() {}, set [x](v) {}})", {
}
}
],
- range: [0, 31],
+ range: [1, 30],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 31}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 30}
}
},
range: [0, 31],
@@ -9883,10 +9883,10 @@ test("({[x]() {}})", {
end: {line: 1, column: 10}
}
}],
- range: [0, 12],
+ range: [1, 11],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 12}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 11}
}
},
range: [0, 12],
@@ -10769,10 +10769,10 @@ test("({f: function({x} = {x: 10}) {}})", {
end: {line: 1, column: 31}
}
}],
- range: [0, 33],
+ range: [1, 32],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 33}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 32}
}
},
range: [0, 33],
@@ -10917,10 +10917,10 @@ test("({f({x} = {x: 10}) {}})", {
end: {line: 1, column: 21}
}
}],
- range: [0, 23],
+ range: [1, 22],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 23}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 22}
}
},
range: [0, 23],
@@ -11073,10 +11073,10 @@ test("(class {f({x} = {x: 10}) {}})", {
end: {line: 1, column: 28}
}
},
- range: [0, 29],
+ range: [1, 28],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 29}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 28}
}
},
range: [0, 29],
@@ -11192,10 +11192,10 @@ test("(({x} = {x: 10}) => {})", {
rest: null,
generator: false,
expression: false,
- range: [0, 23],
+ range: [1, 22],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 23}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 22}
}
},
range: [0, 23],
@@ -12267,10 +12267,10 @@ test("(function x([ a, b ]){})", {
rest: null,
generator: false,
expression: false,
- range: [0, 24],
+ range: [1, 23],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 24}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 23}
}
},
range: [0, 24],
@@ -12388,10 +12388,10 @@ test("(function x({ a, b }){})", {
rest: null,
generator: false,
expression: false,
- range: [0, 24],
+ range: [1, 23],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 24}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 23}
}
},
range: [0, 24],
@@ -12467,10 +12467,10 @@ test("(function x(...[ a, b ]){})", {
},
generator: false,
expression: false,
- range: [0, 27],
+ range: [1, 26],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 27}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 26}
}
},
range: [0, 27],
@@ -12704,10 +12704,10 @@ test("(function x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){})", {
},
generator: false,
expression: false,
- range: [0, 56],
+ range: [1, 55],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 56}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 55}
}
},
range: [0, 56],
@@ -12804,10 +12804,10 @@ test("({ x([ a, b ]){} })", {
end: {line: 1, column: 16}
}
}],
- range: [0, 19],
+ range: [1, 18],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 19}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 18}
}
},
range: [0, 19],
@@ -12904,10 +12904,10 @@ test("({ x(...[ a, b ]){} })", {
end: {line: 1, column: 19}
}
}],
- range: [0, 22],
+ range: [1, 21],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 22}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 21}
}
},
range: [0, 22],
@@ -13162,10 +13162,10 @@ test("({ x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){} })", {
end: {line: 1, column: 48}
}
}],
- range: [0, 51],
+ range: [1, 50],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 51}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 50}
}
},
range: [0, 51],
@@ -15086,10 +15086,10 @@ test("(function () { yield* 10 })", {
rest: null,
generator: false,
expression: false,
- range: [0, 27],
+ range: [1, 26],
loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 27}
+ start: {line: 1, column: 1},
+ end: {line: 1, column: 26}
}
},
range: [0, 27],
@@ -15388,4 +15388,4 @@ test('function normal(x, y = 10) {}', {
},
expression: false
}]
-}, {ecmaVersion: 6});
\ No newline at end of file
+}, {ecmaVersion: 6});
diff --git a/test/tests.js b/test/tests.js
index c39aa3c..5a86572 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -2,9 +2,8 @@
// (http://esprima.org/test/)
if (typeof exports != "undefined") {
- var test = require("./driver.js").test;
- var testFail = require("./driver.js").testFail;
- var testAssert = require("./driver.js").testAssert;
+ var driver = require("./driver.js");
+ var test = driver.test, testFail = driver.testFail, testAssert = driver.testAssert, misMatch = driver.misMatch;
var acorn = require("..");
}
@@ -177,11 +176,11 @@ test("(1 + 2 ) * 3", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 8
+ column: 6
}
}
},
@@ -8202,11 +8201,11 @@ test("( new foo).bar()", {
loc: {
start: {
line: 1,
- column: 0
+ column: 2
},
end: {
line: 1,
- column: 10
+ column: 9
}
}
},
@@ -8371,11 +8370,11 @@ test("( foo )()", {
loc: {
start: {
line: 1,
- column: 0
+ column: 5
},
end: {
line: 1,
- column: 11
+ column: 8
}
}
},
@@ -17217,11 +17216,11 @@ test("if (morning) (function(){})", {
loc: {
start: {
line: 1,
- column: 13
+ column: 14
},
end: {
line: 1,
- column: 27
+ column: 26
}
}
},
@@ -20508,11 +20507,11 @@ test("(function(){ return })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 22
+ column: 21
}
}
},
@@ -20581,11 +20580,11 @@ test("(function(){ return; })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 23
+ column: 22
}
}
},
@@ -20667,11 +20666,11 @@ test("(function(){ return x; })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 25
+ column: 24
}
}
},
@@ -20781,11 +20780,11 @@ test("(function(){ return x * y })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 28
+ column: 27
}
}
},
@@ -23194,11 +23193,11 @@ test("(function test(t, t) { })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 25
+ column: 24
}
}
},
@@ -24412,11 +24411,11 @@ test("(function(){})", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 1,
- column: 14
+ column: 13
}
}
},
@@ -25522,11 +25521,11 @@ test("(function(){ return\nx; })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 2,
- column: 5
+ column: 4
}
}
},
@@ -25622,11 +25621,11 @@ test("(function(){ return // Comment\nx; })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 2,
- column: 5
+ column: 4
}
}
},
@@ -25722,11 +25721,11 @@ test("(function(){ return/* Multiline\nComment */x; })", {
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 2,
- column: 15
+ column: 14
}
}
},
@@ -26026,8 +26025,6 @@ test("", {
test("foo: if (true) break foo;", {
type: "Program",
- start: 0,
- end: 25,
loc: {
start: {
line: 1,
@@ -26041,8 +26038,6 @@ test("foo: if (true) break foo;", {
body: [
{
type: "LabeledStatement",
- start: 0,
- end: 25,
loc: {
start: {
line: 1,
@@ -26055,8 +26050,6 @@ test("foo: if (true) break foo;", {
},
body: {
type: "IfStatement",
- start: 5,
- end: 25,
loc: {
start: {
line: 1,
@@ -26069,8 +26062,6 @@ test("foo: if (true) break foo;", {
},
test: {
type: "Literal",
- start: 9,
- end: 13,
loc: {
start: {
line: 1,
@@ -26085,8 +26076,6 @@ test("foo: if (true) break foo;", {
},
consequent: {
type: "BreakStatement",
- start: 15,
- end: 25,
loc: {
start: {
line: 1,
@@ -26099,8 +26088,6 @@ test("foo: if (true) break foo;", {
},
label: {
type: "Identifier",
- start: 21,
- end: 24,
loc: {
start: {
line: 1,
@@ -26118,8 +26105,6 @@ test("foo: if (true) break foo;", {
},
label: {
type: "Identifier",
- start: 0,
- end: 3,
loc: {
start: {
line: 1,
@@ -26138,8 +26123,6 @@ test("foo: if (true) break foo;", {
test("(function () {\n 'use strict';\n '\0';\n}())", {
type: "Program",
- start: 0,
- end: 40,
loc: {
start: {
line: 1,
@@ -26153,8 +26136,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 40,
loc: {
start: {
line: 1,
@@ -26167,21 +26148,18 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
},
expression: {
type: "CallExpression",
- start: 0,
loc: {
start: {
line: 1,
- column: 0
+ column: 1
},
end: {
line: 4,
- column: 4
+ column: 3
}
},
callee: {
type: "FunctionExpression",
- start: 1,
- end: 37,
loc: {
start: {
line: 1,
@@ -26196,8 +26174,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
params: [],
body: {
type: "BlockStatement",
- start: 13,
- end: 37,
loc: {
start: {
line: 1,
@@ -26211,8 +26187,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
body: [
{
type: "ExpressionStatement",
- start: 16,
- end: 29,
loc: {
start: {
line: 2,
@@ -26225,8 +26199,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
},
expression: {
type: "Literal",
- start: 16,
- end: 28,
loc: {
start: {
line: 2,
@@ -26242,8 +26214,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
},
{
type: "ExpressionStatement",
- start: 31,
- end: 35,
loc: {
start: {
line: 3,
@@ -26256,8 +26226,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
},
expression: {
type: "Literal",
- start: 31,
- end: 34,
loc: {
start: {
line: 3,
@@ -26275,7 +26243,6 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
}
},
arguments: [],
- end: 40
}
}
]
@@ -26283,43 +26250,29 @@ test("(function () {\n 'use strict';\n '\0';\n}())", {
test("123..toString(10)", {
type: "Program",
- start: 0,
- end: 17,
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 17,
expression: {
type: "CallExpression",
- start: 0,
callee: {
type: "MemberExpression",
- start: 0,
object: {
type: "Literal",
- start: 0,
- end: 4,
value: 123
},
property: {
type: "Identifier",
- start: 5,
- end: 13,
name: "toString"
},
computed: false,
- end: 13
},
arguments: [
{
type: "Literal",
- start: 14,
- end: 16,
value: 10
}
],
- end: 17
}
}
]
@@ -26327,30 +26280,20 @@ test("123..toString(10)", {
test("123.+2", {
type: "Program",
- start: 0,
- end: 6,
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 6,
expression: {
type: "BinaryExpression",
- start: 0,
left: {
type: "Literal",
- start: 0,
- end: 4,
value: 123
},
operator: "+",
right: {
type: "Literal",
- start: 5,
- end: 6,
value: 2
},
- end: 6
}
}
]
@@ -26358,28 +26301,18 @@ test("123.+2", {
test("a\u2028b", {
type: "Program",
- start: 0,
- end: 3,
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 1,
expression: {
type: "Identifier",
- start: 0,
- end: 1,
name: "a"
}
},
{
type: "ExpressionStatement",
- start: 2,
- end: 3,
expression: {
type: "Identifier",
- start: 2,
- end: 3,
name: "b"
}
}
@@ -26437,28 +26370,18 @@ test("foo: 10; foo: 20;", {
test("if(1)/ foo/", {
type: "Program",
- start: 0,
- end: 12,
body: [
{
type: "IfStatement",
- start: 0,
- end: 12,
test: {
type: "Literal",
- start: 3,
- end: 4,
value: 1,
raw: "1"
},
consequent: {
type: "ExpressionStatement",
- start: 5,
- end: 12,
expression: {
type: "Literal",
- start: 5,
- end: 12,
raw: "/ foo/"
}
},
@@ -26475,8 +26398,6 @@ test("price_9̶9̶_89", {
expression: {
type: "Identifier",
name: "price_9̶9̶_89",
- start: 0,
- end: 13
}
}
]
@@ -26486,8 +26407,6 @@ test("price_9̶9̶_89", {
test("var a = 1;", {
type: "Program",
- start: 0,
- end: 10,
loc: {
start: {
line: 1,
@@ -26502,8 +26421,6 @@ test("var a = 1;", {
body: [
{
type: "VariableDeclaration",
- start: 0,
- end: 10,
loc: {
start: {
line: 1,
@@ -26518,8 +26435,6 @@ test("var a = 1;", {
declarations: [
{
type: "VariableDeclarator",
- start: 4,
- end: 9,
loc: {
start: {
line: 1,
@@ -26533,8 +26448,6 @@ test("var a = 1;", {
},
id: {
type: "Identifier",
- start: 4,
- end: 5,
loc: {
start: {
line: 1,
@@ -26550,8 +26463,6 @@ test("var a = 1;", {
},
init: {
type: "Literal",
- start: 8,
- end: 9,
loc: {
start: {
line: 1,
@@ -26624,28 +26535,18 @@ test("{}/=/", {
test("foo <!--bar\n+baz", {
type: "Program",
- start: 0,
- end: 16,
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 16,
expression: {
type: "BinaryExpression",
- start: 0,
- end: 16,
left: {
type: "Identifier",
- start: 0,
- end: 3,
name: "foo"
},
operator: "+",
right: {
type: "Identifier",
- start: 13,
- end: 16,
name: "baz"
}
}
@@ -26795,7 +26696,7 @@ testFail("func() = 4",
"Assigning to rvalue (1:0)");
testFail("(1 + 1) = 10",
- "Assigning to rvalue (1:0)");
+ "Assigning to rvalue (1:1)");
testFail("1++",
"Assigning to rvalue (1:0)");
@@ -26810,7 +26711,7 @@ testFail("--1",
"Assigning to rvalue (1:2)");
testFail("for((1 + 1) in list) process(x);",
- "Assigning to rvalue (1:4)");
+ "Assigning to rvalue (1:5)");
testFail("[",
"Unexpected token (1:1)");
@@ -27309,8 +27210,6 @@ testFail("for(let x = 0;;);", "Unexpected token (1:8)");
test("let++", {
type: "Program",
- start: 0,
- end: 5,
loc: {
start: {
line: 1,
@@ -27324,8 +27223,6 @@ test("let++", {
body: [
{
type: "ExpressionStatement",
- start: 0,
- end: 5,
loc: {
start: {
line: 1,
@@ -27338,8 +27235,6 @@ test("let++", {
},
expression: {
type: "UpdateExpression",
- start: 0,
- end: 5,
loc: {
start: {
line: 1,
@@ -27354,8 +27249,6 @@ test("let++", {
prefix: false,
argument: {
type: "Identifier",
- start: 0,
- end: 3,
loc: {
start: {
line: 1,
@@ -28704,8 +28597,6 @@ test("<!--\n;", {
{
type: tokTypes._var,
value: "var",
- start: 0,
- end: 3,
loc: {
start: {line: 1, column: 0},
end: {line: 1, column: 3}
@@ -28714,8 +28605,6 @@ test("<!--\n;", {
{
type: tokTypes.name,
value: "x",
- start: 4,
- end: 5,
loc: {
start: {line: 1, column: 4},
end: {line: 1, column: 5}
@@ -28724,8 +28613,6 @@ test("<!--\n;", {
{
type: tokTypes.eq,
value: "=",
- start: 6,
- end: 7,
loc: {
start: {line: 1, column: 6},
end: {line: 1, column: 7}
@@ -28734,8 +28621,6 @@ test("<!--\n;", {
{
type: tokTypes.parenL,
value: undefined,
- start: 8,
- end: 9,
loc: {
start: {line: 1, column: 8},
end: {line: 1, column: 9}
@@ -28744,8 +28629,6 @@ test("<!--\n;", {
{
type: tokTypes.num,
value: 1,
- start: 9,
- end: 10,
loc: {
start: {line: 1, column: 9},
end: {line: 1, column: 10}
@@ -28754,8 +28637,6 @@ test("<!--\n;", {
{
type: {binop: 9, prefix: true, beforeExpr: true},
value: "+",
- start: 11,
- end: 12,
loc: {
start: {line: 1, column: 11},
end: {line: 1, column: 12}
@@ -28764,8 +28645,6 @@ test("<!--\n;", {
{
type: tokTypes.num,
value: 2,
- start: 13,
- end: 14,
loc: {
start: {line: 1, column: 13},
end: {line: 1, column: 14}
@@ -28774,8 +28653,6 @@ test("<!--\n;", {
{
type: tokTypes.parenR,
value: undefined,
- start: 14,
- end: 15,
loc: {
start: {line: 1, column: 14},
end: {line: 1, column: 15}
@@ -28784,8 +28661,6 @@ test("<!--\n;", {
{
type: tokTypes.eof,
value: undefined,
- start: 15,
- end: 15,
loc: {
start: {line: 1, column: 15},
end: {line: 1, column: 15}
@@ -28794,17 +28669,11 @@ test("<!--\n;", {
];
testAssert('var x = (1 + 2)', function assert(ast) {
if (actualTokens.length !== expectedTokens.length) {
- return JSON.stringify(actualTokens) + " !== " + JSON.stringify(expectedTokens);
+ return "Bad token stream length: expected " + expectedTokens.length + ", got " + actualTokens.length;
} else {
for (var i=0, n=actualTokens.length; i < n; i++) {
- var actualToken = JSON.stringify(
- actualTokens[i],
- // just remove this when startLoc/endLoc support is dropped
- function (key, value) { if (key !== 'startLoc' && key !== 'endLoc') return value; }
- );
- var expectedToken = JSON.stringify(expectedTokens[i]);
- if (actualToken !== expectedToken)
- return actualToken + ' !== ' + expectedToken;
+ var mis = misMatch(expectedTokens[i], actualTokens[i]);
+ if (mis) return mis;
}
}
}, {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list