Skip to content

Commit

Permalink
fix(build): swan 中将 v-for 上的 key 编译为 trackBy (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
allen-zh committed Jul 3, 2019
1 parent 11e216b commit 30febdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ describe('[swan]directive:for', () => {
dirFor(undefined, undefined, attrs, node);

expect(attrs).toEqual({
's-for': 'item, index in items',
's-for': 'item, index in items trackBy item.id',
's-for-index': 'index',
's-for-item': 'item',
's-for-key': 'item.id'
's-for-item': 'item'
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function getPostTrans(options) {

module.exports = function mark(source, options) {
const {
components
components = {}
} = options;

let componentsInUsed = {};
Expand Down
13 changes: 7 additions & 6 deletions packages/mars-build/src/swan/transform/directive/for.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@ module.exports = function dirFor(param, value, attrs, node) {
} = node;

if (forText) {
attrs[MAP_FOR['v-for']] = `${alias || 'item'}, ${iterator1 || 'index'} in ${forText}`;
let forExp = `${alias || 'item'}, ${iterator1 || 'index'} in ${forText}`;

if (iterator1) {
attrs[MAP_FOR.iterator1] = iterator1;
if (key) {
forExp += ` trackBy ${key}`;
}

if (key) {
attrs[MAP_FOR.key] = key;
attrs[MAP_FOR['v-for']] = forExp;

if (iterator1) {
attrs[MAP_FOR.iterator1] = iterator1;
}

if (alias) {
attrs[MAP_FOR.alias] = alias;
}
}

};

0 comments on commit 30febdf

Please sign in to comment.