diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index 70154a169f..0261934f83 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -23,7 +23,7 @@ export const onRE = /^@|^v-on:/ export const dirRE = /^v-|^@|^:/ export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/ -const stripParensRE = /^\(|\)$/g +export const stripParensRE = /^\(|\)$/g const argRE = /:(.*)$/ export const bindRE = /^:|^v-bind:/ diff --git a/src/platforms/weex/compiler/modules/recycle-list/v-for.js b/src/platforms/weex/compiler/modules/recycle-list/v-for.js index baa6de97ce..8f3a19d62f 100644 --- a/src/platforms/weex/compiler/modules/recycle-list/v-for.js +++ b/src/platforms/weex/compiler/modules/recycle-list/v-for.js @@ -1,6 +1,6 @@ /* @flow */ -import { forAliasRE, forIteratorRE } from 'compiler/parser/index' +import { forAliasRE, forIteratorRE, stripParensRE } from 'compiler/parser/index' import { getAndRemoveAttr } from 'compiler/helpers' export function preTransformVFor (el: ASTElement, options: CompilerOptions) { @@ -10,18 +10,19 @@ export function preTransformVFor (el: ASTElement, options: CompilerOptions) { } const inMatch = exp.match(forAliasRE) if (inMatch) { - const alias = inMatch[1].trim() + const alias = inMatch[1].trim().replace(stripParensRE, '') const desc: Object = { '@expression': inMatch[2].trim(), '@alias': alias } const iteratorMatch = alias.match(forIteratorRE) if (iteratorMatch) { - desc['@alias'] = iteratorMatch[1].trim() - desc['@index'] = iteratorMatch[2].trim() - if (iteratorMatch[3]) { - desc['@key'] = iteratorMatch[2].trim() - desc['@index'] = iteratorMatch[3].trim() + desc['@alias'] = alias.replace(forIteratorRE, '') + if (iteratorMatch[2]) { + desc['@key'] = iteratorMatch[1].trim() + desc['@index'] = iteratorMatch[2].trim() + } else { + desc['@index'] = iteratorMatch[1].trim() } } delete el.attrsMap['v-for']