gherkin-ast
Version:
JS model for Gherkin feature files
44 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocString = void 0;
const common_1 = require("../common");
const uniqueObject_1 = require("./uniqueObject");
const debug_1 = require("../debug");
const debug = (0, debug_1.getDebugger)("DocString");
/**
* Model for DocString
*/
class DocString extends uniqueObject_1.UniqueObject {
static parse(obj, comments) {
var _a, _b;
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 || obj.content === undefined) {
throw new TypeError("The given object is not a DocString!");
}
const docString = new DocString(obj.content, obj.delimiter, obj.mediaType);
docString.comment = comments === null || comments === void 0 ? void 0 : comments.parseComment(obj.location);
debug("parse(this: {content: '%s', delimiter: '%s', mediaType: '%s', comment: '%s'})", docString.content, docString.delimiter, docString.mediaType, (_b = docString.comment) === null || _b === void 0 ? void 0 : _b.text);
return docString;
}
constructor(content, delimiter = "\"\"\"", mediaType = null) {
super();
debug("constructor(content: '%s', delimiter: '%s', mediaType: '%s')", content, delimiter, mediaType);
this.content = (0, common_1.normalizeString)(content);
this.delimiter = delimiter;
this.mediaType = mediaType;
}
clone() {
var _a;
debug("clone(this: {content: '%s', delimiter: '%s', mediaType: '%s', comment: '%s'})", this.content, this.delimiter, this.mediaType, (_a = this.comment) === null || _a === void 0 ? void 0 : _a.text);
const docString = new DocString(this.content, this.delimiter, this.mediaType);
docString.comment = this.comment ? this.comment.clone() : null;
return docString;
}
replace(key, value) {
debug("replace(key: '%s', value: '%s')", key, value);
this.content = (0, common_1.replaceAll)(this.content, key, value);
this.comment && this.comment.replace(key, value);
}
}
exports.DocString = DocString;
//# sourceMappingURL=docString.js.map