@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
41 lines • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateFormatPhonePipe = migrateFormatPhonePipe;
const insert_todo_1 = require("../../../../utils/insert-todo");
const template_resource_1 = require("../../../../utils/templates/template-resource");
const PIPE_RENAME_REGEX = /(\|\s*)tuiFormatPhone\b/g;
const TODO_COMMENT_WITH_ARGS = `<!-- ${insert_todo_1.TODO_MARK} \`tuiFormatPhone\` pipe was replaced by \`maskito\` pipe. Replace its arguments with \`maskitoPhone({countryIsoCode, metadata})\` from '@maskito/phone' (note: countryIsoCode is ISO format e.g. 'US', not '+1'). See: https://taiga-ui.dev/components/input-phone-international#phone-format-helpers -->`;
const TODO_COMMENT_NO_ARGS = `<!-- ${insert_todo_1.TODO_MARK} \`tuiFormatPhone\` pipe was replaced by \`maskito\` pipe. Add \`maskitoPhone({countryIsoCode, metadata})\` from '@maskito/phone' as argument. See: https://taiga-ui.dev/components/input-phone-international#phone-format-helpers -->`;
function migrateFormatPhonePipe({ resource, recorder, fileSystem, }) {
var _a, _b;
const template = (0, template_resource_1.getTemplateFromTemplateResource)(resource, fileSystem);
const templateOffset = (0, template_resource_1.getTemplateOffset)(resource);
// For inline templates, getText() includes the opening quote character,
// so offset 0 points to the quote itself (in TS territory).
// We shift by 1 to insert inside the template string.
const isInlineTemplate = 'template' in resource;
const todoInsertedAtLines = new Set();
let match;
while ((match = PIPE_RENAME_REGEX.exec(template)) !== null) {
const pipeNameStart = match.index + ((_b = (_a = match[1]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);
const afterPipeName = template.slice(pipeNameStart + 'tuiFormatPhone'.length);
const hasArgs = /^\s*:/.test(afterPipeName);
recorder.remove(templateOffset + pipeNameStart, 'tuiFormatPhone'.length);
recorder.insertRight(templateOffset + pipeNameStart, 'maskito');
const lineStart = template.lastIndexOf('\n', match.index) + 1;
if (!todoInsertedAtLines.has(lineStart)) {
todoInsertedAtLines.add(lineStart);
const todoComment = hasArgs ? TODO_COMMENT_WITH_ARGS : TODO_COMMENT_NO_ARGS;
if (isInlineTemplate && lineStart === 0) {
// The template string includes the opening quote (offset 0 = quote char).
// Insert after the quote (position 1), without a trailing newline —
// single/double-quoted JS strings cannot contain literal newlines.
recorder.insertLeft(templateOffset + 1, `${todoComment} `);
}
else {
recorder.insertLeft(templateOffset + lineStart, `${todoComment}\n`);
}
}
}
}
//# sourceMappingURL=migrate-format-phone-pipe.js.map