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

Commit77fc29f

Browse files
zhiyuanzmjsxzz
andauthored
feat: upgrade volar support tov2.2.4 (#924)
* chore(deps): update @vue/language-core to 2.2.4* fix: typo* fix: docs* Update pnpm-workspace.yamlCo-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>* chore: pin volar* chore: remove overrides* chore: style* fix: typo---------Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
1 parent4e2ba54 commit77fc29f

File tree

6 files changed

+79
-74
lines changed

6 files changed

+79
-74
lines changed

‎docs/macros/define-prop.md‎

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

4949
```vue twoslash
50-
<script setup>
51-
// @experimentalDefinePropProposal=kevinEdition
52-
// ---cut---
50+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
51+
52+
<script setup lang="ts">
5353
// Declare prop
5454
const count = defineProp('count')
5555
@@ -64,9 +64,9 @@ console.log(count.value)
6464
###With Options
6565

6666
```vue twoslash
67+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
68+
6769
<script setup lang="ts">
68-
// @experimentalDefinePropProposal=kevinEdition
69-
// ---cut---
7070
// Declare prop with options
7171
const count = defineProp('count', {
7272
type: Number,
@@ -80,9 +80,9 @@ const count = defineProp('count', {
8080
###TypeScript
8181

8282
```vue twoslash
83+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
84+
8385
<script setup lang="ts">
84-
// @experimentalDefinePropProposal=kevinEdition
85-
// ---cut---
8686
// Declare prop of type number and infer prop name from variable name
8787
const count = defineProp<number>()
8888
count.value
@@ -95,12 +95,14 @@ disabled.value
9595

9696
###With Reactivity Transform
9797

98-
```ts
98+
```vue twoslash
99+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
100+
101+
<script setup lang="ts">
99102
const foo = $defineProp<string>('foo')
100-
// ^? type: string | undefined
101103
102104
const bar = $(defineProp('bar', { default: 'bar' }))
103-
// ^? type: string
105+
</script>
104106
```
105107

106108
##Johnson's Edition
@@ -118,9 +120,9 @@ const propName = defineProp<T>(defaultValue, required, rest)
118120
###Basic Usage
119121

120122
```vue twoslash
121-
<script setup>
122-
// @experimentalDefinePropProposal=johnsonEdition
123-
// ---cut---
123+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
124+
125+
<script setup lang="ts">
124126
// declare prop `count` with default value `0`
125127
const count = defineProp(0)
126128
@@ -135,9 +137,9 @@ console.log(count.value, disabled.value)
135137
###With Options
136138

137139
```vue twoslash
140+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
141+
138142
<script setup lang="ts">
139-
// @experimentalDefinePropProposal=johnsonEdition
140-
// ---cut---
141143
// Declare prop with options
142144
const count = defineProp(0, false, {
143145
type: Number,
@@ -149,9 +151,9 @@ const count = defineProp(0, false, {
149151
###TypeScript
150152

151153
```vue twoslash
154+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
155+
152156
<script setup lang="ts">
153-
// @experimentalDefinePropProposal=johnsonEdition
154-
// ---cut---
155157
const count = defineProp<number>()
156158
count.value
157159
@@ -163,13 +165,13 @@ disabled.value
163165

164166
###With Reactivity Transform
165167

166-
```vue
168+
```vue twoslash
169+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
170+
167171
<script setup lang="ts">
168172
const foo = $defineProp<number>()
169-
// ^? type: number | undefined
170173
171174
const bar = $(defineProp(0, true))
172-
// ^? type: number
173175
</script>
174176
```
175177

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

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

3535
```vue twoslash
36-
<script setup>
37-
// @experimentalDefinePropProposal=kevinEdition
38-
// ---cut---
36+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
37+
38+
<script setup lang="ts">
3939
// 声明 prop
4040
const count = defineProp('count')
4141
@@ -50,9 +50,9 @@ console.log(count.value)
5050
###选项
5151

5252
```vue twoslash
53+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
54+
5355
<script setup lang="ts">
54-
// @experimentalDefinePropProposal=kevinEdition
55-
// ---cut---
5656
// 使用选项声明 prop
5757
const count = defineProp('count', {
5858
type: Number,
@@ -66,9 +66,9 @@ const count = defineProp('count', {
6666
###TypeScript
6767

6868
```vue twoslash
69+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
70+
6971
<script setup lang="ts">
70-
// @experimentalDefinePropProposal=kevinEdition
71-
// ---cut---
7272
// 使用类型为 number 的 prop 声明,并从变量名中推断 prop 的名称
7373
const count = defineProp<number>()
7474
count.value
@@ -81,11 +81,14 @@ disabled.value
8181

8282
###响应性语法糖
8383

84-
```ts
84+
```vue twoslash
85+
<!-- @experimentalDefinePropProposal "kevinEdition" -->
86+
87+
<script setup lang="ts">
8588
const foo = $defineProp<string>('foo')
86-
// ^? type: string | undefined
89+
8790
const bar = $(defineProp('bar', { default: 'bar' }))
88-
// ^? type: string
91+
</script>
8992
```
9093

9194
##Johnson 的版本
@@ -103,9 +106,9 @@ const propName = defineProp<T>(defaultValue, required, rest)
103106
###基本用法
104107

105108
```vue twoslash
106-
<script setup>
107-
// @experimentalDefinePropProposal=johnsonEdition
108-
// ---cut---
109+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
110+
111+
<script setup lang="ts">
109112
// 声明带有默认值 `0` 的 prop `count`
110113
const count = defineProp(0)
111114
@@ -120,9 +123,9 @@ console.log(count.value, disabled.value)
120123
###选项
121124

122125
```vue twoslash
126+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
127+
123128
<script setup lang="ts">
124-
// @experimentalDefinePropProposal=johnsonEdition
125-
// ---cut---
126129
// 使用选项声明属性
127130
const count = defineProp(0, false, {
128131
type: Number,
@@ -134,9 +137,9 @@ const count = defineProp(0, false, {
134137
###TypeScript
135138

136139
```vue twoslash
140+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
141+
137142
<script setup lang="ts">
138-
// @experimentalDefinePropProposal=johnsonEdition
139-
// ---cut---
140143
const count = defineProp<number>()
141144
count.value
142145
@@ -148,13 +151,13 @@ disabled.value
148151

149152
###响应性语法糖
150153

151-
```vue
154+
```vue twoslash
155+
<!-- @experimentalDefinePropProposal "johnsonEdition" -->
156+
152157
<script setup lang="ts">
153158
const foo = $defineProp<number>()
154-
// ^? type: number | undefined
155159
156160
const bar = $(defineProp(0, true))
157-
// ^? type: number
158161
</script>
159162
```
160163

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
"@shikijs/core":"catalog:",
9898
"@shikijs/transformers":"catalog:",
9999
"@shikijs/types":"catalog:",
100-
"@vue/language-core":"catalog:",
101100
"is-core-module":"npm:@no-shims/is-core-module",
102101
"shiki":"catalog:",
103102
"smartwrap":"npm:@no-shims/smartwrap"

‎packages/volar/src/common.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ export function addProps(
1717
decl:Code[],
1818
vueLibName:string,
1919
):true|undefined{
20-
if(
21-
!decl.length||
22-
codes.toString().includes('{} as __VLS_TypePropsToOption<')
23-
)
20+
constcodeString=codes.toString()
21+
if(!decl.length||codeString.includes('{} as __VLS_TypePropsToOption<'))
2422
return
2523

2624
replace(
@@ -34,10 +32,12 @@ export function addProps(
3432
REGEX_DEFINE_COMPONENT,
3533
'props: {} as __VLS_TypePropsToOption<__VLS_PublicProps>,\n',
3634
)
37-
codes.push(
38-
`type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;\n`,
39-
`type __VLS_TypePropsToOption<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${vueLibName}').PropType<__VLS_NonUndefinedable<T[K]>> } : { type: import('${vueLibName}').PropType<T[K]>, required: true } };\n`,
40-
)
35+
if(!codeString.includes('type __VLS_NonUndefinedable')){
36+
codes.push(
37+
`type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;\n`,
38+
`type __VLS_TypePropsToOption<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? { type: import('${vueLibName}').PropType<__VLS_NonUndefinedable<T[K]>> } : { type: import('${vueLibName}').PropType<T[K]>, required: true } };\n`,
39+
)
40+
}
4141
returntrue
4242
}
4343

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp