@hap-toolkit/compiler
Advanced tools
Comparing version 1.9.4 to 1.9.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;case"model":_validator.default.checkModel(s,t,e,o);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,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 _={};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)&&(_.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.isTextContentAtomic(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,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 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 _={};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)&&(_.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.isTextContentAtomic(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,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; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=model;var _exp=_interopRequireDefault(require("./exp")),_utils=require("../utils"),_validator=_interopRequireDefault(require("./validator.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function model(e,t,n,u){if(!(0,_utils.isValidValue)(e))return!1;e=_exp.default.addExprffix(e);const a=t.result.type,l=getBindingAttr(n,"type")||"";let d=!1;"input"===a&&l.match(/^this\.+/)&&(d=!0),d?genDynamicModel(n,e,t,l):u.importNames&&u.importNames.indexOf(a)>-1?genComponentModel(e,t):"select"===a?genSelectModel(e,t):"input"===a&&"checkbox"===l?genCheckboxModel(n,e,t):"input"===a&&"radio"===l?genRadioModel(n,e,t):"input"===a||"textarea"===a?genDefaultModel(e,t):_validator.default.isReservedTag(a)||genComponentModel(e,t)}function genCheckboxModel(node,value,output){const expValue=(0,_exp.default)(value,!1),valueBinding=getBindingAttr(node,"value",!0)||"null",trueValueBinding=getBindingAttr(node,"true-value",!0)||"true",falseValueBinding=getBindingAttr(node,"false-value",!0)||"false",attrCheckedCode=`\n if (Array.isArray(${expValue})) {\n return ${expValue}.indexOf(${valueBinding}) > -1\n } else {\n return ${expValue}${"true"===trueValueBinding?"":"=== "+trueValueBinding}\n }`,eventChangeCode=`\n const checked = evt.target.checked;\n if (Array.isArray(${expValue})) {\n const index = ${expValue}.indexOf(${valueBinding})\n if (checked) {\n index < 0 && (${expValue} = ${expValue}.concat([${valueBinding}]))\n } else {\n index > -1 && (${expValue} = ${expValue}.slice(0, index).concat(${expValue}.slice(index + 1)))\n }\n } else {\n ${expValue} = checked ? ${trueValueBinding} : ${falseValueBinding}\n }`;return addAttr(output.result,"checked",eval(`(function() {${attrCheckedCode}})`)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{attr:{checked:attrCheckedCode},events:{change:eventChangeCode}}}function genRadioModel(node,value,output){const valueBinding=getBindingAttr(node,"value",!0)||"null",attrCheckedCode=`return ${(0,_exp.default)(value,!1)} === ${valueBinding}`,eventChangeCode=`${(0,_exp.default)(value,!1)} = ${valueBinding}`;return addAttr(output.result,"checked",eval(`(function() {${attrCheckedCode}})`)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{attr:{checked:attrCheckedCode},events:{change:eventChangeCode}}}function genSelectModel(value,output){addHandler(output.result,"change",eval(`(function(evt) { ${(0,_exp.default)(value,!1)} = evt.newValue})`))}function genDefaultModel(value,output){const eventChangeCode=(0,_exp.default)(value,!1)+" = evt.target.value";return addAttr(output.result,"value",(0,_exp.default)(value)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{events:{change:eventChangeCode}}}function genComponentModel(value,output){const expValue=(0,_exp.default)(value,!1);output.result.model={value:(0,_exp.default)(value),callback:eval(`(function (evt) { ${expValue} = evt.detail})`)}}function genDynamicModel(node,value,output,expType){const checkboxCode=genCheckboxModel(node,value,output),radioCode=genRadioModel(node,value,output),textCode=genDefaultModel(value,output);addAttr(output.result,"value",(0,_exp.default)(value)),addAttr(output.result,"checked",eval(`\n (function() { \n if (${expType} === 'checkbox') {\n ${checkboxCode.attr.checked}\n } else if (${expType} === 'radio') {\n ${radioCode.attr.checked}\n } else {\n return false\n }\n })\n `)),addHandler(output.result,"change",eval(`\n (function(evt) {\n if (${expType} === 'checkbox') {\n ${checkboxCode.events.change}\n } else if (${expType} === 'radio') {\n ${radioCode.events.change}\n } else {\n ${textCode.events.change}\n }\n })\n `))}function getBindingAttr(e,t,n=!1){const u=e.attrs||[];for(let e=0;e<u.length;e++){let a=u[e].name;const l=a.match(/^:+/);if(l&&(a=a.slice(l.length)),a===t){const t=(0,_exp.default)(u[e].value,!1);return n&&!t.match(/^this\.+/)?`"${t}"`:t}}}function addAttr(e,t,n){(e.attr||(e.attr={}))[t]=n}function addHandler(e,t,n){(e.events||(e.events={}))[t]=n} | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=model;var _sharedUtils=require("@hap-toolkit/shared-utils"),_exp=_interopRequireDefault(require("./exp")),_utils=require("../utils"),_validator=_interopRequireDefault(require("./validator.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function model(e,t,n,a,u,d){const l=e.replace(/^model:/,"");if(!l)return _sharedUtils.colorconsole.warn(`\`${a.tagName}\` 组件model指令绑定的属性不能为空`),!1;if(!(0,_utils.isValidValue)(t))return!1;t=_exp.default.addExprffix(t);const o=n.result.type,r=getBindingAttr(a,"type")||"";let i=!1;"input"===o&&r.match(/^this\.+/)&&(i=!0),i?genDynamicModel(a,l,t,n,r):"select"===o?genSelectModel(t,n):"input"===o&&"checkbox"===r?genCheckboxModel(a,l,t,n):"input"===o&&"radio"===r?genRadioModel(a,l,t,n):"input"===o||"textarea"===o?genDefaultModel(l,t,n):("component"===o||!_validator.default.isReservedTag(o)||d.importNames&&d.importNames.indexOf(o)>-1)&&genComponentModel(a,l,t,n,u,d)}function genCheckboxModel(node,attrName,value,output){const expValue=(0,_exp.default)(value,!1),valueBinding=getBindingAttr(node,"value",!0)||"null",trueValueBinding=getBindingAttr(node,"true-value",!0)||"true",falseValueBinding=getBindingAttr(node,"false-value",!0)||"false",attrCheckedCode=`\n if (Array.isArray(${expValue})) {\n return ${expValue}.indexOf(${valueBinding}) > -1\n } else {\n return ${expValue}${"true"===trueValueBinding?"":"=== "+trueValueBinding}\n }`,eventChangeCode=`\n const checked = evt.target.checked;\n if (Array.isArray(${expValue})) {\n const index = ${expValue}.indexOf(${valueBinding})\n if (checked) {\n index < 0 && (${expValue} = ${expValue}.concat([${valueBinding}]))\n } else {\n index > -1 && (${expValue} = ${expValue}.slice(0, index).concat(${expValue}.slice(index + 1)))\n }\n } else {\n ${expValue} = checked ? ${trueValueBinding} : ${falseValueBinding}\n }`;return addAttr(output.result,attrName,eval(`(function() {${attrCheckedCode}})`)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{attr:{checked:attrCheckedCode},events:{change:eventChangeCode}}}function genRadioModel(node,attrName,value,output){const valueBinding=getBindingAttr(node,"value",!0)||"null",attrCheckedCode=`return ${(0,_exp.default)(value,!1)} === ${valueBinding}`,eventChangeCode=`${(0,_exp.default)(value,!1)} = ${valueBinding}`;return addAttr(output.result,attrName,eval(`(function() {${attrCheckedCode}})`)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{attr:{checked:attrCheckedCode},events:{change:eventChangeCode}}}function genSelectModel(value,output){addHandler(output.result,"change",eval(`(function(evt) { ${(0,_exp.default)(value,!1)} = evt.newValue})`))}function genDefaultModel(attrName,value,output){const eventChangeCode=(0,_exp.default)(value,!1)+" = evt.target.value";return addAttr(output.result,attrName,(0,_exp.default)(value)),addHandler(output.result,"change",eval(`(function(evt) {${eventChangeCode}})`)),{events:{change:eventChangeCode}}}function genComponentModel(node,attrName,value,output,locationInfo,options){_validator.default.checkAttr(attrName,value,output,node.tagName,locationInfo,options),addHandler(output.result,"update:"+attrName,eval(`(function(evt) { ${(0,_exp.default)(value,!1)} = evt.detail})`))}function genDynamicModel(node,attrName,value,output,expType){const checkboxCode=genCheckboxModel(node,attrName,value,output),radioCode=genRadioModel(node,attrName,value,output),textCode=genDefaultModel(attrName,value,output);addAttr(output.result,attrName,(0,_exp.default)(value)),addAttr(output.result,"checked",eval(`\n (function() { \n if (${expType} === 'checkbox') {\n ${checkboxCode.attr.checked}\n } else if (${expType} === 'radio') {\n ${radioCode.attr.checked}\n } else {\n return false\n }\n })\n `)),addHandler(output.result,"change",eval(`\n (function(evt) {\n if (${expType} === 'checkbox') {\n ${checkboxCode.events.change}\n } else if (${expType} === 'radio') {\n ${radioCode.events.change}\n } else {\n ${textCode.events.change}\n }\n })\n `))}function getBindingAttr(e,t,n=!1){const a=e.attrs||[];for(let e=0;e<a.length;e++){let u=a[e].name;const d=u.match(/^:+/);if(d&&(u=u.slice(d.length)),u===t){const t=(0,_exp.default)(a[e].value,!1);return n&&!t.match(/^this\.+/)?`"${t}"`:t}}}function addAttr(e,t,n){(e.attr||(e.attr={}))[t]=n}function addHandler(e,t,n){(e.events||(e.events={}))[t]=n} | ||
//# sourceMappingURL=model.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",".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","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"]}}},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}}},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"]},autocomplete:{enum:["on","off"]},enterkeytype:{enum:["default","next","go","done","send","search"]},eventtype:{enum:["shortcut"]},model:{},"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"}},events:["load","error"]},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:{},model:{}},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)}},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,attrs:{model:{}}},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:"ERROR: 根节点 `"+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)&&(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;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:"ERROR: 组件 `"+l+"` 不支持属性 `"+e+"`,支持的属性有 ["+Object.keys(tagAttrMap[l]).join(", ")+"]"})}}),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:`'WARNING: 组件 \`${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:"WARNING: 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:"WARNING: 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:"WARNING: 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:"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) { 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 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:"WARNING: "+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:"WARNING: `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,_utils.extend)({},t.attrs);const n={},s={},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&&(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,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",".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]),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"]}}},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}}},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"]},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"}},events:["load","error"]},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)}},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"]},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:"ERROR: 根节点 `"+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)&&(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:"ERROR: 组件 `"+l+"` 不支持属性 `"+e+"`,支持的属性有 ["+Object.keys(tagAttrMap[l]).join(", ")+"]"})}}),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:`'WARNING: 组件 \`${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:"WARNING: 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:"WARNING: 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:"WARNING: 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:"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) { 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:"WARNING: "+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:"WARNING: `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,_utils.extend)({},t.attrs);const n={},s={},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&&(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.4", | ||
"version": "1.9.5", | ||
"description": "compiler of hap-toolkit", | ||
@@ -21,3 +21,3 @@ "engines": { | ||
"dependencies": { | ||
"@hap-toolkit/shared-utils": "1.9.4", | ||
"@hap-toolkit/shared-utils": "1.9.5", | ||
"css": "^2.2.4", | ||
@@ -27,3 +27,3 @@ "css-what": "^2.1.3", | ||
}, | ||
"gitHead": "2052bfdfbc726b3cea43baa972d9e2605d9a5095" | ||
"gitHead": "bc195064bcccb1b83d0c55676b07cdb32b1463ce" | ||
} |
98513
396
+ Added@hap-toolkit/shared-utils@1.9.5(transitive)
- Removed@hap-toolkit/shared-utils@1.9.4(transitive)