@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
35 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateAsyncPipes = migrateAsyncPipes;
const template_resource_1 = require("../../../../utils/templates/template-resource");
const SIGNAL_BASED_PIPES = [
'tuiAmount',
'tuiDecimal',
'tuiFormatNumber',
'tuiSortCountries',
];
/**
* Matches `| tuiPipeName` (with optional args) followed by `| async`.
*
* Breakdown:
* \|\s*(tuiAmount|tuiDecimal|tuiFormatNumber) — pipe name
* (?:[^|]*[^|\s])? — optional arguments (greedy, ends on non-whitespace)
* \s*\|\s*async — trailing `| async` to remove
*
* `[^|]*[^|\s]` is backtracking-safe: `[^|\s]` anchors the boundary so
* the greedy `[^|]*` cannot exchange trailing whitespace with `\s*`.
*/
const PIPE_ASYNC_REGEX = new RegExp(String.raw `(\|\s*(?:${SIGNAL_BASED_PIPES.join('|')})(?:[^|]*[^|\s])?)\s*\|\s*async`, 'gi');
function migrateAsyncPipes({ resource, recorder, fileSystem, }) {
const template = (0, template_resource_1.getTemplateFromTemplateResource)(resource, fileSystem);
const templateOffset = (0, template_resource_1.getTemplateOffset)(resource);
let match;
while ((match = PIPE_ASYNC_REGEX.exec(template)) !== null) {
const fullMatchStart = match.index;
const fullMatchLength = match[0].length;
const pipeWithoutAsync = match[1];
recorder.remove(templateOffset + fullMatchStart, fullMatchLength);
recorder.insertRight(templateOffset + fullMatchStart, pipeWithoutAsync !== null && pipeWithoutAsync !== void 0 ? pipeWithoutAsync : '');
}
}
//# sourceMappingURL=migrate-async-pipes.js.map