diff --git a/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp b/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp index f6d5cd16e1ecb64fefd3bf3f01e6f8c70f368e50..be2725055709191875f1c72fd089e862f29cfcff 100644 --- a/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp +++ b/es2panda/compiler/function/asyncGeneratorFunctionBuilder.cpp @@ -80,11 +80,9 @@ void AsyncGeneratorFunctionBuilder::ExplicitReturn(const ir::AstNode *node) cons VReg resumeValue = pg_->AllocReg(); VReg canSuspend = pg_->AllocReg(); - pg_->StoreAccumulator(node, resumeValue); - pg_->GeneratorComplete(node, funcObj_); - pg_->LoadAccumulator(node, resumeValue); pg_->AsyncFunctionAwait(node, funcObj_); SuspendResumeExecution(node, resumeType, resumeValue); + pg_->GeneratorComplete(node, funcObj_); pg_->StoreConst(node, canSuspend, Constant::JS_TRUE); pg_->AsyncGeneratorResolve(node, funcObj_, resumeValue, canSuspend); pg_->EmitReturn(node); diff --git a/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js new file mode 100644 index 0000000000000000000000000000000000000000..065a555890c6ca2931977c8af596c910f798082b --- /dev/null +++ b/es2panda/test/compiler/js/async-generator/async-generator-explicit-return.js @@ -0,0 +1,23 @@ +/* + * 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. + */ + +async function *f() { + return 0; +} + +const g = f(); +g.next(); +g.next(); +print(1);