Sha256: e40d6fd663d025507fa0c98c585a70c7a60bea92ed09afb1b01524eb5cebbcce

Contents?: true

Size: 1.93 KB

Versions: 10

Compression:

Stored size: 1.93 KB

Contents

const { concat, group, indent, join, line, softline } = require("../prettier");
const { makeList } = require("../utils");

module.exports = {
  massign: (path, opts, print) => {
    let right = path.call(print, "body", 1);

    if (
      ["mrhs_add_star", "mrhs_new_from_args"].includes(
        path.getValue().body[1].type
      )
    ) {
      right = group(join(concat([",", line]), right));
    }

    const parts = [join(concat([",", line]), path.call(print, "body", 0))];
    if (path.getValue().body[0].comma) {
      parts.push(",");
    }

    return group(
      concat([group(concat(parts)), " =", indent(concat([line, right]))])
    );
  },
  mlhs: makeList,
  mlhs_add_post: (path, opts, print) =>
    path.call(print, "body", 0).concat(path.call(print, "body", 1)),
  mlhs_add_star: (path, opts, print) =>
    path
      .call(print, "body", 0)
      .concat([
        path.getValue().body[1]
          ? concat(["*", path.call(print, "body", 1)])
          : "*"
      ]),
  mlhs_paren: (path, opts, print) => {
    if (["massign", "mlhs_paren"].includes(path.getParentNode().type)) {
      // If we're nested in brackets as part of the left hand side of an
      // assignment, i.e., (a, b, c) = 1, 2, 3
      // ignore the current node and just go straight to the content
      return path.call(print, "body", 0);
    }

    const parts = [
      softline,
      join(concat([",", line]), path.call(print, "body", 0))
    ];

    if (path.getValue().body[0].comma) {
      parts.push(",");
    }

    return group(concat(["(", indent(concat(parts)), concat([softline, ")"])]));
  },
  mrhs: makeList,
  mrhs_add_star: (path, opts, print) =>
    path
      .call(print, "body", 0)
      .concat([concat(["*", path.call(print, "body", 1)])]),
  mrhs_new_from_args: (path, opts, print) => {
    const parts = path.call(print, "body", 0);

    if (path.getValue().body.length > 1) {
      parts.push(path.call(print, "body", 1));
    }

    return parts;
  }
};

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prettier-0.21.0 src/nodes/massign.js
prettier-0.20.1 src/nodes/massign.js
prettier-0.20.0 src/nodes/massign.js
prettier-0.19.1 src/nodes/massign.js
prettier-0.19.0 src/nodes/massign.js
prettier-0.18.2 src/nodes/massign.js
prettier-0.18.1 src/nodes/massign.js
prettier-0.18.0 src/nodes/massign.js
prettier-0.17.0 src/nodes/massign.js
prettier-0.16.0 src/nodes/massign.js