UNPKG

gherkin-ast

Version:

JS model for Gherkin feature files

62 lines 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Document = void 0; const common_1 = require("../common"); const feature_1 = require("./feature"); const uniqueObject_1 = require("./uniqueObject"); const path_1 = require("path"); const debug_1 = require("../debug"); const debug = (0, debug_1.getDebugger)("Document"); /** * Model for Document */ class Document extends uniqueObject_1.UniqueObject { static parse(obj) { var _a, _b, _c, _d; debug("parse(obj: %o)", obj); if (!obj || !obj.gherkinDocument) { throw new TypeError("The given object is not a GherkinDocument!"); } const comments = new common_1.GherkinCommentHandler((_a = obj.gherkinDocument) === null || _a === void 0 ? void 0 : _a.comments); const document = new Document(obj.gherkinDocument.uri); document.feature = feature_1.Feature.parse(obj.gherkinDocument.feature, comments); document.startComment = comments.parseStartingComment(); document.endComment = comments.parseEndingComment(); debug("parse(this: {uri: '%s', feature: '%s', startComment: '%s', endComment: '%s'})", document.uri, (_b = document.feature) === null || _b === void 0 ? void 0 : _b.name, (_c = document.startComment) === null || _c === void 0 ? void 0 : _c.text, (_d = document.endComment) === null || _d === void 0 ? void 0 : _d.text); return document; } constructor(uri, feature = null) { var _a, _b, _c; super(); this.feature = feature; this.startComment = null; this.endComment = null; this.uri = uri; this.sourceFile = (0, path_1.basename)(uri); this.sourceFolder = (0, path_1.dirname)(uri); this.targetFile = this.sourceFile; this.targetFolder = this.sourceFolder; debug("constructor(this: {uri: '%s', sourceFile: '%s', sourceFolder: '%s', " + "targetFile: '%s', targetFolder: '%s', " + "feature: '%s', startComment: '%s', endComment: '%s'})", this.uri, this.sourceFile, this.sourceFolder, this.targetFile, this.targetFolder, (_a = this.feature) === null || _a === void 0 ? void 0 : _a.name, (_b = this.startComment) === null || _b === void 0 ? void 0 : _b.text, (_c = this.endComment) === null || _c === void 0 ? void 0 : _c.text); } clone() { var _a, _b, _c; debug("clone(this: {uri: '%s', sourceFile: '%s', sourceFolder: '%s', " + "targetFile: '%s', targetFolder: '%s', " + "feature: '%s', startComment: '%s', endComment: '%s'})", this.uri, this.sourceFile, this.sourceFolder, this.targetFile, this.targetFolder, (_a = this.feature) === null || _a === void 0 ? void 0 : _a.name, (_b = this.startComment) === null || _b === void 0 ? void 0 : _b.text, (_c = this.endComment) === null || _c === void 0 ? void 0 : _c.text); const document = new Document(this.uri); document.feature = this.feature ? this.feature.clone() : null; document.startComment = this.startComment ? this.startComment.clone() : null; document.endComment = this.endComment ? this.endComment.clone() : null; return document; } replace(key, value) { debug("replace(key: '%s', value: '%s')", key, value); this.feature && this.feature.replace(key, value); this.startComment && this.startComment.replace(key, value); this.endComment && this.endComment.replace(key, value); } } exports.Document = Document; //# sourceMappingURL=gherkinDocument.js.map