ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
212 stars 12 forks source link

Deno 2 fmt --unstable-components seems to break vento for loop #81

Closed RickCogley closed 3 days ago

RickCogley commented 1 week ago

Deno 2.0.6, Lume 2.4.2

I mentioned on the discord, but when I used deno fmt --unstable-components on some vento templates in a site, it does indeed work to tidy up the formatting. However, I noticed this:

Changes detected:
- /_includes/layouts/bios.vto
Error: Error rendering the layout of the page /en/team.yml
    at https://deno.land/x/lume@v2.4.2/core/renderer.ts:176:19
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async Promise.all (index 0)
    at async concurrent (https://deno.land/x/lume@v2.4.2/core/utils/concurrent.ts:21:3)
    at async Renderer.renderPages (https://deno.land/x/lume@v2.4.2/core/renderer.ts:155:7)
    at async Site.#buildPages (https://deno.land/x/lume@v2.4.2/core/site.ts:642:5)
    at async Site.update (https://deno.land/x/lume@v2.4.2/core/site.ts:595:9)
    at async Events.dispatchEvent (https://deno.land/x/lume@v2.4.2/core/events.ts:46:13)
    at async callback (https://deno.land/x/lume@v2.4.2/core/watcher.ts:101:24)
Caused by SyntaxError: [6:22-6:25]: Unexpected token: 'for'

This commit shows the before and after, which fixed the error:

https://github.com/eSolia/japanactivationcapital.com/commit/fb19b8d41a964013b2af3a65160f4c40ad0d7c1b

oscarotero commented 3 days ago

I can't reproduce this issue. Can you provide the vento code that throws the error?

RickCogley commented 3 days ago

Sorry I didn't explain well. Before this commit: https://github.com/eSolia/japanactivationcapital.com/commit/fb19b8d41a964013b2af3a65160f4c40ad0d7c1b ... what I was doing was, editing the tag to be searched:

{{
            for 
            item of search.pages(`tags*=Investment type=bio lang=${lang}`, "weight")
          }}

e.g. changing tags*=Investment to something else like tags*=InvestorRelations. I had lume serve running, and, on save of the vento template, the error would occur. When I discarded/undid the changes, lume serve would go back to normal, no error. Then I thought, maybe it's about the spaces the deno fmt added, so I "collapsed" the fors again, and was able to change the tag search to what I wanted, after that.

It's odd because, the site was building successfully after I ran deno fmt with --unstable-components, until I tried messing with something inside of one of those for clauses. I don't understand what editing the tags*= would do to break that, because I was literally only changing the tag name.

oscarotero commented 3 days ago

After following this step, I couldn't reproduce the error. While deno task serve is running, I've formated the code with deno fmt --unstable-components and with the for tag in 2 lines (like your example), I've modified the tags and everything worked fine.

Maybe you have modified something else without realizing it?

RickCogley commented 3 days ago

that's very possible. I just realized: What I could have done is, just run the deno fmt --unstable-components again after editing.

RickCogley commented 3 days ago

If I can make this happen again I'll capture more details and reopen. Thanks for trying to reproduce.