Skip to content

Commit

Permalink
Don't emit "duplicate label" error across function scopes. (#1671)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevkontakte committed Oct 13, 2021
1 parent acb229e commit bc0a14a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8784,6 +8784,10 @@ func (p *parser) visitAndAppendStmt(stmts []js_ast.Stmt, stmt js_ast.Stmt) []js_
fmt.Sprintf("The original label %q is here", name))})
break
}
if scope.Kind == js_ast.ScopeFunctionBody {
// Labels are only visible within the function they are defined in.
break
}
}

p.currentScope.Label = js_ast.LocRef{Loc: s.Name.Loc, Ref: ref}
Expand Down
1 change: 1 addition & 0 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,7 @@ func TestLabels(t *testing.T) {
expectPrinted(t, "x: y: z: 1", "x:\n y:\n z:\n 1;\n")
expectPrinted(t, "x: 1; y: 2; x: 3", "x:\n 1;\ny:\n 2;\nx:\n 3;\n")
expectParseError(t, "x: y: x: 1", "<stdin>: error: Duplicate label \"x\"\n<stdin>: note: The original label \"x\" is here\n")
expectPrinted(t, "x: (function(){ x: 1; })()", "x:\n (function() {\n x:\n 1;\n })();\n")
}

func TestArrow(t *testing.T) {
Expand Down

0 comments on commit bc0a14a

Please sign in to comment.