fix: strip pseudo inline placeholder from string/heredoc/nowdoc output - #2530
Dextheking1 wants to merge 2 commits into
Conversation
parser.mjs injects ___PSEUDO_INLINE_PLACEHOLDER___ into the source text for top-level ?>\n<? sequences. When a heredoc/nowdoc/string happened to contain that sequence, the sentinel leaked into the formatted output, corrupting the string contents. Fixes prettier#2087
|
Thanks for this — I've been running it locally and the output is right. One thing you may want to add: the new Not a bug in the fix: the "expected" AST comes from parsing the source after |
parser.mjs injects ___PSEUDO_INLINE_PLACEHOLDER___ into the source text for top-level ?> newline <? sequences. When it lands inside string, heredoc or nowdoc values, the AST parsed from the original source keeps the sentinel while the formatted output does not, so AST_COMPARE fails. Strip it from string and nowdoc values in clean.mjs. Heredoc parts are string nodes, so they are covered too.
|
Good catch, thanks. Added the strip to clean.mjs for string and nowdoc values (heredoc parts are string nodes, so they are covered too). Verified: AST_COMPARE=1 yarn test:node passes, 102 suites / 1174 tests, and the plain suite is green too (596 tests). |
Fixes #2087
parser.mjsinjects___PSEUDO_INLINE_PLACEHOLDER___into the source text for top-level?>\n<?sequences (workaround for glayzzle/php-parser#170). When a heredoc, nowdoc, or string literal happened to contain that sequence, the sentinel leaked into the formatted output, corrupting the string contents:The
inlineprinter already stripped the sentinel; thestring(plain and encapsed) andnowdocprinters printednode.raw/node.valueverbatim, so they now strip it too via a sharedPSEUDO_INLINE_PLACEHOLDERconstant.Tests: new
tests/heredocfixture (heredoc, nowdoc, and plain-string cases, placeholder leaked before, gone after); full suite 104 suites / 598 tests green.