@@ -4,8 +4,8 @@ import he from 'he'
44import { parseHTML } from './html-parser'
55import { parseText } from './text-parser'
66import { parseFilters } from './filter-parser'
7- import { cached , no , camelize } from 'shared/util'
87import { genAssignmentCode } from '../directives/model'
8+ import { extend , cached , no , camelize } from 'shared/util'
99import { isIE , isEdge , isServerRendering } from 'core/util/env'
1010
1111import {
@@ -23,7 +23,7 @@ export const onRE = /^@|^v-on:/
2323export const dirRE = / ^ v - | ^ @ | ^ : /
2424export const forAliasRE = / ( .* ?) \s + (?: i n | o f ) \s + ( .* ) /
2525export const forIteratorRE = / , ( [ ^ , \} \] ] * ) (?: , ( [ ^ , \} \] ] * ) ) ? $ /
26- export const stripParensRE = / ^ \( | \) $ / g
26+ const stripParensRE = / ^ \( | \) $ / g
2727
2828const argRE = / : ( .* ) $ /
2929export const bindRE = / ^ : | ^ v - b i n d : /
@@ -355,26 +355,34 @@ function processRef (el) {
355355export function processFor ( el : ASTElement ) {
356356 let exp
357357 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 (
361363 `Invalid v-for expression: ${ exp } `
362364 )
363- return
364365 }
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 ( )
376381 }
382+ } else {
383+ res . alias = alias
377384 }
385+ return res
378386}
379387
380388function processIf ( el ) {
0 commit comments