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 1
1
var _ = require ( '../util' )
2
2
var Watcher = require ( '../watcher' )
3
+ var expParser = require ( '../parsers/expression' )
4
+ var literalRE = / ^ ( t r u e | f a l s e | \s ? ( ' [ ^ ' ] * ' | " [ ^ " ] " ) \s ? ) $ /
3
5
4
6
module . exports = {
5
7
@@ -20,6 +22,17 @@ module.exports = {
20
22
_ . warn (
21
23
'v-with must be used on an instance with a parent.'
22
24
)
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
+ }
23
36
} else {
24
37
25
38
// simple lock to avoid circular updates.
Original file line number Diff line number Diff line change @@ -152,5 +152,35 @@ if (_.inBrowser) {
152
152
expect ( el . innerHTML ) . toBe ( '<!--v-start--><p>AAA</p><p>DDD</p><!--v-end--><!--v-component-->' )
153
153
} )
154
154
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
+
155
185
} )
156
186
}
You can’t perform that action at this time.
0 commit comments