[Pkg-javascript-commits] [node-acorn-jsx] 60/484: Add missing labels.pop() to allow re-using labels in a block

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:05 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 d36c70bbbfd2198c42c8ab8f6b22416e920b1b8b
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Thu Nov 22 10:11:00 2012 +0100

    Add missing labels.pop() to allow re-using labels in a block
    
    Issue #15
---
 acorn.js      |  1 +
 index.html    |  1 +
 test/tests.js | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/acorn.js b/acorn.js
index 732c42c..80f0d99 100644
--- a/acorn.js
+++ b/acorn.js
@@ -1233,6 +1233,7 @@
         var kind = tokType.isLoop ? "loop" : tokType === _switch ? "switch" : null;
         labels.push({name: maybeName, kind: kind});
         node.body = parseStatement();
+        labels.pop();
         node.label = expr;
         return finishNode(node, "LabeledStatement");
       } else {
diff --git a/index.html b/index.html
index aae57ab..dbf10f3 100644
--- a/index.html
+++ b/index.html
@@ -902,6 +902,7 @@ Identifier node, we switch to interpreting it as a label.</p>             </td>
         <span class="kd">var</span> <span class="nx">kind</span> <span class="o">=</span> <span class="nx">tokType</span><span class="p">.</span><span class="nx">isLoop</span> <span class="o">?</span> <span class="s2">"loop"</span> <span class="o">:</span> <span class="nx">tokType</span> <span class="o">===</span> <span class="nx">_switch</span> <span class="o">?</span> <span class="s2">"switch"</span> <span class="o">:</span> <span class="kc">null</span><span class=" [...]
         <span class="nx">labels</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span><span class="nx">name</span><span class="o">:</span> <span class="nx">maybeName</span><span class="p">,</span> <span class="nx">kind</span><span class="o">:</span> <span class="nx">kind</span><span class="p">});</span>
         <span class="nx">node</span><span class="p">.</span><span class="nx">body</span> <span class="o">=</span> <span class="nx">parseStatement</span><span class="p">();</span>
+        <span class="nx">labels</span><span class="p">.</span><span class="nx">pop</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">expr</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">"LabeledStatement"</span><span class="p">);</span>
       <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
diff --git a/test/tests.js b/test/tests.js
index ac69bb6..5bd87c2 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26029,6 +26029,42 @@ test("'a\\u0026b'", {
   ]
 });
 
+test("foo: 10; foo: 20;", {
+  type: "Program",
+  body: [
+    {
+      type: "LabeledStatement",
+      body: {
+        type: "ExpressionStatement",
+        expression: {
+          type: "Literal",
+          value: 10,
+          raw: "10"
+        }
+      },
+      label: {
+        type: "Identifier",
+        name: "foo"
+      }
+    },
+    {
+      type: "LabeledStatement",
+      body: {
+        type: "ExpressionStatement",
+        expression: {
+          type: "Literal",
+          value: 20,
+          raw: "20"
+        }
+      },
+      label: {
+        type: "Identifier",
+        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