From 916599a731e09e719d6632ea2fc4e6dd36a09616 Mon Sep 17 00:00:00 2001 From: ElevenDuan Date: Thu, 11 Jan 2024 17:15:47 +0800 Subject: [PATCH] Fixed break label failed Signed-off-by: ElevenDuan Change-Id: If5623d87030d4ef1f19272d1ab0f89e605f006df --- es2panda/compiler/core/dynamicContext.cpp | 3 +- .../parser/ts/test_label_break-expected.txt | 69 +++++++++++++++++++ es2panda/test/parser/ts/test_label_break.ts | 17 +++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 es2panda/test/parser/ts/test_label_break-expected.txt create mode 100644 es2panda/test/parser/ts/test_label_break.ts diff --git a/es2panda/compiler/core/dynamicContext.cpp b/es2panda/compiler/core/dynamicContext.cpp index b2cc4c26d6..7c6b06c619 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 0000000000..02db09a635 --- /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 0000000000..3dc81e0d2a --- /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; -- Gitee