Sha256: 02e2d95347d3be43fd08a7beaba5ea39517f57f635de17912a47424faec7c9fe
Contents?: true
Size: 1.35 KB
Versions: 8
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
8 entries across 8 versions & 1 rubygems