@@ -4,8 +4,8 @@ import he from 'he'
4
4
import { parseHTML } from './html-parser'
5
5
import { parseText } from './text-parser'
6
6
import { parseFilters } from './filter-parser'
7
- import { cached , no , camelize } from 'shared/util'
8
7
import { genAssignmentCode } from '../directives/model'
8
+ import { extend , cached , no , camelize } from 'shared/util'
9
9
import { isIE , isEdge , isServerRendering } from 'core/util/env'
10
10
11
11
import {
@@ -23,7 +23,7 @@ export const onRE = /^@|^v-on:/
23
23
export const dirRE = / ^ v - | ^ @ | ^ : /
24
24
export const forAliasRE = / ( .* ?) \s + (?: i n | o f ) \s + ( .* ) /
25
25
export const forIteratorRE = / , ( [ ^ , \} \] ] * ) (?: , ( [ ^ , \} \] ] * ) ) ? $ /
26
- export const stripParensRE = / ^ \( | \) $ / g
26
+ const stripParensRE = / ^ \( | \) $ / g
27
27
28
28
const argRE = / : ( .* ) $ /
29
29
export const bindRE = / ^ : | ^ v - b i n d : /
@@ -355,26 +355,34 @@ function processRef (el) {
355
355
export function processFor ( el : ASTElement ) {
356
356
let exp
357
357
if ( ( exp = getAndRemoveAttr ( el , 'v-for' ) ) ) {
358
- const inMatch = exp . match ( forAliasRE )
359
- if ( ! inMatch ) {
360
- process . env . NODE_ENV !== 'production' && warn (
358
+ const res = parseFor ( exp )
359
+ if ( res ) {
360
+ extend ( el , res )
361
+ } else if ( process . env . NODE_ENV !== 'production' ) {
362
+ warn (
361
363
`Invalid v-for expression: ${ exp } `
362
364
)
363
- return
364
365
}
365
- el . for = inMatch [ 2 ] . trim ( )
366
- const alias = inMatch [ 1 ] . trim ( ) . replace ( stripParensRE , '' )
367
- const iteratorMatch = alias . match ( forIteratorRE )
368
- if ( iteratorMatch ) {
369
- el . alias = alias . replace ( forIteratorRE , '' )
370
- el . iterator1 = iteratorMatch [ 1 ] . trim ( )
371
- if ( iteratorMatch [ 2 ] ) {
372
- el . iterator2 = iteratorMatch [ 2 ] . trim ( )
373
- }
374
- } else {
375
- el . alias = alias
366
+ }
367
+ }
368
+
369
+ export function parseFor ( exp : string ) : ?Object {
370
+ const inMatch = exp . match ( forAliasRE )
371
+ if ( ! inMatch ) return
372
+ const res = { }
373
+ res . for = inMatch [ 2 ] . trim ( )
374
+ const alias = inMatch [ 1 ] . trim ( ) . replace ( stripParensRE , '' )
375
+ const iteratorMatch = alias . match ( forIteratorRE )
376
+ if ( iteratorMatch ) {
377
+ res . alias = alias . replace ( forIteratorRE , '' )
378
+ res . iterator1 = iteratorMatch [ 1 ] . trim ( )
379
+ if ( iteratorMatch [ 2 ] ) {
380
+ res . iterator2 = iteratorMatch [ 2 ] . trim ( )
376
381
}
382
+ } else {
383
+ res . alias = alias
377
384
}
385
+ return res
378
386
}
379
387
380
388
function processIf ( el ) {
0 commit comments