@hap-toolkit/compiler
Advanced tools
Comparing version 0.7.5-beta.4 to 0.7.5
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _parse=_interopRequireDefault(require("parse5")),_parser=_interopRequireDefault(require("parse5/lib/parser")),_tokenizer=_interopRequireDefault(require("parse5/lib/tokenizer")),_sharedUtils=require("@hap-toolkit/shared-utils"),_compilationConfig=require("@hap-toolkit/shared-utils/compilation-config"),_validator=_interopRequireDefault(require("./validator")),_compress=require("./compress");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function calcSubTextNodesNum(e,t){let a=0;if(_validator.default.isSupportSpan(e)){const l=_validator.default.getTagChildren(e);t.forEach((function(e){("#text"===e.nodeName&&e.value.trim()||l.indexOf(e.nodeName)>-1)&&++a}))}return a}function traverse(e,t,a,l,o){_validator.default.checkTagName(e,t,o),(e.attrs||[]).forEach((function(r){let i=r.name;const n=i.match(/^:+/);n&&(i=i.slice(n.length));const s=r.value;let c={line:1,column:1};switch(e.__location&&(c={line:e.__location.line,column:e.__location.col}),i){case"id":_validator.default.checkId(s,t),_validator.default.checkAttr(i,s,t,e.tagName,c);break;case"class":_validator.default.checkClass(s,t);break;case"style":_validator.default.checkStyle(s,t,c,o);break;case"if":e._isroot||_validator.default.checkIf(s,t,!1,c,l);break;case"is":_validator.default.checkIs(s,t,c);break;case"else":e._isroot||a&&a.__cond__&&_validator.default.checkElse(a.__cond__,t,c,l);break;case"elif":e._isroot||a&&a.__cond__&&(e.__cond__=_validator.default.checkElif(s,a.__cond__,t,c,l));break;case"for":e._isroot||_validator.default.checkFor(s,t,c);break;case"tree":_validator.default.checkBuild("tree",t);break;default:i.match(/^(on|@)/)?_validator.default.checkEvent(i,s,t):_validator.default.checkAttr(i,s,t,e.tagName,c,o)}}));const r=t.result,i=e.childNodes;if(i&&i.length){let a;const l=[],n=calcSubTextNodesNum(r.type,i);i.forEach((function(s,c){if(c>0){const e=i[c-1];e.nodeName.match(/^#/)||(a=e,a.__cond__||a.attrs&&a.attrs.forEach((function(e){"if"!==e.name&&"elif"!==e.name||(a.__cond__=e.value)})))}const u={};if(s.nodeName.match(/^#/)){if("#text"===s.nodeName&&s.value.trim()){const a=_validator.default.isSupportSpan(e.tagName)&&n>=2,l=o.importNames&&o.importNames.indexOf(e.tagName)>-1;if((a||l)&&(u.type="span",t.result=u,r.children=r.children||[],r.children.push(u),t.log.push({line:e.__location.line,column:e.__location.col,reason:`WARNING: 文本和span标签并行存在,编译时将文本节点:"${s.value}" 用span包裹(关于span嵌套的使用,请参考官方文档"span嵌套")`}),_validator.default.checkAttr("value",s.value,t)),"option"===e.tagName){const e=t.result;return t.result=r,r.attr.hasOwnProperty("value")||_validator.default.checkAttr("value",s.value,t),_validator.default.checkAttr("content",s.value,t),void(t.result=e)}if(_validator.default.isSupportSpan(e.tagName)&&1===n||_validator.default.isTextContentAomtic(e.tagName)){const e=t.result;t.result=r,_validator.default.checkAttr("value",s.value,t),t.result=e}}}else t.result=u,r.children=r.children||[],r.children.push(u),traverse(s,t,a,l,o)})),r.children&&0===r.children.length&&(r.children=void 0)}t.result=r}function initParser(e,t,a){const l=new _parser.default(t),o=l._appendElement,r=l._insertElement;function i(e){if(!e.tagName)return;const t=e.tagName.toLowerCase(),o=e.selfClosing,r=_validator.default.isSupportedSelfClosing(t),i=_validator.default.isEmptyElement(t);if(l.__m.tagName&&!l.__m.selfClosing&&!i){const t=String(e.location.line)+":"+String(e.location.col);(!r||t!==l.__m.pos&&e.type===_tokenizer.default.START_TAG_TOKEN)&&(_sharedUtils.colorconsole.warn(`${l.__m.tagName}标签要闭合,请遵循XML规范 ${a}@${l.__m.pos}`),l.__m={})}r&&(e.type!==_tokenizer.default.START_TAG_TOKEN||o||(l.__m.tagName=t,l.__m.selfClosing=!1,l.__m.pos=String(e.location.line)+":"+String(e.location.col)),e.type===_tokenizer.default.END_TAG_TOKEN&&t===l.__m.tagName&&(l.__m.selfClosing=!0))}function n(e){e.tagName&&"plaintext"===e.tagName.toLowerCase()&&_sharedUtils.colorconsole.error(`${a} : 禁止使用 plaintext 标签@${e.location.line}:${e.location.col}`)}return l._insertElement=function(e){const t=(e.tagName||"").toLowerCase(),l=e.selfClosing,i=_validator.default.isSupportedSelfClosing(t);l&&!i&&_sharedUtils.colorconsole.error(`${t}标签,禁止使用自闭合 ${a}@${e.location.line}:${e.location.col}`),i||l&&t?o.apply(this,arguments):r.apply(this,arguments)},l.__m={},l._runParsingLoop=function(e){for(;!this.stopped;){this._setupTokenizerCDATAMode();const t=this.tokenizer.getNextToken();if(i(t),n(t),t.type===_tokenizer.default.HIBERNATION_TOKEN)break;if(this.skipNextNewLine&&(this.skipNextNewLine=!1,t.type===_tokenizer.default.WHITESPACE_CHARACTER_TOKEN&&"\n"===t.chars[0])){if(1===t.chars.length)continue;t.chars=t.chars.substr(1)}if(this._processInputToken(t),e&&this.pendingScript)break}},l.parseFragment(e)}function parse(e,t){const a=initParser(e,{treeAdapter:_parse.default.treeAdapters.default,locationInfo:!0},t.filePath),l={result:{},log:[],depFiles:[]};if(!a||!a.childNodes)return l.log.push({reason:"ERROR: <template>解析失败",line:1,column:1}),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles};const o=a.childNodes.filter((function(e){return"#"!==e.nodeName.charAt(0)}));if(0===o.length)return l.log.push({reason:"ERROR: 没有合法的根节点",line:1,column:1}),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles};if(o.length>1)return l.log.push({reason:"ERROR: <template>节点里只能有一个根节点",line:1,column:1}),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles};const r=o[0];r._isroot=!0;try{traverse(r,l,null,null,t)}catch(e){if(!e.isExpressionError)throw e;l.log.push({reason:`ERROR: 表达式解析失败 ${e.message}\n\n> ${e.expression}\n\nat ${t.filePath}`})}return _compilationConfig.compileOptionsObject.optimizeTemplateAttr&&(0,_compress.compressTemplateAttr)(l.result),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles}}var _default={parse:parse};exports.default=_default; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _parse=_interopRequireDefault(require("parse5")),_parser=_interopRequireDefault(require("parse5/lib/parser")),_tokenizer=_interopRequireDefault(require("parse5/lib/tokenizer")),_sharedUtils=require("@hap-toolkit/shared-utils"),_compilationConfig=require("@hap-toolkit/shared-utils/compilation-config"),_validator=_interopRequireDefault(require("./validator")),_compress=require("./compress");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function calcSubTextNodesNum(e,t){let a=0;if(_validator.default.isSupportSpan(e)){const o=_validator.default.getTagChildren(e);t.forEach((function(e){("#text"===e.nodeName&&e.value.trim()||o.indexOf(e.nodeName)>-1)&&++a}))}return a}function traverse(e,t,a,o,l){_validator.default.checkTagName(e,t,l),(e.attrs||[]).forEach((function(r){let i=r.name;const n=i.match(/^:+/);n&&(i=i.slice(n.length));const s=r.value;let c={line:1,column:1};switch(e.__location&&(c={line:e.__location.line,column:e.__location.col}),i){case"id":_validator.default.checkId(s,t),_validator.default.checkAttr(i,s,t,e.tagName,c);break;case"class":_validator.default.checkClass(s,t);break;case"style":_validator.default.checkStyle(s,t,c,l);break;case"if":e._isroot||_validator.default.checkIf(s,t,!1,c,o);break;case"is":_validator.default.checkIs(s,t,c);break;case"else":e._isroot||a&&a.__cond__&&_validator.default.checkElse(a.__cond__,t,c,o);break;case"elif":e._isroot||a&&a.__cond__&&(e.__cond__=_validator.default.checkElif(s,a.__cond__,t,c,o));break;case"for":e._isroot||_validator.default.checkFor(s,t,c);break;case"tree":_validator.default.checkBuild("tree",t);break;default:i.match(/^(on|@)/)?_validator.default.checkEvent(i,s,t):_validator.default.checkAttr(i,s,t,e.tagName,c,l)}}));const r=t.result,i=e.childNodes;if(i&&i.length){let a,o;const n=[],s=calcSubTextNodesNum(r.type,i);i.forEach((function(c,u){u>0&&(o=i[u-1],o.nodeName.match(/^#/)||(a=o,a.__cond__||a.attrs&&a.attrs.forEach((function(e){"if"!==e.name&&"elif"!==e.name||(a.__cond__=e.value)}))));const _={};if(c.nodeName.match(/^#/)){if("#text"===c.nodeName&&c.value.trim()){o&&_validator.default.isSupportedSelfClosing(o.nodeName)||_validator.default.isNotTextContentAomtic(e.tagName)&&t.log.push({line:e.__location.line,column:e.__location.col,reason:`Warn: 组件 ${e.tagName} 不支持文本内容作为字节点`});const a=_validator.default.isSupportSpan(e.tagName)&&s>=2,i=l.importNames&&l.importNames.indexOf(e.tagName)>-1;if((a||i)&&(_.type="span",t.result=_,r.children=r.children||[],r.children.push(_),t.log.push({line:e.__location.line,column:e.__location.col,reason:`WARNING: 文本和span标签并行存在,编译时将文本节点:"${c.value}" 用span包裹(关于span嵌套的使用,请参考官方文档"span嵌套")`}),_validator.default.checkAttr("value",c.value,t)),"option"===e.tagName){const e=t.result;return t.result=r,r.attr.hasOwnProperty("value")||_validator.default.checkAttr("value",c.value,t),_validator.default.checkAttr("content",c.value,t),void(t.result=e)}if(_validator.default.isSupportSpan(e.tagName)&&1===s||_validator.default.isTextContentAomtic(e.tagName)){const e=t.result;t.result=r,_validator.default.checkAttr("value",c.value,t),t.result=e}}}else t.result=_,r.children=r.children||[],r.children.push(_),traverse(c,t,a,n,l)})),r.children&&0===r.children.length&&(r.children=void 0)}t.result=r}function initParser(e,t,a){const o=new _parser.default(t),l=o._appendElement,r=o._insertElement;function i(e){if(!e.tagName)return;const t=e.tagName.toLowerCase(),l=e.selfClosing,r=_validator.default.isSupportedSelfClosing(t),i=_validator.default.isEmptyElement(t);if(o.__m.tagName&&!o.__m.selfClosing&&!i){const t=String(e.location.line)+":"+String(e.location.col);(!r||t!==o.__m.pos&&e.type===_tokenizer.default.START_TAG_TOKEN)&&(_sharedUtils.colorconsole.warn(`${o.__m.tagName}标签要闭合,请遵循XML规范 ${a}@${o.__m.pos}`),o.__m={})}r&&(e.type!==_tokenizer.default.START_TAG_TOKEN||l||(o.__m.tagName=t,o.__m.selfClosing=!1,o.__m.pos=String(e.location.line)+":"+String(e.location.col)),e.type===_tokenizer.default.END_TAG_TOKEN&&t===o.__m.tagName&&(o.__m.selfClosing=!0))}function n(e){e.tagName&&"plaintext"===e.tagName.toLowerCase()&&_sharedUtils.colorconsole.error(`${a} : 禁止使用 plaintext 标签@${e.location.line}:${e.location.col}`)}return o._insertElement=function(e){const t=(e.tagName||"").toLowerCase(),o=e.selfClosing,i=_validator.default.isSupportedSelfClosing(t);o&&!i&&_sharedUtils.colorconsole.error(`${t}标签,禁止使用自闭合 ${a}@${e.location.line}:${e.location.col}`),i||o&&t?l.apply(this,arguments):r.apply(this,arguments)},o.__m={},o._runParsingLoop=function(e){for(;!this.stopped;){this._setupTokenizerCDATAMode();const t=this.tokenizer.getNextToken();if(i(t),n(t),t.type===_tokenizer.default.HIBERNATION_TOKEN)break;if(this.skipNextNewLine&&(this.skipNextNewLine=!1,t.type===_tokenizer.default.WHITESPACE_CHARACTER_TOKEN&&"\n"===t.chars[0])){if(1===t.chars.length)continue;t.chars=t.chars.substr(1)}if(this._processInputToken(t),e&&this.pendingScript)break}},o.parseFragment(e)}function parse(e,t){const a=initParser(e,{treeAdapter:_parse.default.treeAdapters.default,locationInfo:!0},t.filePath),o={result:{},log:[],depFiles:[]};if(!a||!a.childNodes)return o.log.push({reason:"ERROR: <template>解析失败",line:1,column:1}),{jsonTemplate:o.result,log:o.log,depFiles:o.depFiles};const l=a.childNodes.filter((function(e){return"#"!==e.nodeName.charAt(0)}));if(0===l.length)return o.log.push({reason:"ERROR: 没有合法的根节点",line:1,column:1}),{jsonTemplate:o.result,log:o.log,depFiles:o.depFiles};if(l.length>1)return o.log.push({reason:"ERROR: <template>节点里只能有一个根节点",line:1,column:1}),{jsonTemplate:o.result,log:o.log,depFiles:o.depFiles};const r=l[0];r._isroot=!0;try{traverse(r,o,null,null,t)}catch(e){if(!e.isExpressionError)throw e;o.log.push({reason:`ERROR: 表达式解析失败 ${e.message}\n\n> ${e.expression}\n\nat ${t.filePath}`})}return _compilationConfig.compileOptionsObject.optimizeTemplateAttr&&(0,_compress.compressTemplateAttr)(o.result),{jsonTemplate:o.result,log:o.log,depFiles:o.depFiles}}var _default={parse:parse};exports.default=_default; | ||
//# sourceMappingURL=index.js.map |
@@ -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")),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const extList=[".mix",".ux",".vue"],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]),tagCommon={events:["click","focus","blur","key","longpress","appear","disappear","swipe","touchstart","touchmove","touchend","touchcancel","resize"],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:{}},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"]}}},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"]}}},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"]}},events:["scroll","scrollbottom","scrolltop","scrollend","scrolltouchup"]},"list-item":{excludeRoot:!0,parents:["list"],attrs:{type:{required:!0}}},block:{excludeRoot:!0,supportCard:!0,attrs:{extendCommon:!1,for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},component:{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"]},autocomplete:{enum:["on","off"]},enterkeytype:{enum:["default","next","go","done","send","search"]},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"]}},events:["refresh"]},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"}},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:{atomic:!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:{}},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"]}},events:["error"]},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)}},events:["start","complete"]},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"]}},events:["bounce","finish","start"]},scrollview:{attrs:{"scroll-direction":{enum:["vertical","horizontal","vertical_horizontal"]},"show-scrollbar":{enum:["true","false"]}},events:["scroll","scrollbegindrag","scrollenddrag","scrollstart","scrollstop"]}},tagReserved=[];let tagComponents=[];const tagNativeKeys=Object.keys(tagNatives),tagAliasMap={},tagAttrMap={},tagEnumAttrMap={},tagDefaultAttrMap={},tagRequireAttrMap={},tagAtomics=[],tagTextCotent=[],tagChildrenMap={},tagParentsMap={},tagEventsMap={},tagNotRoot=[];function checkTagName(e,t,a={}){const s=t.result,n=t.log,l=_path.default.extname(a.filePath);let o=e.tagName;const r=e.childNodes||[],i=e.__location||{};tagComponents=a.importNames||[],tagAliasMap[o]&&("img"!==o&&n.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+o+"` 自动转换为 `"+tagAliasMap[o]+"`"}),o=tagAliasMap[o]),s.type=o,RESERVED_TAGS.indexOf(o)>=0?n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+o+"` 是系统保留的组件名, 请修改"}):hasTagDefined(o)||n.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${o}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[o]&&!tagNatives[o].supportCard&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+o+"`, 请修改"}),e._isroot&&tagNotRoot.indexOf(o)>=0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不能作为根组件"}),tagAtomics.indexOf(o)>=0&&(tagTextCotent.indexOf(o)<0?r.length>0&&r.every(e=>"#text"===e.nodeName||(n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 是原子类型,不应该有子节点"}),!1)):(r.length>1||r[0]&&"#text"!==r[0].nodeName)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 只能有一个文字子节点"})),s.attr=s.attr||{};const u=e.attrs||[],c=[];if(u.forEach((function(e){c.push(e.name.toLowerCase())})),tagDefaultAttrMap[o]&&Object.keys(tagDefaultAttrMap[o]).forEach(t=>{const s=c.indexOf(t);s>=0&&""===u[s].value?(u[s].value=tagDefaultAttrMap[o][t],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[o][t]+"`"})):"slot"===o&&s<0&&(e.attrs.push({name:t,value:tagDefaultAttrMap[o][t]}),_sharedUtils.colorconsole.warn(`标签${o}的属性 \`${t}\` 值为空, 默认设置为缺省值 \`${tagDefaultAttrMap[o][t]}\` ${a.filePath}@${i.line||1},${i.col||1}`))}),e._isroot){const e=["for","if","elif","else","show"];c.forEach(t=>{e.indexOf(t)>=0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 根节点 `"+o+"` 不能使用属性 `"+t+"`"})})}if(tagRequireAttrMap[o]&&tagRequireAttrMap[o].forEach(e=>{c.indexOf(e)<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 没有定义属性 `"+e+"`"})}),tagEnumAttrMap[o]&&Object.keys(tagEnumAttrMap[o]).forEach(e=>{const t=c.indexOf(e);if(t>=0){const a=u[t].value;if(!_exp.default.isExpr(a)){const s=tagEnumAttrMap[o][e];s.indexOf(a)<0&&(u[t].value=s[0],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+s[0]+"`"}))}}}),tagAttrMap[o]&&"component"!==o&&c.forEach(e=>{if(!e.match(/^(on|@)/)){if(l.indexOf(extList[2])>=-1&&/^(:|v-|key|ref|is|slot|slot-scope)/.test(e))return;const t=checkDataAttr(e),a=Object.prototype.hasOwnProperty.call(tagAttrMap[o],e);t||a||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持属性 `"+e+"`,支持的属性有 ["+Object.keys(tagAttrMap[o]).join(", ")+"]"})}}),tagEventsMap[o]&&"component"!==o){const e=tagEventsMap[o];c.forEach(t=>{if(t.match(/^(on|@)/)){const s=t.replace(/^(on|@)/,""),l=["appear","disappear","swipe"];a.uxType===_utils.ENTRY_TYPE.CARD&&l.indexOf(s.toLowerCase())>-1&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片组件 `"+o+"` 不支持事件 `"+s+"`"}),e.indexOf(s.toLowerCase())<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持事件 `"+s+"`"})}})}if(r.length>0){const e=new Set;r.forEach(t=>{if(isReservedTag(o)&&isReservedTag(t.nodeName)){const s=tagParentsMap[t.nodeName],l=tagChildrenMap[o];if("slot"===t.nodeName){let s=t.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={};t.attrs.map(e=>{n[e.name]=e.value}),n.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(n.name)&&_sharedUtils.colorconsole.warn(`标签${t.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):n.name="default",e.has(n.name)?_sharedUtils.colorconsole.warn(`标签${o}内存在name为 \`${n.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):e.add(n.name)}(s&&s.indexOf(o)<0||l&&l.indexOf(t.nodeName)<0)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持子组件 `"+t.nodeName+"`"})}})}isSupportedSelfClosing(o)||!i.startTag||i.endTag||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 缺少闭合标签,请检查"}),"list-item"===o&&hasIfOrFor(r)&&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):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})}if(segs.push(className.slice(start)),classList=segs.reduce((e,t)=>_exp.default.isExpr(t)?(hasBinding=!0,e.push((0,_exp.default)(t,!1)),e):e.concat(t.split(/\s+/g).filter(e=>e).map(e=>`'${e}'`)),[]),classList=classList.filter(e=>e.trim()),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 l=t.log;if(e){if(_exp.default.singleExpr(e)){const s=_exp.default.removeExprffix(e);return _exp.default.isExpr(s)?l.push({line:a.line||1,column:a.col||1,reason:"ERROR: style 属性不能嵌套多层{{}}"}):n=(0,_exp.default)(e),void(t.result.style=n)}if(e.split(";").forEach((function(e){let t,o,r,i=e.trim().split(":");i.length>2&&(i[1]=i.slice(1).join(":"),i=i.slice(0,2)),2===i.length&&(t=i[0].trim(),t=(0,_utils.hyphenedToCamelCase)(t),o=i[1].trim(),o=(0,_exp.default)(o),r=_style.default.validateDelaration(t,o,s),o=r.value,o.forEach(e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(n[e.n]=e.v)}),r.log&&l.push({line:a.line||1,column:a.col||1,reason:r.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)):s.push({line:a.line||1,column:a.col||1,reason:"WARNING: is 属性为空"})}function checkIf(e,t,a,s,n){const l=t.log;e?(e=_exp.default.addExprffix(e),a?e="{{"+buildConditionExp(n)+"}}":(n.length>0&&(n.length=0),n.push(`${e.substr(2,e.length-4)}`)),t.result.shown=(0,_exp.default)(e)):a||l.push({line:s.line||1,column:s.col||1,reason:"WARNING: if 属性为空"})}function checkElse(e,t,a,s){checkIf(e,t,!0,a,s),s.length=0}function checkElif(e,t,a,s,n){const l=a.log;let o=t;return e?(e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t),o="{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(n)+"}}",a.result.shown=(0,_exp.default)(o),n.push(`${e.substr(2,e.length-4)}`)):l.push({line:s.line||1,column:s.col||1,reason:"WARNING: Elif 属性为空"}),o}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]}let l;e="{{"+e+"}}",a||s?(l={exp:(0,_exp.default)(e)},a&&(l.key=a),s&&(l.value=s)):l=(0,_exp.default)(e),t.result.repeat=l}else s.push({line:a.line||1,column:a.col||1,reason:"WARNING: 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=eval("(function (evt) {"+(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 checkAttr(e,t,a,s,n,l){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,s)){(0,_utils.fileExists)(t,l.filePath)||a.log.push({line:n.line,column:n.column,reason:"WARNING: "+s+" 属性 "+e+" 的值 "+t+" 下不存在对应的文件资源"}),t=(0,_utils.resolvePath)(t,l.filePath),a.depFiles.push(t)}a.result.attr=a.result.attr||{},a.result.attr[(0,_utils.hyphenedToCamelCase)(e)]=(0,_exp.default)(t),"value"===e&&"text"===s&&a.log.push({line:n.line,column:n.column,reason:"WARNING: `value` 应该写在<text>标签中"})}}function shouldConvertPath(e,t,a){return!(!("src"===e&&t&&["img","video"].indexOf(a)>-1)||/^(data:|http|{{)/.test(t))}function isReservedTag(e){return tagReserved.indexOf(e)>-1}function isTextContentAomtic(e){return tagTextCotent.indexOf(e)>-1&&tagAtomics.indexOf(e)>-1}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=>{return(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}tagNativeKeys.forEach((function(e){tagReserved.push(e);const t=tagNatives[e];t.atomic&&tagAtomics.push(e),t.textContent&&tagTextCotent.push(e),t.alias&&t.alias.length&&t.alias.forEach((function(t){tagAliasMap[t]=e})),!0===t.excludeRoot&&tagNotRoot.push(e);let a=(0,_utils.extend)({},t.attrs);const s={},n={},l=[];t.attrs&&!1===t.attrs.extendCommon||(a=(0,_utils.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&&l.push(e)})),tagAttrMap[e]=a,tagEnumAttrMap[e]=s,tagDefaultAttrMap[e]=n,tagRequireAttrMap[e]=l,tagChildrenMap[e]=t.children?(0,_utils.merge)([],tagCommon.children,t.children):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,checkAttr:checkAttr,checkBuild:checkBuild,isReservedTag:isReservedTag,isTextContentAomtic:isTextContentAomtic,isSupportSpan:isSupportSpan,getTagChildren:getTagChildren,isSupportedSelfClosing:isSupportedSelfClosing,isEmptyElement:isEmptyElement};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")),_utils=require("../utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const extList=[".mix",".ux",".vue"],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]),tagCommon={events:["click","focus","blur","key","longpress","appear","disappear","swipe","touchstart","touchmove","touchend","touchcancel","resize"],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:{}},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"]}}},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"]}}},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"]}},events:["scroll","scrollbottom","scrolltop","scrollend","scrolltouchup"]},"list-item":{excludeRoot:!0,parents:["list"],attrs:{type:{required:!0}}},block:{excludeRoot:!0,supportCard:!0,attrs:{extendCommon:!1,for:{},tid:{},if:{def:"true"},elif:{def:"true"},else:{}}},component:{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"]},autocomplete:{enum:["on","off"]},enterkeytype:{enum:["default","next","go","done","send","search"]},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"]}},events:["refresh"]},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"}},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:{atomic:!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:{}},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"]}},events:["error"]},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)}},events:["start","complete"]},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"]}},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:{children:["drawer-navigation"],attrs:{enableswipe:{enum:["true","false"]}},events:["change","scroll"]},"drawer-navigation":{parents:["drawer"],attrs:{direction:{enum:["start","end"]}}}},tagReserved={};let tagComponents=[];const tagNativeKeys=Object.keys(tagNatives),tagAliasMap={},tagAttrMap={},tagEnumAttrMap={},tagDefaultAttrMap={},tagRequireAttrMap={},tagAtomics={},tagTextCotent={},tagChildrenMap={},tagParentsMap={},tagEventsMap={},tagNotRoot=[];function checkTagName(e,t,a={}){const s=t.result,n=t.log,r=_path.default.extname(a.filePath);let o=e.tagName;const l=e.childNodes||[],i=e.__location||{};tagComponents=a.importNames||[],tagAliasMap[o]&&("img"!==o&&n.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+o+"` 自动转换为 `"+tagAliasMap[o]+"`"}),o=tagAliasMap[o]),s.type=o,RESERVED_TAGS.indexOf(o)>=0?n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+o+"` 是系统保留的组件名, 请修改"}):hasTagDefined(o)||n.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${o}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[o]&&!tagNatives[o].supportCard&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+o+"`, 请修改"}),e._isroot&&tagNotRoot.hasOwnProperty(o)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不能作为根组件"}),tagAtomics.hasOwnProperty(o)&&(tagTextCotent.hasOwnProperty(o)?l.length>0&&l.every(e=>"#text"===e.nodeName||(n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 是原子类型,不应该有子节点"}),!1)):(l.length>1||l[0]&&"#text"!==l[0].nodeName)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 只能有一个文字子节点"})),s.attr=s.attr||{};const c=e.attrs||[],u=[];if(c.forEach((function(e){u.push(e.name.toLowerCase())})),tagDefaultAttrMap[o]&&Object.keys(tagDefaultAttrMap[o]).forEach(t=>{const s=u.indexOf(t);s>=0&&""===c[s].value?(c[s].value=tagDefaultAttrMap[o][t],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[o][t]+"`"})):"slot"===o&&s<0&&(e.attrs.push({name:t,value:tagDefaultAttrMap[o][t]}),_sharedUtils.colorconsole.warn(`标签${o}的属性 \`${t}\` 值为空, 默认设置为缺省值 \`${tagDefaultAttrMap[o][t]}\` ${a.filePath}@${i.line||1},${i.col||1}`))}),e._isroot){const e=["for","if","elif","else","show"];u.forEach(t=>{e.indexOf(t)>=0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 根节点 `"+o+"` 不能使用属性 `"+t+"`"})})}if(tagRequireAttrMap[o]&&tagRequireAttrMap[o].forEach(e=>{u.indexOf(e)<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 没有定义属性 `"+e+"`"})}),tagEnumAttrMap[o]&&Object.keys(tagEnumAttrMap[o]).forEach(e=>{const t=u.indexOf(e);if(t>=0){const a=c[t].value;if(!_exp.default.isExpr(a)){const s=tagEnumAttrMap[o][e];s.indexOf(a)<0&&(c[t].value=s[0],n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+s[0]+"`"}))}}}),tagAttrMap[o]&&"component"!==o&&u.forEach(e=>{if(!e.match(/^(on|@)/)){if(r.indexOf(extList[2])>=-1&&/^(:|v-|key|ref|is|slot|slot-scope)/.test(e))return;const t=checkDataAttr(e),a=Object.prototype.hasOwnProperty.call(tagAttrMap[o],e);t||a||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持属性 `"+e+"`,支持的属性有 ["+Object.keys(tagAttrMap[o]).join(", ")+"]"})}}),tagEventsMap[o]&&"component"!==o){const e=tagEventsMap[o];u.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: 卡片组件 `"+o+"` 不支持事件 `"+s+"`"}),e.indexOf(s.toLowerCase())<0&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持事件 `"+s+"`"})}})}if(l.length>0){const e=new Set;l.forEach(t=>{if(isReservedTag(o)&&isReservedTag(t.nodeName)){const s=tagParentsMap[t.nodeName],r=tagChildrenMap[o];if("slot"===t.nodeName){let s=t.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={};t.attrs.map(e=>{n[e.name]=e.value}),n.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(n.name)&&_sharedUtils.colorconsole.warn(`标签${t.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):n.name="default",e.has(n.name)?_sharedUtils.colorconsole.warn(`标签${o}内存在name为 \`${n.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):e.add(n.name)}(s&&s.indexOf(o)<0||r&&r.indexOf(t.nodeName)<0)&&n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 不支持子组件 `"+t.nodeName+"`"})}})}isSupportedSelfClosing(o)||!i.startTag||i.endTag||n.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+o+"` 缺少闭合标签,请检查"}),"list-item"===o&&hasIfOrFor(l)&&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):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})}if(segs.push(className.slice(start)),classList=segs.reduce((e,t)=>_exp.default.isExpr(t)?(hasBinding=!0,e.push((0,_exp.default)(t,!1)),e):e.concat(t.split(/\s+/g).filter(e=>e).map(e=>`'${e}'`)),[]),classList=classList.filter(e=>e.trim()),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){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),void(t.result.style=n)}if(e.split(";").forEach((function(e){let t,o,l,i=e.trim().split(":");i.length>2&&(i[1]=i.slice(1).join(":"),i=i.slice(0,2)),2===i.length&&(t=i[0].trim(),t=(0,_utils.hyphenedToCamelCase)(t),o=i[1].trim(),o=(0,_exp.default)(o),l=_style.default.validateDelaration(t,o,s),o=l.value,o.forEach(e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(n[e.n]=e.v)}),l.log&&r.push({line:a.line||1,column:a.col||1,reason:l.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)):s.push({line:a.line||1,column:a.col||1,reason:"WARNING: is 属性为空"})}function checkIf(e,t,a,s,n){const r=t.log;e?(e=_exp.default.addExprffix(e),a?e="{{"+buildConditionExp(n)+"}}":(n.length>0&&(n.length=0),n.push(`${e.substr(2,e.length-4)}`)),t.result.shown=(0,_exp.default)(e)):a||r.push({line:s.line||1,column:s.col||1,reason:"WARNING: 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 o=t;return e?(e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t),o="{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(n)+"}}",a.result.shown=(0,_exp.default)(o),n.push(`${e.substr(2,e.length-4)}`)):r.push({line:s.line||1,column:s.col||1,reason:"WARNING: Elif 属性为空"}),o}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]}let r;e="{{"+e+"}}",a||s?(r={exp:(0,_exp.default)(e)},a&&(r.key=a),s&&(r.value=s)):r=(0,_exp.default)(e),t.result.repeat=r}else s.push({line:a.line||1,column:a.col||1,reason:"WARNING: 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=eval("(function (evt) {"+(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 checkAttr(e,t,a,s,n,r){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,s)){(0,_utils.fileExists)(t,r.filePath)||a.log.push({line:n.line,column:n.column,reason:"WARNING: "+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),"value"===e&&"text"===s&&a.log.push({line:n.line,column:n.column,reason:"WARNING: `value` 应该写在<text>标签中"})}}function shouldConvertPath(e,t,a){return!(!("src"===e&&t&&["img","video"].indexOf(a)>-1)||/^(data:|http|{{)/.test(t))}function isReservedTag(e){return tagReserved.hasOwnProperty(e)}function isTextContentAomtic(e){return tagTextCotent.hasOwnProperty(e)&&tagAtomics.hasOwnProperty(e)}function isNotTextContentAomtic(e){return!tagTextCotent.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=>{return(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}tagNativeKeys.forEach((function(e){tagReserved[e]=!0;const t=tagNatives[e];t.atomic&&(tagAtomics[e]=!0),t.textContent&&(tagTextCotent[e]=!0),t.alias&&t.alias.length&&t.alias.forEach((function(t){tagAliasMap[t]=e})),!0===t.excludeRoot&&(tagNotRoot[e]=!0);let a=(0,_utils.extend)({},t.attrs);const s={},n={},r=[];t.attrs&&!1===t.attrs.extendCommon||(a=(0,_utils.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,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,checkAttr:checkAttr,checkBuild:checkBuild,isReservedTag:isReservedTag,isTextContentAomtic:isTextContentAomtic,isSupportSpan:isSupportSpan,getTagChildren:getTagChildren,isSupportedSelfClosing:isSupportedSelfClosing,isEmptyElement:isEmptyElement,isNotTextContentAomtic:isNotTextContentAomtic};exports.default=_default; | ||
//# sourceMappingURL=validator.js.map |
{ | ||
"name": "@hap-toolkit/compiler", | ||
"version": "0.7.5-beta.4", | ||
"version": "0.7.5", | ||
"description": "compiler of hap-toolkit", | ||
@@ -21,3 +21,3 @@ "engines": { | ||
"dependencies": { | ||
"@hap-toolkit/shared-utils": "^0.7.5-beta.4", | ||
"@hap-toolkit/shared-utils": "0.7.5", | ||
"css": "^2.2.4", | ||
@@ -27,3 +27,3 @@ "css-what": "^2.1.3", | ||
}, | ||
"gitHead": "2883d7d1264a4bfeab559de743878f26bd5315e1" | ||
"gitHead": "5e137ce488c0ddd79e2a50de1ece7cd8aeb3a6b1" | ||
} |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
87051
352
1
+ Added@hap-toolkit/shared-utils@0.7.5(transitive)
- Removed@hap-toolkit/shared-utils@0.7.6(transitive)