@guihz/trading-vue-editor-tes 0.0.238 → 0.0.240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -115,7 +115,7 @@ ${this._prefixNameVar}.setVarValue("${v}", ${y}, ${v}, "${h}")`}n==="-="?L=`${v}
115
115
  })
116
116
  `}return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:d}),d}_parserArrowFunction(e){let n=`$_${e.name}`;this._nameMap.set(e.name,n);const r=[...e.params];n=`${n}${e.index?`$${e.index}`:""}`,this._currentFuncName=n,this._dependsObj[n]=new Map;const s=e.hasRequest?", $paramsExpr":"",c=`const ${n} = (${this._parserParameters(r)}$posStr${s}) => {
117
117
  ${this._parserBlock(e.block,!0,!0)}
118
- }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:c}),c}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
118
+ }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:c}),c}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r==="/")return`${this._prefixNameVar}.div(${s}, ${c})`;if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
119
119
  ${this._prefixNameVar}.setCacheData("m${v}_" + ${S}, ${D})
120
120
  `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,s,c){const h=this._memberIndexList[r]||{};e=c&&r!==0?`"${e}_" + $posStr`:`"${e}"`;const d=`${this._prefixNameVar}.setCacheData(${e}, ${n})`;return h[e]=d,this._memberIndexList[r]=h,this._setDepend({name:n,scope:r,memberCode:d}),`${this._prefixNameVar}.getCacheData(${e}, ${s}, ${n})`}_getUserVarMemberIndexs(e,n,r,s,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,s,c)}_parseLiteral(e){return e.type.endsWith(V.COLOR)?`"${this._colorToRgba(e.value)}"`:e.value}_colorToRgba(e){if(e.startsWith("#")){let n;const r=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),c=parseInt(e.substring(5,7),16),h=e.substring(7);return h?n=parseInt(h,16)/255:n=1,`rgba(${Math.round(r)}, ${Math.round(s)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:s,hasMethod:c,arg:h,varPos:d}=e;let v=[];for(const C of r){if(typeof C=="string"){v.push((d==null?void 0:d.reName)||C);continue}let T="";const{column:D,line:L}=((S=C==null?void 0:C.ctx)==null?void 0:S.start)||{},P=`${L}_${D}`;C.selfArg?(T=this._parserMethodElement(C,P,v.join(".")),v=[]):T=this._parserMethodElement(C,P,""),v.push(T)}if(e.expr&&v.unshift(`(${this._parserSingleExpression(e.expr)})`),e.isBuiltIn){const C=v.join(".");C==="strategy.opentrades"?v.push("opentrades"):C==="chart.left_visible_bar_time"?this._hasLeftVisibleBarTime=!0:C==="chart.right_visible_bar_time"&&(this._hasRightVisibleBarTime=!0),v.unshift(e.isConst?this._prefixNameConst:this._prefixNameVar)}else if(wn.includes(v[0])&&(v[0]=`$${v[0]}`),!c){const C={name:v[0],scope:s||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(C)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const s=r.get(n)||{},c={...e,...s};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:s,line:c}=r.start,h=`${c}_${s}`;let d=this._isInFunc?`$posStr + "__${h}"`:`"${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1,S=[];for(const T of n){T.hasMemberIndex&&(v=!0);let D="";T.selfArg?(D=this._parserMethodElement(T,d,S.join(".")),S=[]):D=this._parserMethodElement(T,d,""),S.push(D)}const C=S.join(".");if(this._isInConditionalStmt&&v){const T=`$$result_${this._preRunMemberFuncsCount}`;this._preRunMemberFuncsCount++;const D=this._preRunMembersFuncs[this._blockCount]||[];return D.push(`const ${T} = ${C}`),this._preRunMembersFuncs[this._blockCount]=D,T}return C}_parserMethodElement(e,n,r){let s="",c="";const h={...e.args};e.expr&&(s=`(${this._parserSingleExpression(e.expr)})`),s=s?`${s}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(s=`${this._prefixNameVar}.${s}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(s))s=`${s}.${s}`;else if(s==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}s.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):s.startsWith("request.")&&(d=!0),s=`${this._prefixNameFunc}.${s}`}else{const S=s.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,s=S.join("."))}if(e.selfArg){const S=s.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),s=S[C-1],s=this._nameMap.get(s)||s,this._setDepend({name:S[0],scope:e.varScope||0})}s=`${s}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,s);if(!e.isBuiltIn){const S=s.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:s,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:s,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return s+v}_parserArguments(e,n,r,s=!1,c=!1,h){const d=e.params||[];delete e.params;const v=[],S=[];let C=[],T;const D=(P,b)=>{c&&(this._dependsObj[r]=new Map),s&&b==="expression"&&(this._dependsObj[`$arg_${b}${r}`]=new Map);let y=P.ruleType===le.Brackethesized?this._parserBrackethesized(P):this._parserSingleExpression(P);if(b&&!["arg0, arg1, ...","number0, number1, ..."].includes(b)){P.isSourceType?v.push(`sourceTypeName: "${P.name}"`):b==="defval"&&h===`${this._prefixNameFunc}.input.enum`&&(T=this._enums.get(P.enumName));const g=this._requestParamsHandle(s,b,r,c,y,h);y=(g==null?void 0:g.code)||y,g!=null&&g.paramsExpr&&C.push(g==null?void 0:g.paramsExpr),v.push(`${b}: ${y}`)}else S.push(y)};for(const P of d)D(P,P.originName);for(const P of Object.keys(e))D(e[P],P);s&&this._isInFunc&&v.push("paramsExpr: $paramsExpr"),n&&v.push(n),T&&v.unshift(`options: [${T.join(", ")}]`);const L=C.length?`, [${this._isInFunc?"...$paramsExpr, ":""}${C.join(", ")}]`:"";return S.length?`({${v.join(", ")}}, [${S.join(", ")}], ${r}${L})`:v.length?`({${v.join(", ")}}, ${r}${L})`:`(${r}${L})`}_requestParamsHandle(e,n,r,s,c,h){const d=this._memberIndexList[0],v={};for(const S of Object.keys(d))S.includes("_")||(v[S]=d[S]);if(e&&n==="expression"){const S=this._getDepends(`$arg_${n}${r}`),C=this._getExpressionContext(S);return C.push({scope:1,depends:S.map(T=>(T.isArg&&(T.functionName=this._currentFuncName),T)),code:c,memberCodes:v}),{code:`'${pu(JSON.stringify(C))}'`}}else if(s){const S=this._getDepends(r),C=this._getExpressionContext(S);return C.push({scope:2,varNames:n,methodName:h,depends:S,dependSelf:S.some(T=>T.name===n),code:`${n} = ${c}`,memberCodes:v}),{paramsExpr:`'${pu(JSON.stringify(C))}'`}}}_getExpressionContext(e){const n=[],r=[];return this._getDependsCode(e,n,r),n}_getDependsCode(e,n,r){var s,c;for(const h of e)if(!h.isArg){const d=this._codesCol[h.scope||0],v=d.find(C=>{var T;return((T=C.varNames)==null?void 0:T.includes(h.name))||C.funcName===h.name});v&&(r.includes(v)||(r.push(v),v.depends.length&&this._getDependsCode(v.depends,n,r),n.push({scope:h.scope||0,code:v.code,depends:v.depends,funcName:v.funcName,varNames:(s=v.varNames)==null?void 0:s.join(", ")})));const S=d.filter(C=>C.depends.some(T=>T.name===h.name&&T.scope===h.scope&&T.isAgainAssign));for(const C of S)r.includes(C)||(r.push(C),C.depends.length&&this._getDependsCode(C.depends,n,r),n.push({scope:h.scope||0,code:C.code,depends:C.depends,funcName:C.funcName,varNames:(c=C.varNames)==null?void 0:c.join(", ")}))}}_parserBrackethesized(e){return`[${e.exprs.map(r=>this._parserSingleExpression(r)).join(", ")}]`}_functionalProcess(e,n){return`(function () {
121
121
  let $$_result=${n&&typeof n=="string"&&n.endsWith("string")?'""':"undefined"};
@@ -234,7 +234,7 @@ ${this._prefixNameVar}.againAssignParse(${v}, ${L});
234
234
  `}return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:d}),d}_parserArrowFunction(e){let n=`$_${e.name}`;this._nameMap.set(e.name,n);const r=[...e.params],s=e.index?`$${e.index}`:"";n=`${n}${s}`,e.isExport&&this._exportEles.push({key:`${e.name}${s}`,name:n}),this._currentFuncName=n,this._dependsObj[n]=new Map;const c=e.hasRequest?", $paramsExpr":"",h=`const ${n} = (${this._parserParameters(r)}$posStr${c}) => {
235
235
  if ($posStr.startsWith('export')) return;
236
236
  ${this._parserBlock(e.block,!0,!0)}
237
- }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:h}),h}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + '_' + '${C}'`:`"export_${this._libTitle}_${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
237
+ }`;return this._isInFunc=!1,this._currentFuncName="",this._codesCol[this._blockCount].push({funcName:n,depends:this._getDepends(n),hasRequest:e.hasRequest,code:h}),h}_parserParameters(e){return e.length?`{${e.map(n=>{const{name:r,defaultValue:s}=n;let c=r;if(s){const h=this._parserSingleExpression(s);c=`${c} = ${h}`}return c}).join(", ")}},`:""}_parserBlock(e,n=!1,r=!1){return r&&(this._isInFunc=!0),this._parserBlockLine(Array.isArray(e)?e:[e],n,r)}_addVarList(e){var r,s;const n=this._varlist[this._blockCount]||{};if(e.names){const c=e.posList;for(const[h,d]of e.names.entries()){const v=((r=c[h])==null?void 0:r.reName)||d;n[v]=c[h]}}else{const c=((s=e.pos)==null?void 0:s.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,s=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:s.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${s}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${s} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + '_' + '${C}'`:`"export_${this._libTitle}_${C}"`;v=`let ${s} = ${this._prefixNameVar}.verifyVarAndVarip("${s}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${s}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${s}", ${T}, ${d}, "${n.declare}")`}return c.code=v,c.depends=this._getDepends(h),(S=this._codesCol[this._blockCount])==null||S.push(c),v}_parserDeclareAssignNames(e){var n,r;switch(e==null?void 0:e.ruleType){case"VarMultiple":const s=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=s[h])!=null&&d.reName?(v=s[h])==null?void 0:v.reName:wn.includes(c)?`$${c}`:c}).join(", ")}]`;case"VarSingle":return e.name==="_"?(this.__count++,`_$$${this.__count}`):(n=e.pos)!=null&&n.reName?(r=e.pos)==null?void 0:r.reName:wn.includes(e.name)?`$${e.name}`:e.name}return""}_parserSingleExpression(e){if(!e)return"";const{exprs:n,operator:r}=e;let s="",c=this._isInConditionalStmt;switch(e.ruleType){case le.MemberIndexExpression:return this._parserMemberIndexExpression(e);case le.MethodExpression:return this._parserMethodExpression(e);case le.UnaryExpression:return`${r}${this._parserSingleExpression(n[0])}`;case le.NotExpression:return`!${this._parserSingleExpression(n[0])}`;case le.AdditiveExpression:return this._parserAdditiveExpression(e);case le.MultiplicativeExpression:case le.RelationalExpression:case le.EqualityExpression:return this._parserEqualityExpression(e);case le.LogicalAndExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,s=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,s;case le.TernaryExpression:return s=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,s;case le.Name:return this._parserName(e);case le.Literal:return this._parseLiteral(e);case le.ParenthesizedExpression:return`(${this._parserSingleExpression(e.exprs)})`;default:return e.name||""}}_parserEqualityExpression(e){var v,S;const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r==="/")return`${this._prefixNameVar}.div(${s}, ${c})`;if(r!=="==")return`${s} ${r} ${c}`;const h=(v=n[0])==null?void 0:v.type,d=(S=n[1])==null?void 0:S.type;return`${this._prefixNameVar}.equal(${s}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,s=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${s}, ${c})`:`${this._prefixNameVar}.add(${s}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:s}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=s.start.tokenIndex,S=r?"$posStr":v;if(c.ruleType===le.Name&&!c.hasMethod){let T=this._blockCount;const D=((C=c.varPos)==null?void 0:C.reName)||c.name;for(;T>=0;){const L=this._varlist[T]||{},P=L[D];if(P)return this._getUserVarMemberIndexs(P,D,T,h,r);if(c.isBuiltIn){const b=this._memberIndexList[0]||{};return b[D]=`${this._prefixNameVar}.setCacheData("${D}", ${d})`,`${this._prefixNameVar}.getCacheData("${D}", ${h}, ${d})`}if(D.includes(".")){const b=D.split(".")[0],y=L[b];if(y)return this._getUserVarMemberIndexs(y,D,T,h,r)}T--}return this._getOtherVarMemberIndexs(`${D}_${c.varScope||c.scope}`,D,c.varScope||c.scope,h,r)}else{const T=this._preRunMembers[this._blockCount]||[],D=`$$m${v}_${S}`;T.push(`const ${D} = ${d};
238
238
  ${this._prefixNameVar}.setCacheData("m${v}_" + ${S}, ${D})
239
239
  `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,s,c){const h=this._memberIndexList[r]||{};e=c&&r!==0?`"${e}_" + $posStr`:`"${e}"`;const d=`${this._prefixNameVar}.setCacheData(${e}, ${n})`;return h[e]=d,this._memberIndexList[r]=h,this._setDepend({name:n,scope:r,memberCode:d}),`${this._prefixNameVar}.getCacheData(${e}, ${s}, ${n})`}_getUserVarMemberIndexs(e,n,r,s,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,s,c)}_parseLiteral(e){return e.type.endsWith(V.COLOR)?`"${this._colorToRgba(e.value)}"`:e.value}_colorToRgba(e){if(e.startsWith("#")){let n;const r=parseInt(e.substring(1,3),16),s=parseInt(e.substring(3,5),16),c=parseInt(e.substring(5,7),16),h=e.substring(7);return h?n=(255-parseInt(h,16))/255:n=1,`rgba(${Math.round(r)}, ${Math.round(s)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:s,hasMethod:c,arg:h,varPos:d}=e;let v=[];for(const C of r){if(typeof C=="string"){v.push((d==null?void 0:d.reName)||C);continue}let T="";const{column:D,line:L}=((S=C==null?void 0:C.ctx)==null?void 0:S.start)||{},P=`${L}_${D}`;C.selfArg?(T=this._parserMethodElement(C,P,v.join(".")),v=[]):T=this._parserMethodElement(C,P,""),v.push(T)}if(e.expr&&v.unshift(`(${this._parserSingleExpression(e.expr)})`),e.isBuiltIn)v.join(".")==="strategy.opentrades"&&v.push("opentrades"),v.unshift(e.isConst?this._prefixNameConst:this._prefixNameVar);else if(wn.includes(v[0])&&(v[0]=`$${v[0]}`),!c){const C={name:v[0],scope:s||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(C)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const s=r.get(n)||{},c={...e,...s};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:s,line:c}=r.start,h=`${c}_${s}`;let d=this._isInFunc?`$posStr + "_${h}"`:`"export_${this._libTitle}_${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1,S=[];for(const T of n){T.hasMemberIndex&&(v=!0);let D="";T.selfArg?(D=this._parserMethodElement(T,d,S.join(".")),S=[]):D=this._parserMethodElement(T,d,""),S.push(D)}const C=S.join(".");if(S.length===1&&[...Al,Ii.library].some(T=>S[0].startsWith(`${this._prefixNameFunc}.${T}`)))return"";if(this._isInConditionalStmt&&v){const T=`$$result_${this._preRunMemberFuncsCount}`;this._preRunMemberFuncsCount++;const D=this._preRunMembersFuncs[this._blockCount]||[];return D.push(`const ${T} = ${C}`),this._preRunMembersFuncs[this._blockCount]=D,T}return C}_parserMethodElement(e,n,r){let s="",c="";const h={...e.args};e.expr&&(s=`(${this._parserSingleExpression(e.expr)})`),s=s?`${s}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(s=`${this._prefixNameVar}.${s}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(s))s=`${s}.${s}`;else if(s==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}s.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):s.startsWith("request.")&&(d=!0),s=`${this._prefixNameFunc}.${s}`}else{const S=s.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,s=S.join("."))}if(e.selfArg){const S=s.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),s=S[C-1],s=this._nameMap.get(s)||s,this._setDepend({name:S[0],scope:e.varScope||0})}s=`${s}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,s);if(!e.isBuiltIn){const S=s.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:s,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:s,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return s+v}_parserArguments(e,n,r,s=!1,c=!1,h){const d=e.params||[];delete e.params;const v=[],S=[];let C=[],T;const D=(P,b)=>{c&&(this._dependsObj[r]=new Map),s&&b==="expression"&&(this._dependsObj[`$arg_${b}${r}`]=new Map);let y=P.ruleType===le.Brackethesized?this._parserBrackethesized(P):this._parserSingleExpression(P);if(b&&!["arg0, arg1, ...","number0, number1, ..."].includes(b)){P.isSourceType?v.push(`sourceTypeName: "${P.name}"`):b==="defval"&&h===`${this._prefixNameFunc}.input.enum`&&(T=this._enums.get(P.enumName));const g=this._requestParamsHandle(s,b,r,c,y,h);y=(g==null?void 0:g.code)||y,g!=null&&g.paramsExpr&&C.push(g==null?void 0:g.paramsExpr),v.push(`${b}: ${y}`)}else S.push(y)};for(const P of d)D(P,P.originName);for(const P of Object.keys(e))D(e[P],P);s&&this._isInFunc&&v.push("paramsExpr: $paramsExpr"),n&&v.push(n),T&&v.unshift(`options: [${T.join(", ")}]`);const L=C.length?`, [${this._isInFunc?"...$paramsExpr, ":""}${C.join(", ")}]`:"";return S.length?`({${v.join(", ")}}, [${S.join(", ")}], ${r}${L})`:v.length?`({${v.join(", ")}}, ${r}${L})`:`(${r}${L})`}_requestParamsHandle(e,n,r,s,c,h){const d=this._memberIndexList[0],v={};for(const S of Object.keys(d))S.includes("_")||(v[S]=d[S]);if(e&&n==="expression"){const S=this._getDepends(`$arg_${n}${r}`),C=this._getExpressionContext(S);return C.push({scope:1,depends:S.map(T=>(T.isArg&&(T.functionName=this._currentFuncName),T)),code:c,memberCodes:v}),{code:`'${pu(JSON.stringify(C))}'`}}else if(s){const S=this._getDepends(r),C=this._getExpressionContext(S);return C.push({scope:2,varNames:n,methodName:h,depends:S,dependSelf:S.some(T=>T.name===n),code:`${n} = ${c}`,memberCodes:v}),{paramsExpr:`'${pu(JSON.stringify(C))}'`}}}_getExpressionContext(e){const n=[],r=[];return this._getDependsCode(e,n,r),n}_getDependsCode(e,n,r){var s,c;for(const h of e)if(!h.isArg){const d=this._codesCol[h.scope||0],v=d.find(C=>{var T;return((T=C.varNames)==null?void 0:T.includes(h.name))||C.funcName===h.name});v&&(r.includes(v)||(r.push(v),v.depends.length&&this._getDependsCode(v.depends,n,r),n.push({scope:h.scope||0,code:v.code,depends:v.depends,funcName:v.funcName,varNames:(s=v.varNames)==null?void 0:s.join(", ")})));const S=d.filter(C=>C.depends.some(T=>T.name===h.name&&T.scope===h.scope&&T.isAgainAssign));for(const C of S)r.includes(C)||(r.push(C),C.depends.length&&this._getDependsCode(C.depends,n,r),n.push({scope:h.scope||0,code:C.code,depends:C.depends,funcName:C.funcName,varNames:(c=C.varNames)==null?void 0:c.join(", ")}))}}_parserBrackethesized(e){return`[${e.exprs.map(r=>this._parserSingleExpression(r)).join(", ")}]`}_functionalProcess(e,n){return`(function () {
240
240
  let $$_result=${n&&typeof n=="string"&&n.endsWith("string")?'""':"undefined"};