[Pkg-javascript-commits] [node-acorn-jsx] 22/484: Handle break-to-labeled-non-loop
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:19:59 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 0820a593a665fcd91e8e21648744d996cf904a3c
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Oct 3 10:25:53 2012 +0200
Handle break-to-labeled-non-loop
Closes #1
---
acorn.js | 6 ++--
index.html | 6 ++--
test/tests.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 4 deletions(-)
diff --git a/acorn.js b/acorn.js
index afd5b9f..b390cd7 100644
--- a/acorn.js
+++ b/acorn.js
@@ -970,8 +970,10 @@
// continue to.
for (var i = 0; i < labels.length; ++i) {
var lab = labels[i];
- if ((node.label == null || lab.name === node.label.name) &&
- lab.kind != null && (isBreak || lab.kind === "loop")) break;
+ if (node.label == null || lab.name === node.label.name) {
+ if (lab.kind != null && (isBreak || lab.kind === "loop")) break;
+ if (node.label && isBreak) break;
+ }
}
if (i === labels.length) raise(node.start, "Unsyntactic " + starttype.keyword);
return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement");
diff --git a/index.html b/index.html
index 5af8df0..132399d 100644
--- a/index.html
+++ b/index.html
@@ -660,8 +660,10 @@ complexity.</p> </td> <td class="code"> <d
<span class="p">}</span></pre></div> </td> </tr> <tr id="section-89"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-89">¶</a> </div> <p>Verify that there is an actual destination to break or
continue to.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o"><</span> <span class="nx">labels</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="o">++</span><span class [...]
<span class="kd">var</span> <span class="nx">lab</span> <span class="o">=</span> <span class="nx">labels</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
- <span class="k">if</span> <span class="p">((</span><span class="nx">node</span><span class="p">.</span><span class="nx">label</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">lab</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">node</span><span class="p">.</span><span class="nx">label</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span [...]
- <span class="nx">lab</span><span class="p">.</span><span class="nx">kind</span> <span class="o">!=</span> <span class="kc">null</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">isBreak</span> <span class="o">||</span> <span class="nx">lab</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"loop"</span><span class="p">))</span> <span class="k">break</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">label</span> <span class="o">==</span> <span class="kc">null</span> <span class="o">||</span> <span class="nx">lab</span><span class="p">.</span><span class="nx">name</span> <span class="o">===</span> <span class="nx">node</span><span class="p">.</span><span class="nx">label</span><span class="p">.</span><span class="nx">name</span><span class="p">)</span> <span [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">lab</span><span class="p">.</span><span class="nx">kind</span> <span class="o">!=</span> <span class="kc">null</span> <span class="o">&&</span> <span class="p">(</span><span class="nx">isBreak</span> <span class="o">||</span> <span class="nx">lab</span><span class="p">.</span><span class="nx">kind</span> <span class="o">===</span> <span class="s2">"loop"</span><span class="p">))</span> <span cl [...]
+ <span class="k">if</span> <span class="p">(</span><span class="nx">node</span><span class="p">.</span><span class="nx">label</span> <span class="o">&&</span> <span class="nx">isBreak</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="nx">i</span> <span class="o">===</span> <span class="nx">labels</span><span class="p">.</span><span class="nx">length</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">"Unsyntactic "</span> <span class="o">+</span> <span class="nx">starttype</span><span cl [...]
<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="nx">isBreak</span> <span class="o">?</span> <span class="s2">"BreakStatement"</span> <span class="o">:</span> <span class="s2">"ContinueStatement"</span><span class="p">);</span>
diff --git a/test/tests.js b/test/tests.js
index 83ff7ec..4dbbe7f 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -25724,6 +25724,118 @@ test("", {
}
});
+test("foo: if (true) break foo;", {
+ type: "Program",
+ start: 0,
+ end: 25,
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 25
+ }
+ },
+ body: [
+ {
+ type: "LabeledStatement",
+ start: 0,
+ end: 25,
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 25
+ }
+ },
+ body: {
+ type: "IfStatement",
+ start: 5,
+ end: 25,
+ loc: {
+ start: {
+ line: 1,
+ column: 5
+ },
+ end: {
+ line: 1,
+ column: 25
+ }
+ },
+ test: {
+ type: "Literal",
+ start: 9,
+ end: 13,
+ loc: {
+ start: {
+ line: 1,
+ column: 9
+ },
+ end: {
+ line: 1,
+ column: 13
+ }
+ },
+ value: true
+ },
+ consequent: {
+ type: "BreakStatement",
+ start: 15,
+ end: 25,
+ loc: {
+ start: {
+ line: 1,
+ column: 15
+ },
+ end: {
+ line: 1,
+ column: 25
+ }
+ },
+ label: {
+ type: "Identifier",
+ start: 21,
+ end: 24,
+ loc: {
+ start: {
+ line: 1,
+ column: 21
+ },
+ end: {
+ line: 1,
+ column: 24
+ }
+ },
+ name: "foo"
+ }
+ },
+ alternate: null
+ },
+ label: {
+ type: "Identifier",
+ start: 0,
+ end: 3,
+ loc: {
+ start: {
+ line: 1,
+ column: 0
+ },
+ end: {
+ line: 1,
+ column: 3
+ }
+ },
+ name: "foo"
+ }
+ }
+ ]
+});
+
// Failure tests
testFail("{",
--
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