@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
59 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateCloseable = migrateCloseable;
const ng_morph_1 = require("ng-morph");
const constants_1 = require("../../../constants");
const is_service_method_call_1 = require("../../../utils/is-service-method-call");
const FACTORY_NAME = 'tuiDialog';
const SERVICE_NAMES = [
'TuiDialogService',
'TuiAlertService',
'TuiNotificationService',
'TuiSheetDialogService',
];
const METHOD_NAME = 'open';
function migrateCloseable(_tree, _options) {
(0, ng_morph_1.getSourceFiles)(constants_1.ALL_TS_FILES).forEach((sourceFile) => {
migrateSourceFile(sourceFile);
});
}
function migrateSourceFile(sourceFile) {
const calls = sourceFile.getDescendantsOfKind(ng_morph_1.SyntaxKind.CallExpression);
calls.forEach((call) => {
SERVICE_NAMES.forEach((serviceName) => {
if (call.getExpression().getText() !== FACTORY_NAME &&
!(0, is_service_method_call_1.isServiceMethodCall)(call, serviceName, METHOD_NAME)) {
return;
}
const [, options] = call.getArguments();
if (!options || !ng_morph_1.Node.isObjectLiteralExpression(options)) {
return;
}
renameCloseableKey(options);
});
});
}
function renameCloseableKey(obj) {
obj.getProperties().forEach((prop) => {
if (ng_morph_1.Node.isPropertyAssignment(prop)) {
const nameNode = prop.getNameNode();
if (ng_morph_1.Node.isIdentifier(nameNode) && nameNode.getText() === 'closeable') {
prop.rename('closable');
return;
}
if (ng_morph_1.Node.isStringLiteral(nameNode) &&
nameNode.getLiteralText() === 'closeable') {
const quote = nameNode.getQuoteKind();
nameNode.replaceWithText(`${quote}closable${quote}`);
}
return;
}
if (ng_morph_1.Node.isShorthandPropertyAssignment(prop)) {
const name = prop.getName();
if (name === 'closeable') {
prop.replaceWithText('closable: closeable');
}
}
});
}
//# sourceMappingURL=migrate-closeable.js.map