diff --git a/es2panda/ir/statements/switchStatement.cpp b/es2panda/ir/statements/switchStatement.cpp index 4e51aa02e440c54c0b8632d473dd1cb2a43735d8..38c5c90f260c4936c96ca54ebc823a764a8135f2 100644 --- a/es2panda/ir/statements/switchStatement.cpp +++ b/es2panda/ir/statements/switchStatement.cpp @@ -51,6 +51,10 @@ void SwitchStatement::Compile(compiler::PandaGen *pg) const compiler::LocalRegScope lrs(pg, scope_); uint32_t defaultIndex = 0; + if (cases_.size() == 0) { + return; + } + for (size_t i = 0; i < cases_.size(); i++) { const auto *clause = cases_[i]; diff --git a/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body-expected.txt b/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body.js b/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body.js new file mode 100644 index 0000000000000000000000000000000000000000..1dbfe669828aab3894c0af1a192fc6b8eeb330cf --- /dev/null +++ b/es2panda/test/compiler/js/switchStatement/switchStatement-empty-body.js @@ -0,0 +1,21 @@ +/* + * 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. + */ + +let i = 1; +switch (i) { + +} + +print(i); \ No newline at end of file