Skip to content

Commit b821618

Browse files
committed
feat(define-props): support vue 2
1 parent 6d50584 commit b821618

File tree

11 files changed

+60
-3
lines changed

11 files changed

+60
-3
lines changed

.changeset/modern-bottles-pretend.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@vue-macros/define-props': patch
3+
'unplugin-vue-macros': patch
4+
---
5+
6+
support vue 2

docs/macros/define-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See also [Vue issue](https://github.com/vuejs/core/issues/6876), [Reactivity Tra
1010
| :----------------: | :----------------: |
1111
| Vue 3 | :white_check_mark: |
1212
| Nuxt 3 | :white_check_mark: |
13-
| Vue 2 | :x: |
13+
| Vue 2 | :white_check_mark: |
1414
| TypeScript / Volar | :white_check_mark: |
1515

1616
::: warning

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"vite": "^4.0.4",
4949
"vitest": "^0.27.1",
5050
"vue": "^3.2.45",
51+
"vue2": "npm:vue@^2.7.14",
5152
"webpack": "^5.75.0"
5253
},
5354
"engines": {

packages/define-props/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"dev": "DEV=1 tsup"
6868
},
6969
"peerDependencies": {
70-
"vue": "^3.2.25"
70+
"vue": "^2.7.0 || ^3.2.25"
7171
},
7272
"dependencies": {
7373
"@rollup/pluginutils": "^5.0.2",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { $defineProps as _$defineProps } from './macros'
2+
3+
declare global {
4+
const $defineProps: typeof _$defineProps
5+
}
6+
7+
export {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type {
2+
ComponentObjectPropsOptions,
3+
ExtractPropTypes,
4+
} from 'vue/types/v3-component-props'
5+
// @ts-expect-error
6+
import type { RefValue } from '@vue-macros/reactivity-transform-vue2/macros'
7+
8+
export type RefValueObject<T> = {
9+
[K in keyof T]: RefValue<T[K]>
10+
}
11+
12+
export declare function $defineProps<PropNames extends string = string>(
13+
props: PropNames[]
14+
): Readonly<{
15+
[key in PropNames]?: any
16+
}>
17+
export declare function $defineProps<
18+
PP extends ComponentObjectPropsOptions = ComponentObjectPropsOptions
19+
>(props: PP): RefValueObject<ExtractPropTypes<PP>>
20+
export declare function $defineProps<TypeProps>(): RefValueObject<TypeProps>

packages/macros/vue2-macros-global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="@vue-macros/define-model/macros-global" />
22
/// <reference types="unplugin-vue-define-options/macros-global" />
3+
/// <reference types="@vue-macros/define-props/macros-global" />
34
/// <reference types="@vue-macros/define-render/vue2-macros-global" />
45
/// <reference types="@vue-macros/define-slots/macros-global" />
56
/// <reference types="@vue-macros/reactivity-transform-vue2/macros-global" />

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"files": [],
33
"references": [
44
{ "path": "./tsconfig.lib.json" },
5+
{ "path": "./tsconfig.lib.vue2.json" },
56
{ "path": "./tsconfig.test.json" },
67
{ "path": "./tsconfig.fixture.json" }
78
]

tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"**/dist",
2727
"**/tests",
2828
"**/macros-global.d.ts",
29-
"packages/volar/*.js"
29+
"packages/volar/*.js",
30+
"**/vue2-macros*"
3031
]
3132
}

0 commit comments

Comments
 (0)