cursor-pointer-loader
Version:
一个通过html标签属性快速添加指针移入效果的webpack加载器(A loader that quickly adds cursor pointer effects via html tag attributes)
2 lines (1 loc) • 1.1 kB
JavaScript
import e from"@babel/parser";import t from"@babel/traverse";import r from"@babel/core";import n from"@babel/generator";function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i,s;var a=o(function(){if(s)return i;s=1;const o=e,a=t.default,{types:u}=r,p=n.default;return i=function(e){if(!e.includes("__cursorPointer"))return e;const t=o.parse(e,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],parserOpts:{allowReturnOutsideFunction:!0}});a(t,{JSXElement(e){if(!!e.node.openingElement?.attributes?.find(e=>"__cursorPointer"==e.name.name)){const t=u.objectExpression([u.objectProperty(u.identifier("cursor"),u.stringLiteral("pointer"))]),r=u.jsxAttribute(u.jsxIdentifier("style"),u.jSXExpressionContainer(t)),n=e.node.openingElement.attributes.find(e=>"style"==e.name.name);n?n.value.expression.properties.push(t.properties[0]):e.node.openingElement.attributes.push(r),e.node.openingElement.attributes=e.node.openingElement.attributes.filter(e=>"__cursorPointer"!=e?.name.name)}}});return p(t,{},e).code}}());export{a as default};