"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppendAction = void 0;
const action_1 = require("../action");
const node_mutation_1 = __importDefault(require("../node-mutation"));
/**
* AppendAction to append code to the bottom of node body.
* @extends BaseAction
*/
class AppendAction extends action_1.BaseAction {
/**
* Create an AppendAction
* @param {T} node
* @param {string} code
* @param {object} options
* @param {Adapter<T>} options.adapter - adapter to parse the node
*/
constructor(node, code, { adapter }) {
super(node, code, { adapter });
this.type = "insert";
}
/**
* Calculate the begin and end positions.
* @protected
*/
calculatePositions() {
this.start = this.adapter.getEnd(this.node) - this.adapter.getIndent(this.node) - "}".length;
this.end = this.start;
}
/**
* The rewritten source code.
* @returns {string} rewritten code.
*/
get newCode() {
const source = this.rewrittenSource();
const indent = this.adapter.getIndent(this.node) + node_mutation_1.default.tabWidth;
return this.addIndentToCode(source, indent);
}
}
exports.AppendAction = AppendAction;