UNPKG

gherkin-ast

Version:

JS model for Gherkin feature files

65 lines 4.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Examples = void 0; const common_1 = require("../common"); const tableRow_1 = require("./tableRow"); const tag_1 = require("./tag"); const uniqueObject_1 = require("./uniqueObject"); const debug_1 = require("../debug"); const debug = (0, debug_1.getDebugger)("Examples"); /** * Model for Examples table */ class Examples extends uniqueObject_1.UniqueObject { static parse(obj, comments) { var _a, _b, _c, _d, _e, _f, _g, _h; 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.tableBody)) { throw new TypeError("The given obj is not an Examples!"); } const { location, tags, tableHeader, tableBody, keyword, name } = obj; const examples = new Examples(keyword, name); examples.precedingComment = comments === null || comments === void 0 ? void 0 : comments.parseComment(location, (_b = tags === null || tags === void 0 ? void 0 : tags[tags.length - 1]) === null || _b === void 0 ? void 0 : _b.location); examples.tagComment = comments === null || comments === void 0 ? void 0 : comments.parseTagComment(tags); examples.tags = tag_1.Tag.parseAll(tags, comments); if (tableHeader) { examples.header = tableRow_1.TableRow.parse(tableHeader, comments); } examples.body = tableRow_1.TableRow.parseAll(tableBody, comments); debug("parse(this: {keyword: '%s', name: '%s', tags: %d, header: %d, body: %d, precedingComment: '%s', tagComment: '%s'})", examples.keyword, examples.name, (_c = examples.tags) === null || _c === void 0 ? void 0 : _c.length, (_e = (_d = examples.header) === null || _d === void 0 ? void 0 : _d.cells) === null || _e === void 0 ? void 0 : _e.length, (_f = examples.body) === null || _f === void 0 ? void 0 : _f.length, (_g = examples.precedingComment) === null || _g === void 0 ? void 0 : _g.text, (_h = examples.tagComment) === null || _h === void 0 ? void 0 : _h.text); return examples; } constructor(keyword, name) { super(); debug("constructor(keyword: '%s', name: '%s')", keyword, name); this.keyword = (0, common_1.normalizeString)(keyword); this.name = (0, common_1.normalizeString)(name); this.header = null; this.precedingComment = null; this.tagComment = null; this.tags = []; this.body = []; } clone() { var _a, _b, _c, _d, _e, _f; debug("clone(this: {keyword: '%s', name: '%s', tags: %d, header: %d, body: %d, precedingComment: '%s', tagComment: '%s'})", this.keyword, this.name, (_a = this.tags) === null || _a === void 0 ? void 0 : _a.length, (_c = (_b = this.header) === null || _b === void 0 ? void 0 : _b.cells) === null || _c === void 0 ? void 0 : _c.length, (_d = this.body) === null || _d === void 0 ? void 0 : _d.length, (_e = this.precedingComment) === null || _e === void 0 ? void 0 : _e.text, (_f = this.tagComment) === null || _f === void 0 ? void 0 : _f.text); const examples = new Examples(this.keyword, this.name); examples.header = this.header ? this.header.clone() : null; examples.precedingComment = this.precedingComment ? this.precedingComment.clone() : null; examples.tagComment = this.tagComment ? this.tagComment.clone() : null; examples.tags = (0, common_1.cloneArray)(this.tags); examples.body = (0, common_1.cloneArray)(this.body); return examples; } replace(key, value) { debug("replace(key: '%s', value: '%s')", key, value); this.name = (0, common_1.replaceAll)(this.name, key, value); this.header && this.header.replace(key, value); this.precedingComment && this.precedingComment.replace(key, value); this.tagComment && this.tagComment.replace(key, value); (0, common_1.replaceArray)(this.tags, key, value); (0, common_1.replaceArray)(this.body, key, value); } } exports.Examples = Examples; //# sourceMappingURL=examples.js.map