mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.99k stars 333 forks source link

wip: syntax: flush heredocs before right parens #924

Closed andreykaipov closed 1 year ago

andreykaipov commented 1 year ago

Fixes https://github.com/mvdan/sh/issues/923 😄

andreykaipov commented 1 year ago

Oh no, sorry this is embarrassing... I foolishly was only running go test ./... -run=TestPrintMinify during my testing...

This change as it is breaks a few other wacky cases, like:

foo <<EOF | $(bar)
3
EOF

I did some more digging through the code to see if I can satisfy both (the existing test case of a subshell after the beginning heredoc word, and the new one I added where the heredoc is within a subshell), but I think it would involve a new printer field to keep track of if we're in a heredoc or not.

mvdan commented 1 year ago

Thanks for the PR! I did see it, I just haven't had the time to sit down and debug what's going on :)

mvdan commented 1 year ago

Finally figured it out, it was a bit subtle :) I also noticed that the escaped newlines right before << weren't necessary with the minify mode, that's fixed as well. Fix coming shortly, and I'll credit you for the test cases. Thank you!

andreykaipov commented 1 year ago

Oh - thanks! Sorry this got lost in the inbox. Time sure does fly. Thanks so much! Really appreciate you and this project! 🥳