frontend/.pnpm-store/v3/files/9c/86a5b05564eb29dc24de84f894d210b6a32a3d755259bdeb15a603a4692cffda940e62a9098f48cbad7de67b4f93f69d01d5cd1c8f157389a8a49f341be7c9

38 lines
1.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.transformMarkup = void 0;
async function transformMarkup({ content, filename }, transformer, options = {}) {
let { markupTagName = 'template' } = options;
markupTagName = markupTagName.toLocaleLowerCase();
const markupPattern = new RegExp(`/<!--[^]*?-->|<${markupTagName}(\\s[^]*?)?(?:>([^]*?)<\\/${markupTagName}>|\\/>)`);
const templateMatch = content.match(markupPattern);
/** If no <template> was found, run the transformer over the whole thing */
if (!templateMatch) {
return transformer({ content, attributes: {}, filename, options });
}
const [fullMatch, attributesStr = '', templateCode] = templateMatch;
/** Transform an attribute string into a key-value object */
const attributes = attributesStr
.split(/\s+/)
.filter(Boolean)
.reduce((acc, attr) => {
const [name, value] = attr.split('=');
// istanbul ignore next
acc[name] = value ? value.replace(/['"]/g, '') : true;
return acc;
}, {});
/** Transform the found template code */
let { code, map, dependencies } = await transformer({
content: templateCode,
attributes,
filename,
options,
});
code =
content.slice(0, templateMatch.index) +
code +
content.slice(templateMatch.index + fullMatch.length);
return { code, map, dependencies };
}
exports.transformMarkup = transformMarkup;