Evan You 10 лет назад
Родитель
Сommit
49b62889c6

+ 3 - 8
src/compiler/codegen.js

@@ -1,14 +1,9 @@
 /* @flow */
 
 import { genHandlers } from './events'
-import { ref } from './directives/ref'
 import { baseWarn } from './helpers'
-import { noop } from 'shared/util'
-
-const baseDirectives = {
-  ref,
-  cloak: noop
-}
+import baseDirectives from './directives/index'
+import { no } from 'shared/util'
 
 // configurable state
 let warn
@@ -32,7 +27,7 @@ export function generate (
   warn = options.warn || baseWarn
   platformModules = options.modules || []
   platformDirectives = options.directives || {}
-  isPlatformReservedTag = options.isReservedTag || (() => false)
+  isPlatformReservedTag = options.isReservedTag || no
   const code = ast ? genElement(ast) : '_h(_e("div"))'
   staticRenderFns = prevStaticRenderFns
   return {

+ 7 - 0
src/compiler/directives/index.js

@@ -0,0 +1,7 @@
+import ref from './ref'
+import { noop } from 'shared/util'
+
+export default {
+  ref,
+  cloak: noop
+}

+ 1 - 1
src/compiler/directives/ref.js

@@ -2,7 +2,7 @@
 
 import { addHook } from '../helpers'
 
-export function ref (el: ASTElement, dir: ASTDirective) {
+export default function ref (el: ASTElement, dir: ASTDirective) {
   // go up and check if this node is inside a v-for
   let isFor = false
   let parent = el

+ 3 - 3
src/compiler/parser/index.js

@@ -3,7 +3,7 @@
 import { decodeHTML } from 'entities'
 import { parseHTML } from './html-parser'
 import { parseText } from './text-parser'
-import { hyphenate, cached } from 'shared/util'
+import { hyphenate, cached, no } from 'shared/util'
 import {
   getAndRemoveAttr,
   addProp,
@@ -41,8 +41,8 @@ export function parse (
   options: CompilerOptions
 ): ASTElement | void {
   warn = options.warn || baseWarn
-  platformGetTagNamespace = options.getTagNamespace || (_ => null)
-  platformMustUseProp = options.mustUseProp || (_ => false)
+  platformGetTagNamespace = options.getTagNamespace || no
+  platformMustUseProp = options.mustUseProp || no
   platformModules = options.modules || []
   delimiters = options.delimiters
   const stack = []

+ 13 - 4
src/core/config.js

@@ -1,11 +1,14 @@
 /* @flow */
 
+import { no } from 'shared/util'
+
 export type Config = {
   preserveWhitespace: boolean,
   optionMergeStrategies: { [key: string]: Function },
   silent: boolean,
-  isReservedTag: (x: string) => boolean,
-  isUnknownElement: (x: string) => boolean,
+  isReservedTag: (x?: string) => boolean,
+  isUnknownElement: (x?: string) => boolean,
+  mustUseProp: (x?: string) => boolean,
   _assetTypes: Array<string>,
   _lifecycleHooks: Array<string>,
   _maxUpdateCount: number,
@@ -34,13 +37,19 @@ const config: Config = {
    * Check if a tag is reserved so that it cannot be registered as a
    * component. This is platform-dependent and may be overwritten.
    */
-  isReservedTag: _ => false,
+  isReservedTag: no,
 
   /**
    * Check if a tag is an unknown element.
    * Platform-dependent.
    */
-  isUnknownElement: _ => false,
+  isUnknownElement: no,
+
+  /**
+   * Check if an attribute must be bound using property, e.g. value
+   * Platform-dependent.
+   */
+  mustUseProp: no,
 
   /**
    * List of asset types that a component can own.

+ 5 - 4
src/entries/web-runtime.js

@@ -2,17 +2,18 @@
 
 import Vue from 'core/index'
 import config from 'core/config'
-import { createPatchFunction } from 'core/vdom/patch'
+import { noop } from 'shared/util'
 import * as nodeOps from 'web/runtime/node-ops'
-import platformDirectives from 'web/runtime/directives/index'
+import { createPatchFunction } from 'core/vdom/patch'
 import baseModules from 'core/vdom/modules/index'
 import platformModules from 'web/runtime/modules/index'
-import { query, isUnknownElement, isReservedTag } from 'web/util/index'
-import { noop } from 'core/util/index'
+import platformDirectives from 'web/runtime/directives/index'
+import { query, isUnknownElement, isReservedTag, mustUseProp } from 'web/util/index'
 
 // install platform specific utils
 Vue.config.isUnknownElement = isUnknownElement
 Vue.config.isReservedTag = isReservedTag
+Vue.config.mustUseProp = mustUseProp
 
 // install platform runtime directives
 Vue.options.directives = platformDirectives

+ 5 - 0
src/shared/util.js

@@ -171,6 +171,11 @@ export function toObject (arr: Array<any>): Object {
  */
 export function noop () {}
 
+/**
+ * Always return false.
+ */
+export const no = () => false
+
 /**
  * Generate a static keys string from compiler modules.
  */