overpy 9.6.4 → 9.6.5

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.
Files changed (2) hide show
  1. package/overpy.js +46 -15
  2. package/package.json +1 -1
package/overpy.js CHANGED
@@ -38605,19 +38605,19 @@ ${scriptText}`, {
38605
38605
  return;
38606
38606
  }
38607
38607
  if (content2.startsWith("#!optimizeForSize")) {
38608
- addToken("__enableOptimizeForSize__");
38608
+ currentLine.tokens.push(new Token("__enableOptimizeForSize__", getFileStackCopy()));
38609
38609
  return;
38610
38610
  }
38611
38611
  if (content2.startsWith("#!disableOptimizeForSize")) {
38612
- addToken("__disableOptimizeForSize__");
38612
+ currentLine.tokens.push(new Token("__disableOptimizeForSize__", getFileStackCopy()));
38613
38613
  return;
38614
38614
  }
38615
38615
  if (content2.startsWith("#!optimizeStrict")) {
38616
- addToken("__enableOptimizeStrict__");
38616
+ currentLine.tokens.push(new Token("__enableOptimizeStrict__", getFileStackCopy()));
38617
38617
  return;
38618
38618
  }
38619
38619
  if (content2.startsWith("#!disableOptimizeStrict")) {
38620
- addToken("__disableOptimizeStrict__");
38620
+ currentLine.tokens.push(new Token("__disableOptimizeStrict__", getFileStackCopy()));
38621
38621
  return;
38622
38622
  }
38623
38623
  if (content2.startsWith("#!setupTx") || content2.startsWith("#!setupTags")) {
@@ -38682,10 +38682,10 @@ ${scriptText}`, {
38682
38682
  }
38683
38683
  if (content2.startsWith("#!rulePrefix ")) {
38684
38684
  let prefix = content2.substring("#!rulePrefix ".length).trim();
38685
- addToken("__rulePrefix__");
38686
- addToken("(");
38687
- addToken(prefix);
38688
- addToken(")");
38685
+ currentLine.tokens.push(new Token("__rulePrefix__", getFileStackCopy()));
38686
+ currentLine.tokens.push(new Token("(", getFileStackCopy()));
38687
+ currentLine.tokens.push(new Token(prefix, getFileStackCopy()));
38688
+ currentLine.tokens.push(new Token(")", getFileStackCopy()));
38689
38689
  return;
38690
38690
  }
38691
38691
  if (content2.startsWith("#!rulePrefixTemplate")) {
@@ -39686,6 +39686,10 @@ var Ast2 = class _Ast {
39686
39686
  //Used for translated strings, if set to true then player var won't be used
39687
39687
  forceNotResolvingTranslation;
39688
39688
  //Used for translated strings, if true then the resulting string array won't be indexed and will need to be indexed later on with the _() function
39689
+ isGotoInSameScope;
39690
+ //Used for gotos, if true then the goto doesn't jump to another scope and can be optimized more easily. For now, only set on automatically generated gotos
39691
+ isSwitchIf;
39692
+ //true if it is the "if true" from a switch
39689
39693
  argIndex = 0;
39690
39694
  childIndex = 0;
39691
39695
  wasParsed = false;
@@ -39761,6 +39765,8 @@ var Ast2 = class _Ast {
39761
39765
  clone.numValue = this.numValue;
39762
39766
  clone.stringTokens = structuredClone(this.stringTokens);
39763
39767
  clone.isSpectatorTranslation = this.isSpectatorTranslation;
39768
+ clone.isGotoInSameScope = this.isGotoInSameScope;
39769
+ clone.isSwitchIf = this.isSwitchIf;
39764
39770
  return clone;
39765
39771
  }
39766
39772
  };
@@ -39880,6 +39886,15 @@ function astContainsFunctions(ast, functionNames, errorOnTrue = false) {
39880
39886
  }
39881
39887
  return false;
39882
39888
  }
39889
+ function astIsInLambdaFunction(ast) {
39890
+ if (!ast.parent) {
39891
+ return false;
39892
+ }
39893
+ if (["__filteredArray__", "__mappedArray__"].includes(ast.parent.name) && ast.parent.argIndex === 1) {
39894
+ return true;
39895
+ }
39896
+ return astIsInLambdaFunction(ast.parent);
39897
+ }
39883
39898
  function astIsLiteral(ast) {
39884
39899
  if (typeof ast.type === "string" && !["Hero", "Map", "Gamemode", "Team", "Button", "Color"].includes(ast.type)) {
39885
39900
  if (["IntLiteral", "UnsignedIntLiteral", "SignedIntLiteral", "FloatLiteral", "UnsignedFloatLiteral", "SignedFloatLiteral", "GlobalVariable", "PlayerVariable", "Subroutine", "HeroLiteral", "MapLiteral", "GamemodeLiteral", "TeamLiteral", "ButtonLiteral", "StringLiteral", "LocalizedStringLiteral", "CustomStringLiteral"].concat(Object.keys(constantValues)).includes(ast.type)) {
@@ -44948,6 +44963,9 @@ astParsingFunctions.__equals__ = function(content) {
44948
44963
 
44949
44964
  // src/compiler/functions/__filteredArray__.ts
44950
44965
  astParsingFunctions.__filteredArray__ = function(content) {
44966
+ if (astIsInLambdaFunction(content)) {
44967
+ error("Cannot nest .filter() or .map()");
44968
+ }
44951
44969
  if (enableOptimization) {
44952
44970
  if (!optimizeForSize2) {
44953
44971
  if (!astContainsFunctions(content.args[1], ["__currentArrayElement__", "__currentArrayIndex__"])) {
@@ -45199,7 +45217,9 @@ astParsingFunctions.__if__ = function(content) {
45199
45217
  } else {
45200
45218
  content.args[0] = astParsingFunctions.__not__(new Ast2("__not__", [content.args[0]]));
45201
45219
  }
45202
- return new Ast2("__skipIf__", [content.args[0], new Ast2("__distanceTo__", [new Ast2(label, [], [], "Label")])]);
45220
+ let skip = new Ast2("__skipIf__", [content.args[0], new Ast2("__distanceTo__", [new Ast2(label, [], [], "Label")])]);
45221
+ skip.isGotoInSameScope = true;
45222
+ return skip;
45203
45223
  }
45204
45224
  if (includeEnd) {
45205
45225
  content.parent.children.splice(content.parent.childIndex + 1, 0, getAstForEnd());
@@ -45311,6 +45331,9 @@ astParsingFunctions.__map__ = function(content) {
45311
45331
 
45312
45332
  // src/compiler/functions/__mappedArray__.ts
45313
45333
  astParsingFunctions.__mappedArray__ = function(content) {
45334
+ if (astIsInLambdaFunction(content)) {
45335
+ error("Cannot nest .filter() or .map()");
45336
+ }
45314
45337
  if (enableOptimization) {
45315
45338
  if (content.args[1].name === "__currentArrayElement__") {
45316
45339
  return content.args[0];
@@ -45536,10 +45559,10 @@ astParsingFunctions.__rule__ = function(content) {
45536
45559
  function iterateOnRuleActions(children) {
45537
45560
  for (let i2 = 0; i2 < children.length; i2++) {
45538
45561
  setFileStack(content.fileStack);
45539
- if (children[i2].name === "__skip__" && children[i2].args[0].name !== "__distanceTo__" || children[i2].name === "__skipIf__" && children[i2].args[1].name !== "__distanceTo__") {
45562
+ if ((children[i2].name === "__skip__" && children[i2].args[0].name !== "__distanceTo__" || children[i2].name === "__skipIf__" && children[i2].args[1].name !== "__distanceTo__") && !children[i2].isGotoInSameScope) {
45540
45563
  isRelativeGotoEncountered = true;
45541
45564
  }
45542
- if (children[i2].name === "__skip__" || children[i2].name === "__skipIf__") {
45565
+ if ((children[i2].name === "__skip__" || children[i2].name === "__skipIf__") && !children[i2].isGotoInSameScope) {
45543
45566
  isGotoEncountered = true;
45544
45567
  }
45545
45568
  if (content.type === "Label") {
@@ -45549,7 +45572,7 @@ astParsingFunctions.__rule__ = function(content) {
45549
45572
  declaredLabels.push(content.name);
45550
45573
  }
45551
45574
  iterateOnRuleActions(children[i2].children);
45552
- if (!isRelativeGotoEncountered) {
45575
+ if (!isRelativeGotoEncountered && !children[i2].isSwitchIf) {
45553
45576
  if (children[i2].name === "pass") {
45554
45577
  children.splice(i2, 1);
45555
45578
  i2--;
@@ -45819,7 +45842,10 @@ astParsingFunctions.__switch__ = function(content) {
45819
45842
  error("Parent is undefined in __switch__");
45820
45843
  }
45821
45844
  content.parent.children.splice(content.parent.childIndex + 1, 0, ...casesChildren);
45822
- var result = new Ast2("__if__", [getAstForTrue()], [new Ast2("__skip__", [new Ast2("__valueInArray__", [new Ast2("__array__", caseOffsets), new Ast2("__add__", [getAstFor1(), new Ast2(".index", [new Ast2("__array__", switchCaseArgs), content.args[0]])])])])]);
45845
+ let skip = new Ast2("__skip__", [new Ast2("__valueInArray__", [new Ast2("__array__", caseOffsets), new Ast2("__add__", [getAstFor1(), new Ast2(".index", [new Ast2("__array__", switchCaseArgs), content.args[0]])])])]);
45846
+ skip.isGotoInSameScope = true;
45847
+ var result = new Ast2("__if__", [getAstForTrue()], [skip]);
45848
+ result.isSwitchIf = true;
45823
45849
  result.doNotReparse = true;
45824
45850
  return result;
45825
45851
  };
@@ -65001,7 +65027,7 @@ function astToWs(content) {
65001
65027
  }
65002
65028
  str = str.replaceAll("\uEC51", separator);
65003
65029
  return astToWs(new Ast2(".split", [getAstForCustomString(str), separatorAst]));
65004
- } else if (content.args.length >= 3 && content.args.every((x) => areAstsAlwaysEqual(x, content.args[0]))) {
65030
+ } else if (!astIsInLambdaFunction(content) && content.args.length >= 3 && content.args.every((x) => areAstsAlwaysEqual(x, content.args[0]))) {
65005
65031
  let estimatedElementCount = 1 + (content.args[0].name === "__customString__" ? 4 : content.args[0].args.length);
65006
65032
  if (estimatedElementCount === 1 && content.args.length >= 11 || estimatedElementCount === 2 && content.args.length >= 5 || estimatedElementCount === 3 && content.args.length >= 4 || estimatedElementCount >= 4) {
65007
65033
  return astToWs(new Ast2("__mappedArray__", [
@@ -65068,13 +65094,17 @@ function astToWs(content) {
65068
65094
  content.name = newName;
65069
65095
  } else if (content.name === "__globalVar__") {
65070
65096
  incrementNbElements();
65097
+ content.argIndex = 0;
65071
65098
  return tows("__global__", valueKw) + "." + astToWs(content.args[0]);
65072
65099
  } else if (content.name === "__number__") {
65073
65100
  incrementNbElements(2);
65074
65101
  return trimNb(content.args[0].name);
65075
65102
  } else if (content.name === "__playerVar__") {
65076
65103
  incrementNbElements();
65077
- return "(" + astToWs(content.args[0]) + ")." + astToWs(content.args[1]);
65104
+ content.argIndex = 0;
65105
+ let result2 = "(" + astToWs(content.args[0]) + ").";
65106
+ content.argIndex = 1;
65107
+ return result2 + astToWs(content.args[1]);
65078
65108
  } else if (content.name === "ceil") {
65079
65109
  content.name = "__round__";
65080
65110
  content.args = [content.args[0], new Ast2("__roundUp__", [], [], "__Rounding__")];
@@ -65204,6 +65234,7 @@ function astToWs(content) {
65204
65234
  if (content.args[i].type === "void") {
65205
65235
  error("Expected a value, but got " + functionNameToString(content.args[i]) + " which is an action", content.args[i].fileStack);
65206
65236
  }
65237
+ content.argIndex = i;
65207
65238
  result += astToWs(content.args[i]);
65208
65239
  if (content.type === "void") {
65209
65240
  incrementNbElements(Math.floor(nbHeroesInValue / 2));
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "https://github.com/Zezombye/overpy"
8
8
  },
9
9
  "description": "High-level language for the Overwatch Workshop, with decompilation and compilation.",
10
- "version": "9.6.4",
10
+ "version": "9.6.5",
11
11
  "readme": "README.md",
12
12
  "keywords": [
13
13
  "overpy",