Skip to content

Commit 479e835

Browse files
committed
Mark locations in the tree where newlines can occur
1 parent 25d9699 commit 479e835

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/yarp.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ yp_if_node_create(yp_parser_t *parser,
22022202

22032203
*node = (yp_if_node_t) {
22042204
{
2205-
.type = YP_NODE_IF_NODE,
2205+
.type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE,
22062206
.location = {
22072207
.start = if_keyword->start,
22082208
.end = end
@@ -2228,7 +2228,7 @@ yp_if_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const yp_t
22282228

22292229
*node = (yp_if_node_t) {
22302230
{
2231-
.type = YP_NODE_IF_NODE,
2231+
.type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE,
22322232
.location = {
22332233
.start = statement->location.start,
22342234
.end = predicate->location.end
@@ -2260,7 +2260,7 @@ yp_if_node_ternary_create(yp_parser_t *parser, yp_node_t *predicate, yp_node_t *
22602260

22612261
*node = (yp_if_node_t) {
22622262
{
2263-
.type = YP_NODE_IF_NODE,
2263+
.type = YP_NODE_IF_NODE | YP_NODE_FLAG_NEWLINE,
22642264
.location = {
22652265
.start = predicate->location.start,
22662266
.end = false_expression->location.end,
@@ -3683,6 +3683,9 @@ yp_statements_node_body_append(yp_statements_node_t *node, yp_node_t *statement)
36833683

36843684
yp_node_list_append(&node->body, statement);
36853685
node->base.location.end = statement->location.end;
3686+
3687+
// Every statement gets marked as a place where a newline can occur.
3688+
statement->type |= YP_NODE_FLAG_NEWLINE;
36863689
}
36873690

36883691
// Allocate a new StringConcatNode node.
@@ -3940,7 +3943,7 @@ yp_unless_node_create(yp_parser_t *parser, const yp_token_t *keyword, yp_node_t
39403943

39413944
*node = (yp_unless_node_t) {
39423945
{
3943-
.type = YP_NODE_UNLESS_NODE,
3946+
.type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE,
39443947
.location = {
39453948
.start = keyword->start,
39463949
.end = end
@@ -3966,7 +3969,7 @@ yp_unless_node_modifier_create(yp_parser_t *parser, yp_node_t *statement, const
39663969

39673970
*node = (yp_unless_node_t) {
39683971
{
3969-
.type = YP_NODE_UNLESS_NODE,
3972+
.type = YP_NODE_UNLESS_NODE | YP_NODE_FLAG_NEWLINE,
39703973
.location = {
39713974
.start = statement->location.start,
39723975
.end = predicate->location.end

0 commit comments

Comments
 (0)