Skip to content
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

Mixins with "block", when nested, result in invalid generated Go code #57

Open
servernoj opened this issue Dec 24, 2023 · 1 comment
Open

Comments

@servernoj
Copy link

servernoj commented Dec 24, 2023

My mixin is defined as

mixin parent
  block

and then I use them as

+parent
  +parent
    .content

I expect the generated function to produce (in Pug/Jade sense)

.content

but CLI tool produces Go source that cannot compile (only the function shown for brevity):

func Jade_l(wr io.Writer) {
  buffer := &WriterAsBuffer{wr}
  {
    {
      buffer := new(bytes.Buffer)
      {
        var block []byte
        {
          buffer := new(bytes.Buffer)
          buffer.WriteString(l__0)

          block = buffer.Bytes()
        }

        buffer.Write(block)
      }

      block = buffer.Bytes()
    }

    buffer.Write(block)
  }
}

specifically, it needs one more declaration of block, like this

func Jade_l(wr io.Writer) {
  buffer := &WriterAsBuffer{wr}
  {
    var block []byte // <-- THIS ONE
    {
      buffer := new(bytes.Buffer)
      {
...

My actual code doesn't nest the mixin in itself, but the case above illustrates the problem with a minimal level of unnecessary details.

@servernoj
Copy link
Author

After some more digging, it looks like the generated code is OK up to the point when it is optimized, and one of the needed declarations of the block variable is removed. I believe it is happening here:

dsSl = append(dsSl, xds)

I don't understand the entirety of the logic, but commenting out that statement fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant