Sha256: be9991f71401f5f1253f67dbb02e636aa2962affa015d003e07443a0ac0c5fb3

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 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)]))
    ])
  );
}

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prettier-1.1.0 src/nodes/assign.js
prettier-1.0.1 src/nodes/assign.js
prettier-1.0.0 src/nodes/assign.js
prettier-1.0.0.pre.rc2 src/nodes/assign.js