Skip to content

Commit

Permalink
fix(cli): add directive to stuff empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuifx committed Jun 2, 2020
1 parent 843a00e commit b4147a9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/wxa-cli/src/optimizer/stuffEmptyAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import {parseXML, serializeXML} from '../compilers/xml.js';
import {Parser} from 'htmlparser2';
import path from 'path';

let whiteDirectiveList = [
'hidden',
'wx:else',
];

let whitePropsList = [
'scale-area',
'inertia',
Expand Down Expand Up @@ -79,6 +84,8 @@ let whitePropsList = [
'disable-scroll',
];

let whiteList = whitePropsList.concat(whiteDirectiveList);

export function stuffEmptyAttributs(mdl) {
let dom = parseXML(mdl.code, path.parse(mdl.src));

Expand All @@ -94,7 +101,7 @@ function walkDOM(dom) {
// suff empty attribs
if (
ele.attribs[attrName] === '' &&
~whitePropsList.indexOf(attrName)
~whiteList.indexOf(attrName)
) ele.attribs[attrName] = attrName;
});
}
Expand Down

0 comments on commit b4147a9

Please sign in to comment.