Sha256: 1e35d7d598f11b65a0ecb4d4f0653ae23220d8184a193f181a7ee95775776346
Contents?: true
Size: 1.35 KB
Versions: 6
Compression:
Stored size: 1.35 KB
Contents
const { concat, group, ifBreak, indent, line, removeLines, softline } = require("../prettier"); const { hasAncestor } = require("../utils"); module.exports = { lambda: (path, opts, print) => { let params = path.getValue().body[0]; let paramsConcat = ""; if (params.type === "params") { paramsConcat = path.call(print, "body", 0); } else { [params] = params.body; paramsConcat = path.call(print, "body", 0, "body", 0); } const noParams = params.body.every((type) => !type); const inlineLambda = concat([ "->", noParams ? "" : concat(["(", paramsConcat, ")"]), " { ", path.call(print, "body", 1), " }" ]); if (hasAncestor(path, ["command", "command_call"])) { return group( ifBreak( concat([ "lambda {", noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]), indent(concat([line, path.call(print, "body", 1)])), concat([line, "}"]) ]), inlineLambda ) ); } return group( ifBreak( concat([ "lambda do", noParams ? "" : concat([" |", removeLines(paramsConcat), "|"]), indent(concat([softline, path.call(print, "body", 1)])), concat([softline, "end"]) ]), inlineLambda ) ); } };
Version data entries
6 entries across 6 versions & 1 rubygems