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("{",