From d36c70bbbfd2198c42c8ab8f6b22416e920b1b8b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 22 Nov 2012 10:11:00 +0100 Subject: [PATCH] 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 732c42c92c..80f0d99f96 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 aae57ab37e..dbf10f30c1 100644 --- a/index.html +++ b/index.html @@ -902,6 +902,7 @@ Identifier node, we switch to interpreting it as a label.

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/test/tests.js b/test/tests.js index ac69bb6381..5bd87c2be8 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("{",