Skip to content

Commit c06b4c4

Browse files
committed
alpha.5 syntax update (wip)
1 parent 5b9759c commit c06b4c4

File tree

13 files changed

+64
-66
lines changed

13 files changed

+64
-66
lines changed

src/compiler/compile-props.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ module.exports = function compileProps (el, propOptions) {
2626

2727
if (process.env.NODE_ENV !== 'production' && name === '$data') {
2828
_.warn('Do not use $data as prop.')
29-
el.removeAttribute('$data')
30-
el.removeAttribute(':$data')
31-
el.removeAttribute('bind-$data')
3229
continue
3330
}
3431

@@ -73,9 +70,9 @@ module.exports = function compileProps (el, propOptions) {
7370
prop.filters = parsed.filters
7471
// check binding type
7572
if (_.isLiteral(value)) {
76-
// for bind- literals such as numbers and booleans,
77-
// there's no need to setup a prop binding, so we
78-
// can optimize them as a one-time set.
73+
// for expressions containing literal numbers and
74+
// booleans, there's no need to setup a prop binding,
75+
// so we can optimize them as a one-time set.
7976
prop.optimizedLiteral = true
8077
} else {
8178
prop.dynamic = true

src/compiler/compile.js

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ var templateParser = require('../parsers/template')
88
var resolveAsset = _.resolveAsset
99

1010
// special binding prefixes
11-
var bindRE = /^bind-|^:/
12-
var onRE = /^on-/
13-
var transitionRE = /^(bind-|:)?transition$/
11+
var bindRE = /^v-bind:|^:/
12+
var onRE = /^v-on:|^@/
13+
var literalRE = /#$/
14+
var argRE = /:(.*)$/
15+
var transitionRE = /^(v-bind:|:)?transition$/
1416
var nodeRefRE = /^\$\$\./
1517

1618
// terminal directives
@@ -262,7 +264,7 @@ function compileElement (el, options) {
262264
if (el.tagName === 'TEXTAREA') {
263265
var tokens = textParser.parse(el.value)
264266
if (tokens) {
265-
el.setAttribute('bind-value', textParser.tokensToExp(tokens))
267+
el.setAttribute(':value', textParser.tokensToExp(tokens))
266268
el.value = ''
267269
}
268270
}
@@ -545,49 +547,15 @@ function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
545547
function compileDirectives (attrs, options) {
546548
var i = attrs.length
547549
var dirs = []
548-
var attr, name, value, dirName, dirDef, isLiteral
550+
var attr, name, value, dirName, arg, dirDef, isLiteral
549551
while (i--) {
550552
attr = attrs[i]
551553
name = attr.name
552554
value = attr.value
553-
// Core directive
554-
if (name.indexOf('v-') === 0) {
555-
dirName = name.slice(2)
556-
557-
// check literal
558-
if (dirName.charAt(dirName.length - 1) === '#') {
559-
isLiteral = true
560-
dirName = dirName.slice(0, -1)
561-
} else {
562-
isLiteral = false
563-
}
564-
565-
dirDef = resolveAsset(options, 'directives', dirName)
566-
if (process.env.NODE_ENV !== 'production') {
567-
_.assertAsset(dirDef, 'directive', dirName)
568-
}
569-
if (dirDef) {
570-
if (!isLiteral && _.isLiteral(value)) {
571-
value = _.stripQuotes(value)
572-
isLiteral = true
573-
}
574-
pushDir(dirName, dirDef, {
575-
literal: isLiteral
576-
})
577-
}
578-
} else
579-
580-
// event handlers
581-
if (onRE.test(name)) {
582-
pushDir('on', internalDirectives.on, {
583-
arg: name.replace(onRE, '')
584-
})
585-
} else
586555

587556
// special attribute: transition
588557
if (transitionRE.test(name)) {
589-
dirName = name.replace(bindRE, '')
590-
pushDir(dirName, internalDirectives[dirName], {
558+
pushDir('transition', internalDirectives.transition, {
591559
literal: !bindRE.test(name)
592560
})
593561
} else
@@ -600,6 +568,13 @@ function compileDirectives (attrs, options) {
600568
})
601569
} else
602570

571+
// event handlers
572+
if (onRE.test(name)) {
573+
pushDir('on', internalDirectives.on, {
574+
arg: name.replace(onRE, '')
575+
})
576+
} else
577+
603578
// attribute bindings
604579
if (bindRE.test(name)) {
605580
dirName = name.replace(bindRE, '')
@@ -610,6 +585,37 @@ function compileDirectives (attrs, options) {
610585
arg: dirName
611586
})
612587
}
588+
} else
589+
590+
// normal directives
591+
if (name.indexOf('v-') === 0) {
592+
// check literal
593+
isLiteral = literalRE.test(dirName)
594+
if (isLiteral) {
595+
name = name.replace(literalRE, '')
596+
}
597+
// check arg
598+
arg = (arg = name.match(argRE)) && arg[1]
599+
if (arg) {
600+
name = name.replace(argRE, '')
601+
}
602+
// extract directive name
603+
dirName = name.slice(2)
604+
dirDef = resolveAsset(options, 'directives', dirName)
605+
606+
if (process.env.NODE_ENV !== 'production') {
607+
_.assertAsset(dirDef, 'directive', dirName)
608+
}
609+
610+
if (dirDef) {
611+
if (!isLiteral && _.isLiteral(value)) {
612+
value = _.stripQuotes(value)
613+
isLiteral = true
614+
}
615+
pushDir(dirName, dirDef, {
616+
literal: isLiteral
617+
})
618+
}
613619
}
614620
}
615621

src/compiler/transclude.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function transcludeTemplate (el, options) {
8484
_.resolveAsset(options, 'components', tag) ||
8585
replacer.hasAttribute('is') ||
8686
replacer.hasAttribute(':is') ||
87-
replacer.hasAttribute('bind-is') ||
87+
replacer.hasAttribute('v-bind:is') ||
8888
// element directive
8989
_.resolveAsset(options, 'elementDirectives', tag) ||
9090
// for block

src/directive.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,6 @@ Directive.prototype.param = function (name) {
163163
if (param != null) {
164164
this.el.removeAttribute(name)
165165
param = (this._scope || this.vm).$interpolate(param)
166-
} else {
167-
param = _.getBindAttr(this.el, name)
168-
if (param != null) {
169-
param = (this._scope || this.vm).$eval(param)
170-
process.env.NODE_ENV !== 'production' && _.log(
171-
'You are using bind- syntax on "' + name + '", which ' +
172-
'is a directive param. It will be evaluated only once.'
173-
)
174-
}
175166
}
176167
return param
177168
}

src/directives/internal/component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
* <comp> or <div v-component="comp">
1313
*
1414
* - dynamic:
15-
* <component bind-is="view">
15+
* <component :is="view">
1616
*/
1717

1818
bind: function () {
@@ -84,7 +84,7 @@ module.exports = {
8484

8585
/**
8686
* Public update, called by the watcher in the dynamic
87-
* literal scenario, e.g. <component bind-is="view">
87+
* literal scenario, e.g. <component :is="view">
8888
*/
8989

9090
update: function (value) {

src/directives/internal/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
exports.attr = require('./attr')
2-
exports.class = require('./class')
31
exports.el = require('./el')
4-
exports.on = require('./on')
52
exports.prop = require('./prop')
6-
exports.style = require('./style')
73
exports.transition = require('./transition')
84
exports.component = require('./component')
File renamed without changes.
File renamed without changes.

src/directives/public/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ exports.show = require('./show')
1010
// two-way binding
1111
exports.model = require('./model')
1212

13+
// event handling
14+
exports.on = require('./on')
15+
16+
// attributes
17+
exports.bind = require('./bind')
18+
exports['class'] = require('./class')
19+
exports.style = require('./style')
20+
1321
// cloak
1422
exports.cloak = require('./cloak')

src/directives/public/model/radio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = {
88
var number = this.param('number') != null
99

1010
this.getValue = function () {
11-
// value overwrite via bind-value
11+
// value overwrite via v-bind:value
1212
if (el.hasOwnProperty('_value')) {
1313
return el._value
1414
}

0 commit comments

Comments
 (0)