UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

89 lines (77 loc) 2.24 kB
'use strict'; const badgeConfigMappings = { 'appearance': 'shape', 'badgeStyle': 'fill', 'color': 'themeColor', 'look': 'fill', 'placement': 'position', 'position': 'align', 'value': 'text', }; const badgeMethodMappings = { 'value': 'text', }; function transformBadgeConfig(root, j) { let changed = false; root.find(j.CallExpression) .filter(path => { const callee = path.value.callee; const isBadgeCall = (j.MemberExpression.check(callee) && callee.property.name === 'kendoBadge') || (j.Identifier.check(callee) && callee.name === 'kendoBadge'); return isBadgeCall; }) .forEach(path => { const args = path.value.arguments; args.forEach(arg => { if (j.ObjectExpression.check(arg)) { arg.properties.forEach(prop => { if (j.Property.check(prop)) { const key = prop.key.name || prop.key.value; if (badgeConfigMappings[key]) { prop.key.name = badgeConfigMappings[key]; changed = true; } } }); } }); }); return changed; } function transformBadgeMethods(root, j) { let changed = false; root.find(j.CallExpression) .filter(path => { const callee = path.value.callee; return j.MemberExpression.check(callee) && callee.property.name === 'value'; }) .forEach(path => { const obj = path.value.callee.object; let isKendoBadge = false; if (j.CallExpression.check(obj) && j.MemberExpression.check(obj.callee)) { if (obj.callee.property.name === 'kendoBadge') { isKendoBadge = true; } else if (obj.callee.property.name === 'data') { const args = obj.arguments || []; isKendoBadge = args.some(a => (j.StringLiteral.check(a) && a.value === 'kendoBadge') || (j.Literal.check(a) && a.value === 'kendoBadge') ); } } if (isKendoBadge) { path.value.callee.property.name = 'text'; changed = true; } }); return changed; } module.exports = { badgeConfigMappings, badgeMethodMappings, transformBadgeConfig, transformBadgeMethods, };