gherkin-ast
Version:
JS model for Gherkin feature files
56 lines • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableRow = void 0;
const common_1 = require("../common");
const tableCell_1 = require("./tableCell");
const uniqueObject_1 = require("./uniqueObject");
const debug_1 = require("../debug");
const debug = (0, debug_1.getDebugger)("TableRow");
/**
* Model for TableRow
*/
class TableRow extends uniqueObject_1.UniqueObject {
static parse(obj, comments) {
var _a, _b, _c;
debug("parse(obj: %o, comments: %d)", obj, (_a = comments === null || comments === void 0 ? void 0 : comments.comments) === null || _a === void 0 ? void 0 : _a.length);
if (!obj || !Array.isArray(obj.cells)) {
throw new TypeError("The given object is not a TableRow!");
}
const { cells, location } = obj;
const row = new TableRow();
row.cells = cells === null || cells === void 0 ? void 0 : cells.map(tableCell_1.TableCell.parse);
row.comment = comments === null || comments === void 0 ? void 0 : comments.parseComment(location);
debug("parse(this: {cells: %d, comment: '%s'})", (_b = row.cells) === null || _b === void 0 ? void 0 : _b.length, (_c = row.comment) === null || _c === void 0 ? void 0 : _c.text);
return row;
}
static parseAll(obj, comments) {
var _a;
debug("parse(obj: %d, comments: %d)", obj === null || obj === void 0 ? void 0 : obj.length, (_a = comments === null || comments === void 0 ? void 0 : comments.comments) === null || _a === void 0 ? void 0 : _a.length);
if (!Array.isArray(obj) || !obj.length) {
return [];
}
return obj.map(o => this.parse(o, comments));
}
constructor(cells = []) {
var _a, _b;
super();
this.cells = cells;
debug("constructor(cells: %d)", cells === null || cells === void 0 ? void 0 : cells.length);
this.comment = null;
debug("constructor(this: {cells: %d, comment: '%s'})", (_a = this.cells) === null || _a === void 0 ? void 0 : _a.length, (_b = this.comment) === null || _b === void 0 ? void 0 : _b.text);
}
clone() {
var _a, _b;
debug("clone(this: {cells: %d, comment: '%s'})", (_a = this.cells) === null || _a === void 0 ? void 0 : _a.length, (_b = this.comment) === null || _b === void 0 ? void 0 : _b.text);
const row = new TableRow((0, common_1.cloneArray)(this.cells));
row.comment = this.comment ? this.comment.clone() : null;
return row;
}
replace(key, value) {
debug("replace(key: '%s', value: '%s')", key, value);
(0, common_1.replaceArray)(this.cells, key, value);
this.comment && this.comment.replace(key, value);
}
}
exports.TableRow = TableRow;
//# sourceMappingURL=tableRow.js.map