Skip to content

Commit

Permalink
fix(weex): update recycle-list v-for transform
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 19, 2017
1 parent 3b32652 commit 0ee81b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:/
Expand Down
15 changes: 8 additions & 7 deletions src/platforms/weex/compiler/modules/recycle-list/v-for.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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']
Expand Down

0 comments on commit 0ee81b2

Please sign in to comment.