Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsyntax error when method is passed a heredoc string and a block #301
Comments
|
Oof yeah that's a tough one. I'll take a look. |
Before
After
Expected
|
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Instead of ad-hoc code in various places plucking out heredoc beging, contents, and ending in order to print it more intelligently in certain cases, this changes the way heredocs are printed altogether so they can simply be printed in any context and still work correctly. This prevents heredocs appearing in various parts of the syntax tree from absorbing other lines of code because they break after the heredoc literal and before the heredoc contents because they were manually plucked out the AST and inserted in the Doc contextually. fixes prettier#624 fixes prettier#586 fixes prettier#316 fixes prettier#301 There exists a command in prettier's set of builders called lineSufix. It's listed as used for implementing trailing comments. The doc contents you wrap in lineSuffix() are appended to the end of the line during printing. This seemed appropriate for this use case because of the following facts about heredocs: A heredoc literal beging can appear anywhere and can be treated like a string literal. things can be chained to it, it may need a trailing comma, etc). Conclusion: When printing a heredoc, more code should be able to print after the heredoc literal before the next line. The next line break after the heredoc beging is part of the heredoc contents. period. Conclusion: A line break must always appear, after which the contents printed then the ending. Code can continue on the next line. Conclusion: Code chained or in the same expression as the heredoc beging must fit on the same line as the heredoc beging or be broken and continue on the newline after the ending. Using lineSuffix when printing heredocs allows us to guarantee an append to the end of that line where we can insert a literalline (non-negotiable line break), the contents, and the ending. Code continues printing after this ending newline. Conclusion: lineSuffix's behavior matches the behavior of heredocs in general and would allow a heredoc to be printed correctly in any context. The heredoc print would look like this: concat([ beging, lineSuffix(concat([literalline, concat(parts), ending])) ]); In words: since a heredoc beging appears "here", print the beging "here", but guarantee the following contents will appear at the end of the "here" line: linebreak, contents, ending. Result: Thus, the end of line break and next few lines are guaranteed to be the heredoc contents (no absorbing other lines), the beging is the only doc portion printed in place so trailing commas and method chaining works fine. At this point, _all heredocs are printing themselves correctly anywhere they appear in the AST/Doc. The code used to manually slice up the heredoc and print it correctly in various places (hash.js, array.js, calls.js, utils.js) could now be removed and everything would print valid ruby code.
Metadata
Input
Current output
Expected output