UNPKG

@progress/kendo-ui

Version:

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

65 lines (54 loc) 1.73 kB
'use strict'; function transformCheckboxTemplate(root, j) { let changed = false; root.find(j.CallExpression) .filter(path => { const callee = path.value.callee; return ( j.MemberExpression.check(callee) && callee.property.name === 'kendoTreeView' ); }) .forEach(path => { const args = path.value.arguments; args.forEach(arg => { if (!j.ObjectExpression.check(arg)) { return; } const propIndex = arg.properties.findIndex(prop => j.Property.check(prop) && (prop.key.name === 'checkboxTemplate' || prop.key.value === 'checkboxTemplate') ); if (propIndex === -1) { return; } const prop = arg.properties[propIndex]; const templateValue = prop.value; const existingCheckboxes = arg.properties.find(p => j.Property.check(p) && (p.key.name === 'checkboxes' || p.key.value === 'checkboxes') ); if (existingCheckboxes && j.ObjectExpression.check(existingCheckboxes.value)) { existingCheckboxes.value.properties.push( j.property('init', j.identifier('template'), templateValue) ); } else { const checkboxesObj = j.objectExpression([ j.property('init', j.identifier('template'), templateValue) ]); arg.properties.splice(propIndex, 0, j.property('init', j.identifier('checkboxes'), checkboxesObj) ); } arg.properties.splice( arg.properties.indexOf(prop), 1 ); changed = true; }); }); return changed; } module.exports = { transformCheckboxTemplate, };