Comments (18)
Yep, definitely a bug. Thanks for reporting it so clearly! I'll try to get to it tonight or tomorrow.
In the meantime, you can prefix )
with an @
while in content mode to escape it. This is slightly intentional behavior, but isn't really documented because it breaks on anything that could trigger a switch to an expression or block, such as a valid JS identifier, (
, {
, js keyword (switch, if, etc), or function
.
So your example could be:
@html.extend('layout', function (model) {
@html.block('content', function (model) {
<p>Hello world :-@)!</p>
})
})
from vash.
I was able to make simpler test cases:
@(function() { <p>)</p> })
and
@{ function what() { <p>}</p> } }
In both cases, that content should not be counted as ending the expression or block. Using @
as an escape as mentioned above is your best bet for now, although that particular escape is meant to cover the case of:
@('@)')
Since vash does not have a concept of "within a string" when in code mode.
from vash.
Thanks for replying that fast :-)!
Great to have this workaround at hand! Thanks a lot!
from vash.
Hi, will this also fix an error I am having where there is an unclosed parenthesis in a javascript comment in a view? For instance, this view:
@html.extend('layout', function(model) {
@html.block('content', function(model) {
<script>
// this is a comment (
</script>
})
})
this will make the engine crash. If I close the parenthesis on the comment line, it works fine.
Thanks!
from vash.
Yes, if you prefix it with a @
it shouldn't crash anymore.
from vash.
My first thought was that comments were ignored in terms of matching document structure, like parenthesis and braces. Next time I'll surely spot that kind of error faster though. Shouldn't they (comments) be ignored when checking document structure integrity?
from vash.
Absolutely, and the next version of vash will! But the current version doesn't treat comments any differently, and unfortunately I made a bad decision on how to handle characters like (
that typically have a matching counterpart.
from vash.
Oh then I misunderstood your first answer, I thought the final solution was to prefix those chars (in comments too). Thanks for the follow up and for the module!
from vash.
Hi,
It seems there still is an issue with text parentheses in code blocks.
For the closing ) the workaround with escaping it with @ works, but for opening ( does not.
For example, this works:
@if (model.flash_error) {
<p class="text-error">@model.flash_error happy face :-@)</p>
}
But switching ) with (:
@if (model.flash_error) {
<p class="text-error">@model.flash_error sad face :-@(</p>
}
returns:
UnmatchedCharacterError: Unmatched PAREN_OPEN at line 1, character 12. Value: (
+PROGRAM
| +EXPRESSION
| | [IDENTIFIER (1,1): html]
| | [PERIOD (1,5): .]
| | [IDENTIFIER (1,6): extend]
| -EXPRESSION
-PROGRAM
at Object.VParser.advanceUntilMatched (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:629:44)
at Object.VParser.subParse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:643:20)
at Object.VParser.handleEXP (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:992:10)
at Object.VParser.parse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:543:10)
at Object.compile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:1319:4)
at Object.vash.loadFile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:2068:12)
at View.vash.renderFile as engine
at View.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\view.js:93:8)
at EventEmitter.app.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\application.js:530:10)
at ServerResponse.res.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\response.js:904:7)
from vash.
Hey @v3rt1go! Have you tried removing the @
? I tried your code snippet, and it parsed and rendered fine. Using an explicit @(
implies an explicit expression: @(something)
.
from vash.
Hi! Thanks for coming back so fast.
I did try to remove the leading @ but I get the same:
@if (model.flash_error) {
<p class="text-error">@model.flash_error sad face :-(</p>
}
Output:
UnmatchedCharacterError: Unmatched PAREN_OPEN at line 1, character 12. Value: (
+PROGRAM
| +EXPRESSION
| | [IDENTIFIER (1,1): html]
| | [PERIOD (1,5): .]
| | [IDENTIFIER (1,6): extend]
| -EXPRESSION
-PROGRAM
at Object.VParser.advanceUntilMatched (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:629:44)
at Object.VParser.subParse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:643:20)
at Object.VParser.handleEXP (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:992:10)
at Object.VParser.parse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:543:10)
at Object.compile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:1319:4)
at Object.vash.loadFile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:2068:12)
at View.vash.renderFile as engine
at View.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\view.js:93:8)
at EventEmitter.app.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\application.js:530:10)
at ServerResponse.res.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\response.js:904:7)
from vash.
@v3rt1go I'm definitely not getting that in the playground: http://codepen.io/anon/pen/nlxIJ
What version of vash are you using? Is there more in the template than what you're sharing here?
from vash.
Hey @kirbysayshi I'm using vash 0.7.12-1 (installed from npm). I've played with what you've set up on codepen and indeed I cannot reproduce, however it's still reproducible on my end.
You can find the whole code here: https://github.com/v3rt1go/theboard - it's on /vews/index.vash#27
I'm using VS2013 with Node Js tools for VS on the project, though it's a bit far fetched I'm trying to port the whole project in WebStorm or sublime to see if it's a freaky character encoding issue ... though it's far fetched.
from vash.
@v3rt1go it appears that once you add in the surrounding block the error manifests. The issue is also present in examples such as:
@("(")
and
@(function(model) {
<p>(</p>
}())
Thanks for sending the surrounding code, that helped. So yes, this is the same issue, and I don't have a great workaround at this time. Although one option is to use the reverse frowny face: @):
from vash.
@v3rt1go example: http://codepen.io/anon/pen/tlfEa
I'm sorry, I know this is inadequate, but I don't want you to have to wait for a fix.
from vash.
This is one of few bugs we had found when using vash (the other a similar issue with xml style self terminating elements, such as <br />
instead of <br>
but only in certain situations, like this).
When we looked into the code base we saw that parsing was doing a lot of balancing of braces/parenthesis and seemed like it could be quite a task to fix (although I'm sure you'll know better regarding this).
One work around for this which is relatively clean is to balance the parenthesis out using comments, so your code would become:
@if (model.flash_error) {
<p class="text-error">@model.flash_error sad face :-(</p>@*)*@
}
Thanks.
from vash.
@meandmycode spectacular! And you're absolutely right: vash takes shortcuts that a parser should not really take by balancing tokens without context (like "is in string" or "is within markup tags"). I believe that it's definitely a non-trivial fix, although perhaps possible. I'd started to rewrite vash to be able to handle these cases on the stated branch, https://github.com/kirbysayshi/vash/tree/ksh/stated/experiments/stated, but got stalled due to other commitments.
from vash.
This is fixed as of >= 0.8.0!
from vash.
Related Issues (20)
- Feature Request: Add support for render method HOT 5
- How to make multiple includes for the same component work? HOT 2
- <a> is not considered a void tag, should it?
- ..
- vash block error with koa HOT 6
- Vash HOT 2
- @foreach razor syntax HOT 3
- Conditions inside templates HOT 1
- <a href="@item.html">... HOT 3
- Missing output when using if/else if/else followed by another if HOT 3
- Use syntax highlighting in README.md HOT 1
- Output for blocks with the commandline tool or compile API HOT 2
- [question] How to use vash.helpers.include HOT 1
- Is this library no longer developing? HOT 2
- UnclosedNodeError: Found unclosed VashMarkup HOT 2
- Add Support for Tag Helpers
- Add support for compile file
- Trying to get in touch regarding a security issue HOT 2
- Add TypeScript definitions
- Error running the CodePen playground
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vash.