UNPKG

gherkin-ast

Version:

JS model for Gherkin feature files

79 lines 4.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Step = void 0; const common_1 = require("../common"); const dataTable_1 = require("./dataTable"); const docString_1 = require("./docString"); const uniqueObject_1 = require("./uniqueObject"); const debug_1 = require("../debug"); const debug = (0, debug_1.getDebugger)("Step"); /** * Model for Step */ class Step extends uniqueObject_1.UniqueObject { static parse(obj, comments, prevStepLocation) { var _a, _b, _c, _d, _e, _f; debug("parse(obj: %o, comments: %d, prevStepLocation: %d)", obj, (_a = comments === null || comments === void 0 ? void 0 : comments.comments) === null || _a === void 0 ? void 0 : _a.length, prevStepLocation === null || prevStepLocation === void 0 ? void 0 : prevStepLocation.line); if (!obj || !obj.text) { throw new Error("The given object is not a Step!"); } const { keyword, text, dataTable, docString, location } = obj; const step = new Step(keyword, text); if (dataTable) { step.dataTable = dataTable_1.DataTable.parse(dataTable, comments); } if (docString) { step.docString = docString_1.DocString.parse(docString, comments); } if (prevStepLocation) { step.comment = comments === null || comments === void 0 ? void 0 : comments.parseCommentBetween(prevStepLocation, location); } else { step.comment = comments === null || comments === void 0 ? void 0 : comments.parseComment(location); } debug("parse(this: {keyword: '%s', text: '%s', dataTable: %d, docString: %d, comment: '%s'})", step.keyword, step.text, (_c = (_b = step.dataTable) === null || _b === void 0 ? void 0 : _b.rows) === null || _c === void 0 ? void 0 : _c.length, (_e = (_d = step.docString) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.length, (_f = step.comment) === null || _f === void 0 ? void 0 : _f.text); return step; } static parseAll(obj, comments) { var _a; debug("parseAll(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)) { return []; } let prevStepLocation = null; return obj.map(o => { const step = this.parse(o, comments, prevStepLocation); prevStepLocation = o.location; return step; }); } constructor(keyword, text) { var _a, _b, _c, _d, _e; super(); debug("constructor(keyword: '%s', text: '%s')", keyword, text); this.keyword = (0, common_1.normalizeString)(keyword); this.text = (0, common_1.normalizeString)(text); this.dataTable = null; this.docString = null; this.comment = null; debug("constructor(this: {keyword: '%s', text: '%s', dataTable: %d, docString: %d, comment: '%s'})", this.keyword, this.text, (_b = (_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.length, (_d = (_c = this.docString) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.length, (_e = this.comment) === null || _e === void 0 ? void 0 : _e.text); } clone() { var _a, _b, _c, _d, _e; debug("clone(this: {keyword: '%s', text: '%s', dataTable: %d, docString: %d, comment: '%s'})", this.keyword, this.text, (_b = (_a = this.dataTable) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.length, (_d = (_c = this.docString) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.length, (_e = this.comment) === null || _e === void 0 ? void 0 : _e.text); const step = new Step(this.keyword, this.text); step.dataTable = this.dataTable ? this.dataTable.clone() : null; step.docString = this.docString ? this.docString.clone() : null; step.comment = this.comment ? this.comment.clone() : null; return step; } replace(key, value) { debug("replace(key: '%s', value: '%s')", key, value); this.text = (0, common_1.replaceAll)(this.text, key, value); this.dataTable && this.dataTable.replace(key, value); this.docString && this.docString.replace(key, value); this.comment && this.comment.replace(key, value); } } exports.Step = Step; //# sourceMappingURL=step.js.map