Skip to content

Commit b97baa9

Browse files
authored
Merge pull request #5 from doits/fix_block_braces
allow braces in block arguments
2 parents a3c5351 + 692657b commit b97baa9

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/parser.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const PLACEHOLDER = {
55
end: "~#",
66
};
77

8+
const BLOCK_REGEX = /do(?: \|[\w_, ()]+\|)?$/;
9+
810
const placeholderGenerator = (text) => {
911
let id = 0;
1012

@@ -93,7 +95,7 @@ export const parse = (text) => {
9395
},
9496
};
9597

96-
const expressionIsBlock = expression.match(/do( \|[\w_, ]+\|)?$/) != null;
98+
const expressionIsBlock = expression.match(BLOCK_REGEX) != null;
9799
if (expressionIsBlock) {
98100
// If a expression is opening a block, we'll treat that expression as a statement to
99101
// simplify the logic of blocks
@@ -129,7 +131,7 @@ export const parse = (text) => {
129131
const hasValidKeyword = ["if", "unless", "case"].includes(
130132
start.keyword,
131133
);
132-
const hasBlock = start.content.match(/do( \|[\w_, ]+\|)?$/) != null;
134+
const hasBlock = start.content.match(BLOCK_REGEX) != null;
133135
// If the statement is not matching, replace the content with the placeholder
134136
if (!hasValidKeyword && !hasBlock) {
135137
root.content = replaceAt(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<% @values.each.with_index do |(a, b), i| %>
3+
<li><%= i %>: <%= a %> <%= b %></li>
4+
<% end %>
5+
</ul>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<% @values.each.with_index do |(a, b), i| %>
3+
<li><%= i %>: <%= a %> <%= b %></li>
4+
<% end %>
5+
</ul>

0 commit comments

Comments
 (0)