Sha256: 7a0f5a6e8423471cbd83977bc7ec8051ffe58bcec30de6ff7b1e5f591893c11d
Contents?: true
Size: 1.13 KB
Versions: 7
Compression:
Stored size: 1.13 KB
Contents
const { concat, group, lineSuffix, join } = require("../../prettier"); const { literalLineNoBreak } = require("../../utils"); function printHeredoc(path, opts, print) { const { body, ending } = path.getValue(); const parts = body.map((part, index) => { if (part.type !== "@tstring_content") { // In this case, the part of the string is an embedded expression return path.call(print, "body", index); } // In this case, the part of the string is just regular string content return join(literalLineNoBreak, part.body.split("\n")); }); // We use a literalline break because matching indentation is required // for the heredoc contents and ending. If the line suffix contains a // break-parent, all ancestral groups are broken, and heredocs automatically // break lines in groups they appear in. We prefer them to appear in-line if // possible, so we use a literalline without the break-parent. return group( concat([ path.call(print, "beging"), lineSuffix( group(concat([literalLineNoBreak].concat(parts).concat(ending))) ) ]) ); } module.exports = { heredoc: printHeredoc };
Version data entries
7 entries across 7 versions & 1 rubygems