Sha256: a54aaa5821f41d3ecad267b65d45d1b97f0c22c2a9297811d85024db8363ce04

Contents?: true

Size: 992 Bytes

Versions: 3

Compression:

Stored size: 992 Bytes

Contents

const {
  breakParent,
  concat,
  group,
  hardline,
  ifBreak,
  indent,
  softline
} = require("../prettier");

const printLoop = keyword => (path, { inlineLoops }, print) =>
  group(
    ifBreak(
      concat([
        concat([`${keyword} `, path.call(print, "body", 0)]),
        indent(concat([softline, path.call(print, "body", 1)])),
        concat([softline, "end"])
      ]),
      concat([
        inlineLoops ? "" : breakParent,
        path.call(print, "body", 1),
        ` ${keyword} `,
        path.call(print, "body", 0)
      ])
    )
  );

const printFor = (path, opts, print) =>
  group(
    concat([
      path.call(print, "body", 1),
      ".each do |",
      path.call(print, "body", 0),
      "|",
      indent(concat([hardline, path.call(print, "body", 2)])),
      concat([hardline, "end"])
    ])
  );

module.exports = {
  while: printLoop("while"),
  while_mod: printLoop("while"),
  until: printLoop("until"),
  until_mod: printLoop("until"),
  for: printFor
};

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prettier-0.14.0 src/nodes/loops.js
prettier-0.13.0 src/nodes/loops.js
prettier-0.12.3 src/nodes/loops.js