UNPKG

@progress/kendo-ui

Version:

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

53 lines (42 loc) 1.21 kB
'use strict'; const { applyTreeViewCheckboxWrapperRename, applyTreeViewClassStrips, transformStringLiterals, transformTemplateLiterals, } = require('../_shared.cjs'); function applyAll(str) { return applyTreeViewClassStrips(applyTreeViewCheckboxWrapperRename(str)); } function transformScriptContent(content, j) { let root; try { root = j(content); } catch { return content; } const c1 = transformStringLiterals(root, j, applyAll); const c2 = transformTemplateLiterals(root, j, applyAll); if (!c1 && !c2) { return content; } return root.toSource({ quote: 'single' }); } const SCRIPT_RE = /(<script(?![^>]*\bsrc\b)[^>]*>)([\s\S]*?)(<\/script>)/gi; module.exports = function transformer(fileInfo, api) { if (!/\.html?$/i.test(fileInfo.path)) { return undefined; } const j = api.jscodeshift; let source = fileInfo.source; let changed = false; source = source.replace(SCRIPT_RE, (match, open, content, close) => { const transformed = transformScriptContent(content, j); if (transformed !== content) { changed = true; return open + transformed + close; } return match; }); return changed ? source : undefined; };