From ccfbbe8a153924794b0710246c32545a71971eda Mon Sep 17 00:00:00 2001 From: Genuifx Date: Fri, 22 May 2020 17:55:30 +0800 Subject: [PATCH] perf(cli): add whitePropsList to auto add empty attributes --- .../src/optimizer/stuffEmptyAttributes.js | 81 ++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/packages/wxa-cli/src/optimizer/stuffEmptyAttributes.js b/packages/wxa-cli/src/optimizer/stuffEmptyAttributes.js index 6c915d7b..375ff679 100644 --- a/packages/wxa-cli/src/optimizer/stuffEmptyAttributes.js +++ b/packages/wxa-cli/src/optimizer/stuffEmptyAttributes.js @@ -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)); @@ -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; }); }