Skip to content

Commit

Permalink
💥 Newlines are no longer an expression delimiter, only semicolons are
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 7, 2024
1 parent 12d23e5 commit 166c528
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix custom-element render issue with overlaying variable instances
* Fix setting `value` not working server-side on `<textarea>` elements
* Add `Renderer#handleError()` method
* Newlines are no longer an expression delimiter, only semicolons are

## 2.3.15 (2023-11-27)

Expand Down
27 changes: 4 additions & 23 deletions lib/parser/expressions_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Eparser = Fn.inherits('Hawkejs.Parser.Token', function Expressions(source,
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 2.1.6
* @version 2.3.3
* @version 2.3.16
*
* @param {Object|string} line
*
Expand Down Expand Up @@ -74,28 +74,9 @@ Eparser.setStatic(function compileBlock(config) {

if (token.type == 'whitespace') {

if (literal_count) {
// If we're inside an object or array literal,
// newlines do not start a new expression
nl_count = 0;
} else {
nl_count = Bound.String.count(token.value, "\n");
}

if (nl_count > 0) {

if (line.length) {
// Only push non-starting whitespaces
line.push(token);

lines.push(line);
line = [];
}
} else {
// Only push non-starting whitespaces
if (line.length) {
line.push(token);
}
// Only push non-starting whitespaces
if (line.length) {
line.push(token);
}

continue;
Expand Down
16 changes: 8 additions & 8 deletions test/10-expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,13 @@ NO
],
[
`{%
if false
set my_val = "if"
else
set my_val = "else"
/if
if false;
set my_val = "if";
else;
set my_val = "else";
/if;
print(my_val)
print(my_val);
%}`,
'else'
],
Expand Down Expand Up @@ -784,8 +784,8 @@ This should be a converted variable:
**cool**
{% /markdown %}
{%
print('-')
print('-')
print('-');
print('-');
%}
`,
`<span>»123«</span> <p><strong>cool</strong></p> --`
Expand Down

0 comments on commit 166c528

Please sign in to comment.