Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,19 @@ static bool find_earliest_control_keyword_walker(const pm_node_t* node, void* da
case PM_CALL_NODE: {
pm_call_node_t* call = (pm_call_node_t*) node;

if (call->block != NULL) {
current_type = CONTROL_TYPE_BLOCK;
keyword_offset = (uint32_t) (node->location.start - context->source_start);
if (call->block != NULL && call->block->type == PM_BLOCK_NODE) {
pm_block_node_t* block_node = (pm_block_node_t*) call->block;
size_t opening_length = block_node->opening_loc.end - block_node->opening_loc.start;
bool has_do_opening =
opening_length == 2 && block_node->opening_loc.start[0] == 'd' && block_node->opening_loc.start[1] == 'o';
bool has_brace_opening = opening_length == 1 && block_node->opening_loc.start[0] == '{';
bool has_closing_location = block_node->closing_loc.start != NULL && block_node->closing_loc.end != NULL
&& (block_node->closing_loc.end - block_node->closing_loc.start) > 0;

if (has_do_opening || (has_brace_opening && !has_closing_location)) {
current_type = CONTROL_TYPE_BLOCK;
keyword_offset = (uint32_t) (node->location.start - context->source_start);
}
}
break;
}
Expand Down
6 changes: 6 additions & 0 deletions test/analyze/block_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,11 @@ class BlockTest < Minitest::Spec
<% end %>
HTML
end

test "closed brace block with yield" do
assert_parsed_snapshot(<<~HTML)
<% content = capture { yield } if block_given? %>
HTML
end
end
end

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

Loading