Lines Matching defs:scope
20 #include "binder/scope.h"
105 * Add variable declare like 'var ##var_1;' to nearest statements in namespace function or top level scope
106 * Record the variable name and scope in tempVarDeclStatements_ and will push the VariableDeclaration nodes
149 auto *scope = it.second;
150 if (scope == nullptr) {
154 } else if (scope->IsFunctionScope() || scope->IsTSModuleScope()) {
155 auto *body = scope->Node()->AsScriptFunction()->Body();
157 auto scopeCtx = binder::LexicalScope<binder::Scope>::Enter(Binder(), scope);
216 auto scope = FindEnumMemberScope(name);
217 if (scope) {
218 return CreateMemberExpressionFromIdentifier(scope, ident);
222 auto scope = FindExportVariableInTsModuleScope(name);
223 if (scope) {
224 return CreateMemberExpressionFromIdentifier(scope, ident);
526 auto *scope = Scope();
527 while (scope != nullptr) {
528 auto *v = scope->FindLocal(name, binder::ResolveBindingOptions::BINDINGS);
539 scope = scope->Parent();
918 auto *scope = Binder()->Allocator()->New<binder::FunctionScope>(Allocator(), paramScope);
919 CHECK_NOT_NULL(scope);
920 paramScope->BindFunctionScope(scope);
921 auto *body = AllocNode<ir::BlockStatement>(scope, std::move(statements));
922 auto *func = AllocNode<ir::ScriptFunction>(scope, std::move(params), nullptr, body, nullptr,
924 scope->BindNode(func);
925 scope->BindParamScope(paramScope);
1664 bool Transformer::IsInstantiatedImportEquals(const ir::TSImportEqualsDeclaration *node, binder::Scope *scope) const
1670 auto *var = FindTSModuleVariable(node->ModuleReference(), scope, &isType);
1681 const binder::Scope *scope,
1689 auto *var = FindTSModuleVariable(tsQualifiedName->Left(), scope, isType);
1717 auto *currentScope = scope;
1754 binder::Variable *Transformer::FindTSVariable(const binder::Scope *scope, const util::StringView &name) const
1756 binder::Variable *res = scope->FindLocalTSVariable<type>(name);
1757 if (res == nullptr && scope->IsTSModuleScope()) {
1758 res = scope->AsTSModuleScope()->FindExportTSVariable<type>(name);
1905 auto scope = node->AsTSModuleDeclaration()->Scope();
1906 if (scope && !scope->HasVariableName(name)) {
1911 auto scope = node->AsTSEnumDeclaration()->Scope();
1912 if (scope && !scope->HasDeclarationName(name)) {
2242 bool Transformer::IsStringInitForEnumMember(const ir::Expression *expr, binder::Scope *scope) const
2258 ASSERT(scope && scope->IsTSEnumScope());
2259 binder::Variable *v = scope->AsTSEnumScope()->FindEnumMemberVariable(identName);
2265 if (IsStringInitForEnumMember(initExpr, scope)) {
2277 return IsStringForMemberExpression(expr->AsMemberExpression(), scope);
2283 IsStringInitForEnumMember(right, scope) && IsStringInitForEnumMember(left, scope)) {
2295 bool Transformer::IsStringForMemberExpression(const ir::MemberExpression *memberExpr, binder::Scope *scope) const
2316 ArenaVector<binder::Variable *> findRes = FindFrontIdentifierTSVariables(members.front()->AsIdentifier(), scope);
2328 binder::Scope *scope) const
2333 while (scope != nullptr) {
2335 if (scope->IsTSEnumScope()) {
2336 v = scope->AsTSEnumScope()->FindEnumMemberVariable(name);
2346 FindLocalTSVariables(scope, name, types, findRes);
2348 if (scope->IsTSModuleScope()) {
2349 FindExportTSVariables(scope, name, types, findRes);
2357 v = scope->FindLocal(name);
2359 if (scope->IsTSModuleScope() || scope->IsTSEnumScope()) { // v may be converted from ts variable
2360 v = scope->Parent()->FindLocal(name);
2368 if (scope->IsTSModuleScope()) {
2369 v = scope->AsTSModuleScope()->FindExportVariable(name);
2375 if (scope->IsTSModuleScope() || scope->IsTSEnumScope()) {
2376 scope = scope->Parent();
2378 scope = scope->Parent();
2398 void Transformer::FindLocalTSVariables(binder::Scope *scope, const util::StringView name,
2406 v = scope->FindLocalTSVariable<binder::TSBindingType::NAMESPACE>(name);
2413 v = scope->FindLocalTSVariable<binder::TSBindingType::ENUMLITERAL>(name);
2417 v = scope->FindLocalTSVariable<binder::TSBindingType::IMPORT_EQUALS>(name);
2420 Parent()->AsTSImportEqualsDeclaration(), scope)) {
2434 void Transformer::FindExportTSVariables(binder::Scope *scope, const util::StringView name,
2442 v = scope->AsTSModuleScope()->FindExportTSVariable<binder::TSBindingType::NAMESPACE>(name);
2449 v = scope->AsTSModuleScope()->FindExportTSVariable<binder::TSBindingType::ENUMLITERAL>(name);
2453 v = scope->AsTSModuleScope()->FindExportTSVariable<binder::TSBindingType::IMPORT_EQUALS>(name);
2456 Parent()->AsTSImportEqualsDeclaration(), scope)) {
2487 auto *scope = enumMemberVar->AsEnumVariable()->Declaration()->
2490 if (IsStringInitForEnumMember(initExpr, scope)) {
2586 auto scope = Scope();
2587 while (scope != nullptr) {
2588 if (scope->InLocalTSBindings(name)) {
2591 if (scope->IsTSModuleScope() && scope->AsTSModuleScope()->InExportBindings(name)) {
2594 if (scope->IsTSEnumScope() && scope->AsTSEnumScope()->FindEnumMemberVariable(name)) {
2595 return scope;
2597 if (scope->FindLocal(name)) {
2601 if (scope->IsTSModuleScope() || scope->IsTSEnumScope()) {
2602 scope = scope->Parent();
2604 scope = scope->Parent();
2610 ir::MemberExpression *Transformer::CreateMemberExpressionFromIdentifier(binder::Scope *scope, ir::Identifier *node)
2613 auto moduleName = scope->IsTSEnumScope() ? FindTSEnumNameByScope(scope) : FindTSModuleNameByScope(scope);
2669 auto scope = childNode->AsScriptFunction()->Scope();
2670 ASSERT(scope != nullptr);
2671 scope->SetParent(parentScope);
2675 auto scope = childNode->AsCatchClause()->Scope();
2676 ASSERT(scope != nullptr);
2677 scope->SetParent(parentScope);
2681 auto scope = childNode->AsClassDefinition()->Scope();
2682 ASSERT(scope != nullptr);
2683 scope->SetParent(parentScope);
2687 auto scope = childNode->AsBlockStatement()->Scope();
2688 ASSERT(scope != nullptr);
2689 scope->SetParent(parentScope);
2693 auto scope = childNode->AsDoWhileStatement()->Scope();
2694 ASSERT(scope != nullptr);
2695 scope->SetParent(parentScope);
2699 auto scope = childNode->AsWhileStatement()->Scope();
2700 ASSERT(scope != nullptr);
2701 scope->SetParent(parentScope);
2705 auto scope = childNode->AsForInStatement()->Scope();
2706 ASSERT(scope != nullptr);
2707 scope->SetParent(parentScope);
2711 auto scope = childNode->AsForOfStatement()->Scope();
2712 ASSERT(scope != nullptr);
2713 scope->SetParent(parentScope);
2717 auto scope = childNode->AsForUpdateStatement()->Scope();
2718 ASSERT(scope != nullptr);
2719 scope->SetParent(parentScope);
2723 auto scope = childNode->AsSwitchStatement()->Scope();
2724 ASSERT(scope != nullptr);
2725 scope->SetParent(parentScope);
2729 auto scope = childNode->AsTSEnumDeclaration()->Scope();
2730 ASSERT(scope != nullptr);
2731 scope->SetParent(parentScope);
2735 auto scope = childNode->AsTSInterfaceDeclaration()->Scope();
2736 ASSERT(scope != nullptr);
2737 scope->SetParent(parentScope);
2741 auto scope = childNode->AsTSMethodSignature()->Scope();
2742 ASSERT(scope != nullptr);
2743 scope->SetParent(parentScope);
2747 auto scope = childNode->AsTSModuleDeclaration()->Scope();
2748 ASSERT(scope != nullptr);
2749 scope->SetParent(parentScope);
2753 auto scope = childNode->AsTSSignatureDeclaration()->Scope();
2754 ASSERT(scope != nullptr);
2755 scope->SetParent(parentScope);
2759 auto scope = childNode->AsTSTypeParameterDeclaration()->Scope();
2760 ASSERT(scope != nullptr);
2761 scope->SetParent(parentScope);
2765 auto scope = childNode->AsTSConstructorType()->Scope();
2766 ASSERT(scope != nullptr);
2767 scope->SetParent(parentScope);
2771 auto scope = childNode->AsTSFunctionType()->Scope();
2772 ASSERT(scope != nullptr);
2773 scope->SetParent(parentScope);
2785 auto scope = Scope();
2786 ASSERT(scope != nullptr);
2790 if (scope->FindLocal(name, binder::ResolveBindingOptions::BINDINGS) != nullptr ||
2791 scope->FindLocalTSVariable<binder::TSBindingType::ENUMLITERAL>(name) != nullptr) {
2797 var = scope->FindLocalTSVariable<binder::TSBindingType::NAMESPACE>(name);
2803 var = scope->FindLocalTSVariable<binder::TSBindingType::IMPORT_EQUALS>(name);
2806 return IsInstantiatedImportEquals(node, scope);