Skip to content

Commit bc7c2af

Browse files
authored
fix: only trigger warning in the dev environment (#755)
Co-authored-by: webfansplz <>
1 parent e044215 commit bc7c2af

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

src/apis/createElement.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ type CreateElement = Vue['$createElement']
77

88
let fallbackCreateElement: CreateElement
99

10-
export const createElement = (function createElement(...args: any) {
10+
export const createElement = function createElement(...args: any) {
1111
const instance = getCurrentInstance()?.proxy
1212
if (!instance) {
13-
warn('`createElement()` has been called outside of render function.')
13+
__DEV__ &&
14+
warn('`createElement()` has been called outside of render function.')
1415
if (!fallbackCreateElement) {
15-
fallbackCreateElement = defineComponentInstance(getVueConstructor())
16-
.$createElement
16+
fallbackCreateElement = defineComponentInstance(
17+
getVueConstructor()
18+
).$createElement
1719
}
1820

1921
return fallbackCreateElement.apply(fallbackCreateElement, args)
2022
}
2123

2224
return instance.$createElement.apply(instance, args)
23-
} as any) as CreateElement
25+
} as any as CreateElement

src/apis/inject.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export function inject(
5454

5555
const vm = getCurrentInstance()?.proxy
5656
if (!vm) {
57-
warn(`inject() can only be used inside setup() or functional components.`)
57+
__DEV__ &&
58+
warn(`inject() can only be used inside setup() or functional components.`)
5859
return
5960
}
6061

src/mixin.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,11 @@ export function mixin(Vue: VueConstructor) {
210210
proxy(ctx, key, {
211211
get: () => vm[srcKey],
212212
set() {
213-
warn(
214-
`Cannot assign to '${key}' because it is a read-only property`,
215-
vm
216-
)
213+
__DEV__ &&
214+
warn(
215+
`Cannot assign to '${key}' because it is a read-only property`,
216+
vm
217+
)
217218
},
218219
})
219220
})
@@ -237,10 +238,11 @@ export function mixin(Vue: VueConstructor) {
237238
return data
238239
},
239240
set() {
240-
warn(
241-
`Cannot assign to '${key}' because it is a read-only property`,
242-
vm
243-
)
241+
__DEV__ &&
242+
warn(
243+
`Cannot assign to '${key}' because it is a read-only property`,
244+
vm
245+
)
244246
},
245247
})
246248
})

src/utils/helper.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ export function isComponentInstance(obj: any) {
3434
export function createSlotProxy(vm: ComponentInstance, slotName: string) {
3535
return (...args: any) => {
3636
if (!vm.$scopedSlots[slotName]) {
37-
return warn(
38-
`slots.${slotName}() got called outside of the "render()" scope`,
39-
vm
40-
)
37+
if (__DEV__)
38+
return warn(
39+
`slots.${slotName}() got called outside of the "render()" scope`,
40+
vm
41+
)
42+
return
4143
}
4244

4345
return vm.$scopedSlots[slotName]!.apply(vm, args)

0 commit comments

Comments
 (0)