فهرست منبع

build: use __DEV__ flag

Evan You 3 سال پیش
والد
کامیت
797e72e6fd
54فایلهای تغییر یافته به همراه145 افزوده شده و 206 حذف شده
  1. 3 2
      scripts/config.js
  2. 3 6
      src/compiler/codegen/index.ts
  3. 2 5
      src/compiler/create-compiler.ts
  4. 1 1
      src/compiler/directives/on.ts
  5. 1 6
      src/compiler/helpers.ts
  6. 3 11
      src/compiler/parser/html-parser.ts
  7. 23 37
      src/compiler/parser/index.ts
  8. 3 3
      src/compiler/to-function.ts
  9. 2 2
      src/core/config.ts
  10. 1 1
      src/core/global-api/assets.ts
  11. 1 1
      src/core/global-api/extend.ts
  12. 1 1
      src/core/global-api/index.ts
  13. 1 1
      src/core/instance/events.ts
  14. 1 1
      src/core/instance/index.ts
  15. 3 3
      src/core/instance/init.ts
  16. 2 2
      src/core/instance/inject.ts
  17. 4 4
      src/core/instance/lifecycle.ts
  18. 1 1
      src/core/instance/proxy.ts
  19. 1 5
      src/core/instance/render-helpers/bind-dynamic-keys.ts
  20. 1 2
      src/core/instance/render-helpers/bind-object-listeners.ts
  21. 1 1
      src/core/instance/render-helpers/bind-object-props.ts
  22. 1 1
      src/core/instance/render-helpers/render-slot.ts
  23. 3 3
      src/core/instance/render.ts
  24. 9 12
      src/core/instance/state.ts
  25. 1 1
      src/core/observer/dep.ts
  26. 5 11
      src/core/observer/index.ts
  27. 3 3
      src/core/observer/scheduler.ts
  28. 2 3
      src/core/observer/watcher.ts
  29. 1 1
      src/core/util/debug.ts
  30. 1 1
      src/core/util/error.ts
  31. 10 10
      src/core/util/options.ts
  32. 1 1
      src/core/util/perf.ts
  33. 2 2
      src/core/util/props.ts
  34. 1 1
      src/core/vdom/create-component.ts
  35. 3 8
      src/core/vdom/create-element.ts
  36. 1 1
      src/core/vdom/create-functional-component.ts
  37. 1 1
      src/core/vdom/helpers/extract-props.ts
  38. 2 6
      src/core/vdom/helpers/resolve-async-component.ts
  39. 1 1
      src/core/vdom/helpers/update-listeners.ts
  40. 9 9
      src/core/vdom/patch.ts
  41. 2 0
      src/global.d.ts
  42. 3 3
      src/platforms/web/compiler/directives/model.ts
  43. 1 1
      src/platforms/web/compiler/modules/class.ts
  44. 1 1
      src/platforms/web/compiler/modules/style.ts
  45. 6 6
      src/platforms/web/entry-runtime-with-compiler.ts
  46. 1 1
      src/platforms/web/runtime/components/transition-group.ts
  47. 2 7
      src/platforms/web/runtime/components/transition.ts
  48. 1 1
      src/platforms/web/runtime/directives/model.ts
  49. 2 5
      src/platforms/web/runtime/index.ts
  50. 2 2
      src/platforms/web/runtime/modules/transition.ts
  51. 1 2
      src/platforms/web/util/index.ts
  52. 3 4
      src/server/template-renderer/index.ts
  53. 1 1
      src/sfc/parser.ts
  54. 3 0
      vitest.config.ts

+ 3 - 2
scripts/config.js

@@ -16,7 +16,7 @@ const banner =
   ' */'
 
 const aliases = require('./alias')
-const resolve = (p) => {
+const resolve = p => {
   const base = p.split('/')[0]
   if (aliases[base]) {
     return path.resolve(aliases[base], p.slice(base.length + 1))
@@ -241,12 +241,13 @@ function genConfig(name) {
     __VERSION__: version
   }
   // feature flags
-  Object.keys(featureFlags).forEach((key) => {
+  Object.keys(featureFlags).forEach(key => {
     vars[`process.env.${key}`] = featureFlags[key]
   })
   // build-specific env
   if (opts.env) {
     vars['process.env.NODE_ENV'] = JSON.stringify(opts.env)
+    vars.__DEV__ = opts.env !== 'production'
   }
 
   vars.preventAssignment = true

+ 3 - 6
src/compiler/codegen/index.ts

@@ -137,7 +137,7 @@ function genOnce(el: ASTElement, state: CodegenState): string {
       parent = parent.parent
     }
     if (!key) {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         state.warn(
           `v-once can only be used inside v-for that is keyed. `,
           el.rawAttrsMap['v-once']
@@ -201,7 +201,7 @@ export function genFor(
   const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
 
   if (
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
     state.maybeComponent(el) &&
     el.tag !== 'slot' &&
     el.tag !== 'template' &&
@@ -345,10 +345,7 @@ function genInlineTemplate(
   state: CodegenState
 ): string | undefined {
   const ast = el.children[0]
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    (el.children.length !== 1 || ast.type !== 1)
-  ) {
+  if (__DEV__ && (el.children.length !== 1 || ast.type !== 1)) {
     state.warn(
       'Inline-template components must have exactly one child element.',
       { start: el.start }

+ 2 - 5
src/compiler/create-compiler.ts

@@ -21,10 +21,7 @@ export function createCompilerCreator(baseCompile: Function): Function {
       }
 
       if (options) {
-        if (
-          process.env.NODE_ENV !== 'production' &&
-          options.outputSourceRange
-        ) {
+        if (__DEV__ && options.outputSourceRange) {
           // $flow-disable-line
           const leadingSpaceLength = template.match(/^\s*/)![0].length
 
@@ -69,7 +66,7 @@ export function createCompilerCreator(baseCompile: Function): Function {
       finalOptions.warn = warn
 
       const compiled = baseCompile(template.trim(), finalOptions)
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         detectErrors(compiled.ast, warn)
       }
       compiled.errors = errors

+ 1 - 1
src/compiler/directives/on.ts

@@ -1,7 +1,7 @@
 import { warn } from 'core/util/index'
 
 export default function on(el: ASTElement, dir: ASTDirective) {
-  if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
+  if (__DEV__ && dir.modifiers) {
     warn(`v-on without argument does not support modifiers.`)
   }
   el.wrapListeners = (code: string) => `_g(${code},${dir.value})`

+ 1 - 6
src/compiler/helpers.ts

@@ -101,12 +101,7 @@ export function addHandler(
   modifiers = modifiers || emptyObject
   // warn prevent and passive modifier
   /* istanbul ignore if */
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    warn &&
-    modifiers.prevent &&
-    modifiers.passive
-  ) {
+  if (__DEV__ && warn && modifiers.prevent && modifiers.passive) {
     warn(
       "passive and prevent can't be used together. " +
         "Passive handler can't prevent default event.",

+ 3 - 11
src/compiler/parser/html-parser.ts

@@ -181,11 +181,7 @@ export function parseHTML(html, options) {
 
     if (html === last) {
       options.chars && options.chars(html)
-      if (
-        process.env.NODE_ENV !== 'production' &&
-        !stack.length &&
-        options.warn
-      ) {
+      if (__DEV__ && !stack.length && options.warn) {
         options.warn(`Mal-formatted tag at end of template: "${html}"`, {
           start: index + html.length
         })
@@ -258,7 +254,7 @@ export function parseHTML(html, options) {
         name: args[1],
         value: decodeAttr(value, shouldDecodeNewlines)
       }
-      if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
+      if (__DEV__ && options.outputSourceRange) {
         attrs[i].start = args.start + args[0].match(/^\s*/).length
         attrs[i].end = args.end
       }
@@ -301,11 +297,7 @@ export function parseHTML(html, options) {
     if (pos >= 0) {
       // Close all the open elements, up the stack
       for (let i = stack.length - 1; i >= pos; i--) {
-        if (
-          process.env.NODE_ENV !== 'production' &&
-          (i > pos || !tagName) &&
-          options.warn
-        ) {
+        if (__DEV__ && (i > pos || !tagName) && options.warn) {
           options.warn(`tag <${stack[i].tag}> has no matching end tag.`, {
             start: stack[i].start,
             end: stack[i].end

+ 23 - 37
src/compiler/parser/index.ts

@@ -119,14 +119,14 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
     if (!stack.length && element !== root) {
       // allow root elements with v-if, v-else-if and v-else
       if (root.if && (element.elseif || element.else)) {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           checkRootConstraints(element)
         }
         addIfCondition(root, {
           exp: element.elseif,
           block: element
         })
-      } else if (process.env.NODE_ENV !== 'production') {
+      } else if (__DEV__) {
         warnOnce(
           `Component template should contain exactly one root element. ` +
             `If you are using v-if on multiple elements, ` +
@@ -229,7 +229,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
         element.ns = ns
       }
 
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         if (options.outputSourceRange) {
           element.start = start
           element.end = end
@@ -254,7 +254,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
 
       if (isForbiddenTag(element) && !isServerRendering()) {
         element.forbidden = true
-        process.env.NODE_ENV !== 'production' &&
+        __DEV__ &&
           warn(
             'Templates should only be responsible for mapping the state to the ' +
               'UI. Avoid placing tags with side-effects in your templates, such as ' +
@@ -289,7 +289,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
 
       if (!root) {
         root = element
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           checkRootConstraints(root)
         }
       }
@@ -307,7 +307,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
       // pop stack
       stack.length -= 1
       currentParent = stack[stack.length - 1]
-      if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
+      if (__DEV__ && options.outputSourceRange) {
         element.end = end
       }
       closeElement(element)
@@ -315,7 +315,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
 
     chars(text: string, start: number, end: number) {
       if (!currentParent) {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           if (text === template) {
             warnOnce(
               'Component template requires a root element, rather than just text.',
@@ -382,10 +382,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
           }
         }
         if (child) {
-          if (
-            process.env.NODE_ENV !== 'production' &&
-            options.outputSourceRange
-          ) {
+          if (__DEV__ && options.outputSourceRange) {
             child.start = start
             child.end = end
           }
@@ -402,10 +399,7 @@ export function parse(template: string, options: CompilerOptions): ASTElement {
           text,
           isComment: true
         }
-        if (
-          process.env.NODE_ENV !== 'production' &&
-          options.outputSourceRange
-        ) {
+        if (__DEV__ && options.outputSourceRange) {
           child.start = start
           child.end = end
         }
@@ -465,7 +459,7 @@ export function processElement(element: ASTElement, options: CompilerOptions) {
 function processKey(el) {
   const exp = getBindingAttr(el, 'key')
   if (exp) {
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if (el.tag === 'template') {
         warn(
           `<template> cannot be keyed. Place the key on real elements instead.`,
@@ -508,7 +502,7 @@ export function processFor(el: ASTElement) {
     const res = parseFor(exp)
     if (res) {
       extend(el, res)
-    } else if (process.env.NODE_ENV !== 'production') {
+    } else if (__DEV__) {
       warn(`Invalid v-for expression: ${exp}`, el.rawAttrsMap['v-for'])
     }
   }
@@ -566,7 +560,7 @@ function processIfConditions(el, parent) {
       exp: el.elseif,
       block: el
     })
-  } else if (process.env.NODE_ENV !== 'production') {
+  } else if (__DEV__) {
     warn(
       `v-${el.elseif ? 'else-if="' + el.elseif + '"' : 'else'} ` +
         `used on element <${el.tag}> without corresponding v-if.`,
@@ -581,7 +575,7 @@ function findPrevElement(children: Array<any>): ASTElement | void {
     if (children[i].type === 1) {
       return children[i]
     } else {
-      if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
+      if (__DEV__ && children[i].text !== ' ') {
         warn(
           `text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
             `will be ignored.`,
@@ -614,7 +608,7 @@ function processSlotContent(el) {
   if (el.tag === 'template') {
     slotScope = getAndRemoveAttr(el, 'scope')
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && slotScope) {
+    if (__DEV__ && slotScope) {
       warn(
         `the "scope" attribute for scoped slots have been deprecated and ` +
           `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
@@ -627,7 +621,7 @@ function processSlotContent(el) {
     el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope')
   } else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
+    if (__DEV__ && el.attrsMap['v-for']) {
       warn(
         `Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
           `(v-for takes higher priority). Use a wrapper <template> for the ` +
@@ -659,7 +653,7 @@ function processSlotContent(el) {
       // v-slot on <template>
       const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
       if (slotBinding) {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           if (el.slotTarget || el.slotScope) {
             warn(`Unexpected mixed usage of different slot syntaxes.`, el)
           }
@@ -680,7 +674,7 @@ function processSlotContent(el) {
       // v-slot on component, denotes default slot
       const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
       if (slotBinding) {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           if (!maybeComponent(el)) {
             warn(
               `v-slot can only be used on components or <template>.`,
@@ -729,7 +723,7 @@ function getSlotName(binding) {
   if (!name) {
     if (binding.name[0] !== '#') {
       name = 'default'
-    } else if (process.env.NODE_ENV !== 'production') {
+    } else if (__DEV__) {
       warn(`v-slot shorthand syntax requires a slot name.`, binding)
     }
   }
@@ -744,7 +738,7 @@ function getSlotName(binding) {
 function processSlotOutlet(el) {
   if (el.tag === 'slot') {
     el.slotName = getBindingAttr(el, 'name')
-    if (process.env.NODE_ENV !== 'production' && el.key) {
+    if (__DEV__ && el.key) {
       warn(
         `\`key\` does not work on <slot> because slots are abstract outlets ` +
           `and can possibly expand into multiple elements. ` +
@@ -791,10 +785,7 @@ function processAttrs(el) {
         if (isDynamic) {
           name = name.slice(1, -1)
         }
-        if (
-          process.env.NODE_ENV !== 'production' &&
-          value.trim().length === 0
-        ) {
+        if (__DEV__ && value.trim().length === 0) {
           warn(
             `The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
           )
@@ -885,13 +876,13 @@ function processAttrs(el) {
           modifiers,
           list[i]
         )
-        if (process.env.NODE_ENV !== 'production' && name === 'model') {
+        if (__DEV__ && name === 'model') {
           checkForAliasModel(el, value)
         }
       }
     } else {
       // literal attribute
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         const res = parseText(value, delimiters)
         if (res) {
           warn(
@@ -942,12 +933,7 @@ function parseModifiers(name: string): Object | void {
 function makeAttrsMap(attrs: Array<Record<string, any>>): Record<string, any> {
   const map = {}
   for (let i = 0, l = attrs.length; i < l; i++) {
-    if (
-      process.env.NODE_ENV !== 'production' &&
-      map[attrs[i].name] &&
-      !isIE &&
-      !isEdge
-    ) {
+    if (__DEV__ && map[attrs[i].name] && !isIE && !isEdge) {
       warn('duplicate attribute: ' + attrs[i].name, attrs[i])
     }
     map[attrs[i].name] = attrs[i].value

+ 3 - 3
src/compiler/to-function.ts

@@ -30,7 +30,7 @@ export function createCompileToFunctionFn(compile: Function): Function {
     delete options.warn
 
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       // detect possible CSP restriction
       try {
         new Function('return 1')
@@ -59,7 +59,7 @@ export function createCompileToFunctionFn(compile: Function): Function {
     const compiled = compile(template, options)
 
     // check compilation errors/tips
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if (compiled.errors && compiled.errors.length) {
         if (options.outputSourceRange) {
           compiled.errors.forEach(e => {
@@ -99,7 +99,7 @@ export function createCompileToFunctionFn(compile: Function): Function {
     // this should only happen if there is a bug in the compiler itself.
     // mostly for codegen development use
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
         warn(
           `Failed to generate render function:\n\n` +

+ 2 - 2
src/core/config.ts

@@ -45,12 +45,12 @@ export default {
   /**
    * Show production mode tip message on boot?
    */
-  productionTip: process.env.NODE_ENV !== 'production',
+  productionTip: __DEV__,
 
   /**
    * Whether to enable devtools
    */
-  devtools: process.env.NODE_ENV !== 'production',
+  devtools: __DEV__,
 
   /**
    * Whether to record perf

+ 1 - 1
src/core/global-api/assets.ts

@@ -16,7 +16,7 @@ export function initAssetRegisters(Vue: GlobalAPI) {
         return this.options[type + 's'][id]
       } else {
         /* istanbul ignore if */
-        if (process.env.NODE_ENV !== 'production' && type === 'component') {
+        if (__DEV__ && type === 'component') {
           validateComponentName(id)
         }
         if (type === 'component' && isPlainObject(definition)) {

+ 1 - 1
src/core/global-api/extend.ts

@@ -26,7 +26,7 @@ export function initExtend(Vue: GlobalAPI) {
     }
 
     const name = extendOptions.name || Super.options.name
-    if (process.env.NODE_ENV !== 'production' && name) {
+    if (__DEV__ && name) {
       validateComponentName(name)
     }
 

+ 1 - 1
src/core/global-api/index.ts

@@ -21,7 +21,7 @@ export function initGlobalAPI(Vue: GlobalAPI) {
   // config
   const configDef: Record<string, any> = {}
   configDef.get = () => config
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     configDef.set = () => {
       warn(
         'Do not replace the Vue.config object, set individual fields instead.'

+ 1 - 1
src/core/instance/events.ts

@@ -129,7 +129,7 @@ export function eventsMixin(Vue: Component) {
 
   Vue.prototype.$emit = function (event: string): Component {
     const vm: Component = this
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       const lowerCaseEvent = event.toLowerCase()
       if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
         tip(

+ 1 - 1
src/core/instance/index.ts

@@ -7,7 +7,7 @@ import { warn } from '../util/index'
 import type { GlobalAPI } from 'typescript/global-api'
 
 function Vue(options) {
-  if (process.env.NODE_ENV !== 'production' && !(this instanceof Vue)) {
+  if (__DEV__ && !(this instanceof Vue)) {
     warn('Vue is a constructor and should be called with the `new` keyword')
   }
   this._init(options)

+ 3 - 3
src/core/instance/init.ts

@@ -20,7 +20,7 @@ export function initMixin(Vue: Component) {
 
     let startTag, endTag
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+    if (__DEV__ && config.performance && mark) {
       startTag = `vue-perf-start:${vm._uid}`
       endTag = `vue-perf-end:${vm._uid}`
       mark(startTag)
@@ -42,7 +42,7 @@ export function initMixin(Vue: Component) {
       )
     }
     /* istanbul ignore else */
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       initProxy(vm)
     } else {
       vm._renderProxy = vm
@@ -59,7 +59,7 @@ export function initMixin(Vue: Component) {
     callHook(vm, 'created')
 
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+    if (__DEV__ && config.performance && mark) {
       vm._name = formatComponentName(vm, false)
       mark(endTag)
       measure(`vue ${vm._name} init`, startTag, endTag)

+ 2 - 2
src/core/instance/inject.ts

@@ -20,7 +20,7 @@ export function initInjections(vm: Component) {
     toggleObserving(false)
     Object.keys(result).forEach(key => {
       /* istanbul ignore else */
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         defineReactive(vm, key, result[key], () => {
           warn(
             `Avoid mutating an injected value directly since the changes will be ` +
@@ -67,7 +67,7 @@ export function resolveInject(
             typeof provideDefault === 'function'
               ? provideDefault.call(vm)
               : provideDefault
-        } else if (process.env.NODE_ENV !== 'production') {
+        } else if (__DEV__) {
           warn(`Injection "${key as string}" not found`, vm)
         }
       }

+ 4 - 4
src/core/instance/lifecycle.ts

@@ -147,7 +147,7 @@ export function mountComponent(
   if (!vm.$options.render) {
     // @ts-expect-error invalid type
     vm.$options.render = createEmptyVNode
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       /* istanbul ignore if */
       if (
         (vm.$options.template && vm.$options.template.charAt(0) !== '#') ||
@@ -172,7 +172,7 @@ export function mountComponent(
 
   let updateComponent
   /* istanbul ignore if */
-  if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+  if (__DEV__ && config.performance && mark) {
     updateComponent = () => {
       const name = vm._name
       const id = vm._uid
@@ -229,7 +229,7 @@ export function updateChildComponent(
   parentVnode: MountedComponentVNode,
   renderChildren?: Array<VNode> | null
 ) {
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     isUpdatingChildComponent = true
   }
 
@@ -299,7 +299,7 @@ export function updateChildComponent(
     vm.$forceUpdate()
   }
 
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     isUpdatingChildComponent = false
   }
 }

+ 1 - 1
src/core/instance/proxy.ts

@@ -5,7 +5,7 @@ import { warn, makeMap, isNative } from '../util/index'
 
 let initProxy
 
-if (process.env.NODE_ENV !== 'production') {
+if (__DEV__) {
   const allowedGlobals = makeMap(
     'Infinity,undefined,NaN,isFinite,isNaN,' +
       'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +

+ 1 - 5
src/core/instance/render-helpers/bind-dynamic-keys.ts

@@ -17,11 +17,7 @@ export function bindDynamicKeys(
     const key = values[i]
     if (typeof key === 'string' && key) {
       baseObj[values[i]] = values[i + 1]
-    } else if (
-      process.env.NODE_ENV !== 'production' &&
-      key !== '' &&
-      key !== null
-    ) {
+    } else if (__DEV__ && key !== '' && key !== null) {
       // null is a special value for explicitly removing a binding
       warn(
         `Invalid value for dynamic directive argument (expected string or null): ${key}`,

+ 1 - 2
src/core/instance/render-helpers/bind-object-listeners.ts

@@ -4,8 +4,7 @@ import type { VNodeData } from 'typescript/vnode'
 export function bindObjectListeners(data: any, value: any): VNodeData {
   if (value) {
     if (!isPlainObject(value)) {
-      process.env.NODE_ENV !== 'production' &&
-        warn('v-on without argument expects an Object value', this)
+      __DEV__ && warn('v-on without argument expects an Object value', this)
     } else {
       const on = (data.on = data.on ? extend({}, data.on) : {})
       for (const key in value) {

+ 1 - 1
src/core/instance/render-helpers/bind-object-props.ts

@@ -22,7 +22,7 @@ export function bindObjectProps(
 ): VNodeData {
   if (value) {
     if (!isObject(value)) {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         warn('v-bind without argument expects an Object or Array value', this)
     } else {
       if (Array.isArray(value)) {

+ 1 - 1
src/core/instance/render-helpers/render-slot.ts

@@ -16,7 +16,7 @@ export function renderSlot(
     // scoped slot
     props = props || {}
     if (bindObject) {
-      if (process.env.NODE_ENV !== 'production' && !isObject(bindObject)) {
+      if (__DEV__ && !isObject(bindObject)) {
         warn('slot v-bind without argument expects an Object', this)
       }
       props = extend(extend({}, bindObject), props)

+ 3 - 3
src/core/instance/render.ts

@@ -39,7 +39,7 @@ export function initRender(vm: Component) {
   const parentData = parentVnode && parentVnode.data
 
   /* istanbul ignore else */
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     defineReactive(
       vm,
       '$attrs',
@@ -119,7 +119,7 @@ export function renderMixin(Vue: Component) {
       // return error render result,
       // or previous vnode to prevent render error causing blank component
       /* istanbul ignore else */
-      if (process.env.NODE_ENV !== 'production' && vm.$options.renderError) {
+      if (__DEV__ && vm.$options.renderError) {
         try {
           vnode = vm.$options.renderError.call(
             vm._renderProxy,
@@ -142,7 +142,7 @@ export function renderMixin(Vue: Component) {
     }
     // return empty vnode in case the render function errored out
     if (!(vnode instanceof VNode)) {
-      if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
+      if (__DEV__ && Array.isArray(vnode)) {
         warn(
           'Multiple root nodes returned from render function. Render function ' +
             'should return a single root node.',

+ 9 - 12
src/core/instance/state.ts

@@ -76,7 +76,7 @@ function initProps(vm: Component, propsOptions: Object) {
     keys.push(key)
     const value = validateProp(key, propsOptions, propsData, vm)
     /* istanbul ignore else */
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       const hyphenatedKey = hyphenate(key)
       if (
         isReservedAttribute(hyphenatedKey) ||
@@ -116,7 +116,7 @@ function initData(vm: Component) {
   data = vm._data = typeof data === 'function' ? getData(data, vm) : data || {}
   if (!isPlainObject(data)) {
     data = {}
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         'data functions should return an object:\n' +
           'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
@@ -130,13 +130,13 @@ function initData(vm: Component) {
   let i = keys.length
   while (i--) {
     const key = keys[i]
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if (methods && hasOwn(methods, key)) {
         warn(`Method "${key}" has already been defined as a data property.`, vm)
       }
     }
     if (props && hasOwn(props, key)) {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         warn(
           `The data property "${key}" is already declared as a prop. ` +
             `Use prop default value instead.`,
@@ -174,7 +174,7 @@ function initComputed(vm: Component, computed: Object) {
   for (const key in computed) {
     const userDef = computed[key]
     const getter = typeof userDef === 'function' ? userDef : userDef.get
-    if (process.env.NODE_ENV !== 'production' && getter == null) {
+    if (__DEV__ && getter == null) {
       warn(`Getter is missing for computed property "${key}".`, vm)
     }
 
@@ -193,7 +193,7 @@ function initComputed(vm: Component, computed: Object) {
     // at instantiation here.
     if (!(key in vm)) {
       defineComputed(vm, key, userDef)
-    } else if (process.env.NODE_ENV !== 'production') {
+    } else if (__DEV__) {
       if (key in vm.$data) {
         warn(`The computed property "${key}" is already defined in data.`, vm)
       } else if (vm.$options.props && key in vm.$options.props) {
@@ -227,10 +227,7 @@ export function defineComputed(
       : noop
     sharedPropertyDefinition.set = userDef.set || noop
   }
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    sharedPropertyDefinition.set === noop
-  ) {
+  if (__DEV__ && sharedPropertyDefinition.set === noop) {
     sharedPropertyDefinition.set = function () {
       warn(
         `Computed property "${key}" was assigned to but it has no setter.`,
@@ -265,7 +262,7 @@ function createGetterInvoker(fn) {
 function initMethods(vm: Component, methods: Object) {
   const props = vm.$options.props
   for (const key in methods) {
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if (typeof methods[key] !== 'function') {
         warn(
           `Method "${key}" has type "${typeof methods[
@@ -330,7 +327,7 @@ export function stateMixin(Vue: Component) {
   propsDef.get = function () {
     return this._props
   }
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     dataDef.set = function () {
       warn(
         'Avoid replacing instance root $data. ' +

+ 1 - 1
src/core/observer/dep.ts

@@ -35,7 +35,7 @@ export default class Dep {
   notify() {
     // stabilize the subscriber list first
     const subs = this.subs.slice()
-    if (process.env.NODE_ENV !== 'production' && !config.async) {
+    if (__DEV__ && !config.async) {
       // subs aren't sorted in scheduler if not running async
       // we need to sort them now to make sure they fire in correct
       // order

+ 5 - 11
src/core/observer/index.ts

@@ -175,7 +175,7 @@ export function defineReactive(
         return
       }
       /* eslint-enable no-self-compare */
-      if (process.env.NODE_ENV !== 'production' && customSetter) {
+      if (__DEV__ && customSetter) {
         customSetter()
       }
       // #7981: for accessor properties without setter
@@ -201,10 +201,7 @@ export function set(
   key: any,
   val: any
 ): any {
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    (isUndef(target) || isPrimitive(target))
-  ) {
+  if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
     warn(
       `Cannot set reactive property on undefined, null, or primitive value: ${target}`
     )
@@ -220,7 +217,7 @@ export function set(
   }
   const ob = (target as any).__ob__
   if ((target as any)._isVue || (ob && ob.vmCount)) {
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         'Avoid adding reactive properties to a Vue instance or its root $data ' +
           'at runtime - declare it upfront in the data option.'
@@ -240,10 +237,7 @@ export function set(
  * Delete a property and trigger change if necessary.
  */
 export function del(target: Array<any> | Object, key: any) {
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    (isUndef(target) || isPrimitive(target))
-  ) {
+  if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
     warn(
       `Cannot delete reactive property on undefined, null, or primitive value: ${target}`
     )
@@ -254,7 +248,7 @@ export function del(target: Array<any> | Object, key: any) {
   }
   const ob = (target as any).__ob__
   if ((target as any)._isVue || (ob && ob.vmCount)) {
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         'Avoid deleting properties on a Vue instance or its root $data ' +
           '- just set it to null.'

+ 3 - 3
src/core/observer/scheduler.ts

@@ -21,7 +21,7 @@ let index = 0
 function resetSchedulerState() {
   index = queue.length = activatedChildren.length = 0
   has = {}
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     circular = {}
   }
   waiting = flushing = false
@@ -87,7 +87,7 @@ function flushSchedulerQueue() {
     has[id] = null
     watcher.run()
     // in dev build, check and stop circular updates.
-    if (process.env.NODE_ENV !== 'production' && has[id] != null) {
+    if (__DEV__ && has[id] != null) {
       circular[id] = (circular[id] || 0) + 1
       if (circular[id] > MAX_UPDATE_COUNT) {
         warn(
@@ -172,7 +172,7 @@ export function queueWatcher(watcher: Watcher) {
     if (!waiting) {
       waiting = true
 
-      if (process.env.NODE_ENV !== 'production' && !config.async) {
+      if (__DEV__ && !config.async) {
         flushSchedulerQueue()
         return
       }

+ 2 - 3
src/core/observer/watcher.ts

@@ -78,8 +78,7 @@ export default class Watcher {
     this.newDeps = []
     this.depIds = new Set()
     this.newDepIds = new Set()
-    this.expression =
-      process.env.NODE_ENV !== 'production' ? expOrFn.toString() : ''
+    this.expression = __DEV__ ? expOrFn.toString() : ''
     // parse expression for getter
     if (typeof expOrFn === 'function') {
       this.getter = expOrFn
@@ -87,7 +86,7 @@ export default class Watcher {
       this.getter = parsePath(expOrFn)
       if (!this.getter) {
         this.getter = noop
-        process.env.NODE_ENV !== 'production' &&
+        __DEV__ &&
           warn(
             `Failed watching path: "${expOrFn}" ` +
               'Watcher only accepts simple dot-delimited paths. ' +

+ 1 - 1
src/core/util/debug.ts

@@ -7,7 +7,7 @@ export let tip = noop
 export let generateComponentTrace: (vm: Component) => string // work around flow check
 export let formatComponentName: (vm: Component, includeFile?: false) => string
 
-if (process.env.NODE_ENV !== 'production') {
+if (__DEV__) {
   const hasConsole = typeof console !== 'undefined'
   const classifyRE = /(?:^|[-_])(\w)/g
   const classify = str =>

+ 1 - 1
src/core/util/error.ts

@@ -69,7 +69,7 @@ function globalHandleError(err, vm, info) {
 }
 
 function logError(err, vm, info) {
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     warn(`Error in ${info}: "${err.toString()}"`, vm)
   }
   /* istanbul ignore else */

+ 10 - 10
src/core/util/options.ts

@@ -28,7 +28,7 @@ const strats = config.optionMergeStrategies
 /**
  * Options with restrictions
  */
-if (process.env.NODE_ENV !== 'production') {
+if (__DEV__) {
   strats.el = strats.propsData = function (
     parent: any,
     child: any,
@@ -128,7 +128,7 @@ strats.data = function (
 ): Function | null {
   if (!vm) {
     if (childVal && typeof childVal !== 'function') {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         warn(
           'The "data" option should be a function ' +
             'that returns a per-instance value in component ' +
@@ -190,7 +190,7 @@ function mergeAssets(
 ): Object {
   const res = Object.create(parentVal || null)
   if (childVal) {
-    process.env.NODE_ENV !== 'production' && assertObjectType(key, childVal, vm)
+    __DEV__ && assertObjectType(key, childVal, vm)
     return extend(res, childVal)
   } else {
     return res
@@ -220,7 +220,7 @@ strats.watch = function (
   if (childVal === nativeWatch) childVal = undefined
   /* istanbul ignore if */
   if (!childVal) return Object.create(parentVal || null)
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     assertObjectType(key, childVal, vm)
   }
   if (!parentVal) return childVal
@@ -254,7 +254,7 @@ strats.props =
       vm: Component | null,
       key: string
     ): Object | null {
-      if (childVal && process.env.NODE_ENV !== 'production') {
+      if (childVal && __DEV__) {
         assertObjectType(key, childVal, vm)
       }
       if (!parentVal) return childVal
@@ -317,7 +317,7 @@ function normalizeProps(options: Record<string, any>, vm?: Component | null) {
       if (typeof val === 'string') {
         name = camelize(val)
         res[name] = { type: null }
-      } else if (process.env.NODE_ENV !== 'production') {
+      } else if (__DEV__) {
         warn('props must be strings when using array syntax.')
       }
     }
@@ -327,7 +327,7 @@ function normalizeProps(options: Record<string, any>, vm?: Component | null) {
       name = camelize(key)
       res[name] = isPlainObject(val) ? val : { type: val }
     }
-  } else if (process.env.NODE_ENV !== 'production') {
+  } else if (__DEV__) {
     warn(
       `Invalid value for option "props": expected an Array or an Object, ` +
         `but got ${toRawType(props)}.`,
@@ -355,7 +355,7 @@ function normalizeInject(options: Record<string, any>, vm?: Component | null) {
         ? extend({ from: key }, val)
         : { from: val }
     }
-  } else if (process.env.NODE_ENV !== 'production') {
+  } else if (__DEV__) {
     warn(
       `Invalid value for option "inject": expected an Array or an Object, ` +
         `but got ${toRawType(inject)}.`,
@@ -398,7 +398,7 @@ export function mergeOptions(
   child: Record<string, any>,
   vm?: Component | null
 ): ComponentOptions {
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     checkComponents(child)
   }
 
@@ -467,7 +467,7 @@ export function resolveAsset(
   if (hasOwn(assets, PascalCaseId)) return assets[PascalCaseId]
   // fallback to prototype chain
   const res = assets[id] || assets[camelizedId] || assets[PascalCaseId]
-  if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
+  if (__DEV__ && warnMissing && !res) {
     warn('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options)
   }
   return res

+ 1 - 1
src/core/util/perf.ts

@@ -3,7 +3,7 @@ import { inBrowser } from './env'
 export let mark
 export let measure
 
-if (process.env.NODE_ENV !== 'production') {
+if (__DEV__) {
   const perf = inBrowser && window.performance
   /* istanbul ignore if */
   if (

+ 2 - 2
src/core/util/props.ts

@@ -50,7 +50,7 @@ export function validateProp(
     observe(value)
     toggleObserving(prevShouldObserve)
   }
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     assertProp(prop, key, value, vm, absent)
   }
   return value
@@ -70,7 +70,7 @@ function getPropDefaultValue(
   }
   const def = prop.default
   // warn against non-factory defaults for Object & Array
-  if (process.env.NODE_ENV !== 'production' && isObject(def)) {
+  if (__DEV__ && isObject(def)) {
     warn(
       'Invalid default value for prop "' +
         key +

+ 1 - 1
src/core/vdom/create-component.ts

@@ -114,7 +114,7 @@ export function createComponent(
   // if at this stage it's not a constructor or an async component factory,
   // reject.
   if (typeof Ctor !== 'function') {
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       warn(`Invalid Component definition: ${String(Ctor)}`, context)
     }
     return

+ 3 - 8
src/core/vdom/create-element.ts

@@ -49,7 +49,7 @@ export function _createElement(
   normalizationType?: number
 ): VNode | Array<VNode> {
   if (isDef(data) && isDef((data as any).__ob__)) {
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         `Avoid using observed data object as vnode data: ${JSON.stringify(
           data
@@ -67,12 +67,7 @@ export function _createElement(
     return createEmptyVNode()
   }
   // warn against non-primitive key
-  if (
-    process.env.NODE_ENV !== 'production' &&
-    isDef(data) &&
-    isDef(data.key) &&
-    !isPrimitive(data.key)
-  ) {
+  if (__DEV__ && isDef(data) && isDef(data.key) && !isPrimitive(data.key)) {
     warn(
       'Avoid using non-primitive value as key, ' +
         'use string/number value instead.',
@@ -97,7 +92,7 @@ export function _createElement(
     if (config.isReservedTag(tag)) {
       // platform built-in elements
       if (
-        process.env.NODE_ENV !== 'production' &&
+        __DEV__ &&
         isDef(data) &&
         isDef(data.nativeOn) &&
         data.tag !== 'component'

+ 1 - 1
src/core/vdom/create-functional-component.ts

@@ -158,7 +158,7 @@ function cloneAndMarkFunctionalResult(
   const clone = cloneVNode(vnode)
   clone.fnContext = contextVm
   clone.fnOptions = options
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     ;(clone.devtoolsMeta = clone.devtoolsMeta || ({} as any)).renderContext =
       renderContext
   }

+ 1 - 1
src/core/vdom/helpers/extract-props.ts

@@ -26,7 +26,7 @@ export function extractPropsFromVNodeData(
   if (isDef(attrs) || isDef(props)) {
     for (const key in propOptions) {
       const altKey = hyphenate(key)
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         const keyInLowerCase = key.toLowerCase()
         if (key !== keyInLowerCase && attrs && hasOwn(attrs, keyInLowerCase)) {
           tip(

+ 2 - 6
src/core/vdom/helpers/resolve-async-component.ts

@@ -96,7 +96,7 @@ export function resolveAsyncComponent(
     })
 
     const reject = once(reason => {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         warn(
           `Failed to resolve async component: ${String(factory)}` +
             (reason ? `\nReason: ${reason}` : '')
@@ -143,11 +143,7 @@ export function resolveAsyncComponent(
           timerTimeout = setTimeout(() => {
             timerTimeout = null
             if (isUndef(factory.resolved)) {
-              reject(
-                process.env.NODE_ENV !== 'production'
-                  ? `timeout (${res.timeout}ms)`
-                  : null
-              )
+              reject(__DEV__ ? `timeout (${res.timeout}ms)` : null)
             }
           }, res.timeout)
         }

+ 1 - 1
src/core/vdom/helpers/update-listeners.ts

@@ -74,7 +74,7 @@ export function updateListeners(
     old = oldOn[name]
     event = normalizeEvent(name)
     if (isUndef(cur)) {
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
         warn(
           `Invalid handler for event "${event.name}": got ` + String(cur),
           vm

+ 9 - 9
src/core/vdom/patch.ts

@@ -144,7 +144,7 @@ export function createPatchFunction(backend) {
     const children = vnode.children
     const tag = vnode.tag
     if (isDef(tag)) {
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         if (data && data.pre) {
           creatingElmInVPre++
         }
@@ -171,7 +171,7 @@ export function createPatchFunction(backend) {
       }
       insert(parentElm, vnode.elm, refElm)
 
-      if (process.env.NODE_ENV !== 'production' && data && data.pre) {
+      if (__DEV__ && data && data.pre) {
         creatingElmInVPre--
       }
     } else if (isTrue(vnode.isComment)) {
@@ -262,7 +262,7 @@ export function createPatchFunction(backend) {
 
   function createChildren(vnode, children, insertedVnodeQueue) {
     if (Array.isArray(children)) {
-      if (process.env.NODE_ENV !== 'production') {
+      if (__DEV__) {
         checkDuplicateKeys(children)
       }
       for (let i = 0; i < children.length; ++i) {
@@ -431,7 +431,7 @@ export function createPatchFunction(backend) {
     // during leaving transitions
     const canMove = !removeOnly
 
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       checkDuplicateKeys(newCh)
     }
 
@@ -639,7 +639,7 @@ export function createPatchFunction(backend) {
         if (oldCh !== ch)
           updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
       } else if (isDef(ch)) {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           checkDuplicateKeys(ch)
         }
         if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
@@ -688,7 +688,7 @@ export function createPatchFunction(backend) {
       return true
     }
     // assert node match
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       if (!assertNodeMatch(elm, vnode, inVPre)) {
         return false
       }
@@ -717,7 +717,7 @@ export function createPatchFunction(backend) {
             if (i !== elm.innerHTML) {
               /* istanbul ignore if */
               if (
-                process.env.NODE_ENV !== 'production' &&
+                __DEV__ &&
                 typeof console !== 'undefined' &&
                 !hydrationBailed
               ) {
@@ -747,7 +747,7 @@ export function createPatchFunction(backend) {
             if (!childrenMatch || childNode) {
               /* istanbul ignore if */
               if (
-                process.env.NODE_ENV !== 'production' &&
+                __DEV__ &&
                 typeof console !== 'undefined' &&
                 !hydrationBailed
               ) {
@@ -828,7 +828,7 @@ export function createPatchFunction(backend) {
             if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
               invokeInsertHook(vnode, insertedVnodeQueue, true)
               return oldVnode
-            } else if (process.env.NODE_ENV !== 'production') {
+            } else if (__DEV__) {
               warn(
                 'The client-side rendered virtual DOM tree is not matching ' +
                   'server-rendered content. This is likely caused by incorrect ' +

+ 2 - 0
src/global.d.ts

@@ -1,3 +1,5 @@
+declare const __DEV__: boolean
+
 interface Window {
   __VUE_DEVTOOLS_GLOBAL_HOOK__: DevtoolsHook
 }

+ 3 - 3
src/platforms/web/compiler/directives/model.ts

@@ -20,7 +20,7 @@ export default function model(
   const tag = el.tag
   const type = el.attrsMap.type
 
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     // inputs with type="file" are read only and setting the input's
     // value will throw an error.
     if (tag === 'input' && type === 'file') {
@@ -48,7 +48,7 @@ export default function model(
     genComponentModel(el, value, modifiers)
     // component v-model doesn't need extra runtime
     return false
-  } else if (process.env.NODE_ENV !== 'production') {
+  } else if (__DEV__) {
     warn(
       `<${el.tag} v-model="${value}">: ` +
         `v-model is not supported on this element type. ` +
@@ -142,7 +142,7 @@ function genDefaultModel(
 
   // warn if v-bind:value conflicts with v-model
   // except for inputs with v-bind:type
-  if (process.env.NODE_ENV !== 'production') {
+  if (__DEV__) {
     const value = el.attrsMap['v-bind:value'] || el.attrsMap[':value']
     const typeBinding = el.attrsMap['v-bind:type'] || el.attrsMap[':type']
     if (value && !typeBinding) {

+ 1 - 1
src/platforms/web/compiler/modules/class.ts

@@ -4,7 +4,7 @@ import { getAndRemoveAttr, getBindingAttr, baseWarn } from 'compiler/helpers'
 function transformNode(el: ASTElement, options: CompilerOptions) {
   const warn = options.warn || baseWarn
   const staticClass = getAndRemoveAttr(el, 'class')
-  if (process.env.NODE_ENV !== 'production' && staticClass) {
+  if (__DEV__ && staticClass) {
     const res = parseText(staticClass, options.delimiters)
     if (res) {
       warn(

+ 1 - 1
src/platforms/web/compiler/modules/style.ts

@@ -7,7 +7,7 @@ function transformNode(el: ASTElement, options: CompilerOptions) {
   const staticStyle = getAndRemoveAttr(el, 'style')
   if (staticStyle) {
     /* istanbul ignore if */
-    if (process.env.NODE_ENV !== 'production') {
+    if (__DEV__) {
       const res = parseText(staticStyle, options.delimiters)
       if (res) {
         warn(

+ 6 - 6
src/platforms/web/entry-runtime-with-compiler.ts

@@ -26,7 +26,7 @@ Vue.prototype.$mount = function (
 
   /* istanbul ignore if */
   if (el === document.body || el === document.documentElement) {
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         `Do not mount Vue to <html> or <body> - mount to normal elements instead.`
       )
@@ -42,7 +42,7 @@ Vue.prototype.$mount = function (
         if (template.charAt(0) === '#') {
           template = idToTemplate(template)
           /* istanbul ignore if */
-          if (process.env.NODE_ENV !== 'production' && !template) {
+          if (__DEV__ && !template) {
             warn(
               `Template element not found or is empty: ${options.template}`,
               this
@@ -52,7 +52,7 @@ Vue.prototype.$mount = function (
       } else if (template.nodeType) {
         template = template.innerHTML
       } else {
-        if (process.env.NODE_ENV !== 'production') {
+        if (__DEV__) {
           warn('invalid template option:' + template, this)
         }
         return this
@@ -63,14 +63,14 @@ Vue.prototype.$mount = function (
     }
     if (template) {
       /* istanbul ignore if */
-      if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+      if (__DEV__ && config.performance && mark) {
         mark('compile')
       }
 
       const { render, staticRenderFns } = compileToFunctions(
         template,
         {
-          outputSourceRange: process.env.NODE_ENV !== 'production',
+          outputSourceRange: __DEV__,
           shouldDecodeNewlines,
           shouldDecodeNewlinesForHref,
           delimiters: options.delimiters,
@@ -82,7 +82,7 @@ Vue.prototype.$mount = function (
       options.staticRenderFns = staticRenderFns
 
       /* istanbul ignore if */
-      if (process.env.NODE_ENV !== 'production' && config.performance && mark) {
+      if (__DEV__ && config.performance && mark) {
         mark('compile end')
         measure(`vue ${this._name} compile`, 'compile', 'compile end')
       }

+ 1 - 1
src/platforms/web/runtime/components/transition-group.ts

@@ -69,7 +69,7 @@ export default {
           children.push(c)
           map[c.key] = c
           ;(c.data || (c.data = {})).transition = transitionData
-        } else if (process.env.NODE_ENV !== 'production') {
+        } else if (__DEV__) {
           const opts = c.componentOptions
           const name: string = opts
             ? opts.Ctor.options.name || opts.tag || ''

+ 2 - 7
src/platforms/web/runtime/components/transition.ts

@@ -100,7 +100,7 @@ export default {
     }
 
     // warn multiple elements
-    if (process.env.NODE_ENV !== 'production' && children.length > 1) {
+    if (__DEV__ && children.length > 1) {
       warn(
         '<transition> can only be used on a single element. Use ' +
           '<transition-group> for lists.',
@@ -111,12 +111,7 @@ export default {
     const mode: string = this.mode
 
     // warn invalid mode
-    if (
-      process.env.NODE_ENV !== 'production' &&
-      mode &&
-      mode !== 'in-out' &&
-      mode !== 'out-in'
-    ) {
+    if (__DEV__ && mode && mode !== 'in-out' && mode !== 'out-in') {
       warn('invalid <transition> mode: ' + mode, this.$parent)
     }
 

+ 1 - 1
src/platforms/web/runtime/directives/model.ts

@@ -88,7 +88,7 @@ function actuallySetSelected(el, binding, vm) {
   const value = binding.value
   const isMultiple = el.multiple
   if (isMultiple && !Array.isArray(value)) {
-    process.env.NODE_ENV !== 'production' &&
+    __DEV__ &&
       warn(
         `<select multiple v-model="${binding.expression}"> ` +
           `expects an Array value for its binding, but got ${Object.prototype.toString

+ 2 - 5
src/platforms/web/runtime/index.ts

@@ -48,10 +48,7 @@ if (inBrowser) {
     if (config.devtools) {
       if (devtools) {
         devtools.emit('init', Vue)
-      } else if (
-        process.env.NODE_ENV !== 'production' &&
-        process.env.NODE_ENV !== 'test'
-      ) {
+      } else if (__DEV__ && process.env.NODE_ENV !== 'test') {
         // @ts-expect-error
         console[console.info ? 'info' : 'log'](
           'Download the Vue Devtools extension for a better development experience:\n' +
@@ -60,7 +57,7 @@ if (inBrowser) {
       }
     }
     if (
-      process.env.NODE_ENV !== 'production' &&
+      __DEV__ &&
       process.env.NODE_ENV !== 'test' &&
       config.productionTip !== false &&
       typeof console !== 'undefined'

+ 2 - 2
src/platforms/web/runtime/modules/transition.ts

@@ -91,7 +91,7 @@ export function enter(vnode: VNodeWithData, toggleDisplay?: () => void) {
     isObject(duration) ? duration.enter : duration
   )
 
-  if (process.env.NODE_ENV !== 'production' && explicitEnterDuration != null) {
+  if (__DEV__ && explicitEnterDuration != null) {
     checkDuration(explicitEnterDuration, 'enter', vnode)
   }
 
@@ -203,7 +203,7 @@ export function leave(vnode: VNodeWithData, rm: Function) {
     isObject(duration) ? duration.leave : duration
   )
 
-  if (process.env.NODE_ENV !== 'production' && isDef(explicitLeaveDuration)) {
+  if (__DEV__ && isDef(explicitLeaveDuration)) {
     checkDuration(explicitLeaveDuration, 'leave', vnode)
   }
 

+ 1 - 2
src/platforms/web/util/index.ts

@@ -11,8 +11,7 @@ export function query(el: string | Element): Element {
   if (typeof el === 'string') {
     const selected = document.querySelector(el)
     if (!selected) {
-      process.env.NODE_ENV !== 'production' &&
-        warn('Cannot find element: ' + el)
+      __DEV__ && warn('Cannot find element: ' + el)
       return document.createElement('div')
     }
     return selected

+ 3 - 4
src/server/template-renderer/index.ts

@@ -231,10 +231,9 @@ export default class TemplateRenderer {
     const { contextKey = 'state', windowKey = '__INITIAL_STATE__' } =
       options || {}
     const state = this.serialize(context[contextKey])
-    const autoRemove =
-      process.env.NODE_ENV === 'production'
-        ? ';(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'
-        : ''
+    const autoRemove = __DEV__
+      ? ''
+      : ';(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());'
     const nonceAttr = context.nonce ? ` nonce="${context.nonce}"` : ''
     return context[contextKey]
       ? `<script${nonceAttr}>window.${windowKey}=${state}${autoRemove}</script>`

+ 1 - 1
src/sfc/parser.ts

@@ -27,7 +27,7 @@ export function parseComponent(
     sfc.errors.push(msg)
   }
 
-  if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
+  if (__DEV__ && options.outputSourceRange) {
     warn = (msg, range) => {
       const data: WarningMessage = { msg }
       if (range.start != null) {

+ 3 - 0
vitest.config.ts

@@ -15,6 +15,9 @@ export default defineConfig({
       vue: resolve('src/platforms/web/entry-runtime-with-compiler')
     }
   },
+  define: {
+    __DEV__: true
+  },
   test: {
     globals: true,
     environment: 'jsdom',