@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
33 lines (28 loc) • 1.02 kB
JavaScript
;
const path = require('path');
const jscodeshift = require(path.resolve(__dirname, '../../../../build-v2/node_modules/jscodeshift'));
const { transformScrollThresholdFix } = require('../_shared.cjs');
module.exports = function transformer(fileInfo, api) {
if (!/\.html?$/i.test(fileInfo.path)) {
return undefined;
}
const scriptBlockRe = /(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi;
let changed = false;
const result = fileInfo.source.replace(scriptBlockRe, (match, open, body, close) => {
const j = (api && api.jscodeshift) ? api.jscodeshift : jscodeshift.withParser('babel');
let root;
try {
root = j(body);
} catch (e) {
return match;
}
const c = transformScrollThresholdFix(root, j);
if (c) {
changed = true;
return open + root.toSource() + close;
}
return match;
});
return changed ? result : undefined;
};
module.exports.aiInstructions = `Fixes the scrollTreshold typo in inline <script> blocks inside HTML files.`;