@@ -149,22 +149,26 @@ describe("[variables] elements", () => {
149
149
} )
150
150
} )
151
151
152
- describe ( "References and variables " , ( ) => {
152
+ describe ( "Variables of v-for and references " , ( ) => {
153
153
const code = "<template><div v-for=\"x of xs\" :key=\"x\">{{x + y}}<div>{{x}}</div></div>{{x}}</template>"
154
- let ast = null
154
+ let variables = null
155
+ let vForReferences = null
156
+ let vBindKeyReferences = null
157
+ let mustacheReferences1 = null
158
+ let mustacheReferences2 = null
159
+ let mustacheReferences3 = null
155
160
156
161
before ( ( ) => {
157
- ast = parse ( code , Object . assign ( { filePath : "test.vue" } , PARSER_OPTIONS ) ) . ast
162
+ const ast = parse ( code , Object . assign ( { filePath : "test.vue" } , PARSER_OPTIONS ) ) . ast
163
+ variables = ast . templateBody . children [ 0 ] . variables
164
+ vForReferences = ast . templateBody . children [ 0 ] . startTag . attributes [ 0 ] . value . references
165
+ vBindKeyReferences = ast . templateBody . children [ 0 ] . startTag . attributes [ 1 ] . value . references
166
+ mustacheReferences1 = ast . templateBody . children [ 0 ] . children [ 0 ] . references
167
+ mustacheReferences2 = ast . templateBody . children [ 0 ] . children [ 1 ] . children [ 0 ] . references
168
+ mustacheReferences3 = ast . templateBody . children [ 1 ] . references
158
169
} )
159
170
160
171
it ( "should have relationship each other" , ( ) => {
161
- const variables = ast . templateBody . children [ 0 ] . variables
162
- const vForReferences = ast . templateBody . children [ 0 ] . startTag . attributes [ 0 ] . value . references
163
- const vBindKeyReferences = ast . templateBody . children [ 0 ] . startTag . attributes [ 1 ] . value . references
164
- const mustacheReferences1 = ast . templateBody . children [ 0 ] . children [ 0 ] . references
165
- const mustacheReferences2 = ast . templateBody . children [ 0 ] . children [ 1 ] . children [ 0 ] . references
166
- const mustacheReferences3 = ast . templateBody . children [ 1 ] . references
167
-
168
172
assert ( variables . length === 1 )
169
173
assert ( vForReferences . length === 1 )
170
174
assert ( vBindKeyReferences . length === 1 )
@@ -182,4 +186,63 @@ describe("References and variables", () => {
182
186
assert ( mustacheReferences2 [ 0 ] . variable === variables [ 0 ] )
183
187
assert ( mustacheReferences3 [ 0 ] . variable === null )
184
188
} )
189
+
190
+ it ( "`Variable#references` should be non-enumerable" , ( ) => {
191
+ for ( const variable of variables ) {
192
+ assert ( Object . getOwnPropertyDescriptor ( variable , "references" ) . enumerable === false )
193
+ }
194
+ } )
195
+
196
+ it ( "`Reference#variable` should be non-enumerable" , ( ) => {
197
+ for ( const reference of [ ] . concat ( vForReferences , vBindKeyReferences , mustacheReferences1 , mustacheReferences2 , mustacheReferences3 ) ) {
198
+ assert ( Object . getOwnPropertyDescriptor ( reference , "variable" ) . enumerable === false )
199
+ }
200
+ } )
201
+ } )
202
+
203
+ describe ( "Variables of template-scope and references" , ( ) => {
204
+ const code = "<template><template scope=\"x\" :key=\"x\">{{x + y}}<div>{{x}}</div></template>{{x}}</template>"
205
+ let variables = null
206
+ let vBindKeyReferences = null
207
+ let mustacheReferences1 = null
208
+ let mustacheReferences2 = null
209
+ let mustacheReferences3 = null
210
+
211
+ before ( ( ) => {
212
+ const ast = parse ( code , Object . assign ( { filePath : "test.vue" } , PARSER_OPTIONS ) ) . ast
213
+ variables = ast . templateBody . children [ 0 ] . variables
214
+ vBindKeyReferences = ast . templateBody . children [ 0 ] . startTag . attributes [ 1 ] . value . references
215
+ mustacheReferences1 = ast . templateBody . children [ 0 ] . children [ 0 ] . references
216
+ mustacheReferences2 = ast . templateBody . children [ 0 ] . children [ 1 ] . children [ 0 ] . references
217
+ mustacheReferences3 = ast . templateBody . children [ 1 ] . references
218
+ } )
219
+
220
+ it ( "should have relationship each other" , ( ) => {
221
+ assert ( variables . length === 1 )
222
+ assert ( vBindKeyReferences . length === 1 )
223
+ assert ( mustacheReferences1 . length === 2 )
224
+ assert ( mustacheReferences2 . length === 1 )
225
+ assert ( mustacheReferences3 . length === 1 )
226
+ assert ( variables [ 0 ] . references . length === 3 )
227
+ assert ( variables [ 0 ] . references [ 0 ] === vBindKeyReferences [ 0 ] )
228
+ assert ( variables [ 0 ] . references [ 1 ] === mustacheReferences1 [ 0 ] )
229
+ assert ( variables [ 0 ] . references [ 2 ] === mustacheReferences2 [ 0 ] )
230
+ assert ( vBindKeyReferences [ 0 ] . variable === variables [ 0 ] )
231
+ assert ( mustacheReferences1 [ 0 ] . variable === variables [ 0 ] )
232
+ assert ( mustacheReferences1 [ 1 ] . variable === null )
233
+ assert ( mustacheReferences2 [ 0 ] . variable === variables [ 0 ] )
234
+ assert ( mustacheReferences3 [ 0 ] . variable === null )
235
+ } )
236
+
237
+ it ( "`Variable#references` should be non-enumerable" , ( ) => {
238
+ for ( const variable of variables ) {
239
+ assert ( Object . getOwnPropertyDescriptor ( variable , "references" ) . enumerable === false )
240
+ }
241
+ } )
242
+
243
+ it ( "`Reference#variable` should be non-enumerable" , ( ) => {
244
+ for ( const reference of [ ] . concat ( vBindKeyReferences , mustacheReferences1 , mustacheReferences2 , mustacheReferences3 ) ) {
245
+ assert ( Object . getOwnPropertyDescriptor ( reference , "variable" ) . enumerable === false )
246
+ }
247
+ } )
185
248
} )
0 commit comments