]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat: use internal warning
authorEvan You <yyx990803@gmail.com>
Thu, 11 Oct 2018 21:21:13 +0000 (17:21 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 11 Oct 2018 21:21:13 +0000 (17:21 -0400)
packages/core/src/componentProps.ts
packages/core/src/componentUtils.ts
packages/core/src/componentWatch.ts
packages/core/src/h.ts
packages/core/src/optional/context.ts
packages/core/src/optional/keepAlive.ts
packages/core/src/warning.ts

index 936f733d958e9cadeed884c51507e253dd1ad432..7a4e78976a4faf067a5529da81aff74f14a1b877 100644 (file)
@@ -8,6 +8,7 @@ import {
   PropType
 } from './componentOptions'
 import { EMPTY_OBJ, camelize, hyphenate, capitalize } from './utils'
+import { warn } from './warning'
 
 const EMPTY_PROPS = { props: EMPTY_OBJ }
 
@@ -159,13 +160,13 @@ function normalizePropsOptions(
   if (Array.isArray(raw)) {
     for (let i = 0; i < raw.length; i++) {
       if (__DEV__ && typeof raw !== 'string') {
-        console.warn(`props must be strings when using array syntax.`)
+        warn(`props must be strings when using array syntax.`)
       }
       normalized[camelize(raw[i])] = EMPTY_OBJ
     }
   } else {
     if (__DEV__ && typeof raw !== 'object') {
-      console.warn(`invalid props options: `, raw)
+      warn(`invalid props options`, raw)
     }
     for (const key in raw) {
       const opt = raw[key]
@@ -224,7 +225,7 @@ function validateProp(
   const { type, required, validator } = prop
   // required!
   if (required && isAbsent) {
-    console.warn('Missing required prop: "' + name + '"')
+    warn('Missing required prop: "' + name + '"')
     return
   }
   // missing but optional
@@ -243,15 +244,13 @@ function validateProp(
       isValid = valid
     }
     if (!isValid) {
-      console.warn(getInvalidTypeMessage(name, value, expectedTypes))
+      warn(getInvalidTypeMessage(name, value, expectedTypes))
       return
     }
   }
   // custom validator
   if (validator && !validator(value)) {
-    console.warn(
-      'Invalid prop: custom validator check failed for prop "' + name + '".'
-    )
+    warn('Invalid prop: custom validator check failed for prop "' + name + '".')
   }
 }
 
index d50a0dee1d5b4efa63e7944890f33dbba25c4f35..2950f67c555f23080d352f3e352ac823e2f669ee 100644 (file)
@@ -20,6 +20,7 @@ import { initializeWatch, teardownWatch } from './componentWatch'
 import { ComponentOptions } from './componentOptions'
 import { createRenderProxy } from './componentProxy'
 import { handleError, ErrorTypes } from './errorHandling'
+import { warn } from './warning'
 
 let currentVNode: VNode | null = null
 let currentContextVNode: MountedVNode | null = null
@@ -244,7 +245,7 @@ export function createComponentClassFromOptions(
     } else if (key === 'methods') {
       for (const method in value) {
         if (__DEV__ && proto.hasOwnProperty(method)) {
-          console.warn(
+          warn(
             `Object syntax contains method name that conflicts with ` +
               `lifecycle hook: "${method}"`
           )
index 5abbc62eb92290f6a51be17b8a98519404bcebdf..79aa47e7ffe842f6870128cf4bbfcdfb46207b95 100644 (file)
@@ -4,6 +4,7 @@ import { ComponentWatchOptions, WatchOptions } from './componentOptions'
 import { autorun, stop } from '@vue/observer'
 import { queueJob } from '@vue/scheduler'
 import { handleError, ErrorTypes } from './errorHandling'
+import { warn } from './warning'
 
 export function initializeWatch(
   instance: ComponentInstance,
@@ -40,7 +41,7 @@ export function setupWatcher(
       : () => keyOrFn.call(proxy)
 
   if (__DEV__ && rawGetter === NOOP) {
-    console.warn(
+    warn(
       `Failed watching expression: "${keyOrFn}". ` +
         `Watch expressions can only be dot-delimited paths. ` +
         `For more complex expressions, use $watch with a function instead.`
index d56950ef66ee29ec09cbdbdaac515202248b3050..2b28ae520ed795b38e53e1974fa9d2576e58ef6e 100644 (file)
@@ -10,6 +10,7 @@ import {
   createPortal
 } from './vdom'
 import { isObservable } from '@vue/observer'
+import { warn } from './warning'
 
 export const Fragment = Symbol()
 export const Portal = Symbol()
@@ -79,14 +80,12 @@ export const h = ((tag: ElementType, data?: any, children?: any): VNode => {
     )
   } else if (tag === Fragment) {
     if (__DEV__ && ref) {
-      console.warn(
-        'Ref cannot be used on Fragments. Use it on inner elements instead.'
-      )
+      warn('Ref cannot be used on Fragments. Use it on inner elements instead.')
     }
     return createFragment(children, ChildrenFlags.UNKNOWN_CHILDREN, key)
   } else if (tag === Portal) {
     if (__DEV__ && !portalTarget) {
-      console.warn('Portal must have a target: ', portalTarget)
+      warn('Portal must have a target: ', portalTarget)
     }
     return createPortal(
       portalTarget,
@@ -100,7 +99,7 @@ export const h = ((tag: ElementType, data?: any, children?: any): VNode => {
       __DEV__ &&
       (!tag || (typeof tag !== 'function' && typeof tag !== 'object'))
     ) {
-      console.warn('Invalid component passed to h(): ', tag)
+      warn('Invalid component passed to h(): ', tag)
     }
     // component
     return createComponentVNode(
index 595972f4537f343fedb6e2985ff70f03eab6b3c9..6ab92face4bbf272c5b48b18fbcf4cb10313f009 100644 (file)
@@ -1,5 +1,6 @@
 import { observable } from '@vue/observer'
 import { Component } from '../component'
+import { warn } from '../warning'
 
 const contextStore = observable() as Record<string | symbol, any>
 
@@ -28,14 +29,12 @@ export class Provide extends Component<ProviderProps> {
     if (__DEV__) {
       const { id } = this.$props
       if (contextStore.hasOwnProperty(id)) {
-        console.warn(
-          `A context provider with id ${id.toString()} already exists.`
-        )
+        warn(`A context provider with id ${id.toString()} already exists.`)
       }
       this.$watch(
         () => this.$props.id,
         (id: string, oldId: string) => {
-          console.warn(
+          warn(
             `Context provider id change detected (from "${oldId}" to "${id}"). ` +
               `This is not supported and should be avoided.`
           )
index ec95e6552e5cc11db8ff9f596d50371c8bf2c4c2..664b17770828003630d7040db47f19bf404f6822 100644 (file)
@@ -1,6 +1,7 @@
 import { Component, ComponentClass, ComponentInstance } from '../component'
 import { VNode, Slots, cloneVNode } from '../vdom'
 import { VNodeFlags } from '../flags'
+import { warn } from '../warning'
 
 type MatchPattern = string | RegExp | string[] | RegExp[]
 
@@ -57,12 +58,12 @@ export class KeepAlive extends Component<KeepAliveProps> {
     let vnode = children[0]
     if (children.length > 1) {
       if (__DEV__) {
-        console.warn(`KeepAlive can only have a single child.`)
+        warn(`KeepAlive can only have a single child.`)
       }
       return children
     } else if ((vnode.flags & VNodeFlags.COMPONENT_STATEFUL) === 0) {
       if (__DEV__) {
-        console.warn(`KeepAlive child must be a stateful component.`)
+        warn(`KeepAlive child must be a stateful component.`)
       }
       return children
     }
index 32ed0616ebae27d84ce0c78cb97d209542d29962..22ab6bed917c626279c419ebac5dc38deed9b3fc 100644 (file)
@@ -12,15 +12,15 @@ export function popContext() {
   stack.pop()
 }
 
-export function warn(msg: string) {
+export function warn(msg: string, ...args: any[]) {
   // TODO warn handler?
-  console.warn(`[Vue warn]: ${msg}${getComponentTrace()}`)
+  warn(`[Vue warn]: ${msg}${getComponentTrace()}`, ...args)
 }
 
 function getComponentTrace(): string {
   let current: VNode | null | undefined = stack[stack.length - 1]
   if (!current) {
-    return '\nat <Root/>'
+    return ''
   }
 
   // we can't just use the stack because it will be incomplete during updates