@poe-platform/safe-js 0.1.743 → 0.1.745

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 (101) hide show
  1. package/README.md +4 -3
  2. package/dist/safe-js/chunks/{chunk-F6CV74HU.js → chunk-3NFTBEZR.js} +2 -3
  3. package/dist/safe-js/chunks/{chunk-LMS5SSTN.js → chunk-5WP5IRMP.js} +437 -388
  4. package/dist/safe-js/chunks/{chunk-47JWFV2B.js → chunk-6UP3B5TB.js} +7 -8
  5. package/dist/safe-js/chunks/{chunk-24Z6PSCN.js → chunk-6ZVFR4HR.js} +1 -2
  6. package/dist/safe-js/chunks/{chunk-J3CUCOMP.js → chunk-AB6ERQE5.js} +14798 -14210
  7. package/dist/safe-js/chunks/{chunk-4YIDX44G.js → chunk-CQ52GEHY.js} +0 -1
  8. package/dist/safe-js/chunks/chunk-DHGJSEFX.js +0 -0
  9. package/dist/safe-js/chunks/{chunk-GVKXZW53.js → chunk-DIG26TEI.js} +0 -1
  10. package/dist/safe-js/chunks/{chunk-JCVARKWT.js → chunk-DIMBVKHT.js} +6 -7
  11. package/dist/safe-js/chunks/{chunk-UQPYTZOZ.js → chunk-JCHJGIQA.js} +0 -1
  12. package/dist/safe-js/chunks/{chunk-IRYOK5BR.js → chunk-L265M6OS.js} +2 -3
  13. package/dist/safe-js/chunks/{chunk-3ITVV2R6.js → chunk-L3MIVH3T.js} +1 -2
  14. package/dist/safe-js/chunks/{chunk-AUVGHYM5.js → chunk-LRINZRJA.js} +2 -3
  15. package/dist/safe-js/chunks/{chunk-UIUJHTWG.js → chunk-MKY3MQUB.js} +3 -4
  16. package/dist/safe-js/chunks/{chunk-YDVEVDVT.js → chunk-MLJ4BKDX.js} +102 -20
  17. package/dist/safe-js/chunks/{chunk-YUQFFRUF.js → chunk-MMN3IESA.js} +1 -2
  18. package/dist/safe-js/chunks/{chunk-WEGFNME4.js → chunk-O3S3JVWS.js} +1 -2
  19. package/dist/safe-js/chunks/{chunk-2GVBG23M.js → chunk-ONWFPHUI.js} +0 -1
  20. package/dist/safe-js/chunks/chunk-OQYVEDRN.js +66 -0
  21. package/dist/safe-js/chunks/{chunk-EMH7CXQM.js → chunk-POEMWNHD.js} +1 -2
  22. package/dist/safe-js/chunks/{chunk-G6WTEIJJ.js → chunk-X3YCE3ZH.js} +1 -2
  23. package/dist/safe-js/chunks/{chunk-WWETRQCF.js → chunk-YYF5R6ML.js} +3 -4
  24. package/dist/safe-js/chunks/{cli-runtime-3SOHLG5M.js → cli-runtime-BGB24HNE.js} +19 -20
  25. package/dist/safe-js/chunks/{dump-CSLHITIE.js → dump-M7CMVXW7.js} +5 -6
  26. package/dist/safe-js/chunks/harness-4CPQ7WKS.js +10 -0
  27. package/dist/safe-js/chunks/mcp-7SNWIP5H.js +11 -0
  28. package/dist/safe-js/chunks/migration-file-CPBVNMLD.js +14 -0
  29. package/dist/safe-js/chunks/restore-FLH6OC5F.js +13 -0
  30. package/dist/safe-js/chunks/run-KFAD7GTT.js +19 -0
  31. package/dist/safe-js/chunks/runtime-modules-D6NO4KJW.js +10 -0
  32. package/dist/safe-js/chunks/source-files-BSDM22Y2.js +9 -0
  33. package/dist/safe-js/cli.js +5 -6
  34. package/dist/safe-js/core.d.ts +1 -1
  35. package/dist/safe-js/core.js +14 -15
  36. package/dist/safe-js/extensions.d.ts +17 -0
  37. package/dist/safe-js/index.d.ts +2 -2
  38. package/dist/safe-js/index.js +22 -23
  39. package/dist/safe-js/interp/arguments.d.ts +2 -0
  40. package/dist/safe-js/interp/collection-properties.d.ts +2 -0
  41. package/dist/safe-js/interp/data-copy.d.ts +2 -0
  42. package/dist/safe-js/interp/host-bridge.d.ts +5 -0
  43. package/dist/safe-js/interp/host-capabilities.d.ts +5 -0
  44. package/dist/safe-js/interp/internal-symbols.d.ts +1 -0
  45. package/dist/safe-js/interp/interpreter.d.ts +3 -1
  46. package/dist/safe-js/interp/regex/compile-guard.d.ts +6 -4
  47. package/dist/safe-js/interp/template-cache.d.ts +5 -0
  48. package/dist/safe-js/interp/values.d.ts +11 -0
  49. package/dist/safe-js/modules/fs.d.ts +4 -3
  50. package/dist/safe-js/modules/fs.js +8 -9
  51. package/dist/safe-js/platform/context.d.ts +14 -0
  52. package/dist/safe-js/platform/node.d.ts +16 -0
  53. package/dist/safe-js/platform/types.d.ts +18 -0
  54. package/dist/safe-js/platform/workerd.d.ts +21 -0
  55. package/dist/safe-js/restore.d.ts +1 -1
  56. package/dist/safe-js/snapshot/validation.d.ts +2 -1
  57. package/package.json +5 -5
  58. package/dist/safe-js/chunks/chunk-24Z6PSCN.js.map +0 -7
  59. package/dist/safe-js/chunks/chunk-2GVBG23M.js.map +0 -7
  60. package/dist/safe-js/chunks/chunk-3ITVV2R6.js.map +0 -7
  61. package/dist/safe-js/chunks/chunk-47JWFV2B.js.map +0 -7
  62. package/dist/safe-js/chunks/chunk-4YIDX44G.js.map +0 -7
  63. package/dist/safe-js/chunks/chunk-AUVGHYM5.js.map +0 -7
  64. package/dist/safe-js/chunks/chunk-EMH7CXQM.js.map +0 -7
  65. package/dist/safe-js/chunks/chunk-F6CV74HU.js.map +0 -7
  66. package/dist/safe-js/chunks/chunk-G6WTEIJJ.js.map +0 -7
  67. package/dist/safe-js/chunks/chunk-GVKXZW53.js.map +0 -7
  68. package/dist/safe-js/chunks/chunk-IRYOK5BR.js.map +0 -7
  69. package/dist/safe-js/chunks/chunk-J3CUCOMP.js.map +0 -7
  70. package/dist/safe-js/chunks/chunk-JCVARKWT.js.map +0 -7
  71. package/dist/safe-js/chunks/chunk-LMS5SSTN.js.map +0 -7
  72. package/dist/safe-js/chunks/chunk-U7ZNMTSQ.js +0 -1
  73. package/dist/safe-js/chunks/chunk-U7ZNMTSQ.js.map +0 -7
  74. package/dist/safe-js/chunks/chunk-UIUJHTWG.js.map +0 -7
  75. package/dist/safe-js/chunks/chunk-UQPYTZOZ.js.map +0 -7
  76. package/dist/safe-js/chunks/chunk-V72WS373.js +0 -128
  77. package/dist/safe-js/chunks/chunk-V72WS373.js.map +0 -7
  78. package/dist/safe-js/chunks/chunk-WEGFNME4.js.map +0 -7
  79. package/dist/safe-js/chunks/chunk-WWETRQCF.js.map +0 -7
  80. package/dist/safe-js/chunks/chunk-YDVEVDVT.js.map +0 -7
  81. package/dist/safe-js/chunks/chunk-YUQFFRUF.js.map +0 -7
  82. package/dist/safe-js/chunks/cli-runtime-3SOHLG5M.js.map +0 -7
  83. package/dist/safe-js/chunks/dump-CSLHITIE.js.map +0 -7
  84. package/dist/safe-js/chunks/harness-QKPVLVOT.js +0 -11
  85. package/dist/safe-js/chunks/harness-QKPVLVOT.js.map +0 -7
  86. package/dist/safe-js/chunks/mcp-A4YKQCIS.js +0 -12
  87. package/dist/safe-js/chunks/mcp-A4YKQCIS.js.map +0 -7
  88. package/dist/safe-js/chunks/migration-file-QCZTVXEU.js +0 -15
  89. package/dist/safe-js/chunks/migration-file-QCZTVXEU.js.map +0 -7
  90. package/dist/safe-js/chunks/restore-22OGYS6N.js +0 -14
  91. package/dist/safe-js/chunks/restore-22OGYS6N.js.map +0 -7
  92. package/dist/safe-js/chunks/run-EMFOFJ22.js +0 -20
  93. package/dist/safe-js/chunks/run-EMFOFJ22.js.map +0 -7
  94. package/dist/safe-js/chunks/runtime-modules-QCVDLUVF.js +0 -11
  95. package/dist/safe-js/chunks/runtime-modules-QCVDLUVF.js.map +0 -7
  96. package/dist/safe-js/chunks/source-files-L3SGK63Z.js +0 -10
  97. package/dist/safe-js/chunks/source-files-L3SGK63Z.js.map +0 -7
  98. package/dist/safe-js/cli.js.map +0 -7
  99. package/dist/safe-js/core.js.map +0 -7
  100. package/dist/safe-js/index.js.map +0 -7
  101. package/dist/safe-js/modules/fs.js.map +0 -7
@@ -709,6 +709,13 @@ function normalizeRegexLimit(name, value) {
709
709
 
710
710
  // packages/safe-js/src/interp/regex/compile-guard.ts
711
711
  var compiledData = /* @__PURE__ */ new WeakMap();
712
+ var readCompiledData = WeakMap.prototype.get.bind(compiledData);
713
+ var writeCompiledData = WeakMap.prototype.set.bind(compiledData);
714
+ var freezeCompiledData = Object.freeze;
715
+ var setCompiledDataPrototype = Object.setPrototypeOf;
716
+ function compileData(units, ticket) {
717
+ return freezeCompiledData(setCompiledDataPrototype({ units, ticket }, null));
718
+ }
712
719
  var CompileScope = class {
713
720
  constructor(owner, parent) {
714
721
  this.owner = owner;
@@ -822,7 +829,7 @@ var RegexCompileGuard = class {
822
829
  if (this.ticket !== void 0) {
823
830
  this.ticket.owner.budget.resizeCompileTicket(this.ticket, units + valueUnits);
824
831
  }
825
- compiledData.set(pattern, { units, ticket: this.ticket });
832
+ writeCompiledData(pattern, compileData(units, this.ticket));
826
833
  this.retained = true;
827
834
  }
828
835
  retainScratch() {
@@ -835,7 +842,7 @@ var RegexCompileGuard = class {
835
842
  }
836
843
  };
837
844
  function regexCompiledData(pattern) {
838
- return compiledData.get(pattern) ?? { units: measurePattern(pattern) };
845
+ return readCompiledData(pattern) ?? compileData(measurePattern(pattern), void 0);
839
846
  }
840
847
  function measurePattern(pattern) {
841
848
  let units = 10 + pattern.source.length + measureNode(pattern.body);
@@ -884,197 +891,6 @@ function measureNode(node) {
884
891
  }
885
892
  }
886
893
 
887
- // packages/safe-js/src/error/source-lines.ts
888
- function splitSourceLines(source) {
889
- const lines = [];
890
- let start = 0;
891
- for (let index = 0; index < source.length; index += 1) {
892
- const character = source[index];
893
- if (character !== "\r" && character !== "\n" && character !== "\u2028" && character !== "\u2029") continue;
894
- lines.push(source.slice(start, index));
895
- if (character === "\r" && source[index + 1] === "\n") index += 1;
896
- start = index + 1;
897
- }
898
- lines.push(source.slice(start));
899
- return lines;
900
- }
901
-
902
- // packages/safe-js/src/parse/format-error.ts
903
- var ParseError = class extends Error {
904
- constructor(filename, message, line, column, excerpt, caret, span) {
905
- super(message);
906
- this.filename = filename;
907
- this.name = "ParseError";
908
- this.line = line;
909
- this.column = column;
910
- this.excerpt = excerpt;
911
- this.caret = caret;
912
- this.span = span;
913
- replaceErrorStack(this);
914
- }
915
- filename;
916
- kind = "ParseError";
917
- line;
918
- column;
919
- excerpt;
920
- caret;
921
- span;
922
- };
923
- var MAX_EXCERPT_CONTENT_LENGTH = 120;
924
- var ELLIPSIS = "...";
925
- function formatParseError(source, filename, error, location = parseErrorLocation(error.message)) {
926
- if (location === void 0) {
927
- replaceErrorStack(error);
928
- Object.defineProperty(error, "filename", { configurable: true, value: filename });
929
- throw error;
930
- }
931
- const lines = splitSourceLines(source);
932
- const startLine = Math.max(1, location.line - 2);
933
- const lastSpannedLine = Math.max(location.line, location.endLine);
934
- const sourceEndLine = Math.max(lines.length, 1);
935
- const endLine = Math.min(sourceEndLine, Math.max(lastSpannedLine, location.line) + 1);
936
- const lineNumberWidth = String(endLine).length;
937
- const excerpt = [];
938
- for (let line = startLine; line <= endLine; line += 1) {
939
- excerpt.push(
940
- renderLine(
941
- line,
942
- lines[line - 1] ?? "",
943
- getHighlightStartColumn(location, line),
944
- getHighlightEndColumn(location, line)
945
- )
946
- );
947
- }
948
- const caret = excerpt.filter((line) => line.number >= location.line && line.number <= location.endLine).map((line) => createCaret(line, lineNumberWidth, location)).join("\n");
949
- return new ParseError(
950
- filename,
951
- error.message,
952
- location.line,
953
- location.column,
954
- excerpt.map((line) => `${String(line.number).padStart(lineNumberWidth)} | ${line.content}`).join("\n"),
955
- caret,
956
- createSourceSpan(source, location.line, location.column, location.endLine, location.endColumn)
957
- );
958
- }
959
- function parseErrorLocation(message) {
960
- const linePrefix = " at line ";
961
- const columnPrefix = ", column ";
962
- const lineIndex = message.lastIndexOf(linePrefix);
963
- if (lineIndex === -1) {
964
- return void 0;
965
- }
966
- const columnIndex = message.indexOf(columnPrefix, lineIndex + linePrefix.length);
967
- if (columnIndex === -1) {
968
- return void 0;
969
- }
970
- const line = Number(message.slice(lineIndex + linePrefix.length, columnIndex));
971
- const columnStart = columnIndex + columnPrefix.length;
972
- const columnEnd = findNumberEnd(message, columnStart);
973
- const column = Number(message.slice(columnStart, columnEnd));
974
- if (!Number.isInteger(line) || !Number.isInteger(column)) {
975
- return void 0;
976
- }
977
- const endLocation = parseEndLocation(message, columnEnd);
978
- return {
979
- line,
980
- column,
981
- endLine: endLocation?.line ?? line,
982
- endColumn: endLocation?.column ?? column
983
- };
984
- }
985
- function renderLine(lineNumber, line, startColumn, endColumn) {
986
- const characters = Array.from(line);
987
- if (characters.length <= MAX_EXCERPT_CONTENT_LENGTH) {
988
- return {
989
- number: lineNumber,
990
- content: line,
991
- sourceColumnStart: 1
992
- };
993
- }
994
- const visibleLength = MAX_EXCERPT_CONTENT_LENGTH - ELLIPSIS.length * 2;
995
- const highlightStartIndex = Array.from(line.slice(0, Math.max(startColumn - 1, 0))).length;
996
- const highlightEndIndex = endColumn === Number.MAX_SAFE_INTEGER ? highlightStartIndex : Math.max(Array.from(line.slice(0, Math.max(endColumn - 1, 0))).length, highlightStartIndex);
997
- const highlightCenter = Math.floor((highlightStartIndex + highlightEndIndex) / 2);
998
- let sourceStartIndex = Math.max(0, highlightCenter - Math.floor(visibleLength / 2));
999
- sourceStartIndex = Math.min(sourceStartIndex, Math.max(characters.length - visibleLength, 0));
1000
- const sourceEndIndex = Math.min(sourceStartIndex + visibleLength, characters.length);
1001
- const prefix = sourceStartIndex > 0 ? ELLIPSIS : "";
1002
- const suffix = sourceEndIndex < characters.length ? ELLIPSIS : "";
1003
- return {
1004
- number: lineNumber,
1005
- content: `${prefix}${characters.slice(sourceStartIndex, sourceEndIndex).join("")}${suffix}`,
1006
- sourceColumnStart: characters.slice(0, sourceStartIndex).join("").length + 1 - prefix.length
1007
- };
1008
- }
1009
- function createCaret(line, lineNumberWidth, location) {
1010
- const contentColumns = line.content.length;
1011
- const isSpan = location.line !== location.endLine || location.column !== location.endColumn;
1012
- const startColumn = getHighlightStartColumn(location, line.number);
1013
- const endColumn = isSpan ? getHighlightEndColumn(location, line.number) : startColumn + 1;
1014
- const renderedStartColumn = Math.max(startColumn - line.sourceColumnStart + 1, 1);
1015
- const renderedEndColumn = Math.min(
1016
- Math.max(endColumn - line.sourceColumnStart + 1, renderedStartColumn + 1),
1017
- contentColumns + 1
1018
- );
1019
- const caretPadding = createCaretPadding(line.content, renderedStartColumn);
1020
- const caretLength = Math.max(Array.from(line.content.slice(renderedStartColumn - 1, renderedEndColumn - 1)).length, 1);
1021
- return `${" ".repeat(lineNumberWidth)} | ${caretPadding}${"^".repeat(caretLength)}`;
1022
- }
1023
- function createCaretPadding(line, column) {
1024
- let padding = "";
1025
- const maxColumn = Math.max(column - 1, 0);
1026
- for (const character of line.slice(0, maxColumn)) {
1027
- padding += character === " " ? " " : " ";
1028
- }
1029
- if (maxColumn > line.length) {
1030
- padding += " ".repeat(maxColumn - line.length);
1031
- }
1032
- return padding;
1033
- }
1034
- function getHighlightStartColumn(location, line) {
1035
- if (line === location.line) {
1036
- return location.column;
1037
- }
1038
- return 1;
1039
- }
1040
- function getHighlightEndColumn(location, line) {
1041
- if (line === location.endLine) {
1042
- return location.endColumn;
1043
- }
1044
- return Number.MAX_SAFE_INTEGER;
1045
- }
1046
- function parseEndLocation(message, startIndex) {
1047
- const linePrefix = " to line ";
1048
- const columnPrefix = ", column ";
1049
- const lineIndex = message.indexOf(linePrefix, startIndex);
1050
- if (lineIndex === -1) {
1051
- return void 0;
1052
- }
1053
- const columnIndex = message.indexOf(columnPrefix, lineIndex + linePrefix.length);
1054
- if (columnIndex === -1) {
1055
- return void 0;
1056
- }
1057
- const line = Number(message.slice(lineIndex + linePrefix.length, columnIndex));
1058
- const columnStart = columnIndex + columnPrefix.length;
1059
- const columnEnd = findNumberEnd(message, columnStart);
1060
- const column = Number(message.slice(columnStart, columnEnd));
1061
- if (!Number.isInteger(line) || !Number.isInteger(column)) {
1062
- return void 0;
1063
- }
1064
- return { line, column };
1065
- }
1066
- function findNumberEnd(value, startIndex) {
1067
- let index = startIndex;
1068
- while (index < value.length) {
1069
- const code = value.charCodeAt(index);
1070
- if (code < 48 || code > 57) {
1071
- break;
1072
- }
1073
- index += 1;
1074
- }
1075
- return index;
1076
- }
1077
-
1078
894
  // packages/safe-js/src/parse/compact-spans.ts
1079
895
  var positionOwners = /* @__PURE__ */ new WeakMap();
1080
896
  var getOwner = WeakMap.prototype.get.bind(positionOwners);
@@ -1196,6 +1012,158 @@ function compactSourceSpan(start, end) {
1196
1012
  return owner !== void 0 && getOwner(end) === owner ? owner.span(start.offset, end.offset) : void 0;
1197
1013
  }
1198
1014
 
1015
+ // packages/safe-js/src/platform/types.ts
1016
+ var getter = (prototype, key) => Object.getOwnPropertyDescriptor(prototype, key).get;
1017
+ var regexpPrototype = RegExp.prototype;
1018
+ var regexpSource = getter(regexpPrototype, "source");
1019
+ var booleanValue = Boolean.prototype.valueOf;
1020
+ var numberValue = Number.prototype.valueOf;
1021
+ var stringValue = String.prototype.valueOf;
1022
+ var bigintValue = BigInt.prototype.valueOf;
1023
+ var symbolValue = Symbol.prototype.valueOf;
1024
+ var dateValue = Date.prototype.getTime;
1025
+ var asyncFunctionPrototype = Object.getPrototypeOf(async function() {
1026
+ });
1027
+ var generatorFunctionPrototype = Object.getPrototypeOf(function* () {
1028
+ });
1029
+ var arrayBufferLength = getter(ArrayBuffer.prototype, "byteLength");
1030
+ var dataViewBuffer = getter(DataView.prototype, "buffer");
1031
+ var mapSize = getter(Map.prototype, "size");
1032
+ var promiseThen = Promise.prototype.then;
1033
+ var NativeError = Error;
1034
+ var nativeIsError = Reflect.get(NativeError, "isError");
1035
+ var proxies = /* @__PURE__ */ new WeakSet();
1036
+ function createTrackedProxy(target, handler) {
1037
+ const proxy = new Proxy(target, handler);
1038
+ proxies.add(proxy);
1039
+ return proxy;
1040
+ }
1041
+
1042
+ // packages/safe-js/src/parse/compact-tokens.ts
1043
+ var types = [
1044
+ "identifier",
1045
+ "private-identifier",
1046
+ "keyword",
1047
+ "escaped-keyword",
1048
+ "numeric",
1049
+ "regex",
1050
+ "string",
1051
+ "template",
1052
+ "punctuator",
1053
+ "eof"
1054
+ ];
1055
+ var stride = 3;
1056
+ var legacyEscape = 256;
1057
+ var tokenCacheSize = 256;
1058
+ var readers = /* @__PURE__ */ new WeakMap();
1059
+ var registerReader = WeakMap.prototype.set.bind(readers);
1060
+ var compactTokenReader = WeakMap.prototype.get.bind(readers);
1061
+ var CompactTokens = class {
1062
+ constructor(sourcePositions, lazyPositions = false) {
1063
+ this.sourcePositions = sourcePositions;
1064
+ registerReader(this.indexed, (index) => this.get(index));
1065
+ if (!lazyPositions) return;
1066
+ class ParserToken {
1067
+ constructor(type, value, start, end) {
1068
+ this.type = type;
1069
+ this.value = value;
1070
+ this.#start = start;
1071
+ this.#end = end;
1072
+ }
1073
+ type;
1074
+ value;
1075
+ #start;
1076
+ #end;
1077
+ get start() {
1078
+ if (typeof this.#start === "number") this.#start = sourcePositions.position(this.#start);
1079
+ return this.#start;
1080
+ }
1081
+ get end() {
1082
+ if (typeof this.#end === "number") this.#end = sourcePositions.position(this.#end);
1083
+ return this.#end;
1084
+ }
1085
+ }
1086
+ this.parserToken = (type, value, start, end) => new ParserToken(type, value, start, end);
1087
+ }
1088
+ sourcePositions;
1089
+ rows = new Uint32Array(1024 * stride);
1090
+ values = [];
1091
+ templates = /* @__PURE__ */ new Map();
1092
+ tokens = /* @__PURE__ */ new Map();
1093
+ last;
1094
+ parserToken;
1095
+ // Only indexing, iteration, length, push and at are used by the lexer/parser.
1096
+ // Historical tokens are materialized on demand in a bounded cache.
1097
+ indexed = createTrackedProxy([], {
1098
+ get: (target, key, receiver) => {
1099
+ if (key === "length") return this.values.length;
1100
+ if (key === "push") return this.push;
1101
+ const index = arrayIndex(key);
1102
+ return index === void 0 ? Reflect.get(target, key, receiver) : this.get(index);
1103
+ },
1104
+ set: () => {
1105
+ throw new TypeError("Compiler token rows cannot be reassigned.");
1106
+ }
1107
+ });
1108
+ finish() {
1109
+ this.rows = this.rows.slice(0, this.values.length * stride);
1110
+ if (this.last) {
1111
+ this.last.start = this.sourcePositions.position(this.last.start.offset);
1112
+ this.last.end = this.sourcePositions.position(this.last.end.offset);
1113
+ }
1114
+ return this.indexed;
1115
+ }
1116
+ push = (token) => {
1117
+ if (this.last !== void 0) {
1118
+ const previous = this.values.length - 1;
1119
+ if (this.last.legacyEscape) this.rows[previous * stride + 2] |= legacyEscape;
1120
+ if (this.last.templateExpressions !== void 0)
1121
+ this.templates.set(previous, this.last.templateExpressions);
1122
+ }
1123
+ const index = this.values.length;
1124
+ const base = index * stride;
1125
+ if (base + stride > this.rows.length) {
1126
+ const rows = new Uint32Array(this.rows.length * 2);
1127
+ rows.set(this.rows);
1128
+ this.rows = rows;
1129
+ }
1130
+ this.rows.set([token.start.offset, token.end.offset, types.indexOf(token.type)], base);
1131
+ this.values.push(token.value);
1132
+ this.last = token;
1133
+ return index + 1;
1134
+ };
1135
+ get(index) {
1136
+ if (!Number.isSafeInteger(index) || index < 0 || index >= this.values.length) return void 0;
1137
+ if (index === this.values.length - 1) return this.last;
1138
+ const cached = this.tokens.get(index);
1139
+ if (cached !== void 0) return cached;
1140
+ const base = index * stride;
1141
+ const bits = this.rows[base + 2];
1142
+ const token = this.parserToken?.(
1143
+ types[bits & 255],
1144
+ this.values[index],
1145
+ this.rows[base],
1146
+ this.rows[base + 1]
1147
+ ) ?? {
1148
+ type: types[bits & 255],
1149
+ value: this.values[index],
1150
+ start: this.sourcePositions.position(this.rows[base]),
1151
+ end: this.sourcePositions.position(this.rows[base + 1])
1152
+ };
1153
+ if (bits & legacyEscape) token.legacyEscape = true;
1154
+ const expressions = this.templates.get(index);
1155
+ if (expressions !== void 0) token.templateExpressions = expressions;
1156
+ if (this.tokens.size === tokenCacheSize) this.tokens.delete(this.tokens.keys().next().value);
1157
+ this.tokens.set(index, token);
1158
+ return token;
1159
+ }
1160
+ };
1161
+ function arrayIndex(key) {
1162
+ if (typeof key !== "string") return void 0;
1163
+ const index = Number(key);
1164
+ return Number.isSafeInteger(index) && index >= 0 && String(index) === key ? index : void 0;
1165
+ }
1166
+
1199
1167
  // packages/safe-js/src/parse/function-source.ts
1200
1168
  var functionSources = /* @__PURE__ */ new WeakMap();
1201
1169
  var templateSources = /* @__PURE__ */ new WeakMap();
@@ -1983,170 +1951,22 @@ function validatePrivateNames(root, inheritedNames) {
1983
1951
  if (type === "MemberExpression") {
1984
1952
  const property = compilerField(value, "property");
1985
1953
  if (compilerField(property, "type") === "PrivateIdentifier" && compilerField(compilerField(value, "object"), "type") === "Super")
1986
- throw new Error("super cannot access a private name.");
1987
- }
1988
- if (type === "UnaryExpression" && compilerField(value, "operator") === "delete") {
1989
- const argument = compilerField(value, "argument");
1990
- if (compilerField(argument, "type") === "MemberExpression" && compilerField(compilerField(argument, "property"), "type") === "PrivateIdentifier")
1991
- throw new Error("Private elements cannot be deleted.");
1992
- }
1993
- for (const [key, child] of compilerEntries(value)) {
1994
- if (key === "span") continue;
1995
- pending.push({
1996
- value: child,
1997
- scope,
1998
- declaration: key === "key" && (type === "MethodDefinition" || type === "PropertyDefinition")
1999
- });
2000
- }
2001
- }
2002
- }
2003
-
2004
- // packages/safe-js/src/platform/types.ts
2005
- var getter = (prototype, key) => Object.getOwnPropertyDescriptor(prototype, key).get;
2006
- var regexpPrototype = RegExp.prototype;
2007
- var regexpSource = getter(regexpPrototype, "source");
2008
- var booleanValue = Boolean.prototype.valueOf;
2009
- var numberValue = Number.prototype.valueOf;
2010
- var stringValue = String.prototype.valueOf;
2011
- var bigintValue = BigInt.prototype.valueOf;
2012
- var symbolValue = Symbol.prototype.valueOf;
2013
- var dateValue = Date.prototype.getTime;
2014
- var asyncFunctionPrototype = Object.getPrototypeOf(async function() {
2015
- });
2016
- var generatorFunctionPrototype = Object.getPrototypeOf(function* () {
2017
- });
2018
- var arrayBufferLength = getter(ArrayBuffer.prototype, "byteLength");
2019
- var dataViewBuffer = getter(DataView.prototype, "buffer");
2020
- var mapSize = getter(Map.prototype, "size");
2021
- var promiseThen = Promise.prototype.then;
2022
- var NativeError = Error;
2023
- var nativeIsError = Reflect.get(NativeError, "isError");
2024
- var proxies = /* @__PURE__ */ new WeakSet();
2025
- function createTrackedProxy(target, handler) {
2026
- const proxy = new Proxy(target, handler);
2027
- proxies.add(proxy);
2028
- return proxy;
2029
- }
2030
-
2031
- // packages/safe-js/src/parse/compact-tokens.ts
2032
- var types = [
2033
- "identifier",
2034
- "private-identifier",
2035
- "keyword",
2036
- "escaped-keyword",
2037
- "numeric",
2038
- "regex",
2039
- "string",
2040
- "template",
2041
- "punctuator",
2042
- "eof"
2043
- ];
2044
- var stride = 3;
2045
- var legacyEscape = 256;
2046
- var tokenCacheSize = 256;
2047
- var CompactTokens = class {
2048
- constructor(sourcePositions, lazyPositions = false) {
2049
- this.sourcePositions = sourcePositions;
2050
- if (!lazyPositions) return;
2051
- class ParserToken {
2052
- constructor(type, value, start, end) {
2053
- this.type = type;
2054
- this.value = value;
2055
- this.#start = start;
2056
- this.#end = end;
2057
- }
2058
- type;
2059
- value;
2060
- #start;
2061
- #end;
2062
- get start() {
2063
- if (typeof this.#start === "number") this.#start = sourcePositions.position(this.#start);
2064
- return this.#start;
2065
- }
2066
- get end() {
2067
- if (typeof this.#end === "number") this.#end = sourcePositions.position(this.#end);
2068
- return this.#end;
2069
- }
2070
- }
2071
- this.parserToken = (type, value, start, end) => new ParserToken(type, value, start, end);
2072
- }
2073
- sourcePositions;
2074
- rows = new Uint32Array(1024 * stride);
2075
- values = [];
2076
- templates = /* @__PURE__ */ new Map();
2077
- tokens = /* @__PURE__ */ new Map();
2078
- last;
2079
- parserToken;
2080
- // Only indexing, iteration, length, push and at are used by the lexer/parser.
2081
- // Historical tokens are materialized on demand in a bounded cache.
2082
- indexed = createTrackedProxy([], {
2083
- get: (target, key, receiver) => {
2084
- if (key === "length") return this.values.length;
2085
- if (key === "push") return this.push;
2086
- const index = arrayIndex(key);
2087
- return index === void 0 ? Reflect.get(target, key, receiver) : this.get(index);
2088
- },
2089
- set: () => {
2090
- throw new TypeError("Compiler token rows cannot be reassigned.");
2091
- }
2092
- });
2093
- finish() {
2094
- this.rows = this.rows.slice(0, this.values.length * stride);
2095
- if (this.last) {
2096
- this.last.start = this.sourcePositions.position(this.last.start.offset);
2097
- this.last.end = this.sourcePositions.position(this.last.end.offset);
2098
- }
2099
- return this.indexed;
2100
- }
2101
- push = (token) => {
2102
- if (this.last !== void 0) {
2103
- const previous = this.values.length - 1;
2104
- if (this.last.legacyEscape) this.rows[previous * stride + 2] |= legacyEscape;
2105
- if (this.last.templateExpressions !== void 0)
2106
- this.templates.set(previous, this.last.templateExpressions);
1954
+ throw new Error("super cannot access a private name.");
2107
1955
  }
2108
- const index = this.values.length;
2109
- const base = index * stride;
2110
- if (base + stride > this.rows.length) {
2111
- const rows = new Uint32Array(this.rows.length * 2);
2112
- rows.set(this.rows);
2113
- this.rows = rows;
1956
+ if (type === "UnaryExpression" && compilerField(value, "operator") === "delete") {
1957
+ const argument = compilerField(value, "argument");
1958
+ if (compilerField(argument, "type") === "MemberExpression" && compilerField(compilerField(argument, "property"), "type") === "PrivateIdentifier")
1959
+ throw new Error("Private elements cannot be deleted.");
1960
+ }
1961
+ for (const [key, child] of compilerEntries(value)) {
1962
+ if (key === "span") continue;
1963
+ pending.push({
1964
+ value: child,
1965
+ scope,
1966
+ declaration: key === "key" && (type === "MethodDefinition" || type === "PropertyDefinition")
1967
+ });
2114
1968
  }
2115
- this.rows.set([token.start.offset, token.end.offset, types.indexOf(token.type)], base);
2116
- this.values.push(token.value);
2117
- this.last = token;
2118
- return index + 1;
2119
- };
2120
- get(index) {
2121
- if (index >= this.values.length) return void 0;
2122
- if (index === this.values.length - 1) return this.last;
2123
- const cached = this.tokens.get(index);
2124
- if (cached !== void 0) return cached;
2125
- const base = index * stride;
2126
- const bits = this.rows[base + 2];
2127
- const token = this.parserToken?.(
2128
- types[bits & 255],
2129
- this.values[index],
2130
- this.rows[base],
2131
- this.rows[base + 1]
2132
- ) ?? {
2133
- type: types[bits & 255],
2134
- value: this.values[index],
2135
- start: this.sourcePositions.position(this.rows[base]),
2136
- end: this.sourcePositions.position(this.rows[base + 1])
2137
- };
2138
- if (bits & legacyEscape) token.legacyEscape = true;
2139
- const expressions = this.templates.get(index);
2140
- if (expressions !== void 0) token.templateExpressions = expressions;
2141
- if (this.tokens.size === tokenCacheSize) this.tokens.delete(this.tokens.keys().next().value);
2142
- this.tokens.set(index, token);
2143
- return token;
2144
1969
  }
2145
- };
2146
- function arrayIndex(key) {
2147
- if (typeof key !== "string") return void 0;
2148
- const index = Number(key);
2149
- return Number.isSafeInteger(index) && index >= 0 && String(index) === key ? index : void 0;
2150
1970
  }
2151
1971
 
2152
1972
  // packages/safe-js/src/parse/tokenizer.ts
@@ -3401,6 +3221,197 @@ function assignCompactIds(root) {
3401
3221
  return root;
3402
3222
  }
3403
3223
 
3224
+ // packages/safe-js/src/error/source-lines.ts
3225
+ function splitSourceLines(source) {
3226
+ const lines = [];
3227
+ let start = 0;
3228
+ for (let index = 0; index < source.length; index += 1) {
3229
+ const character = source[index];
3230
+ if (character !== "\r" && character !== "\n" && character !== "\u2028" && character !== "\u2029") continue;
3231
+ lines.push(source.slice(start, index));
3232
+ if (character === "\r" && source[index + 1] === "\n") index += 1;
3233
+ start = index + 1;
3234
+ }
3235
+ lines.push(source.slice(start));
3236
+ return lines;
3237
+ }
3238
+
3239
+ // packages/safe-js/src/parse/format-error.ts
3240
+ var ParseError = class extends Error {
3241
+ constructor(filename, message, line, column, excerpt, caret, span) {
3242
+ super(message);
3243
+ this.filename = filename;
3244
+ this.name = "ParseError";
3245
+ this.line = line;
3246
+ this.column = column;
3247
+ this.excerpt = excerpt;
3248
+ this.caret = caret;
3249
+ this.span = span;
3250
+ replaceErrorStack(this);
3251
+ }
3252
+ filename;
3253
+ kind = "ParseError";
3254
+ line;
3255
+ column;
3256
+ excerpt;
3257
+ caret;
3258
+ span;
3259
+ };
3260
+ var MAX_EXCERPT_CONTENT_LENGTH = 120;
3261
+ var ELLIPSIS = "...";
3262
+ function formatParseError(source, filename, error, location = parseErrorLocation(error.message)) {
3263
+ if (location === void 0) {
3264
+ replaceErrorStack(error);
3265
+ Object.defineProperty(error, "filename", { configurable: true, value: filename });
3266
+ throw error;
3267
+ }
3268
+ const lines = splitSourceLines(source);
3269
+ const startLine = Math.max(1, location.line - 2);
3270
+ const lastSpannedLine = Math.max(location.line, location.endLine);
3271
+ const sourceEndLine = Math.max(lines.length, 1);
3272
+ const endLine = Math.min(sourceEndLine, Math.max(lastSpannedLine, location.line) + 1);
3273
+ const lineNumberWidth = String(endLine).length;
3274
+ const excerpt = [];
3275
+ for (let line = startLine; line <= endLine; line += 1) {
3276
+ excerpt.push(
3277
+ renderLine(
3278
+ line,
3279
+ lines[line - 1] ?? "",
3280
+ getHighlightStartColumn(location, line),
3281
+ getHighlightEndColumn(location, line)
3282
+ )
3283
+ );
3284
+ }
3285
+ const caret = excerpt.filter((line) => line.number >= location.line && line.number <= location.endLine).map((line) => createCaret(line, lineNumberWidth, location)).join("\n");
3286
+ return new ParseError(
3287
+ filename,
3288
+ error.message,
3289
+ location.line,
3290
+ location.column,
3291
+ excerpt.map((line) => `${String(line.number).padStart(lineNumberWidth)} | ${line.content}`).join("\n"),
3292
+ caret,
3293
+ createSourceSpan(source, location.line, location.column, location.endLine, location.endColumn)
3294
+ );
3295
+ }
3296
+ function parseErrorLocation(message) {
3297
+ const linePrefix = " at line ";
3298
+ const columnPrefix = ", column ";
3299
+ const lineIndex = message.lastIndexOf(linePrefix);
3300
+ if (lineIndex === -1) {
3301
+ return void 0;
3302
+ }
3303
+ const columnIndex = message.indexOf(columnPrefix, lineIndex + linePrefix.length);
3304
+ if (columnIndex === -1) {
3305
+ return void 0;
3306
+ }
3307
+ const line = Number(message.slice(lineIndex + linePrefix.length, columnIndex));
3308
+ const columnStart = columnIndex + columnPrefix.length;
3309
+ const columnEnd = findNumberEnd(message, columnStart);
3310
+ const column = Number(message.slice(columnStart, columnEnd));
3311
+ if (!Number.isInteger(line) || !Number.isInteger(column)) {
3312
+ return void 0;
3313
+ }
3314
+ const endLocation = parseEndLocation(message, columnEnd);
3315
+ return {
3316
+ line,
3317
+ column,
3318
+ endLine: endLocation?.line ?? line,
3319
+ endColumn: endLocation?.column ?? column
3320
+ };
3321
+ }
3322
+ function renderLine(lineNumber, line, startColumn, endColumn) {
3323
+ const characters = Array.from(line);
3324
+ if (characters.length <= MAX_EXCERPT_CONTENT_LENGTH) {
3325
+ return {
3326
+ number: lineNumber,
3327
+ content: line,
3328
+ sourceColumnStart: 1
3329
+ };
3330
+ }
3331
+ const visibleLength = MAX_EXCERPT_CONTENT_LENGTH - ELLIPSIS.length * 2;
3332
+ const highlightStartIndex = Array.from(line.slice(0, Math.max(startColumn - 1, 0))).length;
3333
+ const highlightEndIndex = endColumn === Number.MAX_SAFE_INTEGER ? highlightStartIndex : Math.max(Array.from(line.slice(0, Math.max(endColumn - 1, 0))).length, highlightStartIndex);
3334
+ const highlightCenter = Math.floor((highlightStartIndex + highlightEndIndex) / 2);
3335
+ let sourceStartIndex = Math.max(0, highlightCenter - Math.floor(visibleLength / 2));
3336
+ sourceStartIndex = Math.min(sourceStartIndex, Math.max(characters.length - visibleLength, 0));
3337
+ const sourceEndIndex = Math.min(sourceStartIndex + visibleLength, characters.length);
3338
+ const prefix = sourceStartIndex > 0 ? ELLIPSIS : "";
3339
+ const suffix = sourceEndIndex < characters.length ? ELLIPSIS : "";
3340
+ return {
3341
+ number: lineNumber,
3342
+ content: `${prefix}${characters.slice(sourceStartIndex, sourceEndIndex).join("")}${suffix}`,
3343
+ sourceColumnStart: characters.slice(0, sourceStartIndex).join("").length + 1 - prefix.length
3344
+ };
3345
+ }
3346
+ function createCaret(line, lineNumberWidth, location) {
3347
+ const contentColumns = line.content.length;
3348
+ const isSpan = location.line !== location.endLine || location.column !== location.endColumn;
3349
+ const startColumn = getHighlightStartColumn(location, line.number);
3350
+ const endColumn = isSpan ? getHighlightEndColumn(location, line.number) : startColumn + 1;
3351
+ const renderedStartColumn = Math.max(startColumn - line.sourceColumnStart + 1, 1);
3352
+ const renderedEndColumn = Math.min(
3353
+ Math.max(endColumn - line.sourceColumnStart + 1, renderedStartColumn + 1),
3354
+ contentColumns + 1
3355
+ );
3356
+ const caretPadding = createCaretPadding(line.content, renderedStartColumn);
3357
+ const caretLength = Math.max(Array.from(line.content.slice(renderedStartColumn - 1, renderedEndColumn - 1)).length, 1);
3358
+ return `${" ".repeat(lineNumberWidth)} | ${caretPadding}${"^".repeat(caretLength)}`;
3359
+ }
3360
+ function createCaretPadding(line, column) {
3361
+ let padding = "";
3362
+ const maxColumn = Math.max(column - 1, 0);
3363
+ for (const character of line.slice(0, maxColumn)) {
3364
+ padding += character === " " ? " " : " ";
3365
+ }
3366
+ if (maxColumn > line.length) {
3367
+ padding += " ".repeat(maxColumn - line.length);
3368
+ }
3369
+ return padding;
3370
+ }
3371
+ function getHighlightStartColumn(location, line) {
3372
+ if (line === location.line) {
3373
+ return location.column;
3374
+ }
3375
+ return 1;
3376
+ }
3377
+ function getHighlightEndColumn(location, line) {
3378
+ if (line === location.endLine) {
3379
+ return location.endColumn;
3380
+ }
3381
+ return Number.MAX_SAFE_INTEGER;
3382
+ }
3383
+ function parseEndLocation(message, startIndex) {
3384
+ const linePrefix = " to line ";
3385
+ const columnPrefix = ", column ";
3386
+ const lineIndex = message.indexOf(linePrefix, startIndex);
3387
+ if (lineIndex === -1) {
3388
+ return void 0;
3389
+ }
3390
+ const columnIndex = message.indexOf(columnPrefix, lineIndex + linePrefix.length);
3391
+ if (columnIndex === -1) {
3392
+ return void 0;
3393
+ }
3394
+ const line = Number(message.slice(lineIndex + linePrefix.length, columnIndex));
3395
+ const columnStart = columnIndex + columnPrefix.length;
3396
+ const columnEnd = findNumberEnd(message, columnStart);
3397
+ const column = Number(message.slice(columnStart, columnEnd));
3398
+ if (!Number.isInteger(line) || !Number.isInteger(column)) {
3399
+ return void 0;
3400
+ }
3401
+ return { line, column };
3402
+ }
3403
+ function findNumberEnd(value, startIndex) {
3404
+ let index = startIndex;
3405
+ while (index < value.length) {
3406
+ const code = value.charCodeAt(index);
3407
+ if (code < 48 || code > 57) {
3408
+ break;
3409
+ }
3410
+ index += 1;
3411
+ }
3412
+ return index;
3413
+ }
3414
+
3404
3415
  // packages/safe-js/src/parse/syntax-diagnostic.ts
3405
3416
  var syntaxDiagnostics = /* @__PURE__ */ new WeakMap();
3406
3417
  function createSyntaxDiagnostic(source, filename, failure) {
@@ -4461,7 +4472,7 @@ var ordinaryFunctionContext = {
4461
4472
  await: true
4462
4473
  };
4463
4474
  var Parser = class {
4464
- constructor(tokens, source, compilation, functionContext = "top-level", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }, allowImportMeta = true, moduleSyntax, importSpecifiers) {
4475
+ constructor(tokens, source, compilation, functionContext = "top-level", lexicalContext = { ...ordinaryFunctionContext, newTarget: false }, allowImportMeta = true, moduleSyntax, importSpecifiers, conditionalExpressionDepth = 0) {
4465
4476
  this.tokens = tokens;
4466
4477
  this.source = source;
4467
4478
  this.compilation = compilation;
@@ -4470,7 +4481,17 @@ var Parser = class {
4470
4481
  this.allowImportMeta = allowImportMeta;
4471
4482
  this.moduleSyntax = moduleSyntax;
4472
4483
  this.importSpecifiers = importSpecifiers;
4484
+ this.conditionalExpressionDepth = conditionalExpressionDepth;
4485
+ this.readToken = compactTokenReader(tokens) ?? ((index) => tokens[index]);
4473
4486
  this.functionScopes.add(this.scopes[0]);
4487
+ const openings = [];
4488
+ for (let index = 0; index < tokens.length; index++) {
4489
+ const token = this.readToken(index);
4490
+ if (token.type !== "punctuator") continue;
4491
+ if (token.value === "(") openings.push(index);
4492
+ else if (token.value === ")" && openings.length > 0)
4493
+ this.closingParentheses.set(openings.pop(), index);
4494
+ }
4474
4495
  }
4475
4496
  tokens;
4476
4497
  source;
@@ -4480,10 +4501,12 @@ var Parser = class {
4480
4501
  allowImportMeta;
4481
4502
  moduleSyntax;
4482
4503
  importSpecifiers;
4504
+ conditionalExpressionDepth;
4505
+ readToken;
4483
4506
  index = 0;
4507
+ closingParentheses = /* @__PURE__ */ new Map();
4484
4508
  allowIn = true;
4485
4509
  breakableDepth = 0;
4486
- conditionalExpressionDepth = 0;
4487
4510
  conditionalDepths = /* @__PURE__ */ new WeakMap();
4488
4511
  ifStatementDepth = 0;
4489
4512
  loopDepth = 0;
@@ -4504,7 +4527,7 @@ var Parser = class {
4504
4527
  this.astStorage?.finish();
4505
4528
  }
4506
4529
  get position() {
4507
- return (this.tokens[this.index] ?? this.tokens[this.tokens.length - 1]).start;
4530
+ return (this.readToken(this.index) ?? this.readToken(this.tokens.length - 1)).start;
4508
4531
  }
4509
4532
  withFunctionSource(node) {
4510
4533
  if ((node.type === "FunctionDeclaration" || node.type === "FunctionExpression") && node.id !== void 0 && functionBodyStrictness.get(node.body) && STRICT_BINDING_NAMES.has(node.id.name))
@@ -4624,11 +4647,11 @@ var Parser = class {
4624
4647
  span: expression.span
4625
4648
  };
4626
4649
  }
4627
- parseExpression(options = {}) {
4650
+ parseExpression(options = {}, initial) {
4628
4651
  const previousAllowIn = this.allowIn;
4629
4652
  this.allowIn = options.allowIn ?? true;
4630
4653
  try {
4631
- const first = this.parseAssignmentExpression();
4654
+ const first = initial === void 0 ? this.parseAssignmentExpression() : this.parseConditionalExpression(initial);
4632
4655
  if (options.allowSequence !== true || this.consumePunctuator(",") === void 0) {
4633
4656
  return first;
4634
4657
  }
@@ -4789,9 +4812,9 @@ var Parser = class {
4789
4812
  }
4790
4813
  return this.conditionalDepths.get(node);
4791
4814
  }
4792
- parseConditionalExpression() {
4815
+ parseConditionalExpression(initial) {
4793
4816
  const token = this.currentToken();
4794
- const test = this.parseCoalesceExpression();
4817
+ const test = initial ?? this.parseCoalesceExpression();
4795
4818
  if (this.consumePunctuator("?") === void 0) {
4796
4819
  return test;
4797
4820
  }
@@ -4852,13 +4875,13 @@ var Parser = class {
4852
4875
  }
4853
4876
  if (params?.some((param) => param.type !== "Identifier")) {
4854
4877
  for (const statement of body.body) {
4855
- const token = this.tokens[directiveTokenIndex];
4878
+ const token = this.readToken(directiveTokenIndex);
4856
4879
  if (statement.type !== "ExpressionStatement" || statement.expression.type !== "StringLiteral" || token?.type !== "string" || statement.span.start.offset !== token.start.offset || statement.span.end.offset !== token.end.offset) break;
4857
4880
  if (statement.expression.raw === '"use strict"' || statement.expression.raw === "'use strict'")
4858
4881
  throw new Error(
4859
4882
  "A function with non-simple parameters cannot contain a use strict directive."
4860
4883
  );
4861
- directiveTokenIndex += this.tokens[directiveTokenIndex + 1]?.value === ";" ? 2 : 1;
4884
+ directiveTokenIndex += this.readToken(directiveTokenIndex + 1)?.value === ";" ? 2 : 1;
4862
4885
  }
4863
4886
  }
4864
4887
  if (params !== void 0 && this.lexicalContext.grammar !== void 0)
@@ -5894,7 +5917,7 @@ var Parser = class {
5894
5917
  this.index++;
5895
5918
  }
5896
5919
  const computed = this.consumePunctuator("[") !== void 0;
5897
- const key = computed ? this.parseExpression({ allowSequence: true }).node : this.currentToken().type === "string" ? createStringLiteral(this.tokens[this.index++]) : this.currentToken().type === "numeric" ? createNumericLiteral(this.tokens[this.index++]) : this.currentToken().type === "private-identifier" ? this.parsePrivateIdentifier() : this.parseIdentifierName();
5920
+ const key = computed ? this.parseExpression({ allowSequence: true }).node : this.currentToken().type === "string" ? createStringLiteral(this.readToken(this.index++)) : this.currentToken().type === "numeric" ? createNumericLiteral(this.readToken(this.index++)) : this.currentToken().type === "private-identifier" ? this.parsePrivateIdentifier() : this.parseIdentifierName();
5898
5921
  if (computed) this.expectPunctuator("]");
5899
5922
  const name = computed ? void 0 : key.type === "Identifier" ? key.name : key.type === "StringLiteral" || key.type === "NumericLiteral" ? String(key.value) : void 0;
5900
5923
  if (isStatic && name === "prototype") throw new Error("A static class element cannot be named prototype.");
@@ -6822,6 +6845,9 @@ var Parser = class {
6822
6845
  allowMalformedEscapes: false,
6823
6846
  functionContext: this.functionContext,
6824
6847
  lexicalContext: this.lexicalContext,
6848
+ allowImportMeta: this.allowImportMeta,
6849
+ importSpecifiers: this.importSpecifiers,
6850
+ conditionalExpressionDepth: this.conditionalExpressionDepth,
6825
6851
  source: this.source
6826
6852
  },
6827
6853
  this.compilation
@@ -6854,15 +6880,23 @@ var Parser = class {
6854
6880
  };
6855
6881
  }
6856
6882
  if (token.type === "punctuator" && token.value === "(") {
6857
- const start = this.expectPunctuator("(");
6858
- const expression = this.parseExpression({ allowSequence: true });
6859
- const end = this.expectPunctuator(")");
6860
- expression.node.span = createSpan2(start.start, end.end);
6861
- this.parenthesizedNodes.add(expression.node);
6862
- return {
6863
- node: expression.node,
6864
- parenthesized: true
6865
- };
6883
+ const starts = [this.expectPunctuator("(")];
6884
+ while (this.currentToken().value === "(") {
6885
+ const close = this.closingParentheses.get(this.index);
6886
+ const suffix = close === void 0 ? void 0 : this.readToken(close + 1);
6887
+ if (suffix?.type !== "punctuator" || suffix.value !== ")" && suffix.value !== "?") break;
6888
+ starts.push(this.expectPunctuator("("));
6889
+ }
6890
+ let expression = this.parseExpression({ allowSequence: true });
6891
+ while (starts.length > 0) {
6892
+ const start = starts.pop();
6893
+ const end = this.expectPunctuator(")");
6894
+ expression.node.span = createSpan2(start.start, end.end);
6895
+ this.parenthesizedNodes.add(expression.node);
6896
+ expression = { node: expression.node, parenthesized: true };
6897
+ if (starts.length > 0) expression = this.parseExpression({ allowSequence: true }, expression);
6898
+ }
6899
+ return expression;
6866
6900
  }
6867
6901
  if (token.type === "punctuator" && token.value === "[") {
6868
6902
  return {
@@ -6953,6 +6987,9 @@ var Parser = class {
6953
6987
  allowMalformedEscapes: true,
6954
6988
  functionContext: this.functionContext,
6955
6989
  lexicalContext: this.lexicalContext,
6990
+ allowImportMeta: this.allowImportMeta,
6991
+ importSpecifiers: this.importSpecifiers,
6992
+ conditionalExpressionDepth: this.conditionalExpressionDepth,
6956
6993
  source: this.source
6957
6994
  },
6958
6995
  this.compilation
@@ -7491,13 +7528,13 @@ var Parser = class {
7491
7528
  return this.toPatternTarget(this.toAssignmentTarget(value));
7492
7529
  }
7493
7530
  tokenAfterBalancedGroup(startIndex) {
7494
- const startToken = this.tokens[startIndex];
7531
+ const startToken = this.readToken(startIndex);
7495
7532
  if (startToken?.type !== "punctuator" || startToken.value !== "[" && startToken.value !== "{") {
7496
7533
  return void 0;
7497
7534
  }
7498
7535
  const stack = [];
7499
7536
  for (let index = startIndex; index < this.tokens.length; index += 1) {
7500
- const token = this.tokens[index];
7537
+ const token = this.readToken(index);
7501
7538
  if (token.type !== "punctuator") {
7502
7539
  continue;
7503
7540
  }
@@ -7511,7 +7548,7 @@ var Parser = class {
7511
7548
  stack.pop();
7512
7549
  }
7513
7550
  if (stack.length === 0) {
7514
- return this.tokens[index + 1];
7551
+ return this.readToken(index + 1);
7515
7552
  }
7516
7553
  }
7517
7554
  }
@@ -7568,13 +7605,13 @@ var Parser = class {
7568
7605
  return true;
7569
7606
  }
7570
7607
  findArrowFromParenthesizedParams(startIndex) {
7571
- const startToken = this.tokens[startIndex];
7608
+ const startToken = this.readToken(startIndex);
7572
7609
  if (startToken?.type !== "punctuator" || startToken.value !== "(") {
7573
7610
  return void 0;
7574
7611
  }
7575
7612
  let depth = 0;
7576
7613
  for (let index = startIndex; index < this.tokens.length; index += 1) {
7577
- const token = this.tokens[index];
7614
+ const token = this.readToken(index);
7578
7615
  if (token.type !== "punctuator") {
7579
7616
  continue;
7580
7617
  }
@@ -7585,7 +7622,7 @@ var Parser = class {
7585
7622
  if (token.value === ")") {
7586
7623
  depth -= 1;
7587
7624
  if (depth === 0) {
7588
- const arrowToken = this.tokens[index + 1];
7625
+ const arrowToken = this.readToken(index + 1);
7589
7626
  if (arrowToken?.value !== "=>") {
7590
7627
  return void 0;
7591
7628
  }
@@ -7606,7 +7643,7 @@ var Parser = class {
7606
7643
  let conditionalDepth = 0;
7607
7644
  let previousToken;
7608
7645
  for (let index = startIndex; index < this.tokens.length; index += 1) {
7609
- const token = this.tokens[index];
7646
+ const token = this.readToken(index);
7610
7647
  if (token.type === "punctuator") {
7611
7648
  if (token.value === "(" || token.value === "[" || token.value === "{") {
7612
7649
  depth += 1;
@@ -7825,7 +7862,7 @@ var Parser = class {
7825
7862
  }
7826
7863
  }
7827
7864
  currentToken() {
7828
- const token = this.tokens[this.index] ?? this.tokens[this.tokens.length - 1];
7865
+ const token = this.readToken(this.index) ?? this.readToken(this.tokens.length - 1);
7829
7866
  if (this.lexicalContext.grammar?.strict !== false && token.legacyEscape)
7830
7867
  throw new Error("Legacy escape sequences are not supported in strict mode.");
7831
7868
  if (this.lexicalContext.grammar?.strict !== false && token.type === "numeric" && token.value[0] === "0" && isDecimalDigit3(token.value[1] ?? ""))
@@ -7833,10 +7870,10 @@ var Parser = class {
7833
7870
  return token;
7834
7871
  }
7835
7872
  peekToken(offset) {
7836
- return this.tokens[this.index + offset] ?? this.tokens[this.tokens.length - 1];
7873
+ return this.readToken(this.index + offset) ?? this.readToken(this.tokens.length - 1);
7837
7874
  }
7838
7875
  previousToken() {
7839
- return this.tokens[this.index - 1] ?? this.tokens[0];
7876
+ return this.readToken(this.index - 1) ?? this.readToken(0);
7840
7877
  }
7841
7878
  isExportToken(token) {
7842
7879
  return token.value === "export";
@@ -8170,7 +8207,10 @@ function createTemplateLiteral(token, options, compilation) {
8170
8207
  options.functionContext,
8171
8208
  options.lexicalContext,
8172
8209
  options.source,
8173
- compilation
8210
+ compilation,
8211
+ options.allowImportMeta,
8212
+ options.importSpecifiers,
8213
+ options.conditionalExpressionDepth
8174
8214
  )
8175
8215
  );
8176
8216
  quasiStart = expressionEnd + 1;
@@ -8438,7 +8478,7 @@ function decodeHexEscape(value, start) {
8438
8478
  end: index + 2
8439
8479
  };
8440
8480
  }
8441
- function parseEmbeddedExpression(source, base, functionContext, lexicalContext, fullSource, compilation) {
8481
+ function parseEmbeddedExpression(source, base, functionContext, lexicalContext, fullSource, compilation, allowImportMeta, importSpecifiers, conditionalExpressionDepth) {
8442
8482
  const tokens = tokenize(source, {
8443
8483
  allowRegexLiterals: true,
8444
8484
  allowLegacyNumbers: lexicalContext.grammar?.strict === false,
@@ -8450,7 +8490,17 @@ function parseEmbeddedExpression(source, base, functionContext, lexicalContext,
8450
8490
  start: rebasePosition(token.start, base),
8451
8491
  end: rebasePosition(token.end, base)
8452
8492
  }));
8453
- return new Parser(tokens, fullSource, compilation, functionContext, lexicalContext).parseExpressionOnly();
8493
+ return new Parser(
8494
+ tokens,
8495
+ fullSource,
8496
+ compilation,
8497
+ functionContext,
8498
+ lexicalContext,
8499
+ allowImportMeta,
8500
+ void 0,
8501
+ importSpecifiers,
8502
+ conditionalExpressionDepth
8503
+ ).parseExpressionOnly();
8454
8504
  }
8455
8505
  function findRegexLiteral(node) {
8456
8506
  if (node === null || node === void 0) {
@@ -8718,6 +8768,7 @@ var numericTypedArrayConstructors = {
8718
8768
  };
8719
8769
 
8720
8770
  export {
8771
+ createTrackedProxy,
8721
8772
  internalSymbols,
8722
8773
  sandboxErrorNames,
8723
8774
  sandboxErrorTypes,
@@ -8746,7 +8797,6 @@ export {
8746
8797
  boundIdentifiers,
8747
8798
  containsParameterExpression,
8748
8799
  hoistedVarDeclarations,
8749
- createTrackedProxy,
8750
8800
  CompileScope,
8751
8801
  RegexCompileGuard,
8752
8802
  regexCompiledData,
@@ -8780,4 +8830,3 @@ export {
8780
8830
  Float16Array2 as Float16Array,
8781
8831
  numericTypedArrayConstructors
8782
8832
  };
8783
- //# sourceMappingURL=chunk-LMS5SSTN.js.map