ソースを参照

new set of deprecation warnings

Evan You 10 年 前
コミット
ffb2ddab0e
3 ファイル変更110 行追加1 行削除
  1. 34 1
      src/compiler/compile.js
  2. 66 0
      src/deprecations.js
  3. 10 0
      src/parsers/directive.js

+ 34 - 1
src/compiler/compile.js

@@ -7,6 +7,10 @@ var templateParser = require('../parsers/template')
 var resolveAsset = _.resolveAsset
 var componentDef = require('../directives/component')
 
+var propRE = /^prop-/
+var bindRE = /^bind-/
+var onRE = /^on-/
+
 // terminal directives
 var terminalDirectives = [
   'repeat',
@@ -513,11 +517,25 @@ function compileDirectives (attrs, options) {
     attr = attrs[i]
     name = attr.name
     value = attr.value
+    // Core directive
     if (name.indexOf(config.prefix) === 0) {
       dirName = name.slice(config.prefix.length)
       dirDef = resolveAsset(options, 'directives', dirName)
       if (process.env.NODE_ENV !== 'production') {
         _.assertAsset(dirDef, 'directive', dirName)
+
+        if (dirName === 'transition') {
+          _.deprecation.V_TRANSITION()
+        } else if (dirName === 'class') {
+          _.deprecation.V_CLASS()
+        } else if (dirName === 'style') {
+          _.deprecation.V_STYLE()
+        } else if (dirName === 'on') {
+          _.deprecation.V_ON()
+        } else if (dirName === 'attr') {
+          _.deprecation.V_ATTR()
+        }
+
       }
       if (dirDef) {
         dirs.push({
@@ -526,7 +544,17 @@ function compileDirectives (attrs, options) {
           def: dirDef
         })
       }
-    } else if (config.interpolate) {
+    } else
+    // attribute bindings
+    if (bindRE.test(name)) {
+      // TODO handle bind
+    } else
+    // event handlers
+    if (onRE.test(name)) {
+      // TODO handle events
+    } else
+    // deprecated: mustache interpolations inside attribtues
+    if (config.interpolate) {
       dir = collectAttrDirective(name, value, options)
       if (dir) {
         dirs.push(dir)
@@ -586,6 +614,11 @@ function collectAttrDirective (name, value, options) {
   var tokens = textParser.parse(value)
   var isClass = name === 'class'
   if (tokens) {
+
+    if (process.env.NODE_ENV !== 'production') {
+      _.deprecation.ATTR_INTERPOLATION()
+    }
+
     var dirName = isClass ? 'class' : 'attr'
     var def = options.directives[dirName]
     var i = tokens.length

+ 66 - 0
src/deprecations.js

@@ -5,6 +5,8 @@ if (process.env.NODE_ENV !== 'production') {
     _.warn('{DEPRECATION} ' + msg)
   }
 
+  var newBindingSyntaxLink = ' See https://github.com/yyx990803/vue/issues/1173 for details.'
+
   _.deprecation = {
 
     REPEAT: function () {
@@ -62,6 +64,70 @@ if (process.env.NODE_ENV !== 'production') {
         'v-el will be deprecated in 1.0.0. ' +
         'See https://github.com/yyx990803/vue/issues/1198 for details.'
       )
+    },
+
+    DIR_ARGS: function () {
+      warn(
+        'Directives will no longer take arguments in 1.0.0. ' + newBindingSyntaxLink
+      )
+    },
+
+    MUTI_CLAUSES: function () {
+      warn(
+        'Directives will no longer support multiple clause syntax in 1.0.0.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_TRANSITION: function () {
+      warn(
+        'v-transition will no longer be a directive in 1.0.0; It will become a ' +
+        'special attribute without the prefix. Ues "transition" instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_REF: function () {
+      warn(
+        'v-ref will no longer be a directive in 1.0.0; It will become a ' +
+        'special attribute without the prefix. Ues "ref" instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_CLASS: function () {
+      warn(
+        'v-class will no longer be a directive in 1.0.0; Use "bind-class" instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_STYLE: function () {
+      warn(
+        'v-style will no longer be a directive in 1.0.0; Use "bind-style" instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_ATTR: function () {
+      warn(
+        'v-attr will no longer be a directive in 1.0.0; Use the "bind-" syntax instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    V_ON: function () {
+      warn(
+        'v-on will no longer be a directive in 1.0.0; Use the "on-" syntax instead.' +
+        newBindingSyntaxLink
+      )
+    },
+
+    ATTR_INTERPOLATION: function () {
+      warn(
+        'Mustache interpolations inside attributes will be deprecated in 1.0.0. ' +
+        'Use the "bind-" syntax instead.' + newBindingSyntaxLink
+      )
     }
 
   }

+ 10 - 0
src/parsers/directive.js

@@ -143,6 +143,11 @@ exports.parse = function (s) {
       if (argRE.test(arg)) {
         argIndex = i + 1
         dir.arg = _.stripQuotes(arg) || arg
+
+        if (process.env.NODE_ENV !== 'production') {
+          _.deprecation.DIR_ARGS()
+        }
+
       }
     } else if (
       c === 0x7C && // pipe
@@ -176,5 +181,10 @@ exports.parse = function (s) {
   }
 
   cache.put(s, dirs)
+
+  if (dirs.length > 1) {
+    _.deprecation.MUTI_CLAUSES()
+  }
+
   return dirs
 }