|
1 | | -import{ |
2 | | -typeConstantTypes, |
3 | | -typeNodeTransform, |
4 | | -typeNodeTypes, |
5 | | -}from'@vue/compiler-core' |
| 1 | +import{typePlugin}from'rollup' |
| 2 | +import{typePluginasVitePlugin}from'vite' |
| 3 | +import{typeVuePluginApi,getVuePluginApi}from'@vue-macros/common' |
| 4 | +import{typeOptions,transformBooleanProp}from'./core/index' |
| 5 | +import{generatePluginName}from'#macros' assert{type:'macro'} |
6 | 6 |
|
7 | | -exportfunctiontransformBooleanProp():NodeTransform{ |
8 | | -return(node)=>{ |
9 | | -if(node.type!==(1satisfiesNodeTypes.ELEMENT))return |
10 | | -for(const[i,prop]ofnode.props.entries()){ |
11 | | -if( |
12 | | -prop.type!==(6satisfiesNodeTypes.ATTRIBUTE)|| |
13 | | -prop.value!==undefined |
14 | | -) |
15 | | -continue |
16 | | -node.props[i]={ |
17 | | -type:7satisfiesNodeTypes.DIRECTIVE, |
18 | | -name:'bind', |
19 | | -arg:{ |
20 | | -type:4satisfiesNodeTypes.SIMPLE_EXPRESSION, |
21 | | -constType:3satisfiesConstantTypes.CAN_STRINGIFY, |
22 | | -content:'checked', |
23 | | -isStatic:true, |
24 | | -loc:prop.loc, |
25 | | -}, |
26 | | -exp:{ |
27 | | -type:4satisfiesNodeTypes.SIMPLE_EXPRESSION, |
28 | | -constType:3satisfiesConstantTypes.CAN_STRINGIFY, |
29 | | -content:'true', |
30 | | -isStatic:false, |
31 | | -loc:prop.loc, |
32 | | -}, |
33 | | -loc:prop.loc, |
34 | | -modifiers:[], |
| 7 | +// legacy export |
| 8 | +export*from'./api' |
| 9 | + |
| 10 | +constname=generatePluginName() |
| 11 | + |
| 12 | +functionrollup(options:Options={}):Plugin{ |
| 13 | +return{ |
| 14 | + name, |
| 15 | +buildStart(rollupOpts){ |
| 16 | +letapi:VuePluginApi |
| 17 | + |
| 18 | +try{ |
| 19 | +api=getVuePluginApi(rollupOpts) |
| 20 | +}catch(error:any){ |
| 21 | +this.warn(error) |
| 22 | +return |
35 | 23 | } |
36 | | -} |
| 24 | + |
| 25 | +api.options.template||={} |
| 26 | +api.options.template.compilerOptions||={} |
| 27 | +api.options.template.compilerOptions.nodeTransforms||=[] |
| 28 | + |
| 29 | +api.options.template.compilerOptions.nodeTransforms.push( |
| 30 | +transformBooleanProp(options) |
| 31 | +) |
| 32 | +}, |
37 | 33 | } |
38 | 34 | } |
| 35 | + |
| 36 | +exportdefault{ |
| 37 | + rollup, |
| 38 | +vite:rollupas(options?:Options)=>VitePlugin, |
| 39 | +} |