Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98263c6

Browse files
committed
feat: add booleanProp into macros plugin
1 parent0463655 commit98263c6

File tree

13 files changed

+134
-46
lines changed

13 files changed

+134
-46
lines changed

‎.changeset/sharp-brooms-deny.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@vue-macros/boolean-prop':minor
3+
'unplugin-vue-macros':minor
4+
---
5+
6+
feat: add booleanProp into macros plugin

‎docs/guide/configurations.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All features are enabled by default except the following.
1212
-`exportProps`
1313
-`exportRender`
1414
-`setupSFC`
15+
-`booleanProp`
1516

1617
You can disable them by setting the option to`false`.
1718

‎packages/boolean-prop/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"@vue/compiler-core":"^3.3.4"
5050
},
5151
"devDependencies": {
52-
"@vue/compiler-sfc":"^3.3.4"
52+
"@vue/compiler-sfc":"^3.3.4",
53+
"rollup":"^3.28.1"
5354
},
5455
"engines": {
5556
"node":">=16.14.0"

‎packages/boolean-prop/src/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export*from'./core'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export*from'./transformer'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import{
2+
typeConstantTypes,
3+
typeNodeTransform,
4+
typeNodeTypes,
5+
}from'@vue/compiler-core'
6+
7+
exportinterfaceOptions{
8+
// empty
9+
}
10+
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- not be used by now
12+
exportfunctiontransformBooleanProp(_options:Options={}):NodeTransform{
13+
return(node)=>{
14+
if(node.type!==(1satisfiesNodeTypes.ELEMENT))return
15+
for(const[i,prop]ofnode.props.entries()){
16+
if(
17+
prop.type!==(6satisfiesNodeTypes.ATTRIBUTE)||
18+
prop.value!==undefined
19+
)
20+
continue
21+
node.props[i]={
22+
type:7satisfiesNodeTypes.DIRECTIVE,
23+
name:'bind',
24+
arg:{
25+
type:4satisfiesNodeTypes.SIMPLE_EXPRESSION,
26+
constType:3satisfiesConstantTypes.CAN_STRINGIFY,
27+
content:'checked',
28+
isStatic:true,
29+
loc:prop.loc,
30+
},
31+
exp:{
32+
type:4satisfiesNodeTypes.SIMPLE_EXPRESSION,
33+
constType:3satisfiesConstantTypes.CAN_STRINGIFY,
34+
content:'true',
35+
isStatic:false,
36+
loc:prop.loc,
37+
},
38+
loc:prop.loc,
39+
modifiers:[],
40+
}
41+
}
42+
}
43+
}

‎packages/boolean-prop/src/index.ts‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
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'}
66

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
3523
}
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+
},
3733
}
3834
}
35+
36+
exportdefault{
37+
rollup,
38+
vite:rollupas(options?:Options)=>VitePlugin,
39+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importunpluginfrom'.'
2+
3+
exportdefaultunplugin.rollup

‎packages/boolean-prop/src/vite.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importunpluginfrom'.'
2+
3+
exportdefaultunplugin.vite

‎packages/boolean-prop/tests/fixtures.test.ts‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ import {
66
rollupBuild,
77
testFixtures,
88
}from'@vue-macros/test-utils'
9-
import{transformBooleanProp}from'../src/index'
9+
importBooleanPropfrom'../src/vite'
1010

1111
describe('fixtures',async()=>{
1212
awaittestFixtures(
1313
'tests/fixtures/*.{vue,[jt]s?(x)}',
1414
(args,id)=>
1515
rollupBuild(id,[
16-
RollupVue({
17-
template:{
18-
compilerOptions:{
19-
nodeTransforms:[transformBooleanProp()],
20-
},
21-
},
22-
}),
16+
BooleanProp(),
17+
RollupVue(),
2318
RollupEsbuildPlugin({
2419
target:'esnext',
2520
}),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp