prettier-plugin-go-template icon indicating copy to clipboard operation
prettier-plugin-go-template copied to clipboard

fails on html tags using if/else

Open josharian opened this issue 3 years ago • 2 comments

We have code structurally similar to this (only more complex, with different tags):

{{ if .B }}
  <span>
{{ else }}
  <div>
{{ end }}

something

{{ if .B }}
  </span>
{{ else }}
  </div>
{{ end }}

This yields:

Error: An error occured during printing. Found invalid node block.

This is similar to https://github.com/NiklasPor/prettier-plugin-go-template/issues/59, but it causes an error instead of duplication.

josharian avatar Oct 13 '22 22:10 josharian

This obviously can't be solved in the general case. (The if statement could call a Go function, so solving this is equivalent to solving the halting problem.) But some common cases could be special-cased to handle most scenarios.

josharian avatar Oct 13 '22 22:10 josharian

While not exactly the same. This seems like a similar scenario that can be handled correctly every time because the same tag is used in both the if and the else block:

{{ define "test" }}
  {{ if .Active }}
  <li class="active">
  {{ else }}
  <li class="inactive">
  {{ end }}
  </li>
{{ end }}

[error] test.html: Error: An error occured during printing. Found invalid node root.

maxrzaw avatar Nov 05 '23 18:11 maxrzaw