Skip to content

Commit

Permalink
refactor(fe): rename type_alias_scope -> type_scope
Browse files Browse the repository at this point in the history
In a future commit I want to put a scope around all type references,
not just type aliases. Let us reuse the existing
visit_enter_type_alias_scope and visit_exit_type_alias_scope by
renaming them.
  • Loading branch information
strager committed Dec 22, 2023
1 parent 52ecbec commit 2260942
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 141 deletions.
8 changes: 4 additions & 4 deletions src/quick-lint-js/fe/buffering-visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void Buffering_Visitor::copy_into(Parse_Visitor_Base &target) const {
target.visit_enter_namespace_scope();
break;
case Visit_Kind::enter_type_alias_scope:
target.visit_enter_type_alias_scope();
target.visit_enter_type_scope();
break;
case Visit_Kind::exit_block_scope:
target.visit_exit_block_scope();
Expand Down Expand Up @@ -113,7 +113,7 @@ void Buffering_Visitor::copy_into(Parse_Visitor_Base &target) const {
target.visit_exit_namespace_scope();
break;
case Visit_Kind::exit_type_alias_scope:
target.visit_exit_type_alias_scope();
target.visit_exit_type_scope();
break;
case Visit_Kind::keyword_variable_use:
target.visit_keyword_variable_use(v.name);
Expand Down Expand Up @@ -231,7 +231,7 @@ void Buffering_Visitor::visit_enter_namespace_scope() {
this->add(Visit_Kind::enter_namespace_scope);
}

void Buffering_Visitor::visit_enter_type_alias_scope() {
void Buffering_Visitor::visit_enter_type_scope() {
this->add(Visit_Kind::enter_type_alias_scope);
}

Expand Down Expand Up @@ -287,7 +287,7 @@ void Buffering_Visitor::visit_exit_namespace_scope() {
this->add(Visit_Kind::exit_namespace_scope);
}

void Buffering_Visitor::visit_exit_type_alias_scope() {
void Buffering_Visitor::visit_exit_type_scope() {
this->add(Visit_Kind::exit_type_alias_scope);
}

Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/buffering-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Buffering_Visitor final : public Parse_Visitor_Base {
void visit_enter_index_signature_scope() override;
void visit_enter_interface_scope() override;
void visit_enter_namespace_scope() override;
void visit_enter_type_alias_scope() override;
void visit_enter_type_scope() override;
void visit_enter_named_function_scope(Identifier name) override;
void visit_exit_block_scope() override;
void visit_exit_with_scope() override;
Expand All @@ -63,7 +63,7 @@ class Buffering_Visitor final : public Parse_Visitor_Base {
void visit_exit_function_scope() override;
void visit_exit_index_signature_scope() override;
void visit_exit_namespace_scope() override;
void visit_exit_type_alias_scope() override;
void visit_exit_type_scope() override;
void visit_exit_interface_scope() override;
void visit_keyword_variable_use(Identifier name) override;
void visit_property_declaration(
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/debug-parse-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Debug_Parse_Visitor final : public Parse_Visitor_Base {
this->output_->flush();
}

void visit_enter_type_alias_scope() override {
void visit_enter_type_scope() override {
this->output_->append_copy(u8"entered type alias scope\n"_sv);
this->output_->flush();
}
Expand Down Expand Up @@ -174,7 +174,7 @@ class Debug_Parse_Visitor final : public Parse_Visitor_Base {
this->output_->flush();
}

void visit_exit_type_alias_scope() override {
void visit_exit_type_scope() override {
this->output_->append_copy(u8"exited type alias scope\n"_sv);
this->output_->flush();
}
Expand Down
12 changes: 6 additions & 6 deletions src/quick-lint-js/fe/multi-parse-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class Multi_Parse_Visitor final : public Parse_Visitor_Base {
this->visitor_2_->visit_enter_namespace_scope();
}

void visit_enter_type_alias_scope() override {
this->visitor_1_->visit_enter_type_alias_scope();
this->visitor_2_->visit_enter_type_alias_scope();
void visit_enter_type_scope() override {
this->visitor_1_->visit_enter_type_scope();
this->visitor_2_->visit_enter_type_scope();
}

void visit_exit_block_scope() override {
Expand Down Expand Up @@ -168,9 +168,9 @@ class Multi_Parse_Visitor final : public Parse_Visitor_Base {
this->visitor_2_->visit_exit_namespace_scope();
}

void visit_exit_type_alias_scope() override {
this->visitor_1_->visit_exit_type_alias_scope();
this->visitor_2_->visit_exit_type_alias_scope();
void visit_exit_type_scope() override {
this->visitor_1_->visit_exit_type_scope();
this->visitor_2_->visit_exit_type_scope();
}

void visit_keyword_variable_use(Identifier name) override {
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/null-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Null_Visitor final : public Parse_Visitor_Base {
void visit_enter_interface_scope() override {}
void visit_enter_named_function_scope(Identifier) override {}
void visit_enter_namespace_scope() override {}
void visit_enter_type_alias_scope() override {}
void visit_enter_type_scope() override {}
void visit_exit_block_scope() override {}
void visit_exit_with_scope() override {}
void visit_exit_class_construct_scope() override {}
Expand All @@ -42,7 +42,7 @@ class Null_Visitor final : public Parse_Visitor_Base {
void visit_exit_index_signature_scope() override {}
void visit_exit_interface_scope() override {}
void visit_exit_namespace_scope() override {}
void visit_exit_type_alias_scope() override {}
void visit_exit_type_scope() override {}
void visit_keyword_variable_use(Identifier) override {}
void visit_property_declaration(const std::optional<Identifier>&) override {}
void visit_variable_assignment(Identifier) override {}
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,7 +3390,7 @@ void Parser::parse_and_visit_typescript_type_alias(
v.visit_variable_declaration(name, kind, Variable_Declaration_Flags::none);
this->skip();

v.visit_enter_type_alias_scope();
v.visit_enter_type_scope();
if (this->peek().type == Token_Type::less) {
this->parse_and_visit_typescript_generic_parameters(v);
}
Expand All @@ -3403,7 +3403,7 @@ void Parser::parse_and_visit_typescript_type_alias(
.name = name,
.kind = kind,
}});
v.visit_exit_type_alias_scope();
v.visit_exit_type_scope();

this->consume_semicolon_after_statement();
}
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/parse-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Parse_Visitor_Base {
virtual void visit_enter_interface_scope() = 0;
virtual void visit_enter_named_function_scope(Identifier) = 0;
virtual void visit_enter_namespace_scope() = 0;
virtual void visit_enter_type_alias_scope() = 0;
virtual void visit_enter_type_scope() = 0;
virtual void visit_exit_block_scope() = 0;
virtual void visit_exit_with_scope() = 0;
virtual void visit_exit_class_construct_scope() = 0;
Expand All @@ -52,7 +52,7 @@ class Parse_Visitor_Base {
virtual void visit_exit_index_signature_scope() = 0;
virtual void visit_exit_interface_scope() = 0;
virtual void visit_exit_namespace_scope() = 0;
virtual void visit_exit_type_alias_scope() = 0;
virtual void visit_exit_type_scope() = 0;
virtual void visit_keyword_variable_use(Identifier name) = 0;
virtual void visit_property_declaration(
const std::optional<Identifier> &) = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/variable-analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void Variable_Analyzer::visit_enter_named_function_scope(

void Variable_Analyzer::visit_enter_namespace_scope() { this->scopes_.push(); }

void Variable_Analyzer::visit_enter_type_alias_scope() { this->scopes_.push(); }
void Variable_Analyzer::visit_enter_type_scope() { this->scopes_.push(); }

void Variable_Analyzer::visit_exit_block_scope() {
QLJS_ASSERT(!this->scopes_.empty());
Expand Down Expand Up @@ -281,7 +281,7 @@ void Variable_Analyzer::visit_exit_namespace_scope() {
this->scopes_.pop();
}

void Variable_Analyzer::visit_exit_type_alias_scope() {
void Variable_Analyzer::visit_exit_type_scope() {
QLJS_ASSERT(!this->scopes_.empty());
this->propagate_variable_uses_to_parent_scope(
/*allow_variable_use_before_declaration=*/false,
Expand Down
4 changes: 2 additions & 2 deletions src/quick-lint-js/fe/variable-analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Variable_Analyzer final : public Parse_Visitor_Base {
void visit_enter_interface_scope() override;
void visit_enter_named_function_scope(Identifier) override;
void visit_enter_namespace_scope() override;
void visit_enter_type_alias_scope() override;
void visit_enter_type_scope() override;
void visit_exit_block_scope() override;
void visit_exit_with_scope() override;
void visit_exit_class_construct_scope() override;
Expand All @@ -83,7 +83,7 @@ class Variable_Analyzer final : public Parse_Visitor_Base {
void visit_exit_index_signature_scope() override;
void visit_exit_interface_scope() override;
void visit_exit_namespace_scope() override;
void visit_exit_type_alias_scope() override;
void visit_exit_type_scope() override;
void visit_keyword_variable_use(Identifier name) override;
void visit_property_declaration(const std::optional<Identifier> &) override;
void visit_variable_declaration(Identifier name, Variable_Kind kind,
Expand Down
8 changes: 4 additions & 4 deletions test/quick-lint-js/spy-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ struct Parse_Visit_Collector : public Parse_Visitor_Base {
this->visits.emplace_back("visit_enter_namespace_scope");
}

void visit_enter_type_alias_scope() override {
this->visits.emplace_back("visit_enter_type_alias_scope");
void visit_enter_type_scope() override {
this->visits.emplace_back("visit_enter_type_scope");
}

std::vector<String8> enter_named_function_scopes;
Expand Down Expand Up @@ -364,8 +364,8 @@ struct Parse_Visit_Collector : public Parse_Visitor_Base {
this->visits.emplace_back("visit_exit_namespace_scope");
}

void visit_exit_type_alias_scope() override {
this->visits.emplace_back("visit_exit_type_alias_scope");
void visit_exit_type_scope() override {
this->visits.emplace_back("visit_exit_type_scope");
}

void visit_keyword_variable_use(Identifier name) override {
Expand Down
58 changes: 29 additions & 29 deletions test/test-parse-typescript-declare-namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ TEST_F(Test_Parse_TypeScript_Declare_Namespace,
u8"Diag_Declare_Keyword_Is_Not_Allowed_Inside_Declare_Namespace"_diag, //
typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_alias_scope", //
"visit_variable_type_use", // U
"visit_exit_type_alias_scope", //
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_scope", //
"visit_variable_type_use", // U
"visit_exit_type_scope", //
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
}));
}

Expand Down Expand Up @@ -408,16 +408,16 @@ TEST_F(Test_Parse_TypeScript_Declare_Namespace,
test_parse_and_visit_module(u8"declare namespace ns { type T = U; }"_sv,
no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_alias_scope", // {
"visit_variable_type_use", // U
"visit_exit_type_alias_scope", // }
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
"visit_end_of_module", //
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_scope", // {
"visit_variable_type_use", // U
"visit_exit_type_scope", // }
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
"visit_end_of_module", //
}));
}

Expand All @@ -426,16 +426,16 @@ TEST_F(Test_Parse_TypeScript_Declare_Namespace,
u8"declare namespace ns { export type T = U; }"_sv, no_diags,
typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_alias_scope", // {
"visit_variable_type_use", // U
"visit_exit_type_alias_scope", // }
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
"visit_end_of_module", //
"visit_enter_declare_scope", //
"visit_enter_namespace_scope", // {
"visit_variable_declaration", // T
"visit_enter_type_scope", // {
"visit_variable_type_use", // U
"visit_exit_type_scope", // }
"visit_exit_namespace_scope", // }
"visit_variable_declaration", // ns
"visit_exit_declare_scope", //
"visit_end_of_module", //
}));
}
}
Expand Down
20 changes: 10 additions & 10 deletions test/test-parse-typescript-declare-type-alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ TEST_F(Test_Parse_TypeScript_Declare_Type_Alias, declare_type_acts_like_type) {
Spy_Visitor p = test_parse_and_visit_statement(
u8"declare type MyType = OtherType;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_variable_declaration", // MyType
"visit_enter_type_alias_scope", //
"visit_variable_type_use", // OtherType
"visit_exit_type_alias_scope", //
"visit_variable_declaration", // MyType
"visit_enter_type_scope", //
"visit_variable_type_use", // OtherType
"visit_exit_type_scope", //
}));
EXPECT_THAT(p.variable_uses, ElementsAreArray({u8"OtherType"_sv}));
EXPECT_THAT(p.variable_declarations,
Expand All @@ -51,12 +51,12 @@ TEST_F(Test_Parse_TypeScript_Declare_Type_Alias,
Spy_Visitor p = test_parse_and_visit_module(
u8"declare\ntype MyType = OtherType;"_sv, no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_variable_use", // declare
"visit_variable_declaration", // MyType
"visit_enter_type_alias_scope", //
"visit_variable_type_use", // OtherType
"visit_exit_type_alias_scope", //
"visit_end_of_module", //
"visit_variable_use", // declare
"visit_variable_declaration", // MyType
"visit_enter_type_scope", //
"visit_variable_type_use", // OtherType
"visit_exit_type_scope", //
"visit_end_of_module", //
}));
EXPECT_THAT(p.variable_uses,
ElementsAreArray({u8"declare"_sv, u8"OtherType"_sv}));
Expand Down
14 changes: 7 additions & 7 deletions test/test-parse-typescript-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,10 @@ TEST_F(Test_Parse_TypeScript_Module, export_type_alias) {
Spy_Visitor p = test_parse_and_visit_module(u8"export type T = C;"_sv,
no_diags, typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_variable_declaration", // T
"visit_enter_type_alias_scope", //
"visit_variable_type_use", // C
"visit_exit_type_alias_scope", //
"visit_variable_declaration", // T
"visit_enter_type_scope", //
"visit_variable_type_use", // C
"visit_exit_type_scope", //
"visit_end_of_module",
}));
EXPECT_THAT(p.variable_declarations,
Expand All @@ -693,9 +693,9 @@ TEST_F(Test_Parse_TypeScript_Module,
u8" ^^^^ Diag_Newline_Not_Allowed_After_Type_Keyword"_diag, //
typescript_options);
EXPECT_THAT(p.visits, ElementsAreArray({
"visit_variable_declaration", // A
"visit_enter_type_alias_scope", //
"visit_exit_type_alias_scope", //
"visit_variable_declaration", // A
"visit_enter_type_scope", //
"visit_exit_type_scope", //
"visit_end_of_module",
}));
}
Expand Down
Loading

0 comments on commit 2260942

Please sign in to comment.