Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only trigger warning in the dev environment #755

Merged
merged 3 commits into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/apis/createElement.ts
Expand Up @@ -7,17 +7,19 @@ type CreateElement = Vue['$createElement']

let fallbackCreateElement: CreateElement

export const createElement = (function createElement(...args: any) {
export const createElement = function createElement(...args: any) {
const instance = getCurrentInstance()?.proxy
if (!instance) {
warn('`createElement()` has been called outside of render function.')
__DEV__ &&
warn('`createElement()` has been called outside of render function.')
if (!fallbackCreateElement) {
fallbackCreateElement = defineComponentInstance(getVueConstructor())
.$createElement
fallbackCreateElement = defineComponentInstance(
getVueConstructor()
).$createElement
}

return fallbackCreateElement.apply(fallbackCreateElement, args)
}

return instance.$createElement.apply(instance, args)
} as any) as CreateElement
} as any as CreateElement
3 changes: 2 additions & 1 deletion src/apis/inject.ts
Expand Up @@ -54,7 +54,8 @@ export function inject(

const vm = getCurrentInstance()?.proxy
if (!vm) {
warn(`inject() can only be used inside setup() or functional components.`)
__DEV__ &&
warn(`inject() can only be used inside setup() or functional components.`)
return
}

Expand Down
18 changes: 10 additions & 8 deletions src/mixin.ts
Expand Up @@ -210,10 +210,11 @@ export function mixin(Vue: VueConstructor) {
proxy(ctx, key, {
get: () => vm[srcKey],
set() {
warn(
`Cannot assign to '${key}' because it is a read-only property`,
vm
)
__DEV__ &&
warn(
`Cannot assign to '${key}' because it is a read-only property`,
vm
)
},
})
})
Expand All @@ -237,10 +238,11 @@ export function mixin(Vue: VueConstructor) {
return data
},
set() {
warn(
`Cannot assign to '${key}' because it is a read-only property`,
vm
)
__DEV__ &&
warn(
`Cannot assign to '${key}' because it is a read-only property`,
vm
)
},
})
})
Expand Down
10 changes: 6 additions & 4 deletions src/utils/helper.ts
Expand Up @@ -34,10 +34,12 @@ export function isComponentInstance(obj: any) {
export function createSlotProxy(vm: ComponentInstance, slotName: string) {
return (...args: any) => {
if (!vm.$scopedSlots[slotName]) {
return warn(
`slots.${slotName}() got called outside of the "render()" scope`,
vm
)
if (__DEV__)
return warn(
`slots.${slotName}() got called outside of the "render()" scope`,
vm
)
return
}

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