File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 11var _ = require ( '../util' )
22var Watcher = require ( '../watcher' )
3+ var expParser = require ( '../parsers/expression' )
4+ var literalRE = / ^ ( t r u e | f a l s e | \s ? ( ' [ ^ ' ] * ' | " [ ^ " ] " ) \s ? ) $ /
35
46module . exports = {
57
@@ -20,6 +22,17 @@ module.exports = {
2022 _ . warn (
2123 'v-with must be used on an instance with a parent.'
2224 )
25+ } else if ( literalRE . test ( parentKey ) ) {
26+ // no need to setup watchers for literal bindings
27+ if ( ! this . arg ) {
28+ _ . warn (
29+ 'v-with cannot bind literal value as $data: ' +
30+ parentKey
31+ )
32+ } else {
33+ var value = expParser . parse ( parentKey ) . get ( )
34+ child . $set ( childKey , value )
35+ }
2336 } else {
2437
2538 // simple lock to avoid circular updates.
Original file line number Diff line number Diff line change @@ -152,5 +152,35 @@ if (_.inBrowser) {
152152 expect ( el . innerHTML ) . toBe ( '<!--v-start--><p>AAA</p><p>DDD</p><!--v-end--><!--v-component-->' )
153153 } )
154154
155+ it ( 'bind literal values should not trigger setter warning' , function ( done ) {
156+ var vm = new Vue ( {
157+ el : el ,
158+ template : '<div v-component="test" v-with="a:\'test\'"></div>' ,
159+ components : {
160+ test : {
161+ template : '{{a}}'
162+ }
163+ }
164+ } )
165+ expect ( el . firstChild . innerHTML ) . toBe ( 'test' )
166+ vm . _children [ 0 ] . a = 'changed'
167+ _ . nextTick ( function ( ) {
168+ expect ( el . firstChild . innerHTML ) . toBe ( 'changed' )
169+ expect ( _ . warn ) . not . toHaveBeenCalled ( )
170+ done ( )
171+ } )
172+ } )
173+
174+ it ( 'should warn when binding literal value without childKey' , function ( ) {
175+ var vm = new Vue ( {
176+ el : el ,
177+ template : '<div v-component="test" v-with="\'test\'"></div>' ,
178+ components : {
179+ test : { }
180+ }
181+ } )
182+ expect ( _ . warn ) . toHaveBeenCalled ( )
183+ } )
184+
155185 } )
156186}
You can’t perform that action at this time.
0 commit comments