Skip to content

Commit

Permalink
perf(cli): add whitePropsList to auto add empty attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuifx committed May 22, 2020
1 parent 3ff98ac commit ccfbbe8
Showing 1 changed file with 80 additions and 1 deletion.
81 changes: 80 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,82 @@ import {parseXML, serializeXML} from '../compilers/xml.js';
import {Parser} from 'htmlparser2';
import path from 'path';

let whitePropsList = [
'scale-area',
'inertia',
'out-of-bounds',
'disabled',
'scale',
'scroll-x',
'scroll-y',
'scroll-with-animation',
'enable-back-to-top',
'enable-flex',
'scroll-anchoring',
'refresher-enabled',
'refresher-triggered',
'indicator-dots',
'autoplay',
'circular',
'vertical',
'skip-hidden-item-layout',
'hover-stop-propagation',
'show-info',
'active',
'selectable',
'decode',
'plain',
'loading',
'show-message-card',
'checked',
'read-only',
'show-img-size',
'show-img-toolbar',
'show-img-resize',
'report-submit',
'password',
'auto-focus',
'focus',
'confirm-hold',
'hold-keyboard',
'show-value',
'auto-height',
'fixed',
'disable-default-padding',
'loop',
'controls',
'webp',
'lazy-load',
'show-menu-by-longpress',
'muted',
'background-mute',
'autopush',
'zoom',
'mirror',
'remote-mirror',
'enable-agc',
'enable-ans',
'danmu-btn',
'enable-danmu',
'page-gesture',
'show-mute-btn',
'enable-play-gesture',
'vslide-gesture',
'show-casting-button',
'picture-in-picture-show-progress',
'enable-auto-rotation',
'show-screen-lock-button',
'show-location',
'enable-3D',
'show-compass',
'show-scale',
'enable-overlooking',
'enable-rotate',
'enable-satellite',
'enable-traffic',
'disable-scroll',
];

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

Expand All @@ -16,7 +92,10 @@ function walkDOM(dom) {
if (ele.attribs) {
Object.keys(ele.attribs).forEach((attrName)=>{
// suff empty attribs
if (ele.attribs[attrName] === '') ele.attribs[attrName] = attrName;
if (
ele.attribs[attrName] === '' &&
~whitePropsList.indexOf(attrName)
) ele.attribs[attrName] = attrName;
});
}

Expand Down

0 comments on commit ccfbbe8

Please sign in to comment.