UNPKG

@progress/kendo-ui

Version:

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

34 lines (28 loc) 1.03 kB
'use strict'; const path = require('path'); const jscodeshift = require(path.resolve(__dirname, '../../../../build-v2/node_modules/jscodeshift')); const { transformModelIdCalls } = require('../_shared.cjs'); const SCRIPT_RE = /(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi; module.exports = function transformer(fileInfo, api) { if (!/\.html?$/i.test(fileInfo.path)) { return undefined; } let changed = false; const result = fileInfo.source.replace(SCRIPT_RE, (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 = transformModelIdCalls(root, j); if (c) { changed = true; return open + root.toSource() + close; } return match; }); return changed ? result : undefined; }; module.exports.aiInstructions = `Rewrites zero-argument .id() method calls to .id property access inside inline <script> blocks in HTML files.`;