UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

31 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceTag = replaceTag; const START_TAG_OFFSET = 1; const END_TAG_OFFSET = 2; const NON_SELF_CLOSING_NATIVE_TAGS = new Set(['a', 'button', 'div', 'span']); // eslint-disable-next-line @typescript-eslint/max-params,max-params function replaceTag(recorder, sourceCodeLocation, from, to, template, templateOffset = 0, addAttributes = []) { var _a, _b; const startTag = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag; const startTagOffset = (_a = startTag === null || startTag === void 0 ? void 0 : startTag.startOffset) !== null && _a !== void 0 ? _a : 0; const endTagOffset = (_b = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.endTag) === null || _b === void 0 ? void 0 : _b.startOffset; if (startTag && !endTagOffset && NON_SELF_CLOSING_NATIVE_TAGS.has(to) && template.slice(startTag.startOffset, startTag.endOffset).trimEnd().endsWith('/>')) { const slashPos = templateOffset + startTag.endOffset - 2; if (slashPos >= 0) { recorder.remove(slashPos, 1); recorder.insertRight(templateOffset + startTag.endOffset, `</${to}>`); } } if (endTagOffset) { recorder.remove(endTagOffset + templateOffset + END_TAG_OFFSET, from.length); recorder.insertRight(endTagOffset + templateOffset + END_TAG_OFFSET, to); } recorder.remove((startTagOffset !== null && startTagOffset !== void 0 ? startTagOffset : 0) + templateOffset + START_TAG_OFFSET, from.length); const extraAttrs = addAttributes.filter(Boolean).join(' '); recorder.insertRight((startTagOffset !== null && startTagOffset !== void 0 ? startTagOffset : 0) + templateOffset + START_TAG_OFFSET, extraAttrs ? `${to} ${extraAttrs}` : to); } //# sourceMappingURL=replace-tag.js.map