@@ -8115,6 +8115,26 @@ parse_starred_expression(yp_parser_t *parser, yp_binding_power_t binding_power,
8115
8115
return parse_expression(parser, binding_power, diag_id);
8116
8116
}
8117
8117
8118
+ // Convert the name of a method into the corresponding write method name. For
8119
+ // exmaple, foo would be turned into foo=.
8120
+ static void
8121
+ parse_write_name(yp_string_t *string) {
8122
+ // The method name needs to change. If we previously had
8123
+ // foo, we now need foo=. In this case we'll allocate a new
8124
+ // owned string, copy the previous method name in, and
8125
+ // append an =.
8126
+ size_t length = yp_string_length(string);
8127
+ uint8_t *name = calloc(length + 1, sizeof(uint8_t));
8128
+ if (name == NULL) return;
8129
+
8130
+ memcpy(name, yp_string_source(string), length);
8131
+ name[length] = '=';
8132
+
8133
+ // Now switch the name to the new string.
8134
+ yp_string_free(string);
8135
+ yp_string_owned_init(string, name, length + 1);
8136
+ }
8137
+
8118
8138
// Convert the given node into a valid target node.
8119
8139
static yp_node_t *
8120
8140
parse_target(yp_parser_t *parser, yp_node_t *target) {
@@ -8205,23 +8225,8 @@ parse_target(yp_parser_t *parser, yp_node_t *target) {
8205
8225
}
8206
8226
8207
8227
if (*call->message_loc.start == '_' || parser->encoding.alnum_char(call->message_loc.start, call->message_loc.end - call->message_loc.start)) {
8208
- // The method name needs to change. If we previously had
8209
- // foo, we now need foo=. In this case we'll allocate a new
8210
- // owned string, copy the previous method name in, and
8211
- // append an =.
8212
- size_t length = yp_string_length(&call->name);
8213
-
8214
- uint8_t *name = calloc(length + 1, sizeof(uint8_t));
8215
- if (name == NULL) return NULL;
8216
-
8217
- memcpy(name, yp_string_source(&call->name), length);
8218
- name[length] = '=';
8219
-
8220
- // Now switch the name to the new string.
8221
- yp_string_free(&call->name);
8222
- yp_string_owned_init(&call->name, name, length + 1);
8223
-
8224
- return target;
8228
+ parse_write_name(&call->name);
8229
+ return (yp_node_t *) call;
8225
8230
}
8226
8231
}
8227
8232
@@ -8359,25 +8364,12 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
8359
8364
// arguments node, parse the argument, and add it to the list.
8360
8365
yp_arguments_node_t *arguments = yp_arguments_node_create(parser);
8361
8366
call->arguments = arguments;
8362
- yp_arguments_node_arguments_append(arguments, value);
8363
- target->location.end = arguments->base.location.end;
8364
-
8365
- // The method name needs to change. If we previously had foo, we now
8366
- // need foo=. In this case we'll allocate a new owned string, copy
8367
- // the previous method name in, and append an =.
8368
- size_t length = yp_string_length(&call->name);
8369
-
8370
- uint8_t *name = calloc(length + 1, sizeof(uint8_t));
8371
- if (name == NULL) return NULL;
8372
8367
8373
- memcpy(name, yp_string_source(&call->name), length);
8374
- name[length] = '=';
8375
-
8376
- // Now switch the name to the new string.
8377
- yp_string_free(&call->name);
8378
- yp_string_owned_init(&call->name, name, length + 1);
8368
+ yp_arguments_node_arguments_append(arguments, value);
8369
+ call->base.location.end = arguments->base.location.end;
8379
8370
8380
- return target;
8371
+ parse_write_name(&call->name);
8372
+ return (yp_node_t *) call;
8381
8373
}
8382
8374
}
8383
8375
0 commit comments