Skip to content

Commit

Permalink
Add support of array for mods field
Browse files Browse the repository at this point in the history
  • Loading branch information
skad0 committed Oct 1, 2016
1 parent d9e6b2d commit 1d1e8bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/normalize2.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,14 @@ module.exports = function (decl) {
return mods;
}

for (let modName in entity.mods) {
mods[modName] = entity.mods[modName];
if (Array.isArray(entity.mods)) {
entity.mods.forEach(item => {
mods[item] = true;
});
} else {
for (let modName in entity.mods) {
mods[modName] = entity.mods[modName];
}
}

return mods;
Expand Down
13 changes: 13 additions & 0 deletions test/normalize2/block-mods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ test('sould support mods', t => {
]);
});

test('should support mods as array', t => {
const decl = {
block: 'block',
mods: ['m1', 'm2']
};

t.deepEqual(normalize(decl), [
{ entity: { block: 'block' }, tech: undefined },
{ entity: { block: 'block', modName: 'm1', modVal: true }, tech: undefined },
{ entity: { block: 'block', modName: 'm2', modVal: true }, tech: undefined }
]);
});

test('should pass mods to elem', t => {
const decl = {
block: 'block',
Expand Down

0 comments on commit 1d1e8bc

Please sign in to comment.