diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index d2bc3419d4204e9dc01a91e78d572a9b703dbe6f..961499455e10bfc529be42dc73557416d51c3ab4 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -514,9 +514,10 @@ public: bool AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension) override; - void RemoveThisParam() + void RemoveThisParam(const std::string_view &thisParam) { params_.erase(params_.begin()); + bindings_.erase(thisParam); } friend class FunctionScope; diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index b610c74a5086febc1abb2a56aeab59a0d39524a1..b297306853b58271f212434ed06ab0794ad404f6 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -59,7 +59,8 @@ public: if (firstParam->IsIdentifier() && firstParam->AsIdentifier()->Name().Is(THIS_PARAM)) { thisParam_ = firstParam; params_.erase(params_.begin()); - scope_->ParamScope()->RemoveThisParam(); + scope_->ParamScope()->RemoveThisParam(THIS_PARAM); + scope_->Bindings().erase(THIS_PARAM); } } } diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fece8ea852b3f65ede3531dd3d9ac4c58e21cf3d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3-expected.txt @@ -0,0 +1,2 @@ +Test +20 diff --git a/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts new file mode 100644 index 0000000000000000000000000000000000000000..81311acd69a18d9f5e3fdecde671a81c7391d028 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/conformance/functions/test-ts-function-3.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + + +class Employee { + name : string + debug : (number) => void +} + +function dump(this : Employee, age : number) { + print(this.name) + print(age) +} + +let a : Employee = {name : "Test", debug : dump} +a.debug(20) +