@guihz/trading-vue-editor-tes 0.0.234 → 0.0.235

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.
@@ -23,65 +23,65 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
23
23
  /****/
24
24
  `);let v="";d.length>1?v=`${d[0]}
25
25
  let ${a} = ${d[1]}
26
- `:v=`let ${a} = ${h}`;const S={code:v,varNames:a.replace(/[\[\]]/g,"").split(", "),depends:this._getDepends(c)};return this._codesCol[this._blockCount].push(S),v}_getDepends(e){const n=[];for(const[r,a]of this._dependsObj[e])(a.scope||0)>this._blockCount||n.push(a);return delete this._dependsObj[e],n}_parserForToStatement(e,n=!1){let{numerical:r,block:a,name:c}=e;const[h,d,v]=r,S=this._isInLoop;let C=this._count;this._isInLoop=!0;const T=`$start${this._count++}`,D=`$$count${this._count}`,L=`$forTo${this._blockCount}`;n||(this._dependsObj[L]=new Map);const P=this._parserSingleExpression(h),b=this._parserSingleExpression(d),y=v?this._parserSingleExpression(v):"",g=this._parserBlockLine(a,n,!1,!0);wn.includes(c)&&(c=`$${c}`);const O=`var ${T} = Date.now()`,R=`for (let ${c}=${P}; ${c}>=(${b}); ${c}-=(${y||"1"})){
27
- if (Date.now() - ${T} > 500) {
26
+ `:v=`let ${a} = ${h}`;const S={code:v,varNames:a.replace(/[\[\]]/g,"").split(", "),depends:this._getDepends(c)};return this._codesCol[this._blockCount].push(S),v}_getDepends(e){const n=[];for(const[r,a]of this._dependsObj[e])(a.scope||0)>this._blockCount||n.push(a);return delete this._dependsObj[e],n}_parserForToStatement(e,n=!1){let{numerical:r,block:a,name:c,type:h}=e;const[d,v,S]=r,C=this._isInLoop;let T=this._count;this._isInLoop=!0;const D=`$start${this._count++}`,L=`$$count${this._count}`,P=`$forTo${this._blockCount}`;n||(this._dependsObj[P]=new Map);const b=this._parserSingleExpression(d),y=this._parserSingleExpression(v),g=S?this._parserSingleExpression(S):"",O=this._parserBlockLine(a,n,!1,!0);wn.includes(c)&&(c=`$${c}`);const R=`var ${D} = Date.now()`,k=`for (let ${c}=${b}; ${c}>=(${y}); ${c}-=(${g||"1"})){
27
+ if (Date.now() - ${D} > 500) {
28
28
  throw new Error('${pe.loopRuntimeErr}')
29
29
  }
30
- ${D}++
31
- ${g}
32
- }`,k=`for (let ${c}=${P};${c}<=(${b}); ${c}+=(${y||"1"})){
33
- if (Date.now() - ${T} > 500) {
30
+ ${L}++
31
+ ${O}
32
+ }`,U=`for (let ${c}=${b};${c}<=(${y}); ${c}+=(${g||"1"})){
33
+ if (Date.now() - ${D} > 500) {
34
34
  throw new Error('${pe.loopRuntimeErr}')
35
35
  }
36
- ${D}++
37
- ${g}
38
- }`;let U="";return(h==null?void 0:h.ruleType)==="Literal"&&(d==null?void 0:d.ruleType)==="Literal"?U=Number(h.value)>Number(d.value)?R:k:U=`if ((${P})>(${b})) {
39
- ${R}
40
- } else {
36
+ ${L}++
37
+ ${O}
38
+ }`;let X="";return(d==null?void 0:d.ruleType)==="Literal"&&(v==null?void 0:v.ruleType)==="Literal"?X=Number(d.value)>Number(v.value)?k:U:X=`if ((${b})>(${y})) {
41
39
  ${k}
42
- }`,U=`${O};
43
- var ${D} = 0
44
- ${U}`,n||this._codesCol[this._blockCount].push({code:U,depends:this._getDepends(L)}),S&&(this._count=C),this._isInLoop=S,n?this._functionalProcess(U):U}_parserForInStatement(e,n=!1){const{names:r,block:a,array:c}=e,h=this._isInLoop;let d=this._count;this._isInLoop=!0;const v=`$start${this._count++}`,S=`$$count${this._count}`,C=this._parserBlockLine(a,n,!1,!0);let T="",[D,L]=r;wn.includes(D)&&(D=`$${D}`);const P=`var ${v} = Date.now()`;return r.length===1?T=`for (const ${D} of ${this._parserSingleExpression(c)}._value) {
45
- if (Date.now() - ${v} > 500) {
40
+ } else {
41
+ ${U}
42
+ }`,X=`${R};
43
+ var ${L} = 0
44
+ ${X}`,n||this._codesCol[this._blockCount].push({code:X,depends:this._getDepends(P)}),C&&(this._count=T),this._isInLoop=C,n?this._functionalProcess(X,h):X}_parserForInStatement(e,n=!1){const{names:r,block:a,array:c,type:h}=e,d=this._isInLoop;let v=this._count;this._isInLoop=!0;const S=`$start${this._count++}`,C=`$$count${this._count}`,T=this._parserBlockLine(a,n,!1,!0);let D="",[L,P]=r;wn.includes(L)&&(L=`$${L}`);const b=`var ${S} = Date.now()`;return r.length===1?D=`for (const ${L} of ${this._parserSingleExpression(c)}._value) {
45
+ if (Date.now() - ${S} > 500) {
46
46
  throw new Error('${pe.loopRuntimeErr}')
47
47
  }
48
- ${S}++
49
- ${C}
50
- }`:(wn.includes(L)&&(L=`$${L}`),T=`for (const [${D},${L}] of (${this._parserSingleExpression(c)})._value.entries()) {
51
- if (Date.now() - ${v} > 500) {
48
+ ${C}++
49
+ ${T}
50
+ }`:(wn.includes(P)&&(P=`$${P}`),D=`for (const [${L},${P}] of (${this._parserSingleExpression(c)})._value.entries()) {
51
+ if (Date.now() - ${S} > 500) {
52
52
  throw new Error('${pe.loopRuntimeErr}')
53
53
  }
54
- ${S}++
55
- ${C}
56
- }`),this._isInLoop=h,T=`${P};
57
- var ${S} = 0;
58
- ${T}`,h&&(this._count=d),n?this._functionalProcess(T):T}_parserAgainAssign(e){const{operator:n,name:r,value:a}=e,{varPos:c,declare:h}=r,d=`$againAssign${this._blockCount}`;this._dependsObj[d]=new Map;const v=this._parserName(r,!0);let S="",C=this._parserStmt(a,!0);const T=C.split(`
54
+ ${C}++
55
+ ${T}
56
+ }`),this._isInLoop=d,D=`${b};
57
+ var ${C} = 0;
58
+ ${D}`,d&&(this._count=v),n?this._functionalProcess(D,h):D}_parserAgainAssign(e){const{operator:n,name:r,value:a}=e,{varPos:c,declare:h}=r,d=`$againAssign${this._blockCount}`;this._dependsObj[d]=new Map;const v=this._parserName(r,!0);let S="",C=this._parserStmt(a,!0);const T=C.split(`
59
59
  /****/
60
60
  `);let D="";T.length>1&&(D=T[0],C=T[1]);let L=`${v} ${n===":="?`= ${C}`:`${n} ${C}`}`;const P=`${c==null?void 0:c.column}_${c==null?void 0:c.lineNumber}`;if(h){const y=this._isInFunc?`$posStr + "_${P}"`:`"${P}"`;S=`;
61
61
  ${this._prefixNameVar}.setVarValue("${v}", ${y}, ${v}, "${h}")`}n==="-="?L=`${v} = ${this._prefixNameVar}.sub(${v}, ${C})`:n==="+="?L=`${v} = ${this._prefixNameVar}.add(${v}, ${C})`:n===":="&&(D=`${D};
62
- `);const b=`${D}${L}${S}`;return this._codesCol[this._blockCount].push({code:b,depends:this._getDepends(d)}),b}_parserSwitchStatement(e,n=!1){const{condition:r,cases:a,defaultCase:c}=e;let h=`$switch${this._blockCount}`;n||(this._dependsObj[h]=new Map);const d=this._isSwitch;this._isSwitch=!0;const v=a.length?this._parserCases(a,n):"",S=c?this._parserDefaultCase(c,n):"",C=`switch (${r===!0?r:this._parserSingleExpression(r)}) {
63
- ${v}
62
+ `);const b=`${D}${L}${S}`;return this._codesCol[this._blockCount].push({code:b,depends:this._getDepends(d)}),b}_parserSwitchStatement(e,n=!1){const{condition:r,cases:a,defaultCase:c,type:h}=e;let d=`$switch${this._blockCount}`;n||(this._dependsObj[d]=new Map);const v=this._isSwitch;this._isSwitch=!0;const S=a.length?this._parserCases(a,n):"",C=c?this._parserDefaultCase(c,n):"",T=`switch (${r===!0?r:this._parserSingleExpression(r)}) {
64
63
  ${S}
65
- }`;n||this._codesCol[this._blockCount].push({code:C,depends:this._getDepends(h)});const T=n?this._functionalProcess(C):C;return this._isSwitch=d,T}_parserCases(e,n=!1){const r=[];for(const a of e)r.push(this._parserCase(a,n));return r.join(`
64
+ ${C}
65
+ }`;n||this._codesCol[this._blockCount].push({code:T,depends:this._getDepends(d)});const D=n?this._functionalProcess(T,h):T;return this._isSwitch=v,D}_parserCases(e,n=!1){const r=[];for(const a of e)r.push(this._parserCase(a,n));return r.join(`
66
66
  `)}_parserDefaultCase(e,n=!1){return`default:
67
67
  { ${this._parserBlock(e.block,n)} }
68
68
  break;`}_parserCase(e,n=!1){const{condition:r,block:a}=e;return`case ${this._parserSingleExpression(r)}:
69
69
  { ${this._parserBlock(a,n)} }
70
- break;`}_parserWhileStatement(e,n=!1){const{condition:r,block:a}=e;let c=`$while${this._blockCount}`;n||(this._dependsObj[c]=new Map);const h=this._isInLoop,d=this._count;this._isInLoop=!0;const v=`$start${this._count++}`,S=`var ${v} = Date.now()`,C=`$$count${this._count}`;let T=`while (${this._parserSingleExpression(r)}) {
71
- if (Date.now() - ${v} > 500) {
70
+ break;`}_parserWhileStatement(e,n=!1){const{condition:r,block:a,type:c}=e;let h=`$while${this._blockCount}`;n||(this._dependsObj[h]=new Map);const d=this._isInLoop,v=this._count;this._isInLoop=!0;const S=`$start${this._count++}`,C=`var ${S} = Date.now()`,T=`$$count${this._count}`;let D=`while (${this._parserSingleExpression(r)}) {
71
+ if (Date.now() - ${S} > 500) {
72
72
  throw new Error('${pe.loopRuntimeErr}')
73
73
  }
74
- ${C}++
74
+ ${T}++
75
75
  ${this._parserBlockLine(a,n,!1,!0)}
76
- }`;return T=`${S};
77
- var ${C} = 0;
78
- ${T}`,n||this._codesCol[this._blockCount].push({code:T,depends:this._getDepends(c)}),h&&(this._count=d),this._isInLoop=h,n?this._functionalProcess(T):T}_parserIfStatement(e,n=!1){const{condition:r,block:a}=e;let c="",h=`$if${this._blockCount}`;n||(this._dependsObj[h]=new Map);for(const[d,v]of a.entries()){const S=this._parserBlockLine(v,n),C=r[d]&&this._parserSingleExpression(r[d]);d===0?c=`if (${C}) {
79
- ${S}
80
- }`:C?c+=`else if (${C}) {
81
- ${S}
82
- }`:c+=`else {
83
- ${S}
84
- }`}return n||this._codesCol[this._blockCount].push({code:c,depends:this._getDepends(h)}),n?this._functionalProcess(c):c}_parserBlockLine(e,n=!1,r=!1,a=!1){const c=[],h=e.length;this._blockCount++,this._codesCol[this._blockCount]=[];let d=e.slice(-1)[0];(d==null?void 0:d.ruleType)===le.FlowStmt&&(d=e.slice(-2)[0]),a&&c.push("let $$isBreak = false;");for(const[v,S]of e.entries()){const C=n&&v===h-1;if(Array.isArray(S)){const T=[...S];C&&(d=T.pop(),(d==null?void 0:d.ruleType)===le.FlowStmt&&(d=T.pop()));for(const D of T){const L=this._parserStmt(D);L&&c.push(L),(D==null?void 0:D.ruleType)===le.SwitchStatement&&a&&c.push(`
76
+ }`;return D=`${C};
77
+ var ${T} = 0;
78
+ ${D}`,n||this._codesCol[this._blockCount].push({code:D,depends:this._getDepends(h)}),d&&(this._count=v),this._isInLoop=d,n?this._functionalProcess(D,c):D}_parserIfStatement(e,n=!1){const{condition:r,block:a,type:c}=e;let h="",d=`$if${this._blockCount}`;n||(this._dependsObj[d]=new Map);for(const[v,S]of a.entries()){const C=this._parserBlockLine(S,n),T=r[v]&&this._parserSingleExpression(r[v]);v===0?h=`if (${T}) {
79
+ ${C}
80
+ }`:T?h+=`else if (${T}) {
81
+ ${C}
82
+ }`:h+=`else {
83
+ ${C}
84
+ }`}return n||this._codesCol[this._blockCount].push({code:h,depends:this._getDepends(d)}),n?this._functionalProcess(h,c):h}_parserBlockLine(e,n=!1,r=!1,a=!1){const c=[],h=e.length;this._blockCount++,this._codesCol[this._blockCount]=[];let d=e.slice(-1)[0];(d==null?void 0:d.ruleType)===le.FlowStmt&&(d=e.slice(-2)[0]),a&&c.push("let $$isBreak = false;");for(const[v,S]of e.entries()){const C=n&&v===h-1;if(Array.isArray(S)){const T=[...S];C&&(d=T.pop(),(d==null?void 0:d.ruleType)===le.FlowStmt&&(d=T.pop()));for(const D of T){const L=this._parserStmt(D);L&&c.push(L),(D==null?void 0:D.ruleType)===le.SwitchStatement&&a&&c.push(`
85
85
  if ($$isBreak) {
86
86
  break;
87
87
  }
@@ -115,10 +115,10 @@ ${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 a=e.hasRequest?", $paramsExpr":"",c=`const ${n} = (${this._parserParameters(r)}$posStr${a}) => {
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:a}=n;let c=r;if(a){const h=this._parserSingleExpression(a);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,a;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=((a=e.pos)==null?void 0:a.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,a=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:a.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${a}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${a} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${a} = ${this._prefixNameVar}.verifyVarAndVarip("${a}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${a}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${a}", ${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 a=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=a[h])!=null&&d.reName?(v=a[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 a="",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._parserSingleExpression(n[0])} ${r} ${this._parserSingleExpression(n[1])}`;case le.LogicalAndExpression:return this._isInConditionalStmt=!0,a=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,a=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.TernaryExpression:return a=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,a;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||""}}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,a=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${a}, ${c})`:`${this._prefixNameVar}.add(${a}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:a}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=a.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:a}=n;let c=r;if(a){const h=this._parserSingleExpression(a);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,a;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=((a=e.pos)==null?void 0:a.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,a=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:a.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${a}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${a} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + "_${C}"`:`"${C}"`;v=`let ${a} = ${this._prefixNameVar}.verifyVarAndVarip("${a}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${a}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${a}", ${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 a=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=a[h])!=null&&d.reName?(v=a[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 a="",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,a=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,a=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.TernaryExpression:return a=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,a;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,a=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);if(r!=="==")return`${a} ${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(${a}, ${c}, "${h}", "${d}")`}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,a=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${a}, ${c})`:`${this._prefixNameVar}.add(${a}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:a}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=a.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
- `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,a,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}, ${a}, ${n})`}_getUserVarMemberIndexs(e,n,r,a,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,a,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),a=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(a)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){const{exprs:r,varScope:a,hasMethod:c,arg:h,varPos:d}=e,v=r.map(S=>{var L;if(typeof S=="string")return(d==null?void 0:d.reName)||S;const{column:C,line:T}=((L=S==null?void 0:S.ctx)==null?void 0:L.start)||{},D=`${T}_${C}`;return this._parserMethodElement(S,D)});if(e.expr&&v.unshift(`(${this._parserSingleExpression(e.expr)})`),e.isBuiltIn){const S=v.join(".");S==="strategy.opentrades"?v.push("opentrades"):S==="chart.left_visible_bar_time"?this._hasLeftVisibleBarTime=!0:S==="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 S={name:v[0],scope:a||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(S)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const a=r.get(n)||{},c={...e,...a};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:a,line:c}=r.start,h=`${c}_${a}`;let d=this._isInFunc?`$posStr + "__${h}"`:`"${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1;const C=n.map(T=>(T.hasMemberIndex&&(v=!0),this._parserMethodElement(T,d))).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){let r="",a="";const c={...e.args};e.expr&&(r=`(${this._parserSingleExpression(e.expr)})`),r=r?`${r}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(r=`${this._prefixNameVar}.${r}`);let h=!1;if(e.isBuiltIn){if(Mp.includes(r))r=`${r}.${r}`;else if(r==="max_bars_back"){const{name:v,varPos:S}=c.var||c.params[0];a=`var_name: "${S?`${v}_${S.lineNumber}_${S.column}`:v}"`}r.startsWith(V.INPUT)?(a=`index: ${this._inputCount}`,this._inputCount++):r.startsWith("request.")&&(h=!0),r=`${this._prefixNameFunc}.${r}`}else{const v=r.split(".");let S=v[0];wn.includes(S)&&(S=`$${S}`,r=v.join("."))}if(e.selfArg){const v=r.split("."),S=v.length;Object.assign(c,{[e.selfArg.name]:{name:v.slice(0,S-1).join(".")}}),r=v[S-1],r=this._nameMap.get(r)||r,this._setDepend({name:v[0],scope:e.varScope||0})}r=`${r}${e.index?`$${e.index}`:""}`;const d=this._parserArguments(c,a,n,h,e.hasRequest,r);if(!e.isBuiltIn){const v=r.split(".");if(v.length>1?this._setDepend({name:v[0],scope:e.varScope||0}):this._setDepend({name:r,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const S=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:S,originName:r,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return r+d}_parserArguments(e,n,r,a=!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),a&&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(a,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);a&&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,a,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(a){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 a,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:(a=v.varNames)==null?void 0:a.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){return`(function () {
121
- let $$_result=undefined;
120
+ `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,a,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}, ${a}, ${n})`}_getUserVarMemberIndexs(e,n,r,a,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,a,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),a=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(a)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:a,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:a||(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 a=r.get(n)||{},c={...e,...a};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:a,line:c}=r.start,h=`${c}_${a}`;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 a="",c="";const h={...e.args};e.expr&&(a=`(${this._parserSingleExpression(e.expr)})`),a=a?`${a}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(a=`${this._prefixNameVar}.${a}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(a))a=`${a}.${a}`;else if(a==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}a.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):a.startsWith("request.")&&(d=!0),a=`${this._prefixNameFunc}.${a}`}else{const S=a.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,a=S.join("."))}if(e.selfArg){const S=a.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),a=S[C-1],a=this._nameMap.get(a)||a,this._setDepend({name:S[0],scope:e.varScope||0})}a=`${a}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,a);if(!e.isBuiltIn){const S=a.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:a,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:a,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return a+v}_parserArguments(e,n,r,a=!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),a&&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(a,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);a&&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,a,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(a){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 a,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:(a=v.varNames)==null?void 0:a.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
+ let $$_result=${n&&typeof n=="string"&&n.endsWith("string")?'""':"undefined"};
122
122
  ${e}
123
123
  return $$_result
124
124
  })()`}}class Z_{constructor(e,n){w(this,"_nameMap");w(this,"_prefixNameVar");w(this,"_prefixNameFunc");w(this,"_prefixNameConst");w(this,"_userTypes");w(this,"_isInFunc");w(this,"_currentFuncName");w(this,"_varlist");w(this,"_memberIndexList");w(this,"_blockCount");w(this,"_libTitle");w(this,"_exportEles");w(this,"_inputCount");w(this,"_count");w(this,"_isSwitch",!1);w(this,"_isInLoop",!1);w(this,"_codesCol");w(this,"_dependsObj");w(this,"_enums");w(this,"_preRunMembers");w(this,"_isInConditionalStmt",!1);w(this,"_preRunMembersFuncs");w(this,"_preRunMemberFuncsCount",0);w(this,"__count",0);this._nameMap=new Map,this._prefixNameVar=`${e}_var`,this._prefixNameFunc=`${e}_func`,this._prefixNameConst=`${e}_const`,this._userTypes=[],this._isInFunc=!1,this._varlist=[{}],this._memberIndexList=[{}],this._blockCount=0,this._libTitle=n,this._exportEles=[],this._inputCount=0,this._count=0,this._codesCol=[[]],this._dependsObj={},this._enums=new Map,this._preRunMembers=[],this._preRunMembersFuncs=[]}parser(e){const n=[];for(const c of e){if(!c)return;if(Array.isArray(c))for(const h of c)n.push(this._parserStmt(h));else n.push(this._parserStmt(c))}const r=this._memberIndexList[this._blockCount]||{};return n.push(...Object.values(r)),`const $name = (function () {
@@ -236,7 +236,7 @@ ${this._prefixNameVar}.againAssignParse(${v}, ${L});
236
236
  ${this._parserBlock(e.block,!0,!0)}
237
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:a}=n;let c=r;if(a){const h=this._parserSingleExpression(a);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,a;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=((a=e.pos)==null?void 0:a.reName)||e.name;n[c]=e.pos}this._varlist[this._blockCount]=n}_parserDeclareAssign(e){var S;const{nameList:n,value:r}=e,a=this._parserDeclareAssignNames(n);this._addVarList(n);const c={code:"",varNames:a.replace(/[\[\]]/g,"").split(", "),depends:[]},h=`$${a}_${this._blockCount}`;this._dependsObj[h]=new Map;const d=this._parserSingleExpression(r);let v=`let ${a} = ${d}`;if(n.declare){const C=`${n.pos.column}_${n.pos.lineNumber}`,T=this._isInFunc?`$posStr + '_' + '${C}'`:`"export_${this._libTitle}_${C}"`;v=`let ${a} = ${this._prefixNameVar}.verifyVarAndVarip("${a}", ${T}, "${n.declare}") ? ${this._prefixNameVar}.getVarValue("${a}", ${T}, "${n.declare}") : ${this._prefixNameVar}.setVarValue("${a}", ${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 a=e.posList;return`[${e.names.map((c,h)=>{var d,v;return c==="_"?(this.__count++,`_$$${this.__count}`):(d=a[h])!=null&&d.reName?(v=a[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 a="",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._parserSingleExpression(n[0])} ${r} ${this._parserSingleExpression(n[1])}`;case le.LogicalAndExpression:return this._isInConditionalStmt=!0,a=`${this._parserSingleExpression(n[0])} && ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.LogicalOrExpression:return this._isInConditionalStmt=!0,a=`${this._parserSingleExpression(n[0])} || ${this._parserSingleExpression(n[1])}`,this._isInConditionalStmt=c,a;case le.TernaryExpression:return a=`${this._parserSingleExpression(n[0])} ? ${this._parserSingleExpression(n[1])} : ${this._parserSingleExpression(n[2])}`,a;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||""}}_parserAdditiveExpression(e){const{exprs:n,operator:r}=e,a=this._parserSingleExpression(n[0]),c=this._parserSingleExpression(n[1]);return r==="-"?`${this._prefixNameVar}.sub(${a}, ${c})`:`${this._prefixNameVar}.add(${a}, ${c})`}_parserMemberIndexExpression(e){var C;const{exprs:n,isInFunc:r,ctx:a}=e,c=n[0],h=this._parserSingleExpression(n[1]);let d=this._parserSingleExpression(c);const v=a.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
- `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,a,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}, ${a}, ${n})`}_getUserVarMemberIndexs(e,n,r,a,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,a,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),a=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(a)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){const{exprs:r,varScope:a,hasMethod:c,arg:h,varPos:d}=e,v=r.map(S=>{var L;if(typeof S=="string")return(d==null?void 0:d.reName)||S;const{column:C,line:T}=((L=S==null?void 0:S.ctx)==null?void 0:L.start)||{},D=this._isInFunc?`${T}_${C}`:`export_${this._libTitle}_${T}_${C}`;return this._parserMethodElement(S,D)});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 S={name:v[0],scope:a||(h==null?void 0:h.varScope)||0,isAgainAssign:n,isArg:h==null?void 0:h.isArg,functionName:this._currentFuncName};this._setDepend(S)}return v.join(".")}_setDepend(e){const n=e.name;for(const r of Object.values(this._dependsObj)){const a=r.get(n)||{},c={...e,...a};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:a,line:c}=r.start,h=`${c}_${a}`;let d=this._isInFunc?`$posStr + "_${h}"`:`"export_${this._libTitle}_${h}"`;d=this._isInLoop?`$$count${this._count} + ${d}`:d;let v=!1;const S=n.map(T=>(T.hasMemberIndex&&(v=!0),this._parserMethodElement(T,d))),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){let r="",a="";const c={...e.args};e.expr&&(r=`(${this._parserSingleExpression(e.expr)})`),r=r?`${r}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(r=`${this._prefixNameVar}.${r}`);let h=!1;if(e.isBuiltIn){if(Mp.includes(r))r=`${r}.${r}`;else if(r==="max_bars_back"){const{name:v,varPos:S}=c.var||c.params[0];a=`var_name: "${S?`${v}_${S.lineNumber}_${S.column}`:v}"`}r.startsWith(V.INPUT)?(a=`index: ${this._inputCount}`,this._inputCount++):r.startsWith("request.")&&(h=!0),r=`${this._prefixNameFunc}.${r}`}else{const v=r.split(".");let S=v[0];wn.includes(S)&&(S=`$${S}`,r=v.join("."))}if(e.selfArg){const v=r.split("."),S=v.length;Object.assign(c,{[e.selfArg.name]:{name:v.slice(0,S-1).join(".")}}),r=v[S-1],r=this._nameMap.get(r)||r,this._setDepend({name:v[0],scope:e.varScope||0})}r=`${r}${e.index?`$${e.index}`:""}`;const d=this._parserArguments(c,a,n,h,e.hasRequest,r);if(!e.isBuiltIn){const v=r.split(".");if(v.length>1?this._setDepend({name:v[0],scope:e.varScope||0}):this._setDepend({name:r,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const S=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:S,originName:r,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return r+d}_parserArguments(e,n,r,a=!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),a&&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(a,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);a&&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,a,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(a){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 a,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:(a=v.varNames)==null?void 0:a.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){return`(function () {
239
+ `),this._preRunMembers[this._blockCount]=T}return`${this._prefixNameVar}.getCacheData("m${v}_" + ${S}, ${h}, ${d})`}_getOtherVarMemberIndexs(e,n,r,a,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}, ${a}, ${n})`}_getUserVarMemberIndexs(e,n,r,a,c){return this._getOtherVarMemberIndexs(`${n}_${e.lineNumber}_${e.column}`,n,r,a,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),a=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(a)}, ${Math.round(c)}, ${n.toFixed(2)})`}return e}_parserName(e,n=!1){var S;const{exprs:r,varScope:a,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:a||(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 a=r.get(n)||{},c={...e,...a};r.set(n,c)}}_parserMethodExpression(e){const{exprs:n,ctx:r}=e,{column:a,line:c}=r.start,h=`${c}_${a}`;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 a="",c="";const h={...e.args};e.expr&&(a=`(${this._parserSingleExpression(e.expr)})`),a=a?`${a}.${e.name}`:this._nameMap.get(e.name)||e.name,e.hasVarPrefix&&(a=`${this._prefixNameVar}.${a}`);let d=!1;if(e.isBuiltIn){if(Mp.includes(a))a=`${a}.${a}`;else if(a==="max_bars_back"){const{name:S,varPos:C}=h.var||h.params[0];c=`var_name: "${C?`${S}_${C.lineNumber}_${C.column}`:S}"`}a.startsWith(V.INPUT)?(c=`index: ${this._inputCount}`,this._inputCount++):a.startsWith("request.")&&(d=!0),a=`${this._prefixNameFunc}.${a}`}else{const S=a.split(".");let C=S[0];wn.includes(C)&&(C=`$${C}`,a=S.join("."))}if(e.selfArg){const S=a.split("."),C=S.length,T=S.slice(0,C-1);r&&T.unshift(r),Object.assign(h,{[e.selfArg.name]:{name:T.join(".")}}),a=S[C-1],a=this._nameMap.get(a)||a,this._setDepend({name:S[0],scope:e.varScope||0})}a=`${a}${e.index?`$${e.index}`:""}`;const v=this._parserArguments(h,c,n,d,e.hasRequest,a);if(!e.isBuiltIn){const S=a.split(".");if(S.length>1?this._setDepend({name:S[0],scope:e.varScope||0}):this._setDepend({name:a,scope:0,hasRequest:e.hasRequest,isFunc:!0}),e.funcName){const C=this._nameMap.get(e.funcName)||e.funcName;this._setDepend({name:C,originName:a,scope:0,hasRequest:e.hasRequest,isFunc:!0})}}return a+v}_parserArguments(e,n,r,a=!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),a&&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(a,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);a&&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,a,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(a){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 a,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:(a=v.varNames)==null?void 0:a.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){return`(function () {
240
240
  let $$_result=undefined;
241
241
  ${e}
242
242
  return $$_result
@@ -284,4 +284,4 @@ Input files:
284
284
 
285
285
  `),d=new jp(r,h,n),v=await d.visit(c);let S=a.splice(0,1);S.length||(S=d.errors);let C="";const T=new J_("$");let D=e?"":T.preParser(v);const L={};if(e&&!S.some(P=>P.type===Sn.Error)){const{code:P="",hasLeftVisibleBarTime:b,hasRightVisibleBarTime:y}=T.parser(v)||{};Object.assign(L,{hasLeftVisibleBarTime:b,hasRightVisibleBarTime:y}),D=T.preParseCode;try{C=(await Ud(P,{compress:!0,mangle:!0})).code||"";const O={message:pe.indiRunErr,type:Sn.Error,startColumn:0,startLineNumber:0,endColumn:0,endLineNumber:0};if(d.hasUseDrawFunc){if(d.scriptType===Ii.library)d.exportPositions.length||(O.message=pe.libraryExportErr,S.push(O));else if(d.exportPositions.length){const R=d.exportPositions.map(k=>{const{type:U,...X}=k;return{message:_e(pe.exportUseErr,{type:U}),type:Sn.Error,...X}});S.push(...R)}}else switch(d.scriptType){case Ii.indicator:S.push(O);break;case Ii.strategy:d.hasUseCreateOrderFunc||(O.message=pe.strategyRunErr,S.push(O));break}}catch(g){S.push({message:(g==null?void 0:g.message)||"minify error",type:Sn.Error,startColumn:0,startLineNumber:0,endColumn:0,endLineNumber:0})}}return{errors:S,functions:Object.fromEntries(d.userFunctions),variables:Object.fromEntries(d.userVariables),types:Object.fromEntries(d.userTypes),methods:Object.fromEntries(d.userMethods),overloadsFuncs:d.overloadsFuncs,imports:Object.fromEntries(d.imports),enums:Object.fromEntries(d.userEnums),codeStr:C,preParserCode:D,config:L}}async function k0(t,e,n,r){const{ast:a,comments:c}=$d(t+`
286
286
 
287
- `),h=new jp(r,c,n),d=await h.visit(a),{name:v,index:S}=h.endExport,C=d.findIndex(b=>b.name===v&&b.index===S),T=d.slice(0,C+1),L=new Z_("$",e).parser(T)||"",P=await Ud(L,{compress:!0,mangle:!0});return{...h.exportLibs,description:h.description,codeStr:P.code||""}}class w0 extends c_{constructor(){super(...arguments);w(this,"errors",[])}syntaxError(n,r,a,c,h){console.log(h),this.errors.push({message:`syntax error: ${h.replace(/expecting.+/,"")}`,type:Sn.Error,startColumn:c,startLineNumber:a,endColumn:c,endLineNumber:a})}}kl({parseTcc:D0,parseLibraryCode:k0})})();
287
+ `),h=new jp(r,c,n),d=await h.visit(a),{name:v,index:S}=h.endExport,C=d.findIndex(b=>b.name===v&&b.index===S),T=d.slice(0,C+1),L=new Z_("$",e).parser(T)||"",P=await Ud(L,{compress:!0,mangle:!0});return{...h.exportLibs,description:h.description,codeStr:P.code||""}}class w0 extends c_{constructor(){super(...arguments);w(this,"errors",[])}syntaxError(n,r,a,c,h){this.errors.push({message:`syntax error: ${h.replace(/expecting.+/,"")}`,type:Sn.Error,startColumn:c,startLineNumber:a,endColumn:c,endLineNumber:a})}}kl({parseTcc:D0,parseLibraryCode:k0})})();