@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
29 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addHTMLCommentTags = void 0;
const insert_todo_1 = require("../../../utils/insert-todo");
const elements_1 = require("../../../utils/templates/elements");
const template_resource_1 = require("../../../utils/templates/template-resource");
function addHTMLCommentTags({ resource, recorder, fileSystem, data, }) {
const template = (0, template_resource_1.getTemplateFromTemplateResource)(resource, fileSystem);
const templateOffset = (0, template_resource_1.getTemplateOffset)(resource);
data.forEach(({ comment, tag, withAttrs, pattern, filterFn }) => {
if (pattern && template.match(pattern)) {
recorder.insertRight(templateOffset && templateOffset + 1, `<!-- ${insert_todo_1.TODO_MARK} ${comment} -->\n`);
}
if (!tag || !withAttrs) {
return;
}
const elementStartOffsets = [
...(0, elements_1.findElementsWithAttributeOnTag)(template, withAttrs, [tag], filterFn),
...(withAttrs.length
? (0, elements_1.findElementsWithAttributeOnTag)(template, withAttrs.map((attr) => `[${attr}]`), [tag], filterFn)
: []),
].map(({ sourceCodeLocation }) => ((sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startOffset) || 0) + templateOffset);
elementStartOffsets.forEach((offset) => {
recorder.insertLeft(offset, `<!-- ${insert_todo_1.TODO_MARK} ${comment} -->\n`);
});
});
}
exports.addHTMLCommentTags = addHTMLCommentTags;
//# sourceMappingURL=template-comments.js.map