-
-
Notifications
You must be signed in to change notification settings - Fork 18
Fix expression ignoring #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
shows diffs when a test fails
|
@cossssmin Hi, why didn’t you move it to line 154? after all, during the round-trip, regular degeneration with |
|
Rushed to push the fix, sorry about that - doing it now... 🤦♂️ |
|
Don't worry about it |
|
Wait, it won't work there, |
|
Yes, I was a little mistaken, but I would like to endure them or iterate |
|
|
|
I mean, in line 13, initialize them so that they are accessible from any scoup |
|
Not sure what to initialize them to or how you'd like it to work, sorry... I'd appreciate your assistance if you can, feel free to update the PR :) |
|
@cossssmin its ok ? |
|
@anikethsaha ping |
| <p data-username="@{{ user.name }}" data-user-id="user-@{{ user.id }}"> | ||
| Here's one @{{ variable }} and here's @{{ another }}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking suggestion !
can we have one more example here with usual expression and one ignored expression on same element and also or the same attribute?
like this may
<p data-username="@{{ user.name }}" data-user-id="user-@{{ user.id }}-{{ user.id2 }}">
And here's a @{{ variable }} that would be undefined. Here's one {{ variable }} and here's @{{ another }}.ignore if already exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once @{{ is encountered, the entire string/attribute value is returned as-is.
So this:
Here's one @{{ variable }} and here's some {{ foo }}.
will be output as:
Here's one {{ variable }} and here's some {{ foo }}.
So {{ foo }} will not be evaluated. Which come to think about it, may not be ideal, but I can't see how you'd evaluate {{ foo }}...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ummm,
can we do like if @{{ comes, it will ignore till first occurrence of }} ? WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, maybe changing the regexes here:
posthtml-expressions/lib/index.js
Lines 127 to 138 in 77aaf56
| const delimitersRegexp = new RegExp(`${before}(.+?)${after}`, 'g') | |
| before = escapeRegexpString(options.unescapeDelimiters[0]) | |
| after = escapeRegexpString(options.unescapeDelimiters[1]) | |
| const unescapeDelimitersRegexp = new RegExp(`${before}(.+?)${after}`, 'g') | |
| // make array of delimiters | |
| const delimiters = [ | |
| { text: options.delimiters, regexp: delimitersRegexp, escape: true }, | |
| { text: options.unescapeDelimiters, regexp: unescapeDelimitersRegexp, escape: false } | |
| ] |
... to match {{ }} or {{{ }}} as long as they don't start with @, would be better instead? So we only match non-ignored delimiters, and then we no longer have to return 'early', so my example above should (theoretically) correctly return:
Here's one {{ variable }} and here's some bar.
(assuming foo: 'bar' in locals).
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to match
{{ }}or{{{ }}}as long as they don't start with@, would be better instead?
yeah, I think this should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it working, will push it up in a moment 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try ^(?! )[^@]{(.+?)}} ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So although I got it working, I think I found an issue with how placeholders treats unescaped delimiters.
Basically, since it loops over every item in the settings object it receives, it'll still match {{ var }} inside @{{{ var }}}.
I'll push the fix for regular, escaped delimiters and will open a separate issue for unescaped delimiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll push the fix for regular, escaped delimiters and will open a separate issue for unescaped delimiters.
cool 👍
Yes, sorry, I got what you meant now... 👍 |
use negative lookbehind so we only evaluate non-ignored expressions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
|
@cossssmin publish v1.4.1 |
This PR fixes a couple of bugs when ignoring expressions with
@{{ }}, as described in #72.Subsequent ignored expressions now properly work in text nodes:
Result:
Expressions are now also ignored inside attribute values:
Result:
When merged, this PR will close #72.