[Pkg-javascript-commits] [node-acorn-jsx] 53/484: Assign parenthesized expressions a range that includes the parens
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:04 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 905124c291ec8b41b3511abad618e6989bf9daab
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Sun Nov 18 21:17:49 2012 +0100
Assign parenthesized expressions a range that includes the parens
This way, composite expressions that they are part of won't get bogus
unsyntactic substrings as their range (i.e. in '(1)+1', the binop expression
would span '1)+1').
Closes #14
---
acorn.js | 9 ++++++++
index.html | 9 ++++++++
test/tests.js | 72 +++++++++++++++++++++++++++++------------------------------
3 files changed, 54 insertions(+), 36 deletions(-)
diff --git a/acorn.js b/acorn.js
index 81abc2d..deac5bc 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1433,8 +1433,17 @@
return finishNode(node, "Literal");
case _parenL:
+ var tokStartLoc1 = tokStartLoc, tokStart1 = tokStart;
next();
var val = parseExpression();
+ val.start = tokStart1;
+ val.end = tokEnd;
+ if (options.locations) {
+ val.loc.start = tokStartLoc1;
+ val.loc.end = tokEndLoc;
+ }
+ if (options.ranges)
+ val.range = [tokStart1, tokEnd];
expect(_parenR);
return val;
diff --git a/index.html b/index.html
index 0336051..14bbb86 100644
--- a/index.html
+++ b/index.html
@@ -1045,8 +1045,17 @@ or <code>{}</code>.</p> </td> <td class="code">
<span class="k">return</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">node</span><span class="p">,</span> <span class="s2">"Literal"</span><span class="p">);</span>
<span class="k">case</span> <span class="nx">_parenL</span><span class="o">:</span>
+ <span class="kd">var</span> <span class="nx">tokStartLoc1</span> <span class="o">=</span> <span class="nx">tokStartLoc</span><span class="p">,</span> <span class="nx">tokStart1</span> <span class="o">=</span> <span class="nx">tokStart</span><span class="p">;</span>
<span class="nx">next</span><span class="p">();</span>
<span class="kd">var</span> <span class="nx">val</span> <span class="o">=</span> <span class="nx">parseExpression</span><span class="p">();</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStart1</span><span class="p">;</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">tokEnd</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">loc</span><span class="p">.</span><span class="nx">start</span> <span class="o">=</span> <span class="nx">tokStartLoc1</span><span class="p">;</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">loc</span><span class="p">.</span><span class="nx">end</span> <span class="o">=</span> <span class="nx">tokEndLoc</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">ranges</span><span class="p">)</span>
+ <span class="nx">val</span><span class="p">.</span><span class="nx">range</span> <span class="o">=</span> <span class="p">[</span><span class="nx">tokStart1</span><span class="p">,</span> <span class="nx">tokEnd</span><span class="p">];</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="k">return</span> <span class="nx">val</span><span class="p">;</span>
diff --git a/test/tests.js b/test/tests.js
index 464a7f9..f7b169b 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -175,11 +175,11 @@ test("(1 + 2 ) * 3", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 6
+ column: 8
}
}
},
@@ -201,7 +201,7 @@ test("(1 + 2 ) * 3", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
@@ -8175,11 +8175,11 @@ test("( new foo).bar()", {
loc: {
start: {
line: 1,
- column: 2
+ column: 0
},
end: {
line: 1,
- column: 9
+ column: 10
}
}
},
@@ -8201,7 +8201,7 @@ test("( new foo).bar()", {
loc: {
start: {
line: 1,
- column: 2
+ column: 0
},
end: {
line: 1,
@@ -8213,7 +8213,7 @@ test("( new foo).bar()", {
loc: {
start: {
line: 1,
- column: 2
+ column: 0
},
end: {
line: 1,
@@ -8344,11 +8344,11 @@ test("( foo )()", {
loc: {
start: {
line: 1,
- column: 5
+ column: 0
},
end: {
line: 1,
- column: 8
+ column: 11
}
}
},
@@ -8356,7 +8356,7 @@ test("( foo )()", {
loc: {
start: {
line: 1,
- column: 5
+ column: 0
},
end: {
line: 1,
@@ -17190,11 +17190,11 @@ test("if (morning) (function(){})", {
loc: {
start: {
line: 1,
- column: 14
+ column: 13
},
end: {
line: 1,
- column: 26
+ column: 27
}
}
},
@@ -20481,11 +20481,11 @@ test("(function(){ return })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 21
+ column: 22
}
}
},
@@ -20554,11 +20554,11 @@ test("(function(){ return; })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 22
+ column: 23
}
}
},
@@ -20640,11 +20640,11 @@ test("(function(){ return x; })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 24
+ column: 25
}
}
},
@@ -20754,11 +20754,11 @@ test("(function(){ return x * y })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 27
+ column: 28
}
}
},
@@ -23193,11 +23193,11 @@ test("(function test(t, t) { })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 24
+ column: 25
}
}
},
@@ -24099,11 +24099,11 @@ test("(function(){})", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 13
+ column: 14
}
}
},
@@ -25209,11 +25209,11 @@ test("(function(){ return\nx; })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 2,
- column: 4
+ column: 5
}
}
},
@@ -25309,11 +25309,11 @@ test("(function(){ return // Comment\nx; })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 2,
- column: 4
+ column: 5
}
}
},
@@ -25409,11 +25409,11 @@ test("(function(){ return/* Multiline\nComment */x; })", {
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 2,
- column: 14
+ column: 15
}
}
},
@@ -25854,15 +25854,15 @@ test("(function () { 'use strict'; '\0'; }())", {
},
expression: {
type: "CallExpression",
- start: 1,
+ start: 0,
loc: {
start: {
line: 1,
- column: 1
+ column: 0
},
end: {
line: 1,
- column: 37
+ column: 38
}
},
callee: {
@@ -25962,7 +25962,7 @@ test("(function () { 'use strict'; '\0'; }())", {
}
},
arguments: [],
- end: 37
+ end: 38
}
}
]
@@ -26120,7 +26120,7 @@ testFail("func() = 4",
"Assigning to rvalue (1:0)");
testFail("(1 + 1) = 10",
- "Assigning to rvalue (1:1)");
+ "Assigning to rvalue (1:0)");
testFail("1++",
"Assigning to rvalue (1:0)");
@@ -26135,7 +26135,7 @@ testFail("--1",
"Assigning to rvalue (1:2)");
testFail("for((1 + 1) in list) process(x);",
- "Assigning to rvalue (1:5)");
+ "Assigning to rvalue (1:4)");
testFail("[",
"Unexpected token (1:1)");
--
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