@@ -4,6 +4,10 @@ var textParser = require('../parsers/text')
44var dirParser = require ( '../parsers/directive' )
55var templateParser = require ( '../parsers/template' )
66
7+ // internal directives
8+ var propDef = require ( '../directives/prop' )
9+ // var componentDef = require('../directives/component')
10+
711module . exports = compile
812
913/**
@@ -108,12 +112,11 @@ function teardownDirs (vm, dirs, destroying) {
108112
109113/**
110114 * 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:
112116 *
113117 * 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
117120 * replace:true (child scope)
118121 *
119122 * Also, if this is a block instance, we only need to
@@ -129,37 +132,25 @@ function compileRoot (el, options) {
129132 var containerAttrs = options . _containerAttrs
130133 var replacerAttrs = options . _replacerAttrs
131134 var props = options . props
132- var propsLinkFn , withLinkFn , parentLinkFn , replacerLinkFn
135+ var propsLinkFn , parentLinkFn , replacerLinkFn
133136 // 1. props
134137 propsLinkFn = props
135- ? compileProps ( el , containerAttrs , props , options )
138+ ? compileProps ( el , containerAttrs , props )
136139 : 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- }
148140 if ( ! isBlock ) {
149- // 3 . container attributes
141+ // 2 . container attributes
150142 if ( containerAttrs ) {
151143 parentLinkFn = compileDirectives ( containerAttrs , options )
152144 }
153145 if ( replacerAttrs ) {
154- // 4 . replacer attributes
146+ // 3 . replacer attributes
155147 replacerLinkFn = compileDirectives ( replacerAttrs , options )
156148 }
157149 }
158150 return function rootLinkFn ( vm , el , host ) {
159- // explicitly passing null to props and v-with
151+ // explicitly passing null to props
160152 // linkers because they don't need a real element
161153 if ( propsLinkFn ) propsLinkFn ( vm , null )
162- if ( withLinkFn ) withLinkFn ( vm , null )
163154 if ( parentLinkFn ) parentLinkFn ( vm . $parent , el , host )
164155 if ( replacerLinkFn ) replacerLinkFn ( vm , el , host )
165156 }
@@ -384,14 +375,13 @@ function makeChildLinkFn (linkFns) {
384375 * @param {Element|DocumentFragment } el
385376 * @param {Object } attrs
386377 * @param {Array } propNames
387- * @param {Object } options
388378 * @return {Function } propsLinkFn
389379 */
390380
391- function compileProps ( el , attrs , propNames , options ) {
381+ function compileProps ( el , attrs , propNames ) {
392382 var props = [ ]
393383 var i = propNames . length
394- var name , value , param
384+ var name , value , prop
395385 while ( i -- ) {
396386 name = propNames [ i ]
397387 if ( / [ A - Z ] / . test ( name ) ) {
@@ -404,8 +394,9 @@ function compileProps (el, attrs, propNames, options) {
404394 )
405395 }
406396 value = attrs [ name ]
407- if ( value !== null ) {
408- param = {
397+ /* jshint eqeqeq:false */
398+ if ( value != null ) {
399+ prop = {
409400 name : name ,
410401 value : value
411402 }
@@ -415,53 +406,44 @@ function compileProps (el, attrs, propNames, options) {
415406 el . removeAttribute ( name )
416407 }
417408 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
421412 }
422- props . push ( param )
413+ props . push ( prop )
423414 }
424415 }
425- return makeParamsLinkFn ( props , options )
416+ return makePropsLinkFn ( props )
426417}
427418
428419/**
429- * Build a function that applies param attributes to a vm.
420+ * Build a function that applies props to a vm.
430421 *
431422 * @param {Array } props
432- * @param {Object } options
433423 * @return {Function } propsLinkFn
434424 */
435425
436426var dataAttrRE = / ^ d a t a - /
437427
438- function makeParamsLinkFn ( props , options ) {
439- var def = options . directives [ 'with' ]
428+ function makePropsLinkFn ( props ) {
440429 return function propsLinkFn ( vm , el ) {
441430 var i = props . length
442- var param , path
431+ var prop , path
443432 while ( i -- ) {
444- param = props [ i ]
433+ prop = props [ i ]
445434 // props could contain dashes, which will be
446435 // interpreted as minus calculations by the parser
447436 // 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 )
462444 } else {
463445 // just set once
464- vm . $set ( path , param . value )
446+ vm . $set ( path , prop . value )
465447 }
466448 }
467449 }
0 commit comments