Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants on classes and modules #1409

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ nodes:
- name: end_keyword_loc
type: location
- name: name
type: string
type: constant
- name: name_constant
type: constant
comment: |
Expand Down Expand Up @@ -1739,7 +1739,7 @@ nodes:
- name: end_keyword_loc
type: location
- name: name
type: string
type: constant
- name: name_constant
type: constant
comment: |
Expand Down
12 changes: 6 additions & 6 deletions src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,7 @@ yp_case_node_end_keyword_loc_set(yp_case_node_t *node, const yp_token_t *end_key
static yp_class_node_t *
yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *class_keyword, yp_node_t *constant_path, const yp_token_t *name, const yp_token_t *inheritance_operator, yp_node_t *superclass, yp_node_t *body, const yp_token_t *end_keyword) {
yp_class_node_t *node = YP_ALLOC_NODE(parser, yp_class_node_t);
yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name);

*node = (yp_class_node_t) {
{
Expand All @@ -1660,11 +1661,10 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y
.superclass = superclass,
.body = body,
.end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword),
.name = YP_EMPTY_STRING,
.name_constant = yp_parser_constant_id_token(parser, name)
.name = name_constant,
.name_constant = name_constant
};

yp_string_shared_init(&node->name, name->start, name->end);
return node;
}

Expand Down Expand Up @@ -3297,6 +3297,7 @@ yp_match_required_node_create(yp_parser_t *parser, yp_node_t *value, yp_node_t *
static yp_module_node_t *
yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const yp_token_t *module_keyword, yp_node_t *constant_path, const yp_token_t *name, yp_node_t *body, const yp_token_t *end_keyword) {
yp_module_node_t *node = YP_ALLOC_NODE(parser, yp_module_node_t);
yp_constant_id_t name_constant = yp_parser_constant_id_token(parser, name);

*node = (yp_module_node_t) {
{
Expand All @@ -3311,11 +3312,10 @@ yp_module_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const
.constant_path = constant_path,
.body = body,
.end_keyword_loc = YP_LOCATION_TOKEN_VALUE(end_keyword),
.name = YP_EMPTY_STRING,
.name_constant = yp_parser_constant_id_token(parser, name)
.name = name_constant,
.name_constant = name_constant
};

yp_string_shared_init(&node->name, name->start, name->end);
return node;
}

Expand Down
14 changes: 7 additions & 7 deletions test/yarp/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def test_module_name_recoverable
Location(),
ConstantReadNode(:Parent),
StatementsNode(
[ModuleNode([], Location(), MissingNode(), nil, Location(), "", :"")]
[ModuleNode([], Location(), MissingNode(), nil, Location(), :"", :"")]
),
Location(),
"Parent",
:Parent,
:Parent
)

Expand Down Expand Up @@ -394,7 +394,7 @@ def test_module_definition_in_method_body
Location(),
nil,
nil,
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), "A", :A)]),
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:A), nil, Location(), :A, :A)]),
[],
Location(),
nil,
Expand Down Expand Up @@ -425,7 +425,7 @@ def test_module_definition_in_method_body_within_block
BlockNode(
[],
nil,
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), "Foo", :Foo)]),
StatementsNode([ModuleNode([], Location(), ConstantReadNode(:Foo), nil, Location(), :Foo, :Foo)]),
Location(),
Location()
),
Expand Down Expand Up @@ -465,7 +465,7 @@ def test_class_definition_in_method_body
nil,
nil,
Location(),
"A",
:A,
:A
)]
),
Expand Down Expand Up @@ -981,7 +981,7 @@ def test_dont_allow_return_inside_class_body
nil,
StatementsNode([ReturnNode(Location(), nil)]),
Location(),
"A",
:A,
:A
)

Expand All @@ -997,7 +997,7 @@ def test_dont_allow_return_inside_module_body
ConstantReadNode(:A),
StatementsNode([ReturnNode(Location(), nil)]),
Location(),
"A",
:A,
:A
)

Expand Down
14 changes: 7 additions & 7 deletions test/yarp/snapshots/classes.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/yarp/snapshots/method_calls.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions test/yarp/snapshots/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions test/yarp/snapshots/seattlerb/TestRubyParserShared.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/yarp/snapshots/seattlerb/class_comments.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/yarp/snapshots/seattlerb/defn_oneliner_eq2.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/yarp/snapshots/seattlerb/defs_oneliner_eq2.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/yarp/snapshots/seattlerb/magic_encoding_comment.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/yarp/snapshots/seattlerb/module_comments.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.