Sha256: a5a0b7b5e672feced218df92a711aef5400d9a3f0202c1e42ad0e2c23436ee50

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

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

function printAssign(path, opts, print) {
  const [_targetNode, valueNode] = path.getValue().body;
  const [targetDoc, valueDoc] = path.map(print, "body");

  let rightSideDoc = valueDoc;

  // If the right side of this assignment is a multiple assignment, then we need
  // to join it together with commas.
  if (["mrhs_add_star", "mrhs_new_from_args"].includes(valueNode.type)) {
    rightSideDoc = group(join(concat([",", line]), valueDoc));
  }

  if (skipAssignIndent(valueNode)) {
    return group(concat([targetDoc, " = ", rightSideDoc]));
  }

  return group(concat([targetDoc, " =", indent(concat([line, rightSideDoc]))]));
}

function printOpAssign(path, opts, print) {
  return group(
    concat([
      path.call(print, "body", 0),
      " ",
      path.call(print, "body", 1),
      indent(concat([line, path.call(print, "body", 2)]))
    ])
  );
}

function printVarField(path, opts, print) {
  if (path.getValue().body) {
    return path.call(print, "body", 0);
  }

  return "*";
}

module.exports = {
  assign: printAssign,
  opassign: printOpAssign,
  var_field: printVarField,
  var_ref: first
};

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prettier-1.2.0 src/nodes/assign.js