[ruby/prism] Fix eval parsing depth

https://github.com/ruby/prism/commit/89bf7a4948
This commit is contained in:
Kevin Newton 2023-12-15 10:07:55 -05:00 коммит произвёл git
Родитель fe9b42f024
Коммит f38814564b
2 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -17185,9 +17185,14 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
static pm_node_t *
parse_program(pm_parser_t *parser) {
pm_parser_scope_push(parser, !parser->current_scope);
parser_lex(parser);
// If the current scope is NULL, then we want to push a new top level scope.
// The current scope could exist in the event that we are parsing an eval
// and the user has passed into scopes that already exist.
if (parser->current_scope == NULL) {
pm_parser_scope_push(parser, true);
}
parser_lex(parser);
pm_statements_node_t *statements = parse_statements(parser, PM_CONTEXT_MAIN);
if (!statements) {
statements = pm_statements_node_create(parser);

Просмотреть файл

@ -42,7 +42,9 @@ module Prism
assert_kind_of Prism::CallNode, Prism.parse("foo").value.statements.body[0]
assert_kind_of Prism::LocalVariableReadNode, Prism.parse("foo", scopes: [[:foo]]).value.statements.body[0]
assert_equal 2, Prism.parse("foo", scopes: [[:foo], []]).value.statements.body[0].depth
assert_equal 1, Prism.parse("foo", scopes: [[:foo], []]).value.statements.body[0].depth
assert_equal [:foo], Prism.parse("foo", scopes: [[:foo]]).value.locals
end
def test_literal_value_method