Skip to content

Commit 6f8e6b3

Browse files
committed
syntax update per #1308
1 parent a24079e commit 6f8e6b3

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

src/compiler/compile.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ var resolveAsset = _.resolveAsset
99
var componentDef = require('../directives/component')
1010

1111
// special binding prefixes
12-
var bindRE = /^bind-|^:/
13-
var onRE = /^on-/
12+
var bindRE = /^:/
13+
var onRE = /^@/
14+
var argRE = /:(.*)$/
1415
var nodeRefRE = /^\$\$\./
1516

1617
// terminal directives
@@ -547,29 +548,26 @@ function compileDirectives (attrs, options) {
547548
value = attr.value
548549
// Core directive
549550
if (name.indexOf(config.prefix) === 0) {
550-
dirName = name.slice(config.prefix.length)
551-
552551
// check literal
553-
if (dirName.charAt(dirName.length - 1) === '#') {
552+
if (name.charAt(name.length - 1) === '#') {
554553
isLiteral = true
555-
dirName = dirName.slice(0, -1)
554+
name = name.slice(0, -1)
556555
} else {
557556
isLiteral = false
558557
}
559-
558+
// check argument
559+
arg = (arg = name.match(argRE)) && arg[1]
560+
// extract directive name
561+
dirName = name
562+
.slice(config.prefix.length)
563+
.replace(argRE, '')
560564
dirDef = resolveAsset(options, 'directives', dirName)
561565
if (process.env.NODE_ENV !== 'production') {
562566
_.assertAsset(dirDef, 'directive', dirName)
563567

564568
// deprecations
565569
if (dirName === 'transition') {
566570
_.deprecation.V_TRANSITION()
567-
} else if (dirName === 'class') {
568-
_.deprecation.V_CLASS()
569-
} else if (dirName === 'style') {
570-
_.deprecation.V_STYLE()
571-
} else if (dirName === 'on') {
572-
_.deprecation.V_ON()
573571
} else if (dirName === 'attr') {
574572
_.deprecation.V_ATTR()
575573
} else if (dirName === 'el') {
@@ -582,6 +580,7 @@ function compileDirectives (attrs, options) {
582580
name: dirName,
583581
descriptors: dirParser.parse(value),
584582
def: dirDef,
583+
arg: arg,
585584
literal: isLiteral
586585
})
587586
}

src/deprecations.js

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ if (process.env.NODE_ENV !== 'production') {
6868

6969
DIR_ARGS: function (exp) {
7070
warn(
71-
'Directives will no longer take arguments in 1.0.0. Found in directive ' +
72-
'"' + exp + '"' + newBindingSyntaxLink
71+
exp + ': Directive arguments will be moved into the attribute name in 1.0.0 - ' +
72+
'use v-dirname:arg="expression" syntax instead.' + newBindingSyntaxLink
7373
)
7474
},
7575

@@ -95,31 +95,10 @@ if (process.env.NODE_ENV !== 'production') {
9595
)
9696
},
9797

98-
V_CLASS: function () {
99-
warn(
100-
'v-class will no longer be a directive in 1.0.0; Use "bind-class" instead.' +
101-
newBindingSyntaxLink
102-
)
103-
},
104-
105-
V_STYLE: function () {
106-
warn(
107-
'v-style will no longer be a directive in 1.0.0; Use "bind-style" instead.' +
108-
newBindingSyntaxLink
109-
)
110-
},
111-
11298
V_ATTR: function () {
11399
warn(
114-
'v-attr will no longer be a directive in 1.0.0; Use the "bind-" syntax instead.' +
115-
newBindingSyntaxLink
116-
)
117-
},
118-
119-
V_ON: function () {
120-
warn(
121-
'v-on will no longer be a directive in 1.0.0; Use the "on-" syntax instead.' +
122-
newBindingSyntaxLink
100+
'v-attr will be renamed to v-bind in 1.0.0. Also, use v-bind:attr="expression" ' +
101+
'syntax instead.' + newBindingSyntaxLink
123102
)
124103
},
125104

src/directives/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ exports['if'] = require('./if')
2525
// but we still want to expose them for advanced usage.
2626
exports._component = require('./component')
2727
exports._prop = require('./prop')
28+
29+
// 1.0.0 compat
30+
exports.bind = exports.attr

src/directives/on.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
bind: function () {
1010
// 1.0.0 key filter
1111
var rawArg = this.arg
12-
var keyIndex = rawArg.indexOf('-')
12+
var keyIndex = rawArg.indexOf(':')
1313
if (keyIndex > -1) {
1414
this.arg = rawArg.slice(0, keyIndex)
1515
this.key = rawArg.slice(keyIndex + 1)

0 commit comments

Comments
 (0)