@@ -22190,6 +22190,10 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
22190
22190
static pm_statements_node_t *
22191
22191
wrap_statements(pm_parser_t *parser, pm_statements_node_t *statements) {
22192
22192
if (PM_PARSER_COMMAND_LINE_OPTION_P(parser)) {
22193
+ if (statements == NULL) {
22194
+ statements = pm_statements_node_create(parser);
22195
+ }
22196
+
22193
22197
pm_arguments_node_t *arguments = pm_arguments_node_create(parser);
22194
22198
pm_arguments_node_arguments_append(
22195
22199
arguments,
@@ -22205,6 +22209,10 @@ wrap_statements(pm_parser_t *parser, pm_statements_node_t *statements) {
22205
22209
22206
22210
if (PM_PARSER_COMMAND_LINE_OPTION_N(parser)) {
22207
22211
if (PM_PARSER_COMMAND_LINE_OPTION_A(parser)) {
22212
+ if (statements == NULL) {
22213
+ statements = pm_statements_node_create(parser);
22214
+ }
22215
+
22208
22216
pm_arguments_node_t *arguments = pm_arguments_node_create(parser);
22209
22217
pm_arguments_node_arguments_append(
22210
22218
arguments,
@@ -22273,9 +22281,7 @@ parse_program(pm_parser_t *parser) {
22273
22281
parser_lex(parser);
22274
22282
pm_statements_node_t *statements = parse_statements(parser, PM_CONTEXT_MAIN, 0);
22275
22283
22276
- if (statements == NULL) {
22277
- statements = pm_statements_node_create(parser);
22278
- } else if (!parser->parsing_eval) {
22284
+ if (statements != NULL && !parser->parsing_eval) {
22279
22285
// If we have statements, then the top-level statement should be
22280
22286
// explicitly checked as well. We have to do this here because
22281
22287
// everywhere else we check all but the last statement.
@@ -22287,13 +22293,6 @@ parse_program(pm_parser_t *parser) {
22287
22293
pm_locals_order(parser, &parser->current_scope->locals, &locals, true);
22288
22294
pm_parser_scope_pop(parser);
22289
22295
22290
- // If this is an empty file, then we're still going to parse all of the
22291
- // statements in order to gather up all of the comments and such. Here we'll
22292
- // correct the location information.
22293
- if (pm_statements_node_body_length(statements) == 0) {
22294
- pm_statements_node_location_set(statements, parser->start, parser->start);
22295
- }
22296
-
22297
22296
// At the top level, see if we need to wrap the statements in a program
22298
22297
// node with a while loop based on the options.
22299
22298
if (parser->command_line & (PM_OPTIONS_COMMAND_LINE_P | PM_OPTIONS_COMMAND_LINE_N)) {
@@ -22303,6 +22302,14 @@ parse_program(pm_parser_t *parser) {
22303
22302
pm_node_list_free(¤t_block_exits);
22304
22303
}
22305
22304
22305
+ // If this is an empty file, then we're still going to parse all of the
22306
+ // statements in order to gather up all of the comments and such. Here we'll
22307
+ // correct the location information.
22308
+ if (statements == NULL) {
22309
+ statements = pm_statements_node_create(parser);
22310
+ pm_statements_node_location_set(statements, parser->start, parser->start);
22311
+ }
22312
+
22306
22313
return (pm_node_t *) pm_program_node_create(parser, &locals, statements);
22307
22314
}
22308
22315
0 commit comments