@hap-toolkit/compiler
Advanced tools
Comparing version 1.9.17-alpha.7 to 1.9.17-alpha.8
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _path=_interopRequireDefault(require("path")),_sharedUtils=require("@hap-toolkit/shared-utils"),_exp=_interopRequireDefault(require("./exp")),_style=_interopRequireDefault(require("../style")),_model=_interopRequireDefault(require("./model")),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const extList=[".mix",".ux"],richtextType=["mix","ux"],REG_TAG_DATA_ATTR=/^data-\w+/,REG_CLASS_VALUE=/[^{}\s]+((?=\s)|$)|[^{}\s]*\{\{[^]*?\}\}[^\s]*/g,RESERVED_TAGS=Object.keys(_utils.FRAG_TYPE).map((e=>_utils.FRAG_TYPE[e])),RESERVED_DIRECTIVES=/^(model:|dir:)/,tagCommon={events:["click","focus","blur","key","longpress","appear","disappear","swipe","touchstart","touchmove","touchend","touchcancel","resize","animationstart","animationiteration","animationend"],attrs:{id:{},style:{},class:{},disabled:{enum:["false","true"]},if:{def:"true"},elif:{def:"true"},else:{},for:{},tid:{},show:{def:"true"},"aria-label":{},"aria-unfocusable":{enum:["false","true"]},forcedark:{enum:["true","false"]},focusable:{enum:["false","true"]},vtags:{},vindex:{},autofocus:{enum:["false","true"]},descendantfocusability:{enum:["before","after","block"]}},children:["block","slot","component"],parents:["block"]},tagNatives={div:{supportCard:!0,attrs:{enablevideofullscreencontainer:{enum:["false","true"]}}},a:{supportCard:!0,textContent:!0,children:["span"],attrs:{visited:{enum:["false","true"]},href:{}}},text:{supportCard:!0,textContent:!0,children:["a","span"],attrs:{type:{enum:["text","html"]},"letter-spacing":{}}},span:{supportCard:!0,textContent:!0,excludeRoot:!0,children:["span"],parents:["text","a","span"],attrs:{extendCommon:!1,id:{},style:{},class:{},for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},label:{supportCard:!0,textContent:!0,atomic:!0,attrs:{target:{}}},image:{events:["complete","error"],empty:!0,supportCard:!0,selfClosing:!0,alias:["img"],atomic:!0,attrs:{src:{},alt:{},enablenightmode:{enum:["true","false"]},autoplay:{enum:["true","false"]}}},slider:{selfClosing:!0,atomic:!0,attrs:{enabled:{enum:["true","false"]},min:{def:0},max:{def:100},step:{def:1},value:{def:0}},events:["change"]},web:{atomic:!0,events:["pagestart","pagefinish","titlereceive","error","message","progress"],attrs:{src:{},trustedurl:{},allowthirdpartycookies:{enum:["false","true"]},enablenightmode:{enum:["true","false"]},showloadingdialog:{enum:["false","true"]},supportzoom:{enum:["true","false"]}}},list:{children:["list-item"],attrs:{scrollpage:{enum:["false","true"]},focusbehavior:{enum:["aligned","edged"]}},events:["scroll","scrollbottom","scrolltop","scrollend","scrolltouchup","selected"]},"list-item":{excludeRoot:!0,parents:["list"],attrs:{type:{required:!0},disallowintercept:{}}},block:{excludeRoot:!0,supportCard:!0,attrs:{extendCommon:!1,for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},component:{supportCard:!0,excludeRoot:!0,attrs:{extendCommon:!1,is:{required:!0},for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},slot:{excludeRoot:!0,attrs:{name:{def:"default"},extendCommon:!1,content:{}}},input:{supportCard:!0,selfClosing:!0,atomic:!0,empty:!0,attrs:{type:{enum:["text","button","checkbox","radio","email","date","time","number","password","tel","eventbutton","hidetext","showtext"]},autocomplete:{enum:["on","off"]},enterkeytype:{enum:["default","next","go","done","send","search"]},eventtype:{enum:["shortcut"]},"true-value":{},"false-value":{},maxlength:{},checked:{enum:["false","true"]},name:{},value:{},placeholder:{}},events:["change","enterkeyclick","selectionchange"]},button:{supportCard:!0,textContent:!0,atomic:!0},refresh:{attrs:{offset:{def:"132px"},refreshing:{enum:["false","true"]},type:{enum:["auto","pulldown"]},"enable-refresh":{enum:["true","false"]}},events:["refresh"]},refresh2:{attrs:{pulldownrefreshing:{enum:["false","true"]},pulluprefreshing:{enum:["false","true"]},animationduration:{def:300},enablepulldown:{enum:["true","false"]},enablepullup:{enum:["false","true"]},reboundable:{enum:["false","true"]},gesture:{enum:["true","false"]},offset:{def:"132px"},refreshing:{enum:["false","true"]},type:{enum:["auto","pulldown"]}},events:["pulldownrefresh","pulluprefresh","refresh"],onceChildren:["refresh-header","refresh-footer"]},"refresh-header":{attrs:{dragrate:{def:300},triggerratio:{def:300},tiggersize:{def:300},maxdragratio:{def:300},maxdragsize:{def:300},refreshdisplayratio:{def:300},refreshdisplaysize:{def:300},spinnerstyle:{enum:["translation","front","behind"]},autorefresh:{enum:["false","true"]},translationwithcontent:{enum:["false","true"]}},events:["move"],parents:["refresh2"]},"refresh-footer":{attrs:{dragrate:{def:300},triggerratio:{def:300},tiggersize:{def:300},maxdragratio:{def:300},maxdragdize:{def:300},refreshdisplayratio:{def:300},refreshdisplaysize:{def:300},spinnerstyle:{enum:["translation","front","behind"]},autorefresh:{enum:["false","true"]},translationwithcontent:{enum:["true","false"]}},events:["move"],parents:["refresh2"]},ad:{attrs:{unitid:{def:""},type:{def:"native"},adid:{}},events:["adclick","error"]},"ad-clickable-area":{supportCard:!0,textContent:!0,atomic:!0,attrs:{type:{}}},"ad-custom":{attrs:{adUnitId:{},channel:{},extendCommon:!1},events:["load","error","show","click","close"]},swiper:{attrs:{index:{def:0},autoplay:{enum:["false","true"]},interval:{def:3e3},indicator:{enum:["true","false"]},loop:{enum:["true","false"]},duration:{},vertical:{enum:["false","true"]},previousmargin:{def:"0px"},nextmargin:{def:"0px"},enableswipe:{enum:["true","false"]}},events:["change"]},progress:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{percent:{def:0},type:{enum:["horizontal","circular"]}}},picker:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{type:{required:!0,enum:["text","date","time","multi-text"]},start:{def:"1970-1-1"},end:{def:"2100-12-31"},range:{},selected:{},value:{}},events:["change","columnchange","cancel"]},switch:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{checked:{enum:["false","true"]}},events:["change"]},textarea:{supportCard:!0,atomic:!0,textContent:!0,attrs:{placeholder:{},maxlength:{}},events:["change","selectionchange","linechange"]},video:{empty:!0,attrs:{src:{},muted:{enum:["false","true"]},autoplay:{enum:["false","true"]},controls:{enum:["true","false"]},poster:{},orientation:{enum:["landscape","portrait"]},titlebar:{enum:["true","false"]},title:{},playcount:{},speed:{def:1}},events:["prepared","start","pause","finish","error","seeking","seeked","timeupdate","fullscreenchange"]},camera:{atomic:!0,selfClosing:!0,attrs:{deviceposition:{enum:["back","front"]},flash:{enum:["auto","on","off","torch"]},framesize:{enum:["low","normal","high"]},autoexposurelock:{enum:["false","true"]},autowhitebalancelock:{enum:["false","true"]}},events:["error","camerainitdone","cameraframe"]},map:{children:["custommarker"],attrs:{latitude:{},longitude:{},coordtype:{},scale:{def:0},rotate:{def:0},markers:{},showmylocation:{enum:["true","false"]},polylines:{},polygons:{},circles:{},controls:{},groundoverlays:{},includepoints:{},heatmaplayer:{},showcompass:{enum:["true","false"]},enableoverlooking:{enum:["false","true"]},enablezoom:{enum:["true","false"]},enablescroll:{enum:["true","false"]},enablerotate:{enum:["true","false"]},showscale:{enum:["false","true"]},showzoom:{enum:["false","true"]}},events:["loaded","regionchange","tap","markertap","callouttap","controltap","poitap"]},custommarker:{parents:["map"],attrs:{custommarkerattr:{}}},canvas:{atomic:!0},stack:{supportCard:!0,events:["fullscreenchange"]},richtext:{textContent:!0,atomic:!0,attrs:{type:{required:!0,enum:["html"].concat(richtextType)},scene:{}},events:["start","complete","pagechanged","splitpage"]},tabs:{children:["tab-bar","tab-content"],attrs:{index:{def:0}},events:["change"]},"tab-content":{parents:["tabs"],attrs:{scrollable:{enum:["true","false"]}}},"tab-bar":{parents:["tabs"],attrs:{mode:{enum:["fixed","scrollable"]}}},popup:{supportCard:!0,children:["text"],attrs:{target:{required:!0},placement:{enum:["left","top","right","bottom","topLeft","topRight","bottomLeft","bottomRight"],def:"bottom"}},events:["visibilitychange"]},rating:{supportCard:!0,atomic:!0,attrs:{numstars:{def:"5"},rating:{def:"0"},stepsize:{def:"0.5"},indicator:{enum:["false","true"]}},events:["change"]},select:{supportCard:!0,children:["option"],events:["change"],excludeRoot:!0},option:{supportCard:!0,parents:["select"],atomic:!0,textContent:!0,attrs:{selected:{def:!1},value:{}},excludeRoot:!0},marquee:{supportCard:!0,textContent:!0,atomic:!0,attrs:{scrollamount:{def:6},loop:{def:-1},direction:{enum:["left","right"]},value:{def:"6px"}},events:["bounce","finish","start"]},scrollview:{attrs:{"scroll-direction":{enum:["vertical","horizontal","vertical_horizontal"]},"show-scrollbar":{enum:["true","false"]}},events:["scroll","scrollbegindrag","scrollenddrag","scrollstart","scrollstop"]},drawer:{attrs:{enableswipe:{enum:["true","false"]}},events:["change","scroll"]},lottie:{empty:!0,attrs:{source:{required:!0},progress:{},speed:{},loop:{enum:[!0,!1]},autoplay:{enum:[!1,!0]},rendermode:{enum:["AUTOMATIC","HARDWARE","SOFTWARE"]}},events:["complete","error","change"]},"drawer-navigation":{parents:["drawer"],attrs:{direction:{enum:["start","end"]}}},"slide-view":{attrs:{edge:{enum:["right","left"]},enableslide:{enum:["true","false"]},isopen:{enum:["false","true"]},layer:{enum:["above","same"]},buttons:{}},events:["open","close","slide","buttonclick"]},"section-list":{children:["section-group","section-item"],events:["scroll","scrollend","scrolltouchup","scrolltop","scrollbottom"]},"section-group":{children:["section-group","section-item","section-header"],attrs:{expand:{enum:["false","true"]}},events:["change"]},"section-header":{parents:["section-group"]},"section-item":{},"share-button":{empty:!0,attrs:{value:{},title:{},description:{},icon:{},url:{},path:{},params:{},platforms:{},usepageparams:{enum:["true","false"],def:"false"}},events:["success","fail","cancel"]},"shortcut-button":{empty:!0,attrs:{value:{}}}},tagReserved={};let tagComponents=[];const tagNativeKeys=Object.keys(tagNatives),tagAliasMap={},tagAttrMap={},tagEnumAttrMap={},tagDefaultAttrMap={},tagRequireAttrMap={},tagAtomics={},tagEmpty={},tagTextContent={},tagChildrenMap={},tagOnceChildrenMap={},tagParentsMap={},tagEventsMap={},tagNotRoot=[];function checkTagName(e,t,a={}){const s=t.result,n=t.log,r=_path.default.extname(a.filePath);let l=e.tagName;const o=e.childNodes||[],i=e.__location||{};tagComponents=a.importNames||[];const u=tagComponents.includes(l);!u&&tagAliasMap[l]&&("img"!==l&&n.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+l+"` 自动转换为 `"+tagAliasMap[l]+"`"}),l=tagAliasMap[l]),s.type=l,RESERVED_TAGS.indexOf(l)>=0?n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+l+"` 是系统保留的组件名, 请修改"}):hasTagDefined(l)||n.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${l}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[l]&&!tagNatives[l].supportCard&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+l+"`, 请修改"}),e._isroot&&tagNotRoot.hasOwnProperty(l)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不能作为根组件"}),s.attr=s.attr||{};const c=e.attrs||[],p=[];if(c.forEach((function(e){p.push(e.name.toLowerCase())})),e._isroot){const e=["for","if","elif","else","show"];p.forEach((t=>{e.indexOf(t)>=0&&n.push({line:i.line||1,column:i.col||1,reason:"WARN: 根节点 `"+l+"` 不能使用属性 `"+t+"`"})}))}if(!u){if(tagEmpty.hasOwnProperty(l)&&o.length>0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 内不能有子节点与文字,请修改"}),tagAtomics.hasOwnProperty(l)&&"ad-clickable-area"!==l&&(tagTextContent.hasOwnProperty(l)?o.length>0&&o.every((e=>"#text"===e.nodeName||(n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 是原子类型,不应该有子节点"}),!1))):(o.length>1||o[0]&&"#text"!==o[0].nodeName)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 只能有一个文字子节点"})),tagDefaultAttrMap[l]&&Object.keys(tagDefaultAttrMap[l]).forEach((t=>{const s=p.indexOf(t);s>=0&&""===c[s].value?(c[s].value=tagDefaultAttrMap[l][t],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[l][t]+"`"})):"slot"===l&&s<0&&(e.attrs.push({name:t,value:tagDefaultAttrMap[l][t]}),_sharedUtils.colorconsole.warn(`标签 ${l} 的属性 \`${t}\` 值为空, 默认设置为缺省值 \`${tagDefaultAttrMap[l][t]}\` ${a.filePath} @${i.line||1},${i.col||1}`))})),tagRequireAttrMap[l]&&tagRequireAttrMap[l].forEach((e=>{p.indexOf(e)<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 没有定义属性 `"+e+"`"})})),tagEnumAttrMap[l]&&Object.keys(tagEnumAttrMap[l]).forEach((e=>{const t=p.indexOf(e);if(t>=0){const a=c[t].value;if(!_exp.default.isExpr(a)){const s=tagEnumAttrMap[l][e];s.indexOf(a)<0&&(c[t].value=s[0],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+s[0]+"`"}))}}})),tagAttrMap[l]&&"component"!==l&&p.forEach((e=>{if(!e.match(/^(on|@)/)){if(r.indexOf(extList[2])>=-1&&/^(:|v-|key|ref|is|slot|slot-scope)/.test(e))return;if(RESERVED_DIRECTIVES.test(e))return;const t=checkDataAttr(e),a=Object.prototype.hasOwnProperty.call(tagAttrMap[l],e);t||a||n.push({line:i.line||1,column:i.col||1,reason:"WARN: 组件 `"+l+"` 不支持属性 `"+e})}})),tagEventsMap[l]&&"component"!==l){const e=tagEventsMap[l];p.forEach((t=>{if(t.match(/^(on|@)/)){const s=t.replace(/^(on|@)/,""),r=["appear","disappear","swipe"];a.uxType===_utils.ENTRY_TYPE.CARD&&r.indexOf(s.toLowerCase())>-1&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片组件 `"+l+"` 不支持事件 `"+s+"`"}),e.indexOf(s.toLowerCase())<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持事件 `"+s+"`"})}}))}if(o.length>0){const t=new Set,s={};o.forEach(((e,r)=>{if(isReservedTag(l)&&isReservedTag(e.nodeName)){const o=tagParentsMap[e.nodeName],u=tagChildrenMap[l],c=tagOnceChildrenMap[l];if("slot"===e.nodeName){let s=e.parentNode;for(;s;){if("slot"===s.tagName){_sharedUtils.colorconsole.warn(`slot标签内不应该嵌套slot ${a.filePath}@${i.line||1},${i.col||1}`);break}s=s.parentNode}const n={};e.attrs.map((e=>{n[e.name]=e.value})),n.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(n.name)&&_sharedUtils.colorconsole.warn(`标签${e.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):n.name="default",t.has(n.name)?_sharedUtils.colorconsole.warn(`标签${l}内存在name为 \`${n.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):t.add(n.name)}if(o&&o.indexOf(l)<0||u&&u.indexOf(e.nodeName)<0)n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持子组件 `"+e.nodeName+"`"});else if(c&&c.indexOf(e.nodeName)>-1){let t;(s[e.nodeName]||0===s[e.nodeName])&&(t=!0),s[e.nodeName]={index:r,duplicated:t}}}}));const r=Object.keys(s);r.length&&(r.filter((e=>s[e].duplicated)).forEach((e=>{n.push({line:i.line||1,column:i.col||1,reason:`'WARN: 组件 \`${e}\` 只允许在 \`${l}\` 组件中出现一次`})})),e.childNodes=o.filter(((e,t)=>!(s[e.nodeName]&&s[e.nodeName].duplicated&&t!==s[e.nodeName].index))))}isSupportedSelfClosing(l)||!i.startTag||i.endTag||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 缺少闭合标签,请检查"}),"list-item"===l&&hasIfOrFor(o)&&n.push({line:i.line||1,column:i.col||1,reason:"WARN: `list-item` 内部需谨慎使用指令 if 或 for,相同 type 属性的 list-item, DOM 结构必须完全相同`"})}}function checkId(e,t){e&&(t.result.id=_exp.default.isExpr(e)?(0,_exp.default)(e,!0,t.isLite):e)}function checkDataAttr(e){return REG_TAG_DATA_ATTR.test(e)}function checkBuild(e,t){e&&(t.result.append="tree"===e?"tree":"single")}function checkClass(className,output){let hasBinding,classList=[];if(className=className.trim(),className){let start=0,end=0;const segs=[],matched=className.match(REG_CLASS_VALUE);if(matched){let e;matched.forEach((t=>{end=className.indexOf(t,start),e=className.slice(start,end),e.length&&segs.push(e),segs.push(t),start+=e.length+t.length}))}segs.push(className.slice(start));const isLite=output.isLite;if(classList=segs.reduce(((e,t)=>_exp.default.isExpr(t)?(hasBinding=!0,e.push((0,_exp.default)(t,!1,isLite)),e):e.concat(t.split(/\s+/g).filter((e=>e)).map((e=>isLite?e:`'${e}'`)))),[]),classList=classList.filter((e=>e.trim())),isLite){if(!isValidClassArray(segs)){const e=new Error("轻卡 class 样式不支持动态数据绑定 {{}} 和静态样式混用");throw e.isExpressionError=!0,e.expression=className,e}output.result.class=className,output.result.classList=classList}else if(hasBinding){const code="(function () {return ["+classList.join(", ")+"]})";try{output.result.classList=eval(code)}catch(e){throw e.isExpressionError=!0,e.expression=className,e}}else output.result.classList=classList.map((e=>e.slice(1,-1)))}}function checkStyle(e,t,a,s){let n={};const r=t.log;if(e){const l=t.isLite;if(_exp.default.singleExpr(e)){const s=_exp.default.removeExprffix(e);return _exp.default.isExpr(s)?r.push({line:a.line||1,column:a.col||1,reason:"ERROR: style 属性不能嵌套多层{{}}"}):n=(0,_exp.default)(e,!0,l),void(t.result.style=n)}if(e.split(";").forEach((function(e){let t,o,i,u=e.trim().split(":");u.length>2&&(u[1]=u.slice(1).join(":"),u=u.slice(0,2)),2===u.length&&(t=u[0].trim(),t=(0,_utils.hyphenedToCamelCase)(t),o=u[1].trim(),o=(0,_exp.default)(o,!0,l),l?n[t]=o:(i=_style.default.validateDelaration(t,o,s),o=i.value,o.forEach((e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(n[e.n]=e.v)})),i.log&&r.push({line:a.line||1,column:a.col||1,reason:i.log.reason})))})),"object"==typeof n)for(let e in n)_style.default.shouldAddToDependency(e,n[e])&&t.depFiles.push(n[e]);t.result.style=n}}function checkIs(e,t,a){const s=t.log;e?(e=_exp.default.addExprffix(e),t.result.is=(0,_exp.default)(e,!0,t.isLite)):s.push({line:a.line||1,column:a.col||1,reason:"WARN: is 属性为空"})}function checkIf(e,t,a,s,n){const r=t.log;if(e){e=_exp.default.addExprffix(e);const s=t.isLite;a?e="{{"+buildConditionExp(n)+"}}":(n.length>0&&(n.length=0),n.push(`${e.substr(2,e.length-4)}`)),t.result.shown=s?e:(0,_exp.default)(e,!0)}else a||r.push({line:s.line||1,column:s.col||1,reason:"WARN: if 属性为空"})}function checkElse(e,t,a,s){checkIf(e,t,!0,a,s),s.length=0}function checkElif(e,t,a,s,n){const r=a.log;let l=t;if(e){e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t);const s=a.isLite;l="{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(n)+"}}",a.result.shown=s?l:(0,_exp.default)(l),n.push(`${e.substr(2,e.length-4)}`)}else r.push({line:s.line||1,column:s.col||1,reason:"WARN: Elif 属性为空"});return l}function checkFor(e,t,a){const s=t.log;if(e){let a,s;const n=(e=_exp.default.removeExprffix(e)).match(/(.*) (?:in) (.*)/);if(n){const t=n[1].match(/\((.*),(.*)\)/);t?(a=t[1].trim(),s=t[2].trim()):s=n[1].trim(),e=n[2]}e="{{"+e+"}}";const r=t.isLite;let l;a||s?(l={exp:(0,_exp.default)(e,!0,r)},a&&(l.key=a),s&&(l.value=s)):l=(0,_exp.default)(e,!0,r),t.result.repeat=l}else s.push({line:a.line||1,column:a.col||1,reason:"WARN: for 属性为空"})}function checkEvent(name,value,output){const originValue=value,eventName=name.replace(/^(on|@)/,"");if(eventName&&value){value=_exp.default.removeExprffix(value);const paramsMatch=value.match(/(.*)\((.*)\)/);if(paramsMatch){const funcName=paramsMatch[1];let params=paramsMatch[2];params?(params=params.split(/\s*,\s*/),-1===params.indexOf("evt")&&(params[params.length]="evt")):params=["evt"],value="{{"+funcName+"("+params.join(",")+")}}";try{value=output.isLite?value:eval("(function (evt) { return "+(0,_exp.default)(value,!1).replace("this.evt","evt")+"})")}catch(e){throw e.isExpressionError=!0,e.expression=originValue,e}}output.result.events=output.result.events||{},output.result.events[eventName]=value}}function checkCustomDirective(e,t,a,s){const n=e.replace(/^dir:/,"");if(!n)return _sharedUtils.colorconsole.warn(`\`${s.tagName}\` 组件自定义指令名称不能为空`),!1;a.result.directives=a.result.directives||[],a.result.directives.push({name:n,value:_exp.default.isExpr(t)?(0,_exp.default)(t,!0,a.isLite):t})}function checkAttr(e,t,a,s,n,r){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,s)){if(!_exp.default.isExpr(t)){(0,_utils.fileExists)(t,r.filePath)||a.log.push({line:n.line,column:n.column,reason:"WARN: "+s+" 属性 "+e+" 的值 "+t+" 下不存在对应的文件资源"})}t=(0,_utils.resolvePath)(t,r.filePath),a.depFiles.push(t)}a.result.attr=a.result.attr||{},a.result.attr[(0,_utils.hyphenedToCamelCase)(e)]=(0,_exp.default)(t,!0,a.isLite),"value"===e&&"text"===s&&a.log.push({line:n.line,column:n.column,reason:"WARN: `value` 应该写在<text>标签中"})}}function shouldConvertPath(e,t,a){return!("alt"===e&&"blank"===t)&&!(!(["src","alt"].includes(e)&&t&&["img","video"].indexOf(a)>-1)||/^(data:|http|{{)/.test(t))}function isReservedTag(e){return tagReserved.hasOwnProperty(e)}function isTextContentAtomic(e){return tagTextContent.hasOwnProperty(e)&&tagAtomics.hasOwnProperty(e)}function isNotTextContentAtomic(e){return!tagTextContent.hasOwnProperty(e)&&!tagAtomics.hasOwnProperty(e)}function isSupportSpan(e){if(e&&"string"==typeof e)return tagChildrenMap[e]&&tagChildrenMap[e].indexOf("span")>-1}function getTagChildren(e){if(e&&"string"==typeof e)return tagChildrenMap[e]||[]}function isSupportedSelfClosing(e){if(e&&"string"==typeof e)return e=tagAliasMap[e]||e,tagNatives[e]&&!!tagNatives[e].selfClosing}function hasTagDefined(e){return tagNativeKeys.indexOf(e)>-1||tagComponents.indexOf(e)>-1}function isEmptyElement(e){return e=tagAliasMap[e]||e,tagNatives[e]&&!0===tagNatives[e].empty}function buildConditionExp(e){return e.map((e=>`!(${e})`)).join(" && ")}function hasIfOrFor(e){let t=!1;return e.find((e=>(e.attrs||[]).findIndex((e=>["for","if"].indexOf(e.name)>-1))>-1?(t=!0,t):Array.isArray(e.childNodes)?(t=hasIfOrFor(e.childNodes),t):void 0)),t}function isValidClassArray(e){const t=e.filter((e=>e.length>0));let a=!1;for(let e=0;e<t.length;e++)if(_exp.default.isExpr(t[e])){a=!0;break}return!a||1===t.length}tagNativeKeys.forEach((function(e){tagReserved[e]=!0;const t=tagNatives[e];t.atomic&&(tagAtomics[e]=!0),t.textContent&&(tagTextContent[e]=!0),t.empty&&(tagEmpty[e]=!0),t.alias&&t.alias.length&&t.alias.forEach((function(t){tagAliasMap[t]=e})),!0===t.excludeRoot&&(tagNotRoot[e]=!0);let a=(0,_sharedUtils.extend)({},t.attrs);const s={},n={},r=[];t.attrs&&!1===t.attrs.extendCommon||(a=(0,_sharedUtils.extend)(a,tagCommon.attrs)),"extendCommon"in a&&delete a.extendCommon,Object.keys(a).forEach((function(e){const t=a[e];t.enum&&t.enum.length>0&&(s[e]=t.enum,n[e]=t.enum[0]),t.def&&(n[e]=t.def),!0===t.required&&r.push(e)})),tagAttrMap[e]=a,tagEnumAttrMap[e]=s,tagDefaultAttrMap[e]=n,tagRequireAttrMap[e]=r,tagChildrenMap[e]=t.children?(0,_utils.merge)([],tagCommon.children,t.children):null,tagOnceChildrenMap[e]=t.onceChildren?(0,_utils.merge)([],t.onceChildren):null,tagParentsMap[e]=t.parents?(0,_utils.merge)([],tagCommon.parents,t.parents):null,tagEventsMap[e]=(0,_utils.merge)([],tagCommon.events,t.events)}));var _default={checkTagName:checkTagName,checkId:checkId,checkClass:checkClass,checkStyle:checkStyle,checkIs:checkIs,checkIf:checkIf,checkElse:checkElse,checkElif:checkElif,checkFor:checkFor,checkEvent:checkEvent,checkCustomDirective:checkCustomDirective,checkAttr:checkAttr,checkBuild:checkBuild,checkModel:_model.default,isReservedTag:isReservedTag,isTextContentAtomic:isTextContentAtomic,isSupportSpan:isSupportSpan,getTagChildren:getTagChildren,isSupportedSelfClosing:isSupportedSelfClosing,isEmptyElement:isEmptyElement,isNotTextContentAtomic:isNotTextContentAtomic,isExpr:_exp.default.isExpr,parseText:_exp.default.parseText};exports.default=_default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _path=_interopRequireDefault(require("path")),_sharedUtils=require("@hap-toolkit/shared-utils"),_exp=_interopRequireDefault(require("./exp")),_style=_interopRequireDefault(require("../style")),_model=_interopRequireDefault(require("./model")),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const extList=[".mix",".ux"],richtextType=["mix","ux"],REG_TAG_DATA_ATTR=/^data-\w+/,REG_CLASS_VALUE=/[^{}\s]+((?=\s)|$)|[^{}\s]*\{\{[^]*?\}\}[^\s]*/g,RESERVED_TAGS=Object.keys(_utils.FRAG_TYPE).map((e=>_utils.FRAG_TYPE[e])),RESERVED_DIRECTIVES=/^(model:|dir:)/,tagCommon={events:["click","focus","blur","key","longpress","appear","disappear","swipe","touchstart","touchmove","touchend","touchcancel","resize","animationstart","animationiteration","animationend"],attrs:{id:{},style:{},class:{},disabled:{enum:["false","true"]},if:{def:"true"},elif:{def:"true"},else:{},for:{},tid:{},show:{def:"true"},"aria-label":{},"aria-unfocusable":{enum:["false","true"]},forcedark:{enum:["true","false"]},focusable:{enum:["false","true"]},vtags:{},vindex:{},autofocus:{enum:["false","true"]},descendantfocusability:{enum:["before","after","block"]}},children:["block","slot","component"],parents:["block"]},tagNatives={div:{supportCard:!0,attrs:{enablevideofullscreencontainer:{enum:["false","true"]}}},a:{supportCard:!0,textContent:!0,children:["span"],attrs:{visited:{enum:["false","true"]},href:{}}},text:{supportCard:!0,textContent:!0,children:["a","span"],attrs:{type:{enum:["text","html"]},"letter-spacing":{}}},span:{supportCard:!0,textContent:!0,excludeRoot:!0,children:["span"],parents:["text","a","span"],attrs:{extendCommon:!1,id:{},style:{},class:{},for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},label:{supportCard:!0,textContent:!0,atomic:!0,attrs:{target:{}}},image:{events:["complete","error"],empty:!0,supportCard:!0,selfClosing:!0,alias:["img"],atomic:!0,attrs:{src:{},alt:{},enablenightmode:{enum:["true","false"]},autoplay:{enum:["true","false"]}}},slider:{selfClosing:!0,atomic:!0,attrs:{enabled:{enum:["true","false"]},min:{def:0},max:{def:100},step:{def:1},value:{def:0}},events:["change"]},web:{atomic:!0,events:["pagestart","pagefinish","titlereceive","error","message","progress"],attrs:{src:{},trustedurl:{},allowthirdpartycookies:{enum:["false","true"]},enablenightmode:{enum:["true","false"]},showloadingdialog:{enum:["false","true"]},supportzoom:{enum:["true","false"]}}},list:{children:["list-item"],attrs:{scrollpage:{enum:["false","true"]},focusbehavior:{enum:["aligned","edged"]}},events:["scroll","scrollbottom","scrolltop","scrollend","scrolltouchup","selected"]},"list-item":{excludeRoot:!0,parents:["list"],attrs:{type:{required:!0},disallowintercept:{}}},block:{excludeRoot:!0,supportCard:!0,attrs:{extendCommon:!1,for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},component:{supportCard:!0,excludeRoot:!0,attrs:{extendCommon:!1,is:{required:!0},for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},slot:{excludeRoot:!0,attrs:{name:{def:"default"},extendCommon:!1,content:{}}},input:{supportCard:!0,selfClosing:!0,atomic:!0,empty:!0,attrs:{type:{enum:["text","button","checkbox","radio","email","date","time","number","password","tel","eventbutton","hidetext","showtext"]},autocomplete:{enum:["on","off"]},enterkeytype:{enum:["default","next","go","done","send","search"]},eventtype:{enum:["shortcut"]},"true-value":{},"false-value":{},maxlength:{},checked:{enum:["false","true"]},name:{},value:{},placeholder:{}},events:["change","enterkeyclick","selectionchange"]},button:{supportCard:!0,textContent:!0,atomic:!0},refresh:{attrs:{offset:{def:"132px"},refreshing:{enum:["false","true"]},type:{enum:["auto","pulldown"]},"enable-refresh":{enum:["true","false"]}},events:["refresh"]},refresh2:{attrs:{pulldownrefreshing:{enum:["false","true"]},pulluprefreshing:{enum:["false","true"]},animationduration:{def:300},enablepulldown:{enum:["true","false"]},enablepullup:{enum:["false","true"]},reboundable:{enum:["false","true"]},gesture:{enum:["true","false"]},offset:{def:"132px"},refreshing:{enum:["false","true"]},type:{enum:["auto","pulldown"]}},events:["pulldownrefresh","pulluprefresh","refresh"],onceChildren:["refresh-header","refresh-footer"]},"refresh-header":{attrs:{dragrate:{def:300},triggerratio:{def:300},tiggersize:{def:300},maxdragratio:{def:300},maxdragsize:{def:300},refreshdisplayratio:{def:300},refreshdisplaysize:{def:300},spinnerstyle:{enum:["translation","front","behind"]},autorefresh:{enum:["false","true"]},translationwithcontent:{enum:["false","true"]}},events:["move"],parents:["refresh2"]},"refresh-footer":{attrs:{dragrate:{def:300},triggerratio:{def:300},tiggersize:{def:300},maxdragratio:{def:300},maxdragdize:{def:300},refreshdisplayratio:{def:300},refreshdisplaysize:{def:300},spinnerstyle:{enum:["translation","front","behind"]},autorefresh:{enum:["false","true"]},translationwithcontent:{enum:["true","false"]}},events:["move"],parents:["refresh2"]},ad:{attrs:{unitid:{def:""},type:{def:"native"},adid:{}},events:["adclick","error"]},"ad-clickable-area":{supportCard:!0,textContent:!0,atomic:!0,attrs:{type:{}}},"ad-custom":{attrs:{adUnitId:{},channel:{},extendCommon:!1},events:["load","error","show","click","close"]},swiper:{attrs:{index:{def:0},autoplay:{enum:["false","true"]},interval:{def:3e3},indicator:{enum:["true","false"]},loop:{enum:["true","false"]},duration:{},vertical:{enum:["false","true"]},previousmargin:{def:"0px"},nextmargin:{def:"0px"},enableswipe:{enum:["true","false"]}},events:["change"]},progress:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{percent:{def:0},type:{enum:["horizontal","circular"]}}},picker:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{type:{required:!0,enum:["text","date","time","multi-text"]},start:{def:"1970-1-1"},end:{def:"2100-12-31"},range:{},selected:{},value:{}},events:["change","columnchange","cancel"]},switch:{supportCard:!0,selfClosing:!0,atomic:!0,attrs:{checked:{enum:["false","true"]}},events:["change"]},textarea:{supportCard:!0,atomic:!0,textContent:!0,attrs:{placeholder:{},maxlength:{}},events:["change","selectionchange","linechange"]},video:{empty:!0,attrs:{src:{},muted:{enum:["false","true"]},autoplay:{enum:["false","true"]},controls:{enum:["true","false"]},poster:{},orientation:{enum:["landscape","portrait"]},titlebar:{enum:["true","false"]},title:{},playcount:{},speed:{def:1}},events:["prepared","start","pause","finish","error","seeking","seeked","timeupdate","fullscreenchange"]},camera:{atomic:!0,selfClosing:!0,attrs:{deviceposition:{enum:["back","front"]},flash:{enum:["auto","on","off","torch"]},framesize:{enum:["low","normal","high"]},autoexposurelock:{enum:["false","true"]},autowhitebalancelock:{enum:["false","true"]}},events:["error","camerainitdone","cameraframe"]},map:{children:["custommarker"],attrs:{latitude:{},longitude:{},coordtype:{},scale:{def:0},rotate:{def:0},markers:{},showmylocation:{enum:["true","false"]},polylines:{},polygons:{},circles:{},controls:{},groundoverlays:{},includepoints:{},heatmaplayer:{},showcompass:{enum:["true","false"]},enableoverlooking:{enum:["false","true"]},enablezoom:{enum:["true","false"]},enablescroll:{enum:["true","false"]},enablerotate:{enum:["true","false"]},showscale:{enum:["false","true"]},showzoom:{enum:["false","true"]}},events:["loaded","regionchange","tap","markertap","callouttap","controltap","poitap"]},custommarker:{parents:["map"],attrs:{custommarkerattr:{}}},canvas:{atomic:!0},stack:{supportCard:!0,events:["fullscreenchange"]},richtext:{textContent:!0,atomic:!0,attrs:{type:{required:!0,enum:["html"].concat(richtextType)},scene:{}},events:["start","complete","pagechanged","splitpage"]},tabs:{children:["tab-bar","tab-content"],attrs:{index:{def:0}},events:["change"]},"tab-content":{parents:["tabs"],attrs:{scrollable:{enum:["true","false"]}}},"tab-bar":{parents:["tabs"],attrs:{mode:{enum:["fixed","scrollable"]}}},popup:{supportCard:!0,children:["text"],attrs:{target:{required:!0},placement:{enum:["left","top","right","bottom","topLeft","topRight","bottomLeft","bottomRight"],def:"bottom"}},events:["visibilitychange"]},rating:{supportCard:!0,atomic:!0,attrs:{numstars:{def:"5"},rating:{def:"0"},stepsize:{def:"0.5"},indicator:{enum:["false","true"]}},events:["change"]},select:{supportCard:!0,children:["option"],events:["change"],excludeRoot:!0},option:{supportCard:!0,parents:["select"],atomic:!0,textContent:!0,attrs:{selected:{def:!1},value:{}},excludeRoot:!0},marquee:{supportCard:!0,textContent:!0,atomic:!0,attrs:{scrollamount:{def:6},loop:{def:-1},direction:{enum:["left","right"]},value:{def:"6px"}},events:["bounce","finish","start"]},scrollview:{attrs:{"scroll-direction":{enum:["vertical","horizontal","vertical_horizontal"]},"show-scrollbar":{enum:["true","false"]}},events:["scroll","scrollbegindrag","scrollenddrag","scrollstart","scrollstop"]},drawer:{attrs:{enableswipe:{enum:["true","false"]}},events:["change","scroll"]},lottie:{empty:!0,attrs:{source:{required:!0},progress:{},speed:{},loop:{enum:[!0,!1]},autoplay:{enum:[!1,!0]},rendermode:{enum:["AUTOMATIC","HARDWARE","SOFTWARE"]}},events:["complete","error","change"]},"drawer-navigation":{parents:["drawer"],attrs:{direction:{enum:["start","end"]}}},"slide-view":{attrs:{edge:{enum:["right","left"]},enableslide:{enum:["true","false"]},isopen:{enum:["false","true"]},layer:{enum:["above","same"]},buttons:{}},events:["open","close","slide","buttonclick"]},"section-list":{children:["section-group","section-item"],events:["scroll","scrollend","scrolltouchup","scrolltop","scrollbottom"]},"section-group":{children:["section-group","section-item","section-header"],attrs:{expand:{enum:["false","true"]}},events:["change"]},"section-header":{parents:["section-group"]},"section-item":{},"share-button":{empty:!0,attrs:{value:{},title:{},description:{},icon:{},url:{},path:{},params:{},platforms:{},usepageparams:{enum:["true","false"],def:"false"}},events:["success","fail","cancel"]},"shortcut-button":{empty:!0,attrs:{value:{}}}},tagReserved={};let tagComponents=[];const tagNativeKeys=Object.keys(tagNatives),tagAliasMap={},tagAttrMap={},tagEnumAttrMap={},tagDefaultAttrMap={},tagRequireAttrMap={},tagAtomics={},tagEmpty={},tagTextContent={},tagChildrenMap={},tagOnceChildrenMap={},tagParentsMap={},tagEventsMap={},tagNotRoot=[];function checkTagName(e,t,a={}){const s=t.result,n=t.log,r=_path.default.extname(a.filePath);let l=e.tagName;const o=e.childNodes||[],i=e.__location||{};tagComponents=a.importNames||[];const u=tagComponents.includes(l);!u&&tagAliasMap[l]&&("img"!==l&&n.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+l+"` 自动转换为 `"+tagAliasMap[l]+"`"}),l=tagAliasMap[l]),s.type=l,RESERVED_TAGS.indexOf(l)>=0?n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+l+"` 是系统保留的组件名, 请修改"}):hasTagDefined(l)||n.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${l}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[l]&&!tagNatives[l].supportCard&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+l+"`, 请修改"}),e._isroot&&tagNotRoot.hasOwnProperty(l)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不能作为根组件"}),s.attr=s.attr||{};const c=e.attrs||[],p=[];if(c.forEach((function(e){p.push(e.name.toLowerCase())})),e._isroot){const e=["for","if","elif","else","show"];p.forEach((t=>{e.indexOf(t)>=0&&n.push({line:i.line||1,column:i.col||1,reason:"WARN: 根节点 `"+l+"` 不能使用属性 `"+t+"`"})}))}if(!u){if(tagEmpty.hasOwnProperty(l)&&o.length>0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 内不能有子节点与文字,请修改"}),tagAtomics.hasOwnProperty(l)&&"ad-clickable-area"!==l&&(tagTextContent.hasOwnProperty(l)?o.length>0&&o.every((e=>"#text"===e.nodeName||(n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 是原子类型,不应该有子节点"}),!1))):(o.length>1||o[0]&&"#text"!==o[0].nodeName)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 只能有一个文字子节点"})),tagDefaultAttrMap[l]&&Object.keys(tagDefaultAttrMap[l]).forEach((t=>{const s=p.indexOf(t);s>=0&&""===c[s].value?(c[s].value=tagDefaultAttrMap[l][t],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[l][t]+"`"})):"slot"===l&&s<0&&(e.attrs.push({name:t,value:tagDefaultAttrMap[l][t]}),_sharedUtils.colorconsole.warn(`标签 ${l} 的属性 \`${t}\` 值为空, 默认设置为缺省值 \`${tagDefaultAttrMap[l][t]}\` ${a.filePath} @${i.line||1},${i.col||1}`))})),tagRequireAttrMap[l]&&tagRequireAttrMap[l].forEach((e=>{p.indexOf(e)<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 没有定义属性 `"+e+"`"})})),tagEnumAttrMap[l]&&Object.keys(tagEnumAttrMap[l]).forEach((e=>{const t=p.indexOf(e);if(t>=0){const a=c[t].value;if(!_exp.default.isExpr(a)){const s=tagEnumAttrMap[l][e];s.indexOf(a)<0&&(c[t].value=s[0],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+s[0]+"`"}))}}})),tagAttrMap[l]&&"component"!==l&&p.forEach((e=>{if(!e.match(/^(on|@)/)){if(r.indexOf(extList[2])>=-1&&/^(:|v-|key|ref|is|slot|slot-scope)/.test(e))return;if(RESERVED_DIRECTIVES.test(e))return;const t=checkDataAttr(e),a=Object.prototype.hasOwnProperty.call(tagAttrMap[l],e);t||a||n.push({line:i.line||1,column:i.col||1,reason:"WARN: 组件 `"+l+"` 不支持属性 `"+e})}})),tagEventsMap[l]&&"component"!==l){const e=tagEventsMap[l];p.forEach((t=>{if(t.match(/^(on|@)/)){const s=t.replace(/^(on|@)/,""),r=["appear","disappear","swipe"];a.uxType===_utils.ENTRY_TYPE.CARD&&r.indexOf(s.toLowerCase())>-1&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片组件 `"+l+"` 不支持事件 `"+s+"`"}),e.indexOf(s.toLowerCase())<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持事件 `"+s+"`"})}}))}if(o.length>0){const t=new Set,s={};o.forEach(((e,r)=>{if(isReservedTag(l)&&isReservedTag(e.nodeName)){const o=tagParentsMap[e.nodeName],u=tagChildrenMap[l],c=tagOnceChildrenMap[l];if("slot"===e.nodeName){let s=e.parentNode;for(;s;){if("slot"===s.tagName){_sharedUtils.colorconsole.warn(`slot标签内不应该嵌套slot ${a.filePath}@${i.line||1},${i.col||1}`);break}s=s.parentNode}const n={};e.attrs.map((e=>{n[e.name]=e.value})),n.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(n.name)&&_sharedUtils.colorconsole.warn(`标签${e.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):n.name="default",t.has(n.name)?_sharedUtils.colorconsole.warn(`标签${l}内存在name为 \`${n.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):t.add(n.name)}if(o&&o.indexOf(l)<0||u&&u.indexOf(e.nodeName)<0)n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持子组件 `"+e.nodeName+"`"});else if(c&&c.indexOf(e.nodeName)>-1){let t;(s[e.nodeName]||0===s[e.nodeName])&&(t=!0),s[e.nodeName]={index:r,duplicated:t}}}}));const r=Object.keys(s);r.length&&(r.filter((e=>s[e].duplicated)).forEach((e=>{n.push({line:i.line||1,column:i.col||1,reason:`'WARN: 组件 \`${e}\` 只允许在 \`${l}\` 组件中出现一次`})})),e.childNodes=o.filter(((e,t)=>!(s[e.nodeName]&&s[e.nodeName].duplicated&&t!==s[e.nodeName].index))))}isSupportedSelfClosing(l)||!i.startTag||i.endTag||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 缺少闭合标签,请检查"}),"list-item"===l&&hasIfOrFor(o)&&n.push({line:i.line||1,column:i.col||1,reason:"WARN: `list-item` 内部需谨慎使用指令 if 或 for,相同 type 属性的 list-item, DOM 结构必须完全相同`"})}}function checkId(e,t){e&&(t.result.id=_exp.default.isExpr(e)?(0,_exp.default)(e,!0,t.isLite):e)}function checkDataAttr(e){return REG_TAG_DATA_ATTR.test(e)}function checkBuild(e,t){e&&(t.result.append="tree"===e?"tree":"single")}function checkClass(className,output){let hasBinding,classList=[];if(className=className.trim(),className){let start=0,end=0;const segs=[],matched=className.match(REG_CLASS_VALUE);if(matched){let e;matched.forEach((t=>{end=className.indexOf(t,start),e=className.slice(start,end),e.length&&segs.push(e),segs.push(t),start+=e.length+t.length}))}segs.push(className.slice(start));const isLite=output.isLite;if(classList=segs.reduce(((e,t)=>_exp.default.isExpr(t)?(hasBinding=!0,e.push((0,_exp.default)(t,!1,isLite)),e):e.concat(t.split(/\s+/g).filter((e=>e)).map((e=>isLite?e:`'${e}'`)))),[]),classList=classList.filter((e=>e.trim())),isLite){if(!isValidClassArray(segs)){const e=new Error("轻卡 class 样式不支持动态数据绑定 {{}} 和静态样式混用");throw e.isExpressionError=!0,e.expression=className,e}output.result.class=className,output.result.classList=classList}else if(hasBinding){const code="(function () {return ["+classList.join(", ")+"]})";try{output.result.classList=eval(code)}catch(e){throw e.isExpressionError=!0,e.expression=className,e}}else output.result.classList=classList.map((e=>e.slice(1,-1)))}}function checkStyle(e,t,a,s){let n={};const r=t.log;if(e){const l=t.isLite;if(_exp.default.singleExpr(e)){const s=_exp.default.removeExprffix(e);return _exp.default.isExpr(s)?r.push({line:a.line||1,column:a.col||1,reason:"ERROR: style 属性不能嵌套多层{{}}"}):n=(0,_exp.default)(e,!0,l),void(t.result.style=n)}if(e.split(";").forEach((function(e){let t,o,i,u=e.trim().split(":");u.length>2&&(u[1]=u.slice(1).join(":"),u=u.slice(0,2)),2===u.length&&(t=u[0].trim(),t=(0,_utils.hyphenedToCamelCase)(t),o=u[1].trim(),o=(0,_exp.default)(o,!0,l),i=_style.default.validateDelaration(t,o,s),o=i.value,o.forEach((e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(n[e.n]=e.v)})),i.log&&r.push({line:a.line||1,column:a.col||1,reason:i.log.reason}))})),"object"==typeof n)for(let e in n)_style.default.shouldAddToDependency(e,n[e])&&t.depFiles.push(n[e]);t.result.style=n}}function checkIs(e,t,a){const s=t.log;e?(e=_exp.default.addExprffix(e),t.result.is=(0,_exp.default)(e,!0,t.isLite)):s.push({line:a.line||1,column:a.col||1,reason:"WARN: is 属性为空"})}function checkIf(e,t,a,s,n){const r=t.log;if(e){e=_exp.default.addExprffix(e);const s=t.isLite;a?e="{{"+buildConditionExp(n)+"}}":(n.length>0&&(n.length=0),n.push(`${e.substr(2,e.length-4)}`)),t.result.shown=s?e:(0,_exp.default)(e,!0)}else a||r.push({line:s.line||1,column:s.col||1,reason:"WARN: if 属性为空"})}function checkElse(e,t,a,s){checkIf(e,t,!0,a,s),s.length=0}function checkElif(e,t,a,s,n){const r=a.log;let l=t;if(e){e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t);const s=a.isLite;l="{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(n)+"}}",a.result.shown=s?l:(0,_exp.default)(l),n.push(`${e.substr(2,e.length-4)}`)}else r.push({line:s.line||1,column:s.col||1,reason:"WARN: Elif 属性为空"});return l}function checkFor(e,t,a){const s=t.log;if(e){let a,s;const n=(e=_exp.default.removeExprffix(e)).match(/(.*) (?:in) (.*)/);if(n){const t=n[1].match(/\((.*),(.*)\)/);t?(a=t[1].trim(),s=t[2].trim()):s=n[1].trim(),e=n[2]}e="{{"+e+"}}";const r=t.isLite;let l;a||s?(l={exp:(0,_exp.default)(e,!0,r)},a&&(l.key=a),s&&(l.value=s)):l=(0,_exp.default)(e,!0,r),t.result.repeat=l}else s.push({line:a.line||1,column:a.col||1,reason:"WARN: for 属性为空"})}function checkEvent(name,value,output){const originValue=value,eventName=name.replace(/^(on|@)/,"");if(eventName&&value){value=_exp.default.removeExprffix(value);const paramsMatch=value.match(/(.*)\((.*)\)/);if(paramsMatch){const funcName=paramsMatch[1];let params=paramsMatch[2];params?(params=params.split(/\s*,\s*/),-1===params.indexOf("evt")&&(params[params.length]="evt")):params=["evt"],value="{{"+funcName+"("+params.join(",")+")}}";try{value=output.isLite?value:eval("(function (evt) { return "+(0,_exp.default)(value,!1).replace("this.evt","evt")+"})")}catch(e){throw e.isExpressionError=!0,e.expression=originValue,e}}output.result.events=output.result.events||{},output.result.events[eventName]=value}}function checkCustomDirective(e,t,a,s){const n=e.replace(/^dir:/,"");if(!n)return _sharedUtils.colorconsole.warn(`\`${s.tagName}\` 组件自定义指令名称不能为空`),!1;a.result.directives=a.result.directives||[],a.result.directives.push({name:n,value:_exp.default.isExpr(t)?(0,_exp.default)(t,!0,a.isLite):t})}function checkAttr(e,t,a,s,n,r){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,s)){if(!_exp.default.isExpr(t)){(0,_utils.fileExists)(t,r.filePath)||a.log.push({line:n.line,column:n.column,reason:"WARN: "+s+" 属性 "+e+" 的值 "+t+" 下不存在对应的文件资源"})}t=(0,_utils.resolvePath)(t,r.filePath),a.depFiles.push(t)}a.result.attr=a.result.attr||{},a.result.attr[(0,_utils.hyphenedToCamelCase)(e)]=(0,_exp.default)(t,!0,a.isLite),"value"===e&&"text"===s&&a.log.push({line:n.line,column:n.column,reason:"WARN: `value` 应该写在<text>标签中"})}}function shouldConvertPath(e,t,a){return!("alt"===e&&"blank"===t)&&!(!(["src","alt"].includes(e)&&t&&["img","video"].indexOf(a)>-1)||/^(data:|http|{{)/.test(t))}function isReservedTag(e){return tagReserved.hasOwnProperty(e)}function isTextContentAtomic(e){return tagTextContent.hasOwnProperty(e)&&tagAtomics.hasOwnProperty(e)}function isNotTextContentAtomic(e){return!tagTextContent.hasOwnProperty(e)&&!tagAtomics.hasOwnProperty(e)}function isSupportSpan(e){if(e&&"string"==typeof e)return tagChildrenMap[e]&&tagChildrenMap[e].indexOf("span")>-1}function getTagChildren(e){if(e&&"string"==typeof e)return tagChildrenMap[e]||[]}function isSupportedSelfClosing(e){if(e&&"string"==typeof e)return e=tagAliasMap[e]||e,tagNatives[e]&&!!tagNatives[e].selfClosing}function hasTagDefined(e){return tagNativeKeys.indexOf(e)>-1||tagComponents.indexOf(e)>-1}function isEmptyElement(e){return e=tagAliasMap[e]||e,tagNatives[e]&&!0===tagNatives[e].empty}function buildConditionExp(e){return e.map((e=>`!(${e})`)).join(" && ")}function hasIfOrFor(e){let t=!1;return e.find((e=>(e.attrs||[]).findIndex((e=>["for","if"].indexOf(e.name)>-1))>-1?(t=!0,t):Array.isArray(e.childNodes)?(t=hasIfOrFor(e.childNodes),t):void 0)),t}function isValidClassArray(e){const t=e.filter((e=>e.length>0));let a=!1;for(let e=0;e<t.length;e++)if(_exp.default.isExpr(t[e])){a=!0;break}return!a||1===t.length}tagNativeKeys.forEach((function(e){tagReserved[e]=!0;const t=tagNatives[e];t.atomic&&(tagAtomics[e]=!0),t.textContent&&(tagTextContent[e]=!0),t.empty&&(tagEmpty[e]=!0),t.alias&&t.alias.length&&t.alias.forEach((function(t){tagAliasMap[t]=e})),!0===t.excludeRoot&&(tagNotRoot[e]=!0);let a=(0,_sharedUtils.extend)({},t.attrs);const s={},n={},r=[];t.attrs&&!1===t.attrs.extendCommon||(a=(0,_sharedUtils.extend)(a,tagCommon.attrs)),"extendCommon"in a&&delete a.extendCommon,Object.keys(a).forEach((function(e){const t=a[e];t.enum&&t.enum.length>0&&(s[e]=t.enum,n[e]=t.enum[0]),t.def&&(n[e]=t.def),!0===t.required&&r.push(e)})),tagAttrMap[e]=a,tagEnumAttrMap[e]=s,tagDefaultAttrMap[e]=n,tagRequireAttrMap[e]=r,tagChildrenMap[e]=t.children?(0,_utils.merge)([],tagCommon.children,t.children):null,tagOnceChildrenMap[e]=t.onceChildren?(0,_utils.merge)([],t.onceChildren):null,tagParentsMap[e]=t.parents?(0,_utils.merge)([],tagCommon.parents,t.parents):null,tagEventsMap[e]=(0,_utils.merge)([],tagCommon.events,t.events)}));var _default={checkTagName:checkTagName,checkId:checkId,checkClass:checkClass,checkStyle:checkStyle,checkIs:checkIs,checkIf:checkIf,checkElse:checkElse,checkElif:checkElif,checkFor:checkFor,checkEvent:checkEvent,checkCustomDirective:checkCustomDirective,checkAttr:checkAttr,checkBuild:checkBuild,checkModel:_model.default,isReservedTag:isReservedTag,isTextContentAtomic:isTextContentAtomic,isSupportSpan:isSupportSpan,getTagChildren:getTagChildren,isSupportedSelfClosing:isSupportedSelfClosing,isEmptyElement:isEmptyElement,isNotTextContentAtomic:isNotTextContentAtomic,isExpr:_exp.default.isExpr,parseText:_exp.default.parseText};exports.default=_default; | ||
//# sourceMappingURL=validator.js.map |
{ | ||
"name": "@hap-toolkit/compiler", | ||
"version": "1.9.17-alpha.7", | ||
"version": "1.9.17-alpha.8", | ||
"description": "compiler of hap-toolkit", | ||
@@ -25,3 +25,3 @@ "engines": { | ||
"dependencies": { | ||
"@hap-toolkit/shared-utils": "1.9.17-alpha.7", | ||
"@hap-toolkit/shared-utils": "1.9.17-alpha.8", | ||
"@jayfate/path": "^0.0.13", | ||
@@ -32,3 +32,3 @@ "css": "^2.2.4", | ||
}, | ||
"gitHead": "0e2cca38ba9e9014de56f0f70ab64c6edd43b3a0" | ||
"gitHead": "3564470418092eeee34c6543b315b0604a6e5ea4" | ||
} |
113158
+ Added@hap-toolkit/shared-utils@1.9.17-alpha.8(transitive)
- Removed@hap-toolkit/shared-utils@1.9.17-alpha.7(transitive)