Skip to content

Commit 0ee81b2

Browse files
committedDec 19, 2017
fix(weex): update recycle-list v-for transform
1 parent 3b32652 commit 0ee81b2

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

‎src/compiler/parser/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const onRE = /^@|^v-on:/
2323
export const dirRE = /^v-|^@|^:/
2424
export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
2525
export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
26-
const stripParensRE = /^\(|\)$/g
26+
export const stripParensRE = /^\(|\)$/g
2727

2828
const argRE = /:(.*)$/
2929
export const bindRE = /^:|^v-bind:/

‎src/platforms/weex/compiler/modules/recycle-list/v-for.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow */
22

3-
import { forAliasRE, forIteratorRE } from 'compiler/parser/index'
3+
import { forAliasRE, forIteratorRE, stripParensRE } from 'compiler/parser/index'
44
import { getAndRemoveAttr } from 'compiler/helpers'
55

66
export function preTransformVFor (el: ASTElement, options: CompilerOptions) {
@@ -10,18 +10,19 @@ export function preTransformVFor (el: ASTElement, options: CompilerOptions) {
1010
}
1111
const inMatch = exp.match(forAliasRE)
1212
if (inMatch) {
13-
const alias = inMatch[1].trim()
13+
const alias = inMatch[1].trim().replace(stripParensRE, '')
1414
const desc: Object = {
1515
'@expression': inMatch[2].trim(),
1616
'@alias': alias
1717
}
1818
const iteratorMatch = alias.match(forIteratorRE)
1919
if (iteratorMatch) {
20-
desc['@alias'] = iteratorMatch[1].trim()
21-
desc['@index'] = iteratorMatch[2].trim()
22-
if (iteratorMatch[3]) {
23-
desc['@key'] = iteratorMatch[2].trim()
24-
desc['@index'] = iteratorMatch[3].trim()
20+
desc['@alias'] = alias.replace(forIteratorRE, '')
21+
if (iteratorMatch[2]) {
22+
desc['@key'] = iteratorMatch[1].trim()
23+
desc['@index'] = iteratorMatch[2].trim()
24+
} else {
25+
desc['@index'] = iteratorMatch[1].trim()
2526
}
2627
}
2728
delete el.attrsMap['v-for']

0 commit comments

Comments
 (0)
Please sign in to comment.