Skip to content

Commit 067f018

Browse files
committed
feat(vue-jsx-vapor): add getCurrentInstance
1 parent 033d62f commit 067f018

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

packages/macros/src/core/define-expose.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export function transformDefineExpose(
88
s.overwriteNode(node.callee, ';')
99
s.appendRight(
1010
node.arguments[0]?.start || node.end! - 1,
11-
`${importHelperFn(s, 0, 'getCurrentInstance')}(true).exposed = `,
11+
`${importHelperFn(s, 0, 'getCurrentInstance', undefined, 'vue-jsx-vapor')}().exposed = `,
1212
)
1313
}

packages/macros/src/options.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
// detectVueVersion,
32
REGEX_NODE_MODULES,
43
REGEX_SETUP_SFC,
54
REGEX_SRC_FILE,
@@ -28,8 +27,6 @@ export type OptionsResolved = MarkRequired<Options, 'include' | 'version'> & {
2827
}
2928

3029
export function resolveOptions(options: Options): OptionsResolved {
31-
// waiting for vue@3.6 release
32-
// const version = options.version || detectVueVersion()
3330
const version = options.version || 3.6
3431
return {
3532
include: [REGEX_SRC_FILE],

packages/vue-jsx-vapor/src/core/runtime.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
createComponent as _createComponent,
33
EffectScope,
4-
getCurrentInstance,
54
insert,
65
isFragment,
76
isVaporComponent,
@@ -12,8 +11,16 @@ import {
1211
useAttrs,
1312
VaporFragment,
1413
type Block,
14+
type GenericComponentInstance,
1515
} from 'vue'
1616

17+
import * as Vue from 'vue'
18+
19+
export function getCurrentInstance(): GenericComponentInstance | null {
20+
// @ts-ignore
21+
return Vue.currentInstance || Vue.getCurrentInstance()
22+
}
23+
1724
export { shallowRef as useRef } from 'vue'
1825

1926
export const createComponent: typeof _createComponent = (...args) => {
@@ -34,7 +41,7 @@ export const createComponent: typeof _createComponent = (...args) => {
3441
* ```
3542
*/
3643
export function useProps() {
37-
const i = getCurrentInstance(true)
44+
const i = getCurrentInstance()
3845
return i!.props
3946
}
4047

0 commit comments

Comments
 (0)