diff --git a/es2panda/compiler/core/dynamicContext.cpp b/es2panda/compiler/core/dynamicContext.cpp index b2cc4c26d6b318403443810631e8a7e2372d8060..7c6b06c61976c060010de9dd4c4bc66d1ac9b2bb 100644 --- a/es2panda/compiler/core/dynamicContext.cpp +++ b/es2panda/compiler/core/dynamicContext.cpp @@ -36,7 +36,8 @@ DynamicContext::~DynamicContext() LabelContext::LabelContext(PandaGen *pg, const ir::LabelledStatement *labelledStmt) : DynamicContext(pg, LabelTarget(labelledStmt->Ident()->Name())), labelledStmt_(labelledStmt) { - if (!labelledStmt->Body()->IsBlockStatement() && !labelledStmt->Body()->IsIfStatement()) { + if (!labelledStmt->Body()->IsBlockStatement() && !labelledStmt->Body()->IsIfStatement() && + !labelledStmt->Body()->IsBreakStatement()) { return; } diff --git a/es2panda/test/parser/ts/test_label_break-expected.txt b/es2panda/test/parser/ts/test_label_break-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..02db09a63585c8982fae0d1ebc16d1ddbc90a040 --- /dev/null +++ b/es2panda/test/parser/ts/test_label_break-expected.txt @@ -0,0 +1,69 @@ +{ + "type": "Program", + "statements": [ + { + "type": "LabelledStatement", + "label": { + "type": "Identifier", + "name": "target", + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 7 + } + } + }, + "body": { + "type": "BreakStatement", + "label": { + "type": "Identifier", + "name": "target", + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test_label_break.ts b/es2panda/test/parser/ts/test_label_break.ts new file mode 100644 index 0000000000000000000000000000000000000000..3dc81e0d2aa0907d980f2896ce81f9b68408727c --- /dev/null +++ b/es2panda/test/parser/ts/test_label_break.ts @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +target: + break target;