Skip to content

Commit d2b253b

Browse files
authored
feat(define-prop): migrate defineProp from @vue/language-tools (#961)
1 parent 8b4ce97 commit d2b253b

File tree

19 files changed

+139
-169
lines changed

19 files changed

+139
-169
lines changed

docs/macros/define-prop.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ const propName = defineProp<T>()
4747
### Basic Usage
4848

4949
```vue twoslash
50-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
51-
5250
<script setup lang="ts">
5351
// Declare prop
5452
const count = defineProp('count')
@@ -64,8 +62,6 @@ console.log(count.value)
6462
### With Options
6563

6664
```vue twoslash
67-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
68-
6965
<script setup lang="ts">
7066
// Declare prop with options
7167
const count = defineProp('count', {
@@ -80,8 +76,6 @@ const count = defineProp('count', {
8076
### TypeScript
8177

8278
```vue twoslash
83-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
84-
8579
<script setup lang="ts">
8680
// Declare prop of type number and infer prop name from variable name
8781
const count = defineProp<number>()
@@ -96,8 +90,6 @@ disabled.value
9690
### With Reactivity Transform
9791

9892
```vue twoslash
99-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
100-
10193
<script setup lang="ts">
10294
const foo = $defineProp<string>('foo')
10395
@@ -119,9 +111,7 @@ const propName = defineProp<T>(defaultValue, required, rest)
119111

120112
### Basic Usage
121113

122-
```vue twoslash
123-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
124-
114+
```vue
125115
<script setup lang="ts">
126116
// declare prop `count` with default value `0`
127117
const count = defineProp(0)
@@ -136,9 +126,7 @@ console.log(count.value, disabled.value)
136126

137127
### With Options
138128

139-
```vue twoslash
140-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
141-
129+
```vue
142130
<script setup lang="ts">
143131
// Declare prop with options
144132
const count = defineProp(0, false, {
@@ -150,9 +138,7 @@ const count = defineProp(0, false, {
150138

151139
### TypeScript
152140

153-
```vue twoslash
154-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
155-
141+
```vue
156142
<script setup lang="ts">
157143
const count = defineProp<number>()
158144
count.value
@@ -165,9 +151,7 @@ disabled.value
165151

166152
### With Reactivity Transform
167153

168-
```vue twoslash
169-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
170-
154+
```vue
171155
<script setup lang="ts">
172156
const foo = $defineProp<number>()
173157
@@ -177,15 +161,16 @@ const bar = $(defineProp(0, true))
177161

178162
### Volar Configuration
179163

180-
```jsonc {3,5} [tsconfig.json]
164+
```jsonc {3,7} [tsconfig.json]
181165
{
182166
"vueCompilerOptions": {
183167
"plugins": ["vue-macros/volar"],
184168
"vueMacros": {
185-
"defineProp": true,
169+
"defineProp": {
170+
// "kevinEdition" | "johnsonEdition"
171+
"edition": "kevinEdition",
172+
},
186173
},
187-
// "kevinEdition" | "johnsonEdition" | false
188-
"experimentalDefinePropProposal": "kevinEdition",
189174
},
190175
}
191176
```

docs/zh-CN/macros/define-prop.md

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const propName = defineProp<T>()
3333
### 基本用法
3434

3535
```vue twoslash
36-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
37-
3836
<script setup lang="ts">
3937
// 声明 prop
4038
const count = defineProp('count')
@@ -50,8 +48,6 @@ console.log(count.value)
5048
### 选项
5149

5250
```vue twoslash
53-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
54-
5551
<script setup lang="ts">
5652
// 使用选项声明 prop
5753
const count = defineProp('count', {
@@ -66,8 +62,6 @@ const count = defineProp('count', {
6662
### TypeScript
6763

6864
```vue twoslash
69-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
70-
7165
<script setup lang="ts">
7266
// 使用类型为 number 的 prop 声明,并从变量名中推断 prop 的名称
7367
const count = defineProp<number>()
@@ -82,8 +76,6 @@ disabled.value
8276
### 响应性语法糖
8377

8478
```vue twoslash
85-
<!-- @experimentalDefinePropProposal "kevinEdition" -->
86-
8779
<script setup lang="ts">
8880
const foo = $defineProp<string>('foo')
8981
@@ -105,9 +97,7 @@ const propName = defineProp<T>(defaultValue, required, rest)
10597

10698
### 基本用法
10799

108-
```vue twoslash
109-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
110-
100+
```vue
111101
<script setup lang="ts">
112102
// 声明带有默认值 `0` 的 prop `count`
113103
const count = defineProp(0)
@@ -122,9 +112,7 @@ console.log(count.value, disabled.value)
122112

123113
### 选项
124114

125-
```vue twoslash
126-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
127-
115+
```vue
128116
<script setup lang="ts">
129117
// 使用选项声明属性
130118
const count = defineProp(0, false, {
@@ -136,9 +124,7 @@ const count = defineProp(0, false, {
136124

137125
### TypeScript
138126

139-
```vue twoslash
140-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
141-
127+
```vue
142128
<script setup lang="ts">
143129
const count = defineProp<number>()
144130
count.value
@@ -151,9 +137,7 @@ disabled.value
151137

152138
### 响应性语法糖
153139

154-
```vue twoslash
155-
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
156-
140+
```vue
157141
<script setup lang="ts">
158142
const foo = $defineProp<number>()
159143
@@ -163,15 +147,16 @@ const bar = $(defineProp(0, true))
163147

164148
## Volar 配置
165149

166-
```jsonc {3,5} [tsconfig.json]
150+
```jsonc {3,7} [tsconfig.json]
167151
{
168152
"vueCompilerOptions": {
169153
"plugins": ["vue-macros/volar"],
170154
"vueMacros": {
171-
"defineProp": true,
155+
"defineProp": {
156+
// "kevinEdition" | "johnsonEdition"
157+
"edition": "kevinEdition",
158+
},
172159
},
173-
// "kevinEdition" | "johnsonEdition" | false
174-
"experimentalDefinePropProposal": "kevinEdition",
175160
},
176161
}
177162
```

packages/define-prop/macros-global.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/define-prop/macros-johnson.d.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/define-prop/macros.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/define-prop/package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"author": "三咲智子 Kevin Deng <sxzz@sxzz.moe>",
2727
"funding": "https://github.com/sponsors/vue-macros",
2828
"files": [
29-
"*.d.ts",
3029
"dist"
3130
],
3231
"main": "./dist/index.js",
@@ -65,10 +64,7 @@
6564
"dev": "./src/webpack.ts",
6665
"default": "./dist/webpack.js"
6766
},
68-
"./*": [
69-
"./*",
70-
"./*.d.ts"
71-
]
67+
"./*": "./*"
7268
},
7369
"typesVersions": {
7470
"*": {
@@ -89,10 +85,7 @@
8985
"./rspack": "./dist/rspack.js",
9086
"./vite": "./dist/vite.js",
9187
"./webpack": "./dist/webpack.js",
92-
"./*": [
93-
"./*",
94-
"./*.d.ts"
95-
]
88+
"./*": "./*"
9689
},
9790
"tag": "next"
9891
},

packages/define-prop/tests/__snapshots__/fixtures.test.ts.snap

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const __MACROS_props = defineProps({
1515
1616
import { toRef as __MACROS_toRef } from "vue";
1717
import { expectTypeOf } from 'expect-type'
18-
import type { ComputedRef } from 'vue'
19-
import { defineProp } from '../../../macros-johnson'
18+
import { type ComputedRef } from 'vue'
2019
2120
// defineProp()
2221
const qux = __MACROS_toRef(__props, "qux")
@@ -72,7 +71,6 @@ import { toRef as __MACROS_toRef } from "vue";
7271
import { expectTypeOf } from 'expect-type'
7372
import type { ComputedRef } from 'vue'
7473
import type { Qux } from '../types'
75-
import { defineProp } from '../../../macros'
7674
7775
// defineProp(prop_name)
7876
const foo = __MACROS_toRef(__props, "foo")

packages/define-prop/tests/fixtures/johnson-edition/basic.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import { expectTypeOf } from 'expect-type'
3-
import type { ComputedRef } from 'vue'
4-
import { defineProp } from '../../../macros-johnson'
3+
import { type ComputedRef } from 'vue'
54
65
// defineProp()
76
const qux = defineProp<string>()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../../../../tsconfig.fixture.json",
3+
"include": ["./*"],
4+
"vueCompilerOptions": {
5+
"vueMacros": {
6+
"defineProp": {
7+
"edition": "johnsonEdition"
8+
}
9+
}
10+
},
11+
"compilerOptions": {
12+
"composite": true,
13+
"tsBuildInfoFile": "./fixture.tsbuildinfo"
14+
}
15+
}

packages/define-prop/tests/fixtures/kevin-edition/basic.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { expectTypeOf } from 'expect-type'
33
import type { ComputedRef } from 'vue'
44
import type { Qux } from '../types'
5-
import { defineProp } from '../../../macros'
65
76
// defineProp(prop_name)
87
const foo = defineProp<string>('foo')

0 commit comments

Comments
 (0)