Skip to content

Commit 9e51df0

Browse files
committed
refactor: remove getCurrentInstance
1 parent af822e4 commit 9e51df0

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
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', undefined, 'vue-jsx-vapor/runtime')}().exposed = `,
11+
`${importHelperFn(s, 0, 'getCurrentInstance')}(true).exposed = `,
1212
)
1313
}

packages/macros/tests/__snapshots__/fixtures.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,22 @@ defineComponent((__MACROS_props) => {
204204

205205
exports[`fixtures > ./fixtures/define-expose.tsx 1`] = `
206206
"
207-
import { getCurrentInstance as __MACROS_getCurrentInstance } from "vue-jsx-vapor/runtime";export function Comp(__MACROS_props) {
208-
;(__MACROS_getCurrentInstance().exposed = {
207+
import { getCurrentInstance as __MACROS_getCurrentInstance } from "vue";export function Comp(__MACROS_props) {
208+
;(__MACROS_getCurrentInstance(true).exposed = {
209209
foo: 1,
210210
})
211211
return <div />
212212
}
213213
214214
export const Comp1 = function (props: any) {
215-
;(__MACROS_getCurrentInstance().exposed = {
215+
;(__MACROS_getCurrentInstance(true).exposed = {
216216
foo: props.foo,
217217
})
218218
return <div />
219219
}
220220
221221
export const Comp2 = ({ foo, ...__MACROS_props }: any) => {
222-
;(__MACROS_getCurrentInstance().exposed = {
222+
;(__MACROS_getCurrentInstance(true).exposed = {
223223
foo,
224224
})
225225
return <div />

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
2+
createComponent as _createComponent,
23
EffectScope,
4+
getCurrentInstance,
35
insert,
46
isFragment,
57
isVaporComponent,
@@ -10,18 +12,10 @@ import {
1012
useAttrs,
1113
VaporFragment,
1214
type Block,
13-
type GenericComponentInstance,
1415
} from 'vue'
1516

16-
import * as Vue from 'vue'
17-
1817
export { shallowRef as useRef } from 'vue'
1918

20-
export function getCurrentInstance(): GenericComponentInstance | null {
21-
// @ts-ignore
22-
return Vue.currentInstance || Vue.getCurrentInstance()
23-
}
24-
2519
/**
2620
* Returns the props of the current component instance.
2721
*
@@ -35,7 +29,7 @@ export function getCurrentInstance(): GenericComponentInstance | null {
3529
* ```
3630
*/
3731
export function useProps() {
38-
const i = getCurrentInstance()
32+
const i = getCurrentInstance(true)
3933
return i!.props
4034
}
4135

0 commit comments

Comments
 (0)