New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hap-toolkit/compiler

Package Overview
Dependencies
Maintainers
0
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hap-toolkit/compiler - npm Package Compare versions

Comparing version 1.9.16 to 1.9.17-alpha.0

2

lib/index.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _exportNames={parseFragmentsWithCache:!0,parseTemplate:!0,parseStyle:!0,parseScript:!0,templater:!0,styler:!0,scripter:!0,serialize:!0,ENTRY_TYPE:!0,FRAG_TYPE:!0,isEmptyObject:!0};Object.defineProperty(exports,"ENTRY_TYPE",{enumerable:!0,get:function(){return _utils.ENTRY_TYPE}}),Object.defineProperty(exports,"FRAG_TYPE",{enumerable:!0,get:function(){return _utils.FRAG_TYPE}}),Object.defineProperty(exports,"isEmptyObject",{enumerable:!0,get:function(){return _utils.isEmptyObject}}),exports.parseFragmentsWithCache=parseFragmentsWithCache,exports.parseScript=parseScript,exports.parseStyle=parseStyle,exports.parseTemplate=parseTemplate,Object.defineProperty(exports,"scripter",{enumerable:!0,get:function(){return _script.default}}),Object.defineProperty(exports,"serialize",{enumerable:!0,get:function(){return _utils.serialize}}),Object.defineProperty(exports,"styler",{enumerable:!0,get:function(){return _style.default}}),Object.defineProperty(exports,"templater",{enumerable:!0,get:function(){return _template.default}});var _parse=_interopRequireDefault(require("parse5")),_template=_interopRequireDefault(require("./template")),_style=_interopRequireWildcard(require("./style"));Object.keys(_style).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(_exportNames,e)||e in exports&&exports[e]===_style[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _style[e]}}))}));var _script=_interopRequireDefault(require("./script")),_utils=require("./utils");function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(_getRequireWildcardCache=function(e){return e?r:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var r=_getRequireWildcardCache(t);if(r&&r.has(e))return r.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if("default"!==s&&Object.prototype.hasOwnProperty.call(e,s)){var o=n?Object.getOwnPropertyDescriptor(e,s):null;o&&(o.get||o.set)?Object.defineProperty(a,s,o):a[s]=e[s]}return a.default=e,r&&r.set(e,a),a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _formatFragment(e,t){let r,a,n,s;const o={};if(t.__location){const e=t.__location;e.startTag&&e.endTag?(r=e.startTag.endOffset||0,a=e.endTag.startOffset||0):(r=e.startOffset||0,a=e.endOffset||0),n=e.line,s=e.col}else r=a=n=s=0;return t.attrs&&t.attrs.length&&t.attrs.forEach((function(e){o[e.name]=e.value})),{type:t.nodeName,attrs:o,content:e.substring(r,a),location:{start:r,end:a,line:n,column:s}}}function parseFragments(e,t){const r={import:[],template:[],style:[],script:[]};return _parse.default.parseFragment(e,{treeAdapter:_parse.default.treeAdapters.default,locationInfo:!0}).childNodes.forEach((a=>{const n=_formatFragment(e,a);if(r[a.nodeName]&&r[a.nodeName].push(n),"import"===a.nodeName&&a.__location&&!a.__location.endTag)throw new Error(`${t} : <import> 组件缺少闭合标签,请检查 @${n.location.line} : ${n.location.column}`);if("plaintext"===a.nodeName.toLowerCase())throw new Error(`${t} : 禁止使用plaintext @${n.location.line} : ${n.location.column}`)})),r}const fragsCache=new Map;function parseFragmentsWithCache(e,t){return fragsCache.has(t)&&fragsCache.get(t).source===e||fragsCache.set(t,{source:e,frags:parseFragments(e,t)}),fragsCache.get(t).frags}function parseTemplate(e,t){const r=_template.default.parse(e,t),{jsonTemplate:a,log:n,depFiles:s}=r;return{parsed:(0,_utils.serialize)(a,2),log:n,depFiles:s}}function parseStyle(e){const t=_style.default.parse(e),{jsonStyle:r,depList:a,log:n,depFiles:s}=t;return{parsed:JSON.stringify(r,null,2),depList:a,log:n,depFiles:s,jsonStyle:r}}function parseScript(e){return{parsed:_script.default.parse(e)}}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _exportNames={parseFragmentsWithCache:!0,parseTemplate:!0,parseStyle:!0,parseScript:!0,templater:!0,styler:!0,scripter:!0,serialize:!0,ENTRY_TYPE:!0,FRAG_TYPE:!0,isEmptyObject:!0};Object.defineProperty(exports,"ENTRY_TYPE",{enumerable:!0,get:function(){return _utils.ENTRY_TYPE}}),Object.defineProperty(exports,"FRAG_TYPE",{enumerable:!0,get:function(){return _utils.FRAG_TYPE}}),Object.defineProperty(exports,"isEmptyObject",{enumerable:!0,get:function(){return _utils.isEmptyObject}}),exports.parseFragmentsWithCache=parseFragmentsWithCache,exports.parseScript=parseScript,exports.parseStyle=parseStyle,exports.parseTemplate=parseTemplate,Object.defineProperty(exports,"scripter",{enumerable:!0,get:function(){return _script.default}}),Object.defineProperty(exports,"serialize",{enumerable:!0,get:function(){return _utils.serialize}}),Object.defineProperty(exports,"styler",{enumerable:!0,get:function(){return _style.default}}),Object.defineProperty(exports,"templater",{enumerable:!0,get:function(){return _template.default}});var _parse=_interopRequireDefault(require("parse5")),_template=_interopRequireDefault(require("./template")),_style=_interopRequireWildcard(require("./style"));Object.keys(_style).forEach((function(e){"default"!==e&&"__esModule"!==e&&(Object.prototype.hasOwnProperty.call(_exportNames,e)||e in exports&&exports[e]===_style[e]||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return _style[e]}}))}));var _script=_interopRequireDefault(require("./script")),_utils=require("./utils");function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(_getRequireWildcardCache=function(e){return e?r:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var r=_getRequireWildcardCache(t);if(r&&r.has(e))return r.get(e);var a={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var s in e)if("default"!==s&&Object.prototype.hasOwnProperty.call(e,s)){var o=n?Object.getOwnPropertyDescriptor(e,s):null;o&&(o.get||o.set)?Object.defineProperty(a,s,o):a[s]=e[s]}return a.default=e,r&&r.set(e,a),a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _formatFragment(e,t){let r,a,n,s;const o={};if(t.__location){const e=t.__location;e.startTag&&e.endTag?(r=e.startTag.endOffset||0,a=e.endTag.startOffset||0):(r=e.startOffset||0,a=e.endOffset||0),n=e.line,s=e.col}else r=a=n=s=0;return t.attrs&&t.attrs.length&&t.attrs.forEach((function(e){o[e.name]=e.value})),{type:t.nodeName,attrs:o,content:e.substring(r,a),location:{start:r,end:a,line:n,column:s}}}function parseFragments(e,t){const r={import:[],template:[],style:[],script:[],data:[]};return _parse.default.parseFragment(e,{treeAdapter:_parse.default.treeAdapters.default,locationInfo:!0}).childNodes.forEach((a=>{const n=_formatFragment(e,a);if(r[a.nodeName]&&r[a.nodeName].push(n),"import"===a.nodeName&&a.__location&&!a.__location.endTag)throw new Error(`${t} : <import> 组件缺少闭合标签,请检查 @${n.location.line} : ${n.location.column}`);if("plaintext"===a.nodeName.toLowerCase())throw new Error(`${t} : 禁止使用plaintext @${n.location.line} : ${n.location.column}`)})),r}const fragsCache=new Map;function parseFragmentsWithCache(e,t){return fragsCache.has(t)&&fragsCache.get(t).source===e||fragsCache.set(t,{source:e,frags:parseFragments(e,t)}),fragsCache.get(t).frags}function parseTemplate(e,t){const r=_template.default.parse(e,t),{jsonTemplate:a,log:n,depFiles:s}=r;return{parsed:(0,_utils.serialize)(a,2),log:n,depFiles:s}}function parseStyle(e){const t=_style.default.parse(e),{jsonStyle:r,depList:a,log:n,depFiles:s}=t;return{parsed:JSON.stringify(r,null,2),depList:a,log:n,depFiles:s,jsonStyle:r}}function parseScript(e){return{parsed:_script.default.parse(e)}}
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

"use strict";var _expression=_interopRequireDefault(require("./lib/expression")),_text=_interopRequireDefault(require("./lib/text")),_filterParser=_interopRequireDefault(require("./lib/filter-parser"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function trimhtml(e){if((e=e.replace(/^\s\s+/," ")).length<=1)return e;const t=" "===e.charAt(0)?1:0;return e.length-(e=e.trim()).length-t>=1&&(e+=" "),(t?" ":"")+e}function transExpr(expContent,toFunc){let ret;const trimExpContent=expContent.trim();if(_text.default.isExpr(trimExpContent)){ret=[];const tokens=_text.default.parseText(trimExpContent),isSingle=1===tokens.length;if(tokens.forEach((function(e){if(e.tag){let t=_expression.default.parseExpression((0,_filterParser.default)(e.value));isSingle||(t="("+t+")"),ret.push(t)}else ret.push("'"+e.value+"'")})),isSingle||ret.unshift("''"),ret=ret.join(" + "),!1!==toFunc)try{ret=eval("(function () {return "+ret+"})")}catch(e){throw e.isExpressionError=!0,e.expression=trimExpContent,e}}else ret=trimhtml(expContent);return ret}transExpr.isExpr=_text.default.isExpr,transExpr.singleExpr=_text.default.singleExpr,transExpr.removeExprffix=_text.default.removeExprffix,transExpr.addExprffix=_text.default.addExprffix,module.exports=transExpr;
"use strict";var _expression=_interopRequireDefault(require("./lib/expression")),_text=_interopRequireDefault(require("./lib/text")),_filterParser=_interopRequireDefault(require("./lib/filter-parser"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function trimhtml(e){if((e=e.replace(/^\s\s+/," ")).length<=1)return e;const t=" "===e.charAt(0)?1:0;return e.length-(e=e.trim()).length-t>=1&&(e+=" "),(t?" ":"")+e}function transExpr(expContent,toFunc,isLite){let ret;const trimExpContent=expContent.trim();if(_text.default.isExpr(trimExpContent))if(isLite)ret=trimExpContent;else{ret=[];const tokens=_text.default.parseText(trimExpContent),isSingle=1===tokens.length;if(tokens.forEach((function(e){if(e.tag){let t=_expression.default.parseExpression((0,_filterParser.default)(e.value));isSingle||(t="("+t+")"),ret.push(t)}else ret.push("'"+e.value+"'")})),isSingle||ret.unshift("''"),ret=ret.join(" + "),!1!==toFunc)try{ret=eval("(function () {return "+ret+"})")}catch(e){throw e.isExpressionError=!0,e.expression=trimExpContent,e}}else ret=trimhtml(expContent);return ret}transExpr.isExpr=_text.default.isExpr,transExpr.singleExpr=_text.default.singleExpr,transExpr.removeExprffix=_text.default.removeExprffix,transExpr.addExprffix=_text.default.addExprffix,module.exports=transExpr;
//# sourceMappingURL=exp.js.map

@@ -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"),_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):i.match(/^model:/)?_validator.default.checkModel(i,s,t,e,c,o):i.match(/^dir:/)?_validator.default.checkCustomDirective(i,s,t,e):_validator.default.checkAttr(i,s,t,e.tagName,c,o)}}));const r=t.result,i=e.childNodes;if(i&&i.length){let a,l;const n=[],s=calcSubTextNodesNum(r.type,i);i.forEach((function(c,u){u>0&&(l=i[u-1],l.nodeName.match(/^#/)||(a=l,a.__cond__||a.attrs&&a.attrs.forEach((function(e){"if"!==e.name&&"elif"!==e.name||(a.__cond__=e.value)}))));const d={};if(c.nodeName.match(/^#/)){if("#text"===c.nodeName&&c.value.trim()){l&&_validator.default.isSupportedSelfClosing(l.nodeName)||_validator.default.isNotTextContentAtomic(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=o.importNames&&o.importNames.indexOf(e.tagName)>-1;if((a||i)&&(d.type="span",t.result=d,r.children=r.children||[],r.children.push(d),t.log.push({line:e.__location.line,column:e.__location.col,reason:`WARN: 文本和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.isTextContentAtomic(e.tagName)){const e=t.result;t.result=r,_validator.default.checkAttr("value",c.value,t),t.result=e}}}else t.result=d,r.children=r.children||[],r.children.push(d),traverse(c,t,a,n,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 _sharedUtils.compileOptionsObject.optimizeTemplateAttr&&(0,_compress.compressTemplateAttr)(l.result),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles}}var _default={parse:parse,validator:_validator.default};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"),_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):i.match(/^model:/)?_validator.default.checkModel(i,s,t,e,c,o):i.match(/^dir:/)?_validator.default.checkCustomDirective(i,s,t,e):_validator.default.checkAttr(i,s,t,e.tagName,c,o)}}));const r=t.result,i=e.childNodes;if(i&&i.length){let a,l;const n=[],s=calcSubTextNodesNum(r.type,i);i.forEach((function(c,u){u>0&&(l=i[u-1],l.nodeName.match(/^#/)||(a=l,a.__cond__||a.attrs&&a.attrs.forEach((function(e){"if"!==e.name&&"elif"!==e.name||(a.__cond__=e.value)}))));const d={};if(c.nodeName.match(/^#/)){if("#text"===c.nodeName&&c.value.trim()){l&&_validator.default.isSupportedSelfClosing(l.nodeName)||_validator.default.isNotTextContentAtomic(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=o.importNames&&o.importNames.indexOf(e.tagName)>-1;if((a||i)&&(d.type="span",t.result=d,r.children=r.children||[],r.children.push(d),t.log.push({line:e.__location.line,column:e.__location.col,reason:`WARN: 文本和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.isTextContentAtomic(e.tagName)){const e=t.result;t.result=r,_validator.default.checkAttr("value",c.value,t),t.result=e}}}else t.result=d,r.children=r.children||[],r.children.push(d),traverse(c,t,a,n,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:[],isLite:!!t.lite};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 _sharedUtils.compileOptionsObject.optimizeTemplateAttr&&(0,_compress.compressTemplateAttr)(l.result),{jsonTemplate:l.result,log:l.log,depFiles:l.depFiles}}var _default={parse:parse,validator:_validator.default};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")),_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:{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 n=t.result,s=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&&s.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+l+"` 自动转换为 `"+tagAliasMap[l]+"`"}),l=tagAliasMap[l]),n.type=l,RESERVED_TAGS.indexOf(l)>=0?s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+l+"` 是系统保留的组件名, 请修改"}):hasTagDefined(l)||s.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${l}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[l]&&!tagNatives[l].supportCard&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+l+"`, 请修改"}),e._isroot&&tagNotRoot.hasOwnProperty(l)&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不能作为根组件"}),n.attr=n.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&&s.push({line:i.line||1,column:i.col||1,reason:"WARN: 根节点 `"+l+"` 不能使用属性 `"+t+"`"})}))}if(!u){if(tagEmpty.hasOwnProperty(l)&&o.length>0&&s.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||(s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 是原子类型,不应该有子节点"}),!1))):(o.length>1||o[0]&&"#text"!==o[0].nodeName)&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 只能有一个文字子节点"})),tagDefaultAttrMap[l]&&Object.keys(tagDefaultAttrMap[l]).forEach((t=>{const n=p.indexOf(t);n>=0&&""===c[n].value?(c[n].value=tagDefaultAttrMap[l][t],s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[l][t]+"`"})):"slot"===l&&n<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&&s.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 n=tagEnumAttrMap[l][e];n.indexOf(a)<0&&(c[t].value=n[0],s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+n[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||s.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 n=t.replace(/^(on|@)/,""),r=["appear","disappear","swipe"];a.uxType===_utils.ENTRY_TYPE.CARD&&r.indexOf(n.toLowerCase())>-1&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片组件 `"+l+"` 不支持事件 `"+n+"`"}),e.indexOf(n.toLowerCase())<0&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持事件 `"+n+"`"})}}))}if(o.length>0){const t=new Set,n={};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 n=e.parentNode;for(;n;){if("slot"===n.tagName){_sharedUtils.colorconsole.warn(`slot标签内不应该嵌套slot ${a.filePath}@${i.line||1},${i.col||1}`);break}n=n.parentNode}const s={};e.attrs.map((e=>{s[e.name]=e.value})),s.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(s.name)&&_sharedUtils.colorconsole.warn(`标签${e.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):s.name="default",t.has(s.name)?_sharedUtils.colorconsole.warn(`标签${l}内存在name为 \`${s.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):t.add(s.name)}if(o&&o.indexOf(l)<0||u&&u.indexOf(e.nodeName)<0)s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持子组件 `"+e.nodeName+"`"});else if(c&&c.indexOf(e.nodeName)>-1){let t;(n[e.nodeName]||0===n[e.nodeName])&&(t=!0),n[e.nodeName]={index:r,duplicated:t}}}}));const r=Object.keys(n);r.length&&(r.filter((e=>n[e].duplicated)).forEach((e=>{s.push({line:i.line||1,column:i.col||1,reason:`'WARN: 组件 \`${e}\` 只允许在 \`${l}\` 组件中出现一次`})})),e.childNodes=o.filter(((e,t)=>!(n[e.nodeName]&&n[e.nodeName].duplicated&&t!==n[e.nodeName].index))))}isSupportedSelfClosing(l)||!i.startTag||i.endTag||s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 缺少闭合标签,请检查"}),"list-item"===l&&hasIfOrFor(o)&&s.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,n){let s={};const r=t.log;if(e){if(_exp.default.singleExpr(e)){const n=_exp.default.removeExprffix(e);return _exp.default.isExpr(n)?r.push({line:a.line||1,column:a.col||1,reason:"ERROR: style 属性不能嵌套多层{{}}"}):s=(0,_exp.default)(e),void(t.result.style=s)}if(e.split(";").forEach((function(e){let t,l,o,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),l=i[1].trim(),l=(0,_exp.default)(l),o=_style.default.validateDelaration(t,l,n),l=o.value,l.forEach((e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(s[e.n]=e.v)})),o.log&&r.push({line:a.line||1,column:a.col||1,reason:o.log.reason}))})),"object"==typeof s)for(let e in s)_style.default.shouldAddToDependency(e,s[e])&&t.depFiles.push(s[e]);t.result.style=s}}function checkIs(e,t,a){const n=t.log;e?(e=_exp.default.addExprffix(e),t.result.is=(0,_exp.default)(e)):n.push({line:a.line||1,column:a.col||1,reason:"WARN: is 属性为空"})}function checkIf(e,t,a,n,s){const r=t.log;e?(e=_exp.default.addExprffix(e),a?e="{{"+buildConditionExp(s)+"}}":(s.length>0&&(s.length=0),s.push(`${e.substr(2,e.length-4)}`)),t.result.shown=(0,_exp.default)(e)):a||r.push({line:n.line||1,column:n.col||1,reason:"WARN: if 属性为空"})}function checkElse(e,t,a,n){checkIf(e,t,!0,a,n),n.length=0}function checkElif(e,t,a,n,s){const r=a.log;let l=t;return e?(e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t),l="{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(s)+"}}",a.result.shown=(0,_exp.default)(l),s.push(`${e.substr(2,e.length-4)}`)):r.push({line:n.line||1,column:n.col||1,reason:"WARN: Elif 属性为空"}),l}function checkFor(e,t,a){const n=t.log;if(e){let a,n;const s=(e=_exp.default.removeExprffix(e)).match(/(.*) (?:in) (.*)/);if(s){const t=s[1].match(/\((.*),(.*)\)/);t?(a=t[1].trim(),n=t[2].trim()):n=s[1].trim(),e=s[2]}let r;e="{{"+e+"}}",a||n?(r={exp:(0,_exp.default)(e)},a&&(r.key=a),n&&(r.value=n)):r=(0,_exp.default)(e),t.result.repeat=r}else n.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=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,n){const s=e.replace(/^dir:/,"");if(!s)return _sharedUtils.colorconsole.warn(`\`${n.tagName}\` 组件自定义指令名称不能为空`),!1;a.result.directives=a.result.directives||[],a.result.directives.push({name:s,value:_exp.default.isExpr(t)?(0,_exp.default)(t):t})}function checkAttr(e,t,a,n,s,r){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,n)){(0,_utils.fileExists)(t,r.filePath)||a.log.push({line:s.line,column:s.column,reason:"WARN: "+n+" 属性 "+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"===n&&a.log.push({line:s.line,column:s.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}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 n={},s={},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&&(n[e]=t.enum,s[e]=t.enum[0]),t.def&&(s[e]=t.def),!0===t.required&&r.push(e)})),tagAttrMap[e]=a,tagEnumAttrMap[e]=n,tagDefaultAttrMap[e]=s,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};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:{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 n=t.result,s=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&&s.push({line:i.line||1,column:i.col||1,reason:"NOTE: 组件名 `"+l+"` 自动转换为 `"+tagAliasMap[l]+"`"}),l=tagAliasMap[l]),n.type=l,RESERVED_TAGS.indexOf(l)>=0?s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件名 `"+l+"` 是系统保留的组件名, 请修改"}):hasTagDefined(l)||s.push({line:i.line||1,column:i.col||1,reason:`WARN: 未识别的标签名 '${l}',如果是自定义组件,请确认已经引入`}),a.uxType===_utils.ENTRY_TYPE.CARD&&tagNatives[l]&&!tagNatives[l].supportCard&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片不支持组件名 `"+l+"`, 请修改"}),e._isroot&&tagNotRoot.hasOwnProperty(l)&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不能作为根组件"}),n.attr=n.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&&s.push({line:i.line||1,column:i.col||1,reason:"WARN: 根节点 `"+l+"` 不能使用属性 `"+t+"`"})}))}if(!u){if(tagEmpty.hasOwnProperty(l)&&o.length>0&&s.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||(s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 是原子类型,不应该有子节点"}),!1))):(o.length>1||o[0]&&"#text"!==o[0].nodeName)&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 只能有一个文字子节点"})),tagDefaultAttrMap[l]&&Object.keys(tagDefaultAttrMap[l]).forEach((t=>{const n=p.indexOf(t);n>=0&&""===c[n].value?(c[n].value=tagDefaultAttrMap[l][t],s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+t+"` 值为空, 默认设置为缺省值 `"+tagDefaultAttrMap[l][t]+"`"})):"slot"===l&&n<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&&s.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 n=tagEnumAttrMap[l][e];n.indexOf(a)<0&&(c[t].value=n[0],s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 属性 `"+e+"` 的值 `"+a+"`非法, 默认设置为缺省值 `"+n[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||s.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 n=t.replace(/^(on|@)/,""),r=["appear","disappear","swipe"];a.uxType===_utils.ENTRY_TYPE.CARD&&r.indexOf(n.toLowerCase())>-1&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 卡片组件 `"+l+"` 不支持事件 `"+n+"`"}),e.indexOf(n.toLowerCase())<0&&s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持事件 `"+n+"`"})}}))}if(o.length>0){const t=new Set,n={};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 n=e.parentNode;for(;n;){if("slot"===n.tagName){_sharedUtils.colorconsole.warn(`slot标签内不应该嵌套slot ${a.filePath}@${i.line||1},${i.col||1}`);break}n=n.parentNode}const s={};e.attrs.map((e=>{s[e.name]=e.value})),s.hasOwnProperty("name")?/\{\{\s*[\w$]+\s*\}\}/.test(s.name)&&_sharedUtils.colorconsole.warn(`标签${e.nodeName}的name属性暂时不支持动态绑定 ${a.filePath}@${i.line||1},${i.col||1}`):s.name="default",t.has(s.name)?_sharedUtils.colorconsole.warn(`标签${l}内存在name为 \`${s.name}\` 重复slot ${a.filePath}@${i.line||1},${i.col||1}`):t.add(s.name)}if(o&&o.indexOf(l)<0||u&&u.indexOf(e.nodeName)<0)s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 不支持子组件 `"+e.nodeName+"`"});else if(c&&c.indexOf(e.nodeName)>-1){let t;(n[e.nodeName]||0===n[e.nodeName])&&(t=!0),n[e.nodeName]={index:r,duplicated:t}}}}));const r=Object.keys(n);r.length&&(r.filter((e=>n[e].duplicated)).forEach((e=>{s.push({line:i.line||1,column:i.col||1,reason:`'WARN: 组件 \`${e}\` 只允许在 \`${l}\` 组件中出现一次`})})),e.childNodes=o.filter(((e,t)=>!(n[e.nodeName]&&n[e.nodeName].duplicated&&t!==n[e.nodeName].index))))}isSupportedSelfClosing(l)||!i.startTag||i.endTag||s.push({line:i.line||1,column:i.col||1,reason:"ERROR: 组件 `"+l+"` 缺少闭合标签,请检查"}),"list-item"===l&&hasIfOrFor(o)&&s.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)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,n){let s={};const r=t.log;if(e){const l=t.isLite;if(_exp.default.singleExpr(e)){const n=_exp.default.removeExprffix(e);return _exp.default.isExpr(n)?r.push({line:a.line||1,column:a.col||1,reason:"ERROR: style 属性不能嵌套多层{{}}"}):s=(0,_exp.default)(e,!0,l),void(t.result.style=s)}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?s[t]=o:(i=_style.default.validateDelaration(t,o,n),o=i.value,o.forEach((e=>{((0,_utils.isValidValue)(e.v)||"function"==typeof e.v)&&(s[e.n]=e.v)})),i.log&&r.push({line:a.line||1,column:a.col||1,reason:i.log.reason})))})),"object"==typeof s)for(let e in s)_style.default.shouldAddToDependency(e,s[e])&&t.depFiles.push(s[e]);t.result.style=s}}function checkIs(e,t,a){const n=t.log;e?(e=_exp.default.addExprffix(e),t.result.is=(0,_exp.default)(e,!0,t.isLite)):n.push({line:a.line||1,column:a.col||1,reason:"WARN: is 属性为空"})}function checkIf(e,t,a,n,s){const r=t.log;if(e){e=_exp.default.addExprffix(e);const n=t.isLite;a?e=n?buildLiteConditionExp(s):"{{"+buildConditionExp(s)+"}}":(s.length>0&&(s.length=0),s.push(`${e.substr(2,e.length-4)}`)),t.result.shown=n?e:(0,_exp.default)(e,!0)}else a||r.push({line:n.line||1,column:n.col||1,reason:"WARN: if 属性为空"})}function checkElse(e,t,a,n){checkIf(e,t,!0,a,n),n.length=0}function checkElif(e,t,a,n,s){const r=a.log;let l=t;if(e){e=_exp.default.addExprffix(e),t=_exp.default.addExprffix(t);const n=a.isLite;l=n?"{{"+e.substr(2,e.length-4)+"}}&&"+buildLiteConditionExp(s):"{{("+e.substr(2,e.length-4)+") && "+buildConditionExp(s)+"}}",a.result.shown=n?l:(0,_exp.default)(l),s.push(`${e.substr(2,e.length-4)}`)}else r.push({line:n.line||1,column:n.col||1,reason:"WARN: Elif 属性为空"});return l}function checkFor(e,t,a){const n=t.log;if(e){let a,n;const s=(e=_exp.default.removeExprffix(e)).match(/(.*) (?:in) (.*)/);if(s){const t=s[1].match(/\((.*),(.*)\)/);t?(a=t[1].trim(),n=t[2].trim()):n=s[1].trim(),e=s[2]}e="{{"+e+"}}";const r=t.isLite;let l;a||n?(l={exp:(0,_exp.default)(e,!0,r)},a&&(l.key=a),n&&(l.value=n)):l=(0,_exp.default)(e,!0,r),t.result.repeat=l}else n.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,n){const s=e.replace(/^dir:/,"");if(!s)return _sharedUtils.colorconsole.warn(`\`${n.tagName}\` 组件自定义指令名称不能为空`),!1;a.result.directives=a.result.directives||[],a.result.directives.push({name:s,value:_exp.default.isExpr(t)?(0,_exp.default)(t,!0,a.isLite):t})}function checkAttr(e,t,a,n,s,r){if(e&&(0,_utils.isValidValue)(t)){if(shouldConvertPath(e,t,n)){(0,_utils.fileExists)(t,r.filePath)||a.log.push({line:s.line,column:s.column,reason:"WARN: "+n+" 属性 "+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"===n&&a.log.push({line:s.line,column:s.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 buildLiteConditionExp(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}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 n={},s={},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&&(n[e]=t.enum,s[e]=t.enum[0]),t.def&&(s[e]=t.def),!0===t.required&&r.push(e)})),tagAttrMap[e]=a,tagEnumAttrMap[e]=n,tagDefaultAttrMap[e]=s,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};exports.default=_default;
//# sourceMappingURL=validator.js.map
{
"name": "@hap-toolkit/compiler",
"version": "1.9.16",
"version": "1.9.17-alpha.0",
"description": "compiler of hap-toolkit",

@@ -25,3 +25,3 @@ "engines": {

"dependencies": {
"@hap-toolkit/shared-utils": "1.9.16",
"@hap-toolkit/shared-utils": "1.9.17-alpha.0",
"@jayfate/path": "^0.0.13",

@@ -32,3 +32,3 @@ "css": "^2.2.4",

},
"gitHead": "0df7ba5931619030424b2415be5c5c49cd9eaad6"
"gitHead": "265c5c907c972b2ac1b86627a82f9f2ee3f5b822"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc