Giter VIP home page Giter VIP logo

Comments (18)

kirbysayshi avatar kirbysayshi commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

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.

goloroden avatar goloroden commented on August 27, 2024

Thanks for replying that fast :-)!

Great to have this workaround at hand! Thanks a lot!

from vash.

sowee15 avatar sowee15 commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

Yes, if you prefix it with a @ it shouldn't crash anymore.

from vash.

sowee15 avatar sowee15 commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

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.

sowee15 avatar sowee15 commented on August 27, 2024

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.

v3rt1go avatar v3rt1go commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

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.

v3rt1go avatar v3rt1go commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@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.

v3rt1go avatar v3rt1go commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@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.

meandmycode avatar meandmycode commented on August 27, 2024

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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

@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.

kirbysayshi avatar kirbysayshi commented on August 27, 2024

This is fixed as of >= 0.8.0!

from vash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.