[Pkg-javascript-commits] [node-acorn-jsx] 113/484: Use a single .handler property on TryStatements
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:12 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 62bc3641afc125276605fb7f5ea0f1f07457d9c5
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Tue Apr 2 09:30:35 2013 +0200
Use a single .handler property on TryStatements
As the wiki page for the spec currently seems to prescribe.
---
acorn.js | 8 ++++----
acorn_loose.js | 8 ++++----
index.html | 8 ++++----
test/tests.js | 27 +++++++++++++--------------
util/walk.js | 11 +++++------
5 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/acorn.js b/acorn.js
index 0500d20..510cc45 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1235,8 +1235,8 @@
case _try:
next();
node.block = parseBlock();
- node.handlers = [];
- while (tokType === _catch) {
+ node.handler = null;
+ if (tokType === _catch) {
var clause = startNode();
next();
expect(_parenL);
@@ -1246,10 +1246,10 @@
expect(_parenR);
clause.guard = null;
clause.body = parseBlock();
- node.handlers.push(finishNode(clause, "CatchClause"));
+ node.handler = finishNode(clause, "CatchClause");
}
node.finalizer = eat(_finally) ? parseBlock() : null;
- if (!node.handlers.length && !node.finalizer)
+ if (!node.handler && !node.finalizer)
raise(node.start, "Missing catch or finally clause");
return finishNode(node, "TryStatement");
diff --git a/acorn_loose.js b/acorn_loose.js
index 114e0c9..e91bad3 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -377,8 +377,8 @@
case tt.try:
next();
node.block = parseBlock();
- node.handlers = [];
- while (token.type === tt.catch) {
+ node.handler = null;
+ if (token.type === tt.catch) {
var clause = startNode();
next();
expect(tt.parenL);
@@ -386,10 +386,10 @@
expect(tt.parenR);
clause.guard = null;
clause.body = parseBlock();
- node.handlers.push(finishNode(clause, "CatchClause"));
+ node.handler = finishNode(clause, "CatchClause");
}
node.finalizer = eat(tt.finally) ? parseBlock() : null;
- if (!node.handlers.length && !node.finalizer) return node.block;
+ if (!node.handler && !node.finalizer) return node.block;
return finishNode(node, "TryStatement");
case tt.var:
diff --git a/index.html b/index.html
index 76826c3..ade82c8 100644
--- a/index.html
+++ b/index.html
@@ -901,8 +901,8 @@ adding statements to.</p> </td> <td class="code">
<span class="k">case</span> <span class="nx">_try</span><span class="o">:</span>
<span class="nx">next</span><span class="p">();</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">block</span> <span class="o">=</span> <span class="nx">parseBlock</span><span class="p">();</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">handlers</span> <span class="o">=</span> <span class="p">[];</span>
- <span class="k">while</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_catch</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">handler</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_catch</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">clause</span> <span class="o">=</span> <span class="nx">startNode</span><span class="p">();</span>
<span class="nx">next</span><span class="p">();</span>
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenL</span><span class="p">);</span>
@@ -912,10 +912,10 @@ adding statements to.</p> </td> <td class="code">
<span class="nx">expect</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
<span class="nx">clause</span><span class="p">.</span><span class="nx">guard</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
<span class="nx">clause</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseBlock</span><span class="p">();</span>
- <span class="nx">node</span><span class="p">.</span><span class="nx">handlers</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">finishNode</span><span class="p">(</span><span class="nx">clause</span><span class="p">,</span> <span class="s2">"CatchClause"</span><span class="p">));</span>
+ <span class="nx">node</span><span class="p">.</span><span class="nx">handler</span> <span class="o">=</span> <span class="nx">finishNode</span><span class="p">(</span><span class="nx">clause</span><span class="p">,</span> <span class="s2">"CatchClause"</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">node</span><span class="p">.</span><span class="nx">finalizer</span> <span class="o">=</span> <span class="nx">eat</span><span class="p">(</span><span class="nx">_finally</span><span class="p">)</span> <span class="o">?</span> <span class="nx">parseBlock</span><span class="p">()</span> <span class="o">:</span> <span class="kc">null</span><span class="p">;</span>
- <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">node</span><span class="p">.</span><span class="nx">handlers</span><span class="p">.</span><span class="nx">length</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">node</span><span class="p">.</span><span class="nx">finalizer</span><span class="p">)</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">node</span><span class="p">.</span><span class="nx">handler</span> <span class="o">&&</span> <span class="o">!</span><span class="nx">node</span><span class="p">.</span><span class="nx">finalizer</span><span class="p">)</span>
<span class="nx">raise</span><span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Missing catch or finally clause"</span><span class="p">);</span>
<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">"TryStatement"</span><span class="p">);</span>
diff --git a/test/tests.js b/test/tests.js
index 4bc8754..da467f1 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -21819,8 +21819,7 @@ test("try { } catch (e) { }", {
}
}
},
- handlers: [
- {
+ handler: {
type: "CatchClause",
param: {
type: "Identifier",
@@ -21862,7 +21861,7 @@ test("try { } catch (e) { }", {
}
}
}
- ],
+ ,
finalizer: null,
loc: {
start: {
@@ -21907,7 +21906,7 @@ test("try { } catch (eval) { }", {
}
}
},
- handlers: [
+ handler:
{
type: "CatchClause",
param: {
@@ -21950,7 +21949,7 @@ test("try { } catch (eval) { }", {
}
}
}
- ],
+ ,
finalizer: null,
loc: {
start: {
@@ -21995,7 +21994,7 @@ test("try { } catch (arguments) { }", {
}
}
},
- handlers: [
+ handler:
{
type: "CatchClause",
param: {
@@ -22038,7 +22037,7 @@ test("try { } catch (arguments) { }", {
}
}
}
- ],
+ ,
finalizer: null,
loc: {
start: {
@@ -22083,7 +22082,7 @@ test("try { } catch (e) { say(e) }", {
}
}
},
- handlers: [
+ handler:
{
type: "CatchClause",
param: {
@@ -22183,7 +22182,7 @@ test("try { } catch (e) { say(e) }", {
}
}
}
- ],
+ ,
finalizer: null,
loc: {
start: {
@@ -22228,7 +22227,7 @@ test("try { } finally { cleanup(stuff) }", {
}
}
},
- handlers: [],
+ handler: null,
finalizer: {
type: "BlockStatement",
body: [
@@ -22385,7 +22384,7 @@ test("try { doThat(); } catch (e) { say(e) }", {
}
}
},
- handlers: [
+ handler:
{
type: "CatchClause",
param: {
@@ -22485,7 +22484,7 @@ test("try { doThat(); } catch (e) { say(e) }", {
}
}
}
- ],
+ ,
finalizer: null,
loc: {
start: {
@@ -22572,7 +22571,7 @@ test("try { doThat(); } catch (e) { say(e) } finally { cleanup(stuff) }", {
}
}
},
- handlers: [
+ handler:
{
type: "CatchClause",
param: {
@@ -22672,7 +22671,7 @@ test("try { doThat(); } catch (e) { say(e) } finally { cleanup(stuff) }", {
}
}
}
- ],
+ ,
finalizer: {
type: "BlockStatement",
body: [
diff --git a/util/walk.js b/util/walk.js
index 054c289..ea7eea1 100644
--- a/util/walk.js
+++ b/util/walk.js
@@ -188,8 +188,7 @@
};
base.TryStatement = function(node, st, c) {
c(node.block, st, "Statement");
- for (var i = 0; i < node.handlers.length; ++i)
- c(node.handlers[i].body, st, "ScopeBody");
+ if (node.handler) c(node.handler.body, st, "ScopeBody");
if (node.finalizer) c(node.finalizer, st, "Statement");
};
base.WhileStatement = function(node, st, c) {
@@ -290,10 +289,10 @@
},
TryStatement: function(node, scope, c) {
c(node.block, scope, "Statement");
- for (var i = 0; i < node.handlers.length; ++i) {
- var handler = node.handlers[i], inner = makeScope(scope);
- inner.vars[handler.param.name] = {type: "catch clause", node: handler.param};
- c(handler.body, inner, "ScopeBody");
+ if (node.handler) {
+ var inner = makeScope(scope);
+ inner.vars[node.handler.param.name] = {type: "catch clause", node: node.handler.param};
+ c(node.handler.body, inner, "ScopeBody");
}
if (node.finalizer) c(node.finalizer, scope, "Statement");
},
--
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