Changeset: Improve `copyOp()` API

Use `Object.assign()` to implement `copyOp()`, which simplifies the
code and provides a return value. Also make the second op optional.
pull/5268/head
Richard Hansen 2021-10-02 18:17:11 -04:00
parent 02ef78e174
commit 94f5507671
1 changed files with 3 additions and 7 deletions

View File

@ -205,14 +205,10 @@ exports.newOp = (optOpcode) => ({
* Copies op1 to op2
*
* @param {Op} op1 - src Op
* @param {Op} op2 - dest Op
* @param {Op} [op2] - dest Op. If not given, a new Op is used.
* @returns {Op} `op2`
*/
const copyOp = (op1, op2) => {
op2.opcode = op1.opcode;
op2.chars = op1.chars;
op2.lines = op1.lines;
op2.attribs = op1.attribs;
};
const copyOp = (op1, op2 = exports.newOp()) => Object.assign(op2, op1);
/**
* Serializes a sequence of Ops.