@@ -4,6 +4,10 @@ var textParser = require('../parsers/text')
4
4
var dirParser = require ( '../parsers/directive' )
5
5
var templateParser = require ( '../parsers/template' )
6
6
7
+ // internal directives
8
+ var propDef = require ( '../directives/prop' )
9
+ // var componentDef = require('../directives/component')
10
+
7
11
module . exports = compile
8
12
9
13
/**
@@ -108,12 +112,11 @@ function teardownDirs (vm, dirs, destroying) {
108
112
109
113
/**
110
114
* Compile the root element of a component. There are
111
- * 4 types of things to process here:
115
+ * 3 types of things to process here:
112
116
*
113
117
* 1. props on parent container (child scope)
114
- * 2. v-with on parent container (child scope)
115
- * 3. other attrs on parent container (parent scope)
116
- * 4. attrs on the component template root node, if
118
+ * 2. other attrs on parent container (parent scope)
119
+ * 3. attrs on the component template root node, if
117
120
* replace:true (child scope)
118
121
*
119
122
* Also, if this is a block instance, we only need to
@@ -129,37 +132,25 @@ function compileRoot (el, options) {
129
132
var containerAttrs = options . _containerAttrs
130
133
var replacerAttrs = options . _replacerAttrs
131
134
var props = options . props
132
- var propsLinkFn , withLinkFn , parentLinkFn , replacerLinkFn
135
+ var propsLinkFn , parentLinkFn , replacerLinkFn
133
136
// 1. props
134
137
propsLinkFn = props
135
- ? compileProps ( el , containerAttrs , props , options )
138
+ ? compileProps ( el , containerAttrs , props )
136
139
: null
137
- // 2. v-with
138
- var withName = config . prefix + 'with'
139
- var withVal = containerAttrs && containerAttrs [ withName ]
140
- if ( withVal ) {
141
- containerAttrs [ withName ] = null
142
- withLinkFn = makeNodeLinkFn ( [ {
143
- name : 'with' ,
144
- descriptors : dirParser . parse ( withVal ) ,
145
- def : options . directives [ 'with' ]
146
- } ] )
147
- }
148
140
if ( ! isBlock ) {
149
- // 3 . container attributes
141
+ // 2 . container attributes
150
142
if ( containerAttrs ) {
151
143
parentLinkFn = compileDirectives ( containerAttrs , options )
152
144
}
153
145
if ( replacerAttrs ) {
154
- // 4 . replacer attributes
146
+ // 3 . replacer attributes
155
147
replacerLinkFn = compileDirectives ( replacerAttrs , options )
156
148
}
157
149
}
158
150
return function rootLinkFn ( vm , el , host ) {
159
- // explicitly passing null to props and v-with
151
+ // explicitly passing null to props
160
152
// linkers because they don't need a real element
161
153
if ( propsLinkFn ) propsLinkFn ( vm , null )
162
- if ( withLinkFn ) withLinkFn ( vm , null )
163
154
if ( parentLinkFn ) parentLinkFn ( vm . $parent , el , host )
164
155
if ( replacerLinkFn ) replacerLinkFn ( vm , el , host )
165
156
}
@@ -384,14 +375,13 @@ function makeChildLinkFn (linkFns) {
384
375
* @param {Element|DocumentFragment } el
385
376
* @param {Object } attrs
386
377
* @param {Array } propNames
387
- * @param {Object } options
388
378
* @return {Function } propsLinkFn
389
379
*/
390
380
391
- function compileProps ( el , attrs , propNames , options ) {
381
+ function compileProps ( el , attrs , propNames ) {
392
382
var props = [ ]
393
383
var i = propNames . length
394
- var name , value , param
384
+ var name , value , prop
395
385
while ( i -- ) {
396
386
name = propNames [ i ]
397
387
if ( / [ A - Z ] / . test ( name ) ) {
@@ -404,8 +394,9 @@ function compileProps (el, attrs, propNames, options) {
404
394
)
405
395
}
406
396
value = attrs [ name ]
407
- if ( value !== null ) {
408
- param = {
397
+ /* jshint eqeqeq:false */
398
+ if ( value != null ) {
399
+ prop = {
409
400
name : name ,
410
401
value : value
411
402
}
@@ -415,53 +406,44 @@ function compileProps (el, attrs, propNames, options) {
415
406
el . removeAttribute ( name )
416
407
}
417
408
attrs [ name ] = null
418
- param . dynamic = true
419
- param . value = textParser . tokensToExp ( tokens )
420
- param . oneTime = tokens . length === 1 && tokens [ 0 ] . oneTime
409
+ prop . dynamic = true
410
+ prop . value = textParser . tokensToExp ( tokens )
411
+ prop . oneTime = tokens . length === 1 && tokens [ 0 ] . oneTime
421
412
}
422
- props . push ( param )
413
+ props . push ( prop )
423
414
}
424
415
}
425
- return makeParamsLinkFn ( props , options )
416
+ return makePropsLinkFn ( props )
426
417
}
427
418
428
419
/**
429
- * Build a function that applies param attributes to a vm.
420
+ * Build a function that applies props to a vm.
430
421
*
431
422
* @param {Array } props
432
- * @param {Object } options
433
423
* @return {Function } propsLinkFn
434
424
*/
435
425
436
426
var dataAttrRE = / ^ d a t a - /
437
427
438
- function makeParamsLinkFn ( props , options ) {
439
- var def = options . directives [ 'with' ]
428
+ function makePropsLinkFn ( props ) {
440
429
return function propsLinkFn ( vm , el ) {
441
430
var i = props . length
442
- var param , path
431
+ var prop , path
443
432
while ( i -- ) {
444
- param = props [ i ]
433
+ prop = props [ i ]
445
434
// props could contain dashes, which will be
446
435
// interpreted as minus calculations by the parser
447
436
// so we need to wrap the path here
448
- path = _ . camelize ( param . name . replace ( dataAttrRE , '' ) )
449
- if ( param . dynamic ) {
450
- if ( param . oneTime ) {
451
- vm . $set ( path , vm . $parent . $get ( param . value ) )
452
- } else {
453
- // dynamic param attribtues are bound as v-with.
454
- // we can directly duck the descriptor here beacuse
455
- // param attributes cannot use expressions or
456
- // filters.
457
- vm . _bindDir ( 'with' , el , {
458
- arg : path ,
459
- expression : param . value
460
- } , def )
461
- }
437
+ path = _ . camelize ( prop . name . replace ( dataAttrRE , '' ) )
438
+ if ( prop . dynamic ) {
439
+ vm . _bindDir ( 'prop' , el , {
440
+ arg : path ,
441
+ expression : prop . value ,
442
+ oneWay : prop . oneTime
443
+ } , propDef )
462
444
} else {
463
445
// just set once
464
- vm . $set ( path , param . value )
446
+ vm . $set ( path , prop . value )
465
447
}
466
448
}
467
449
}
0 commit comments