@poe-platform/safe-js 0.1.582 → 0.1.584

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 (58) hide show
  1. package/dist/safe-js/chunks/{chunk-2LRIFIS2.js → chunk-4DPRV34R.js} +2 -2
  2. package/dist/safe-js/chunks/{chunk-FGSHNQZD.js → chunk-63JRSQOL.js} +3 -3
  3. package/dist/safe-js/chunks/{chunk-WBFZHDKE.js → chunk-7PX7MOB4.js} +6 -6
  4. package/dist/safe-js/chunks/{chunk-GT6KJSXR.js → chunk-AMO5WXVQ.js} +4 -4
  5. package/dist/safe-js/chunks/{chunk-BZ2HQIKQ.js → chunk-AMY5ETO5.js} +4 -4
  6. package/dist/safe-js/chunks/{chunk-GMWNREUZ.js → chunk-EAHOLZQ2.js} +3 -3
  7. package/dist/safe-js/chunks/{chunk-ONUOT3QR.js → chunk-EUQCKN74.js} +3 -3
  8. package/dist/safe-js/chunks/{chunk-J56RIONZ.js → chunk-F6K7WXYP.js} +2 -2
  9. package/dist/safe-js/chunks/{chunk-H4K3LRXJ.js → chunk-J23VJ4EG.js} +2 -2
  10. package/dist/safe-js/chunks/{chunk-47LQJKGT.js → chunk-OMSG6GZF.js} +95 -39
  11. package/dist/safe-js/chunks/chunk-OMSG6GZF.js.map +7 -0
  12. package/dist/safe-js/chunks/{chunk-6H4RX6ZZ.js → chunk-PTB5KJXJ.js} +2 -2
  13. package/dist/safe-js/chunks/{chunk-FVBRBOAB.js → chunk-Q2PTRBJS.js} +2 -2
  14. package/dist/safe-js/chunks/{chunk-ADUXPMQM.js → chunk-XXUVGE2L.js} +2 -2
  15. package/dist/safe-js/chunks/{cli-runtime-GKFPKXDB.js → cli-runtime-PRCR2J63.js} +13 -13
  16. package/dist/safe-js/chunks/{dump-QOUJIAJ6.js → dump-SGDGD32M.js} +4 -4
  17. package/dist/safe-js/chunks/{fs-IAKJ3MES.js → fs-LOAD43QB.js} +4 -4
  18. package/dist/safe-js/chunks/harness-PYDC7ICR.js +10 -0
  19. package/dist/safe-js/chunks/mcp-SL5B3WKQ.js +11 -0
  20. package/dist/safe-js/chunks/migration-file-RIMCERFB.js +12 -0
  21. package/dist/safe-js/chunks/restore-CJSMB4QO.js +13 -0
  22. package/dist/safe-js/chunks/run-ZTGDITEC.js +17 -0
  23. package/dist/safe-js/chunks/runtime-modules-M5XUCL6O.js +10 -0
  24. package/dist/safe-js/cli.js +2 -2
  25. package/dist/safe-js/core.js +7 -7
  26. package/dist/safe-js/index.js +13 -13
  27. package/dist/safe-js/parse/tokenizer.d.ts +1 -0
  28. package/dist/safe-js/workerd.js +93 -37
  29. package/dist/safe-js/workerd.js.map +2 -2
  30. package/package.json +2 -2
  31. package/dist/safe-js/chunks/chunk-47LQJKGT.js.map +0 -7
  32. package/dist/safe-js/chunks/harness-6OV7HVLE.js +0 -10
  33. package/dist/safe-js/chunks/mcp-6IGCCQLK.js +0 -11
  34. package/dist/safe-js/chunks/migration-file-BOE3NXK3.js +0 -12
  35. package/dist/safe-js/chunks/restore-B6CSGGER.js +0 -13
  36. package/dist/safe-js/chunks/run-OGRMHDQG.js +0 -17
  37. package/dist/safe-js/chunks/runtime-modules-M3KCXZ62.js +0 -10
  38. /package/dist/safe-js/chunks/{chunk-2LRIFIS2.js.map → chunk-4DPRV34R.js.map} +0 -0
  39. /package/dist/safe-js/chunks/{chunk-FGSHNQZD.js.map → chunk-63JRSQOL.js.map} +0 -0
  40. /package/dist/safe-js/chunks/{chunk-WBFZHDKE.js.map → chunk-7PX7MOB4.js.map} +0 -0
  41. /package/dist/safe-js/chunks/{chunk-GT6KJSXR.js.map → chunk-AMO5WXVQ.js.map} +0 -0
  42. /package/dist/safe-js/chunks/{chunk-BZ2HQIKQ.js.map → chunk-AMY5ETO5.js.map} +0 -0
  43. /package/dist/safe-js/chunks/{chunk-GMWNREUZ.js.map → chunk-EAHOLZQ2.js.map} +0 -0
  44. /package/dist/safe-js/chunks/{chunk-ONUOT3QR.js.map → chunk-EUQCKN74.js.map} +0 -0
  45. /package/dist/safe-js/chunks/{chunk-J56RIONZ.js.map → chunk-F6K7WXYP.js.map} +0 -0
  46. /package/dist/safe-js/chunks/{chunk-H4K3LRXJ.js.map → chunk-J23VJ4EG.js.map} +0 -0
  47. /package/dist/safe-js/chunks/{chunk-6H4RX6ZZ.js.map → chunk-PTB5KJXJ.js.map} +0 -0
  48. /package/dist/safe-js/chunks/{chunk-FVBRBOAB.js.map → chunk-Q2PTRBJS.js.map} +0 -0
  49. /package/dist/safe-js/chunks/{chunk-ADUXPMQM.js.map → chunk-XXUVGE2L.js.map} +0 -0
  50. /package/dist/safe-js/chunks/{cli-runtime-GKFPKXDB.js.map → cli-runtime-PRCR2J63.js.map} +0 -0
  51. /package/dist/safe-js/chunks/{dump-QOUJIAJ6.js.map → dump-SGDGD32M.js.map} +0 -0
  52. /package/dist/safe-js/chunks/{fs-IAKJ3MES.js.map → fs-LOAD43QB.js.map} +0 -0
  53. /package/dist/safe-js/chunks/{harness-6OV7HVLE.js.map → harness-PYDC7ICR.js.map} +0 -0
  54. /package/dist/safe-js/chunks/{mcp-6IGCCQLK.js.map → mcp-SL5B3WKQ.js.map} +0 -0
  55. /package/dist/safe-js/chunks/{migration-file-BOE3NXK3.js.map → migration-file-RIMCERFB.js.map} +0 -0
  56. /package/dist/safe-js/chunks/{restore-B6CSGGER.js.map → restore-CJSMB4QO.js.map} +0 -0
  57. /package/dist/safe-js/chunks/{run-OGRMHDQG.js.map → run-ZTGDITEC.js.map} +0 -0
  58. /package/dist/safe-js/chunks/{runtime-modules-M3KCXZ62.js.map → runtime-modules-M5XUCL6O.js.map} +0 -0
@@ -4456,7 +4456,7 @@ var KEYWORDS = /* @__PURE__ */ new Set([
4456
4456
  ]);
4457
4457
  var EXPRESSION_ENDING_KEYWORDS = /* @__PURE__ */ new Set(["true", "false", "null"]);
4458
4458
  var RESERVED_IDENTIFIER_SPELLINGS = /* @__PURE__ */ new Set(["case", "default", "debugger", "enum", "export", "new", "switch", "var"]);
4459
- var CONTROL_FLOW_PAREN_KEYWORDS = /* @__PURE__ */ new Set(["if", "while", "with", "for", "catch"]);
4459
+ var CONTROL_FLOW_PAREN_KEYWORDS = /* @__PURE__ */ new Set(["if", "while", "with", "for", "catch", "switch"]);
4460
4460
  var MAX_UNICODE_CODE_POINT = 1114111;
4461
4461
  var IDENTIFIER_START_PATTERN = /^\p{ID_Start}$/u;
4462
4462
  var IDENTIFIER_PART_PATTERN = /^\p{ID_Continue}$/u;
@@ -4536,8 +4536,8 @@ var Lexer = class {
4536
4536
  line = 1;
4537
4537
  column = 1;
4538
4538
  tokens = [];
4539
- groupingStack = [];
4540
- lastClosedControlParenthesis = false;
4539
+ groupingState = { stack: [], classHeads: [], tokenCount: 0 };
4540
+ lastClosedStatementBoundary = false;
4541
4541
  legacyStringEscape = false;
4542
4542
  lineHasToken = false;
4543
4543
  tokenize() {
@@ -4709,8 +4709,8 @@ var Lexer = class {
4709
4709
  skipTemplateExpression(start) {
4710
4710
  let depth = 1;
4711
4711
  const tokens = [];
4712
- const groupingStack = [];
4713
- let lastClosedControlParenthesis = false;
4712
+ const groupingState = { stack: [], classHeads: [], tokenCount: 0 };
4713
+ let lastClosedStatementBoundary = false;
4714
4714
  while (!this.isAtEnd() && depth > 0) {
4715
4715
  this.skipTrivia();
4716
4716
  if (this.isAtEnd()) break;
@@ -4721,13 +4721,13 @@ var Lexer = class {
4721
4721
  if (char === "'" || char === '"') {
4722
4722
  this.skipQuotedString(char);
4723
4723
  tokens.push({ type: "string", value: char });
4724
- lastClosedControlParenthesis = false;
4724
+ lastClosedStatementBoundary = false;
4725
4725
  continue;
4726
4726
  }
4727
4727
  if (char === "`") {
4728
4728
  this.skipNestedTemplate();
4729
4729
  tokens.push({ type: "template", value: "`" });
4730
- lastClosedControlParenthesis = false;
4730
+ lastClosedStatementBoundary = false;
4731
4731
  continue;
4732
4732
  }
4733
4733
  if (char === "/" && this.peekChar(1) === "/") {
@@ -4766,22 +4766,23 @@ var Lexer = class {
4766
4766
  isStart = false;
4767
4767
  }
4768
4768
  tokens.push({ type: KEYWORDS.has(value) ? "keyword" : "identifier", value });
4769
- lastClosedControlParenthesis = false;
4769
+ lastClosedStatementBoundary = false;
4770
4770
  continue;
4771
4771
  }
4772
4772
  if (isDecimalDigit(char) || char === "." && isDecimalDigit(this.peekChar(1))) {
4773
4773
  const start2 = this.position();
4774
4774
  const value = this.scanNumber(start2);
4775
4775
  tokens.push({ type: "numeric", value });
4776
- lastClosedControlParenthesis = false;
4776
+ lastClosedStatementBoundary = false;
4777
4777
  continue;
4778
4778
  }
4779
4779
  if (char === "{") {
4780
4780
  depth += 1;
4781
4781
  this.advance();
4782
- groupingStack.push({ value: "{" });
4782
+ const previousToken = tokens[tokens.length - 1];
4783
4783
  tokens.push({ type: "punctuator", value: "{" });
4784
- lastClosedControlParenthesis = false;
4784
+ updateGroupingState(groupingState, previousToken, "{", lastClosedStatementBoundary, false, tokens);
4785
+ lastClosedStatementBoundary = false;
4785
4786
  continue;
4786
4787
  }
4787
4788
  if (char === "}") {
@@ -4790,19 +4791,19 @@ var Lexer = class {
4790
4791
  if (depth === 0) {
4791
4792
  return;
4792
4793
  }
4793
- popGroupingContext(groupingStack, "{");
4794
+ const previousToken = tokens[tokens.length - 1];
4794
4795
  tokens.push({ type: "punctuator", value: "}" });
4795
- lastClosedControlParenthesis = false;
4796
+ lastClosedStatementBoundary = updateGroupingState(groupingState, previousToken, "}", lastClosedStatementBoundary, false, tokens);
4796
4797
  continue;
4797
4798
  }
4798
- if (char === "/" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedControlParenthesis, tokens)) {
4799
+ if (char === "/" && shouldRejectRegexLiteral(tokens[tokens.length - 1], lastClosedStatementBoundary, tokens)) {
4799
4800
  if (!this.options.allowRegexLiterals) {
4800
4801
  this.syntaxError("Regular expression literals are not supported", this.position());
4801
4802
  }
4802
4803
  const start2 = this.position();
4803
4804
  const value = this.scanRegexLiteral(start2);
4804
4805
  tokens.push({ type: "regex", value });
4805
- lastClosedControlParenthesis = false;
4806
+ lastClosedStatementBoundary = false;
4806
4807
  continue;
4807
4808
  }
4808
4809
  const punctuator = matchPunctuator(this.source, this.index);
@@ -4810,10 +4811,13 @@ var Lexer = class {
4810
4811
  const previousToken = tokens[tokens.length - 1];
4811
4812
  this.advanceBy(punctuator.length);
4812
4813
  tokens.push({ type: "punctuator", value: punctuator });
4813
- lastClosedControlParenthesis = updateGroupingState(
4814
- groupingStack,
4814
+ lastClosedStatementBoundary = updateGroupingState(
4815
+ groupingState,
4815
4816
  previousToken,
4816
- punctuator
4817
+ punctuator,
4818
+ lastClosedStatementBoundary,
4819
+ false,
4820
+ tokens
4817
4821
  );
4818
4822
  continue;
4819
4823
  }
@@ -5084,7 +5088,7 @@ var Lexer = class {
5084
5088
  }
5085
5089
  }
5086
5090
  readSlashOrPunctuator(start) {
5087
- if (this.currentChar() === "/" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedControlParenthesis, this.tokens)) {
5091
+ if (this.currentChar() === "/" && shouldRejectRegexLiteral(this.lastSignificantToken(), this.lastClosedStatementBoundary, this.tokens)) {
5088
5092
  if (!this.options.allowRegexLiterals) {
5089
5093
  this.syntaxError("Regular expression literals are not supported", start);
5090
5094
  }
@@ -5171,14 +5175,17 @@ var Lexer = class {
5171
5175
  };
5172
5176
  this.tokens.push(token);
5173
5177
  if (type === "punctuator") {
5174
- this.lastClosedControlParenthesis = updateGroupingState(
5175
- this.groupingStack,
5178
+ this.lastClosedStatementBoundary = updateGroupingState(
5179
+ this.groupingState,
5176
5180
  previousToken,
5177
- value
5181
+ value,
5182
+ this.lastClosedStatementBoundary,
5183
+ this.options.statementList === true,
5184
+ this.tokens
5178
5185
  );
5179
5186
  return;
5180
5187
  }
5181
- this.lastClosedControlParenthesis = false;
5188
+ this.lastClosedStatementBoundary = false;
5182
5189
  }
5183
5190
  currentChar() {
5184
5191
  return this.source[this.index] ?? "";
@@ -5380,7 +5387,7 @@ function matchPunctuator(source, index) {
5380
5387
  (punctuator) => source.startsWith(punctuator, index) && (punctuator !== "?." || !isDecimalDigit(source[index + 2] ?? ""))
5381
5388
  );
5382
5389
  }
5383
- function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis, tokens) {
5390
+ function shouldRejectRegexLiteral(previousToken, lastClosedStatementBoundary, tokens) {
5384
5391
  if (previousToken === void 0) {
5385
5392
  return true;
5386
5393
  }
@@ -5391,8 +5398,8 @@ function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis, t
5391
5398
  if (previousToken.value === "of") return endsWithForOfSeparator(tokens);
5392
5399
  return !EXPRESSION_ENDING_KEYWORDS.has(previousToken.value);
5393
5400
  }
5394
- if (previousToken.value === ")") {
5395
- return lastClosedControlParenthesis;
5401
+ if (previousToken.value === ")" || previousToken.value === "}") {
5402
+ return lastClosedStatementBoundary;
5396
5403
  }
5397
5404
  return !isExpressionEndingPunctuator(previousToken.value);
5398
5405
  }
@@ -5425,11 +5432,39 @@ function endsWithForOfSeparator(tokens) {
5425
5432
  }
5426
5433
  return false;
5427
5434
  }
5428
- function updateGroupingState(groupingStack, previousToken, punctuator) {
5435
+ function updateGroupingState(state, previousToken, punctuator, previousStatementBoundary, initialStatementList, tokens) {
5436
+ const groupingStack = state.stack;
5437
+ const functionBody = state.functionBody;
5438
+ state.functionBody = false;
5439
+ for (let index = state.tokenCount; index < tokens.length; index++) {
5440
+ const token = tokens[index];
5441
+ if (token.type !== "keyword" || token.value !== "class") continue;
5442
+ const before = tokens[index - 1];
5443
+ if (before?.value === "." || before?.value === "?.") continue;
5444
+ const next = tokens[index + 1]?.value;
5445
+ const afterName = tokens[index + 2]?.value;
5446
+ if (next !== "{" && next !== "extends" && afterName !== "{" && afterName !== "extends") continue;
5447
+ const parent = groupingStack[groupingStack.length - 1];
5448
+ if (parent?.classBody && (before === void 0 || ["{", "}", ";", "static"].includes(before.value) || ["identifier", "numeric", "string", "template", "regex"].includes(before.type))) continue;
5449
+ state.classHeads.push({
5450
+ depth: groupingStack.length,
5451
+ declaration: isDeclarationPosition(tokens, index, groupingStack, initialStatementList)
5452
+ });
5453
+ }
5454
+ state.tokenCount = tokens.length;
5455
+ const beforePreviousToken = tokens[tokens.length - 3];
5429
5456
  if (punctuator === "(") {
5457
+ let functionIndex = tokens.length - 2;
5458
+ if (tokens[functionIndex]?.value !== "function") {
5459
+ if (tokens[functionIndex]?.value !== "*") functionIndex--;
5460
+ if (tokens[functionIndex]?.value === "*") functionIndex--;
5461
+ }
5462
+ const functionParameters = tokens[functionIndex]?.type === "keyword" && tokens[functionIndex].value === "function";
5463
+ const functionDeclaration = functionParameters && isDeclarationPosition(tokens, functionIndex, groupingStack, initialStatementList);
5430
5464
  groupingStack.push({
5431
5465
  value: "(",
5432
- isControlCondition: previousToken?.type === "keyword" && CONTROL_FLOW_PAREN_KEYWORDS.has(previousToken.value)
5466
+ functionParameters,
5467
+ isControlCondition: functionDeclaration || (previousToken?.type === "keyword" || previousToken?.type === "identifier") && (CONTROL_FLOW_PAREN_KEYWORDS.has(previousToken.value) || previousToken.value === "await" && beforePreviousToken?.type === "keyword" && beforePreviousToken.value === "for") && beforePreviousToken?.value !== "." && beforePreviousToken?.value !== "?."
5433
5468
  });
5434
5469
  return false;
5435
5470
  }
@@ -5438,22 +5473,42 @@ function updateGroupingState(groupingStack, previousToken, punctuator) {
5438
5473
  return false;
5439
5474
  }
5440
5475
  if (punctuator === "{") {
5441
- groupingStack.push({ value: "{" });
5476
+ const classHead = state.classHeads[state.classHeads.length - 1];
5477
+ if (!functionBody && previousToken?.value !== "=>" && classHead?.depth === groupingStack.length) {
5478
+ state.classHeads.pop();
5479
+ groupingStack.push({ value: "{", classBody: true, closesStatement: classHead.declaration });
5480
+ return false;
5481
+ }
5482
+ const parent = groupingStack[groupingStack.length - 1];
5483
+ const closesStatement = previousToken === void 0 ? initialStatementList : previousStatementBoundary || ["{", ";"].includes(previousToken.value) && (parent === void 0 || parent.statementList === true) || previousToken.type === "keyword" && ["else", "do", "try", "finally"].includes(previousToken.value);
5484
+ groupingStack.push({
5485
+ value: "{",
5486
+ closesStatement,
5487
+ statementList: closesStatement || previousToken?.value === ")" || previousToken?.value === "=>" || previousToken?.value === "static"
5488
+ });
5442
5489
  return false;
5443
5490
  }
5444
5491
  if (punctuator === ")") {
5445
- return popGroupingContext(groupingStack, "(")?.isControlCondition === true;
5492
+ const group = popGroupingContext(groupingStack, "(");
5493
+ state.functionBody = group?.functionParameters === true;
5494
+ return group?.isControlCondition === true;
5446
5495
  }
5447
5496
  if (punctuator === "]") {
5448
5497
  popGroupingContext(groupingStack, "[");
5449
5498
  return false;
5450
5499
  }
5451
5500
  if (punctuator === "}") {
5452
- popGroupingContext(groupingStack, "{");
5453
- return false;
5501
+ return popGroupingContext(groupingStack, "{")?.closesStatement === true;
5454
5502
  }
5455
5503
  return false;
5456
5504
  }
5505
+ function isDeclarationPosition(tokens, index, groupingStack, initialStatementList) {
5506
+ const parent = groupingStack[groupingStack.length - 1];
5507
+ if (parent === void 0 ? !initialStatementList : parent.statementList !== true) return false;
5508
+ if (tokens[index - 1]?.value === "async") index--;
5509
+ const previous = tokens[index - 1];
5510
+ return previous === void 0 || ["{", "}", ";", ")", "]", "export", "default"].includes(previous.value) || ["identifier", "numeric", "string", "template", "regex"].includes(previous.type) || previous.type === "keyword" && EXPRESSION_ENDING_KEYWORDS.has(previous.value);
5511
+ }
5457
5512
  function popGroupingContext(groupingStack, expected) {
5458
5513
  const top = groupingStack[groupingStack.length - 1];
5459
5514
  if (top?.value !== expected) {
@@ -6621,7 +6676,7 @@ function parseModule(source, filename = "<input>", owner) {
6621
6676
  try {
6622
6677
  const result = assignIds(
6623
6678
  new Parser(
6624
- tokenize(source, { allowRegexLiterals: true, compilation }),
6679
+ tokenize(source, { allowRegexLiterals: true, statementList: true, compilation }),
6625
6680
  source,
6626
6681
  compilation
6627
6682
  ).parseModule()
@@ -6645,7 +6700,7 @@ function parseExecutableModule(source, filename = "<input>", owner) {
6645
6700
  try {
6646
6701
  const result = assignIds(
6647
6702
  new Parser(
6648
- tokenize(source, { allowRegexLiterals: true, compilation }),
6703
+ tokenize(source, { allowRegexLiterals: true, statementList: true, compilation }),
6649
6704
  source,
6650
6705
  compilation,
6651
6706
  "top-level",
@@ -6677,6 +6732,7 @@ function parseEvalScript(source, context = {}, owner) {
6677
6732
  const grammar = { await: false, yield: false, strict: context.strict === true };
6678
6733
  const parser = new Parser(tokenize(source, {
6679
6734
  allowRegexLiterals: true,
6735
+ statementList: true,
6680
6736
  allowLegacyNumbers: true,
6681
6737
  allowLegacyEscapes: true,
6682
6738
  allowHtmlComments: true,
@@ -6720,8 +6776,8 @@ ${body}
6720
6776
  }`;
6721
6777
  const source = `${prefix} anonymous(${parameters}
6722
6778
  ) ${bodySource}`;
6723
- const createParser = (text) => new Parser(
6724
- tokenize(text, { allowRegexLiterals: true, allowLegacyNumbers: true, allowLegacyEscapes: true, allowHtmlComments: true, compilation }),
6779
+ const createParser = (text, statementList = false) => new Parser(
6780
+ tokenize(text, { allowRegexLiterals: true, statementList, allowLegacyNumbers: true, allowLegacyEscapes: true, allowHtmlComments: true, compilation }),
6725
6781
  text,
6726
6782
  compilation,
6727
6783
  kind,
@@ -6733,7 +6789,7 @@ ${body}
6733
6789
  false
6734
6790
  );
6735
6791
  createParser(parameterSource).parseDynamicParameters();
6736
- createParser(bodySource).parseDynamicBody();
6792
+ createParser(bodySource, true).parseDynamicBody();
6737
6793
  const node = assignIds(createParser(source).parseDynamicExpression());
6738
6794
  if (source.includes("#")) validatePrivateNames(node);
6739
6795
  return node;