diff --git a/packages/babylon/acorn.js b/packages/babylon/acorn.js index afd5b9fedb4e..b390cd7aa028 100644 --- a/packages/babylon/acorn.js +++ b/packages/babylon/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/packages/babylon/index.html b/packages/babylon/index.html index 5af8df0c75cb..132399d79352 100644 --- a/packages/babylon/index.html +++ b/packages/babylon/index.html @@ -660,8 +660,10 @@ }

Verify that there is an actual destination to break or 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/packages/babylon/test/tests.js b/packages/babylon/test/tests.js
index 83ff7ec82363..4dbbe7fd73c8 100644
--- a/packages/babylon/test/tests.js
+++ b/packages/babylon/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("{",