poe-code 14.0.75 → 14.0.77

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 (48) hide show
  1. package/dist/index.js +359 -60
  2. package/dist/index.js.map +4 -4
  3. package/dist/metafile.json +1 -1
  4. package/package.json +1 -1
  5. package/packages/safe-js/dist/chunks/{chunk-EOTY4PCT.js → chunk-EIW7KQCL.js} +335 -60
  6. package/packages/safe-js/dist/chunks/chunk-EIW7KQCL.js.map +7 -0
  7. package/packages/safe-js/dist/chunks/{chunk-BAJI3K4B.js → chunk-P5IREABH.js} +2 -2
  8. package/packages/safe-js/dist/cli.js +2 -2
  9. package/packages/safe-js/dist/core.js +1 -1
  10. package/packages/safe-js/dist/index.js +2 -2
  11. package/packages/safe-js/dist/index.js.map +1 -1
  12. package/packages/safe-js/dist/interp/bigint-operators.d.ts +3 -0
  13. package/packages/safe-js/dist/interp/bigint-operators.js +62 -0
  14. package/packages/safe-js/dist/interp/boxed.d.ts +2 -2
  15. package/packages/safe-js/dist/interp/boxed.js +4 -1
  16. package/packages/safe-js/dist/interp/globals/bigint.d.ts +2 -0
  17. package/packages/safe-js/dist/interp/globals/bigint.js +85 -0
  18. package/packages/safe-js/dist/interp/globals/console-json.js +59 -24
  19. package/packages/safe-js/dist/interp/globals/object-array.js +1 -1
  20. package/packages/safe-js/dist/interp/globals.d.ts +1 -0
  21. package/packages/safe-js/dist/interp/globals.js +2 -0
  22. package/packages/safe-js/dist/interp/host-bridge.js +2 -0
  23. package/packages/safe-js/dist/interp/interpreter.js +59 -12
  24. package/packages/safe-js/dist/interp/methods/number.js +1 -1
  25. package/packages/safe-js/dist/interp/methods/string.js +2 -2
  26. package/packages/safe-js/dist/interp/string-coercion.d.ts +1 -1
  27. package/packages/safe-js/dist/interp/string-coercion.js +8 -3
  28. package/packages/safe-js/dist/interp/values.d.ts +1 -1
  29. package/packages/safe-js/dist/interp/values.js +5 -0
  30. package/packages/safe-js/dist/lint/rules/AS-async-not-needed.js +2 -0
  31. package/packages/safe-js/dist/lint/rules/AS-missing-async.js +2 -0
  32. package/packages/safe-js/dist/lint/rules/known-globals.d.ts +1 -1
  33. package/packages/safe-js/dist/lint/rules/known-globals.js +1 -0
  34. package/packages/safe-js/dist/parse/parser.d.ts +6 -1
  35. package/packages/safe-js/dist/parse/parser.js +8 -0
  36. package/packages/safe-js/dist/parse/tokenizer.js +12 -4
  37. package/packages/safe-js/dist/parse.d.ts +1 -1
  38. package/packages/safe-js/dist/snapshot/bigint.d.ts +1 -0
  39. package/packages/safe-js/dist/snapshot/bigint.js +14 -0
  40. package/packages/safe-js/dist/snapshot/dump-format.js +2 -0
  41. package/packages/safe-js/dist/snapshot/replay-data.d.ts +3 -0
  42. package/packages/safe-js/dist/snapshot/replay-data.js +9 -1
  43. package/packages/safe-js/dist/snapshot/restore.js +2 -0
  44. package/packages/safe-js/dist/snapshot/serialize.d.ts +1 -1
  45. package/packages/safe-js/dist/snapshot/serialize.js +2 -0
  46. package/packages/safe-js/dist/snapshot/validation.js +19 -0
  47. package/packages/safe-js/dist/chunks/chunk-EOTY4PCT.js.map +0 -7
  48. /package/packages/safe-js/dist/chunks/{chunk-BAJI3K4B.js.map → chunk-P5IREABH.js.map} +0 -0
@@ -1,4 +1,5 @@
1
1
  import { promiseReplayContext } from "./promise-replay.js";
2
+ import { bigIntOperation } from "./bigint-operators.js";
2
3
  import { accessorAdapter, readPropertyDescriptor, writePropertyDescriptor } from "./accessors.js";
3
4
  import { deleteHostObjectMember, getHostObjectKeys, getHostObjectMember, hasHostObjectMember, isGuestHostObject, setHostObjectMember } from "./host-capabilities.js";
4
5
  import { propertyFunctionName, toPropertyKey } from "./property-key.js";
@@ -51,6 +52,17 @@ const dispatchTable = {
51
52
  ArrowFunctionExpression: evaluateArrowFunction,
52
53
  AwaitExpression: evaluateAwait,
53
54
  BinaryExpression: evaluateBinaryExpression,
55
+ BigIntLiteral: async (node, context) => {
56
+ const allocation = {};
57
+ context.budget.visitNode(node.value.length);
58
+ context.budget.setRetainedDataUsage(allocation, node.value.length);
59
+ try {
60
+ return { kind: "normal", hasValue: true, value: BigInt(node.value) };
61
+ }
62
+ finally {
63
+ context.budget.setRetainedDataUsage(allocation, 0);
64
+ }
65
+ },
54
66
  BlockStatement: evaluateBlockStatement,
55
67
  BooleanLiteral: evaluatePrimitiveLiteral,
56
68
  CallExpression: evaluateCallExpression,
@@ -1805,8 +1817,11 @@ async function evaluateIdentifierUpdateExpression(node, context) {
1805
1817
  error: createError("UNBOUND_IDENTIFIER", node.argument, `Identifier '${node.argument.name}' is not defined.`)
1806
1818
  };
1807
1819
  }
1808
- const current = toNumber(await toNumericPrimitive(binding.value, context));
1809
- const next = node.operator === "++" ? current + 1 : current - 1;
1820
+ const primitive = await toNumericPrimitive(binding.value, context);
1821
+ const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
1822
+ const next = typeof current === "bigint"
1823
+ ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget)
1824
+ : node.operator === "++" ? current + 1 : current - 1;
1810
1825
  context.scope.assign(node.argument.name, next);
1811
1826
  return {
1812
1827
  kind: "normal",
@@ -1823,8 +1838,11 @@ async function evaluateMemberUpdateExpression(node, context) {
1823
1838
  throw new TypeError("Cannot update properties of null or undefined.");
1824
1839
  }
1825
1840
  const property = await toPropertyKey(member.property, context.budget, createCoercionContext(context));
1826
- const current = toNumber(await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === undefined ? member.object : member.superReceiver.value), context));
1827
- const next = node.operator === "++" ? current + 1 : current - 1;
1841
+ const primitive = await toNumericPrimitive(await getPropertyValue(member.object, property, context, member.superReceiver === undefined ? member.object : member.superReceiver.value), context);
1842
+ const current = typeof primitive === "bigint" ? primitive : toNumber(primitive);
1843
+ const next = typeof current === "bigint"
1844
+ ? bigIntOperation(node.operator === "++" ? "+" : "-", current, 1n, context.budget)
1845
+ : node.operator === "++" ? current + 1 : current - 1;
1828
1846
  if (member.superReceiver === undefined)
1829
1847
  await setSandboxProperty(member.object, property, next, context.budget, true, createCoercionContext(context));
1830
1848
  else
@@ -1858,7 +1876,7 @@ function getPropertyValue(target, property, context, receiver = target) {
1858
1876
  return readPropertyDescriptor(descriptor, receiver, createCoercionContext(context), true);
1859
1877
  if (isSandboxRegExpIterator(target))
1860
1878
  return getRegExpIteratorMember(property, context.budget);
1861
- if (typeof target === "symbol") {
1879
+ if (typeof target === "symbol" || typeof target === "bigint") {
1862
1880
  const prototype = getBoxedPrototype(target, context.budget);
1863
1881
  return prototype === undefined ? undefined : getPropertyValue(prototype, property, context, receiver);
1864
1882
  }
@@ -2041,6 +2059,8 @@ async function evaluateObjectPropertyKey(node, context) {
2041
2059
  return evaluateMemberProperty(node.key, context);
2042
2060
  }
2043
2061
  function getStaticPropertyName(node) {
2062
+ if (node.type === "BigIntLiteral")
2063
+ return BigInt(node.value).toString();
2044
2064
  if (node.type === "Identifier") {
2045
2065
  return node.name;
2046
2066
  }
@@ -2074,7 +2094,7 @@ async function evaluateMemberCallExpression(node, context) {
2074
2094
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
2075
2095
  if (Array.isArray(member.object) && hasExplicitSandboxPrototype(member.object))
2076
2096
  return evaluateResolvedCallExpression(node, await getPropertyValue(member.object, member.property, context), context, member.object);
2077
- if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "boolean" || typeof member.object === "symbol") &&
2097
+ if ((typeof member.object === "string" || typeof member.object === "number" || typeof member.object === "bigint" || typeof member.object === "boolean" || typeof member.object === "symbol") &&
2078
2098
  getBoxedPrototype(member.object, context.budget) !== undefined) {
2079
2099
  if (isDefaultBoxedMethod(member.object, member.property, context.budget)) {
2080
2100
  if (typeof member.object === "string" && isStringMethodName(member.property))
@@ -2259,10 +2279,14 @@ async function applyUnaryOperator(operator, value, context) {
2259
2279
  return undefined;
2260
2280
  case "+":
2261
2281
  return toNumber(await toNumericPrimitive(value, context));
2262
- case "-":
2263
- return -toNumber(await toNumericPrimitive(value, context));
2264
- case "~":
2265
- return ~toNumber(await toNumericPrimitive(value, context));
2282
+ case "-": {
2283
+ const primitive = await toNumericPrimitive(value, context);
2284
+ return typeof primitive === "bigint" ? bigIntOperation("-", 0n, primitive, context.budget) : -toNumber(primitive);
2285
+ }
2286
+ case "~": {
2287
+ const primitive = await toNumericPrimitive(value, context);
2288
+ return typeof primitive === "bigint" ? bigIntOperation("^", primitive, -1n, context.budget) : ~toNumber(primitive);
2289
+ }
2266
2290
  }
2267
2291
  }
2268
2292
  function describeTypeofValue(value) {
@@ -2278,6 +2302,12 @@ function isTruthy(value) {
2278
2302
  return Boolean(value);
2279
2303
  }
2280
2304
  function applyBinaryOperator(node, left, right, context) {
2305
+ if ((typeof left === "bigint" || typeof right === "bigint") &&
2306
+ ["-", "*", "/", "%", "**", "&", "|", "^", "<<", ">>", ">>>"].includes(node.operator)) {
2307
+ if (typeof left !== "bigint" || typeof right !== "bigint")
2308
+ throw new TypeError("Cannot mix BigInt and other numeric types.");
2309
+ return bigIntOperation(node.operator, left, right, context.budget);
2310
+ }
2281
2311
  switch (node.operator) {
2282
2312
  case "+":
2283
2313
  return applyAdditionOperator(left, right, context);
@@ -2410,6 +2440,11 @@ async function applyCompoundAssignmentOperator(operator, left, right, context) {
2410
2440
  if (convertingObject)
2411
2441
  convertedLeft = left;
2412
2442
  right = await toNumericPrimitive(right, context, operator === "+=" ? "default" : "number");
2443
+ if (operator !== "+=" && (typeof left === "bigint" || typeof right === "bigint")) {
2444
+ if (typeof left !== "bigint" || typeof right !== "bigint")
2445
+ throw new TypeError("Cannot mix BigInt and other numeric types.");
2446
+ return bigIntOperation(operator.slice(0, -1), left, right, context.budget);
2447
+ }
2413
2448
  switch (operator) {
2414
2449
  case "+=":
2415
2450
  return applyAdditionOperator(left, right, context);
@@ -2447,6 +2482,11 @@ function applyAdditionOperator(left, right, context) {
2447
2482
  if (typeof leftPrimitive === "string" || typeof rightPrimitive === "string") {
2448
2483
  return context.budget.allocateString(toString(leftPrimitive) + toString(rightPrimitive));
2449
2484
  }
2485
+ if (typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint") {
2486
+ if (typeof leftPrimitive !== "bigint" || typeof rightPrimitive !== "bigint")
2487
+ throw new TypeError("Cannot mix BigInt and other numeric types.");
2488
+ return bigIntOperation("+", leftPrimitive, rightPrimitive, context.budget);
2489
+ }
2450
2490
  return toNumber(leftPrimitive) + toNumber(rightPrimitive);
2451
2491
  }
2452
2492
  function compareRelational(left, right, operator) {
@@ -2464,8 +2504,9 @@ function compareRelational(left, right, operator) {
2464
2504
  return leftPrimitive >= rightPrimitive;
2465
2505
  }
2466
2506
  }
2467
- const leftNumber = toNumber(leftPrimitive);
2468
- const rightNumber = toNumber(rightPrimitive);
2507
+ const hasBigInt = typeof leftPrimitive === "bigint" || typeof rightPrimitive === "bigint";
2508
+ const leftNumber = typeof leftPrimitive === "bigint" || (hasBigInt && typeof leftPrimitive === "string") ? leftPrimitive : toNumber(leftPrimitive);
2509
+ const rightNumber = typeof rightPrimitive === "bigint" || (hasBigInt && typeof rightPrimitive === "string") ? rightPrimitive : toNumber(rightPrimitive);
2469
2510
  switch (operator) {
2470
2511
  case "<":
2471
2512
  return leftNumber < rightNumber;
@@ -2478,6 +2519,8 @@ function compareRelational(left, right, operator) {
2478
2519
  }
2479
2520
  }
2480
2521
  function isLooselyEqual(left, right) {
2522
+ if (typeof left === "bigint" || typeof right === "bigint")
2523
+ return left == right;
2481
2524
  const leftType = getCoercionType(left);
2482
2525
  const rightType = getCoercionType(right);
2483
2526
  if (leftType === rightType) {
@@ -2510,6 +2553,8 @@ function isPrimitiveCoercionType(type) {
2510
2553
  return type !== "object";
2511
2554
  }
2512
2555
  function getCoercionType(value) {
2556
+ if (typeof value === "bigint")
2557
+ return "bigint";
2513
2558
  if (typeof value === "symbol")
2514
2559
  return "symbol";
2515
2560
  if (value === null) {
@@ -2544,6 +2589,8 @@ async function toNumericPrimitive(value, context, hint = "number") {
2544
2589
  throw new TypeError("Expected a sandbox value.");
2545
2590
  }
2546
2591
  function toNumber(value) {
2592
+ if (typeof value === "bigint")
2593
+ throw new TypeError("Cannot convert a BigInt value to a number");
2547
2594
  if (typeof value === "symbol")
2548
2595
  throw new TypeError("Cannot convert a Symbol value to a number");
2549
2596
  if (isSandboxDate(value))
@@ -30,7 +30,7 @@ export function callNumberMethod(value, methodName, args, budget, context) {
30
30
  if (argument !== null && typeof argument === "object") {
31
31
  return formatObjectArgument(value, methodName, argument, budget, context);
32
32
  }
33
- return formatNumber(value, methodName, argument === undefined ? undefined : Number(argument), budget);
33
+ return formatNumber(value, methodName, argument === undefined ? undefined : +argument, budget);
34
34
  }
35
35
  async function formatObjectArgument(value, methodName, argument, budget, context) {
36
36
  const retainedArgument = {};
@@ -852,10 +852,10 @@ function splitString(value, separator, limit) {
852
852
  return split.call(value, separator, limit);
853
853
  }
854
854
  function asNumber(value) {
855
- return Number(value);
855
+ return +value;
856
856
  }
857
857
  function asNumberOrUndefined(value) {
858
- return value === undefined ? undefined : Number(value);
858
+ return value === undefined ? undefined : +value;
859
859
  }
860
860
  function asStringOrUndefined(value) {
861
861
  return value === undefined ? undefined : String(value);
@@ -1,6 +1,6 @@
1
1
  import type { Budget } from "./budget.js";
2
2
  import { type SandboxCallContext, type SandboxPrimitive, type SandboxValue } from "./values.js";
3
- export declare function sandboxNumber(value: SandboxValue, budget: Budget, context?: SandboxCallContext): number | Promise<number>;
3
+ export declare function sandboxNumber(value: SandboxValue, budget: Budget, context?: SandboxCallContext, allowBigInt?: boolean): number | Promise<number>;
4
4
  export declare function sandboxString(value: SandboxValue, budget: Budget, context?: SandboxCallContext, joining?: Set<object>): string | Promise<string>;
5
5
  export declare function joinSandboxArray(value: SandboxValue & object, length: number, separator: string, budget: Budget, context?: SandboxCallContext, joining?: Set<object>): Promise<string>;
6
6
  export declare function objectToPrimitive(value: SandboxValue & object, budget: Budget, context: SandboxCallContext | undefined, joining: Set<object>, hint: "string" | "number" | "default", ordinary?: boolean): Promise<SandboxPrimitive>;
@@ -17,13 +17,18 @@ import { isSandboxClosure, isSandboxPromise, isSandboxMap, isSandboxSet, isSandb
17
17
  const defaultStringHook = Symbol("defaultStringHook");
18
18
  const defaultValueHook = Symbol("defaultValueHook");
19
19
  const joiningArrays = new WeakSet();
20
- export function sandboxNumber(value, budget, context) {
20
+ export function sandboxNumber(value, budget, context, allowBigInt = false) {
21
+ const convert = (primitive) => {
22
+ if (typeof primitive === "bigint" && !allowBigInt)
23
+ throw new TypeError("Cannot convert a BigInt value to a number");
24
+ return Number(primitive);
25
+ };
21
26
  if (value === null || typeof value !== "object") {
22
27
  if (typeof value === "function")
23
28
  throw new TypeError("Expected a sandbox value.");
24
- return Number(value);
29
+ return convert(value);
25
30
  }
26
- return objectToPrimitive(value, budget, context, new Set(), "number").then(Number);
31
+ return objectToPrimitive(value, budget, context, new Set(), "number").then(convert);
27
32
  }
28
33
  export function sandboxString(value, budget, context, joining = new Set()) {
29
34
  if (typeof value === "symbol")
@@ -15,7 +15,7 @@ declare const sandboxPromiseBrand: unique symbol;
15
15
  declare const sandboxRegexBrand: unique symbol;
16
16
  declare const sandboxRegexPattern: unique symbol;
17
17
  declare const sandboxRetainedValues: unique symbol;
18
- export type SandboxPrimitive = string | number | boolean | symbol | null | undefined;
18
+ export type SandboxPrimitive = string | number | bigint | boolean | symbol | null | undefined;
19
19
  export type SandboxValue = SandboxPrimitive | Date | Float32Array | SandboxObject | SandboxArray | SandboxClosure | SandboxGenerator | SandboxCollectionIterator | SandboxRegExpIterator | SandboxMap | SandboxSet | SandboxPromise | SandboxRegex;
20
20
  export type SandboxObject = {
21
21
  [key: string]: SandboxValue;
@@ -299,6 +299,10 @@ export function measureSandboxData(values, options = {}) {
299
299
  const seenSymbols = new Set();
300
300
  let usage = 0;
301
301
  const visit = (value, depth = 0) => {
302
+ if (typeof value === "bigint") {
303
+ usage += value.toString(16).length;
304
+ return;
305
+ }
302
306
  if (typeof value === "symbol") {
303
307
  if (!seenSymbols.has(value)) {
304
308
  seenSymbols.add(value);
@@ -994,6 +998,7 @@ function isSandboxPrimitive(value) {
994
998
  value === undefined ||
995
999
  typeof value === "string" ||
996
1000
  typeof value === "number" ||
1001
+ typeof value === "bigint" ||
997
1002
  typeof value === "boolean" ||
998
1003
  typeof value === "symbol");
999
1004
  }
@@ -229,6 +229,7 @@ class ASAsyncNotNeededScanner {
229
229
  case "MetaProperty":
230
230
  case "NullLiteral":
231
231
  case "NumericLiteral":
232
+ case "BigIntLiteral":
232
233
  case "RegexLiteral":
233
234
  case "StringLiteral":
234
235
  case "UndefinedLiteral":
@@ -539,6 +540,7 @@ function expressionContainsAwait(node) {
539
540
  case "MetaProperty":
540
541
  case "NullLiteral":
541
542
  case "NumericLiteral":
543
+ case "BigIntLiteral":
542
544
  case "RegexLiteral":
543
545
  case "StringLiteral":
544
546
  case "ThisExpression":
@@ -213,6 +213,7 @@ class ASMissingAsyncScanner {
213
213
  case "MetaProperty":
214
214
  case "NullLiteral":
215
215
  case "NumericLiteral":
216
+ case "BigIntLiteral":
216
217
  case "RegexLiteral":
217
218
  case "StringLiteral":
218
219
  case "UndefinedLiteral":
@@ -509,6 +510,7 @@ function expressionContainsAwait(node) {
509
510
  case "MetaProperty":
510
511
  case "NullLiteral":
511
512
  case "NumericLiteral":
513
+ case "BigIntLiteral":
512
514
  case "RegexLiteral":
513
515
  case "StringLiteral":
514
516
  case "ThisExpression":
@@ -1 +1 @@
1
- export declare const KNOWN_RUNTIME_GLOBALS: readonly ["AggregateError", "Array", "Boolean", "Date", "Error", "Infinity", "isFinite", "isNaN", "JSON", "Map", "Float32Array", "Math", "NaN", "Number", "Object", "parseFloat", "parseInt", "Promise", "RangeError", "ReferenceError", "RegExp", "Set", "String", "Symbol", "structuredClone", "SyntaxError", "TypeError", "console"];
1
+ export declare const KNOWN_RUNTIME_GLOBALS: readonly ["AggregateError", "Array", "Boolean", "BigInt", "Date", "Error", "Infinity", "isFinite", "isNaN", "JSON", "Map", "Float32Array", "Math", "NaN", "Number", "Object", "parseFloat", "parseInt", "Promise", "RangeError", "ReferenceError", "RegExp", "Set", "String", "Symbol", "structuredClone", "SyntaxError", "TypeError", "console"];
@@ -2,6 +2,7 @@ export const KNOWN_RUNTIME_GLOBALS = [
2
2
  "AggregateError",
3
3
  "Array",
4
4
  "Boolean",
5
+ "BigInt",
5
6
  "Date",
6
7
  "Error",
7
8
  "Infinity",
@@ -26,6 +26,11 @@ export type NumericLiteral = BaseNode & {
26
26
  raw: string;
27
27
  value: number;
28
28
  };
29
+ export type BigIntLiteral = BaseNode & {
30
+ type: "BigIntLiteral";
31
+ raw: string;
32
+ value: string;
33
+ };
29
34
  export type StringLiteral = BaseNode & {
30
35
  type: "StringLiteral";
31
36
  raw: string;
@@ -390,7 +395,7 @@ export type ArrowFunctionExpression = BaseNode & {
390
395
  params: Array<AssignmentPattern | ArrayPattern | Identifier | ObjectPattern | RestElement>;
391
396
  };
392
397
  export type FunctionNode = ArrowFunctionExpression | FunctionDeclaration | FunctionExpression;
393
- export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | ClassExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NewTargetExpression | NullLiteral | NumericLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | SuperExpression | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
398
+ export type Expression = ArrowFunctionExpression | AssignmentExpression | ArrayExpression | AwaitExpression | BinaryExpression | BooleanLiteral | CallExpression | ConditionalExpression | ClassExpression | FunctionExpression | Identifier | LogicalExpression | MemberExpression | MetaProperty | NewExpression | NewTargetExpression | NullLiteral | NumericLiteral | BigIntLiteral | ObjectExpression | RegexLiteral | SequenceExpression | StringLiteral | SuperExpression | TaggedTemplateExpression | TemplateLiteral | ThisExpression | UnaryExpression | UpdateExpression | UndefinedLiteral | YieldExpression;
394
399
  export type ParseResult = Expression | Statement;
395
400
  export declare function parse(source: string, filename?: string, owner?: CompileOwner): ParseResult;
396
401
  export declare function parseModule(source: string, filename?: string, owner?: CompileOwner): Module;
@@ -3082,6 +3082,7 @@ function findImportMetaAssignmentInNode(node) {
3082
3082
  case "BooleanLiteral":
3083
3083
  case "NullLiteral":
3084
3084
  case "NumericLiteral":
3085
+ case "BigIntLiteral":
3085
3086
  case "StringLiteral":
3086
3087
  case "ThisExpression":
3087
3088
  case "RegexLiteral":
@@ -3159,6 +3160,13 @@ function isYieldArgumentTerminator(value) {
3159
3160
  return value === ";" || value === "}" || value === ")" || value === "]" || value === ",";
3160
3161
  }
3161
3162
  function createNumericLiteral(token) {
3163
+ if (token.value.endsWith("n"))
3164
+ return {
3165
+ type: "BigIntLiteral",
3166
+ raw: token.value,
3167
+ value: token.value.slice(0, -1).replaceAll("_", ""),
3168
+ span: createTokenSpan(token)
3169
+ };
3162
3170
  return {
3163
3171
  type: "NumericLiteral",
3164
3172
  raw: token.value,
@@ -480,7 +480,8 @@ class Lexer {
480
480
  this.advance();
481
481
  this.advance();
482
482
  this.consumeDigitsForBase(isHexDigit, "hexadecimal");
483
- this.rejectBigIntSuffix();
483
+ if (this.currentChar() === "n")
484
+ this.advance();
484
485
  this.rejectInvalidNumericLiteralContinuation();
485
486
  return this.source.slice(start.offset, this.index);
486
487
  }
@@ -488,7 +489,8 @@ class Lexer {
488
489
  this.advance();
489
490
  this.advance();
490
491
  this.consumeDigitsForBase(isBinaryDigit, "binary");
491
- this.rejectBigIntSuffix();
492
+ if (this.currentChar() === "n")
493
+ this.advance();
492
494
  this.rejectInvalidNumericLiteralContinuation();
493
495
  return this.source.slice(start.offset, this.index);
494
496
  }
@@ -496,7 +498,8 @@ class Lexer {
496
498
  this.advance();
497
499
  this.advance();
498
500
  this.consumeDigitsForBase(isOctalDigit, "octal");
499
- this.rejectBigIntSuffix();
501
+ if (this.currentChar() === "n")
502
+ this.advance();
500
503
  this.rejectInvalidNumericLiteralContinuation();
501
504
  return this.source.slice(start.offset, this.index);
502
505
  }
@@ -512,6 +515,11 @@ class Lexer {
512
515
  }
513
516
  }
514
517
  this.consumeDecimalDigits();
518
+ if (this.currentChar() === "n") {
519
+ this.advance();
520
+ this.rejectInvalidNumericLiteralContinuation();
521
+ return this.source.slice(start.offset, this.index);
522
+ }
515
523
  if (this.currentChar() === "." && (this.peekChar(1) !== "." || this.peekChar(2) !== ".")) {
516
524
  this.advance();
517
525
  this.consumeOptionalDecimalDigits();
@@ -610,7 +618,7 @@ class Lexer {
610
618
  }
611
619
  rejectBigIntSuffix() {
612
620
  if (this.currentChar() === "n") {
613
- this.syntaxError("BigInt not supported", this.position());
621
+ this.syntaxError("BigInt literals cannot contain a fraction or exponent", this.position());
614
622
  }
615
623
  }
616
624
  rejectInvalidNumericLiteralContinuation() {
@@ -1,4 +1,4 @@
1
1
  import { type ParseResult as ParsedNode } from "./parse/parser.js";
2
2
  export { DisallowedSyntaxError } from "./parse/parser.js";
3
3
  export declare const parse: (source: string, filename?: string) => ParsedNode;
4
- export type { ArrayPattern, ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AssignmentPattern, AssignmentProperty, AwaitExpression, BinaryExpression, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ClassBody, ClassDeclaration, ClassElement, ClassExpression, ClassNode, ConditionalExpression, ContinueStatement, DoWhileStatement, EmptyStatement, Expression, ExpressionStatement, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, LogicalExpression, MemberExpression, MetaProperty, NewExpression, NewTargetExpression, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ParseResult, PatternTarget, Property, RegexLiteral, RestElement, ReturnStatement, SequenceExpression, SourceSpan, SpreadElement, Statement, StringLiteral, SuperExpression, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UndefinedLiteral, UpdateExpression, UpdateTarget, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement } from "./parse/parser.js";
4
+ export type { ArrayPattern, ArrayExpression, ArrowFunctionExpression, AssignmentExpression, AssignmentPattern, AssignmentProperty, AwaitExpression, BinaryExpression, BigIntLiteral, BlockStatement, BooleanLiteral, BreakStatement, CallExpression, CatchClause, ClassBody, ClassDeclaration, ClassElement, ClassExpression, ClassNode, ConditionalExpression, ContinueStatement, DoWhileStatement, EmptyStatement, Expression, ExpressionStatement, ExportDefaultDeclaration, ExportNamedDeclaration, ImportDeclaration, ImportDefaultSpecifier, ImportNamespaceSpecifier, ImportSpecifier, ForInStatement, ForOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, LogicalExpression, MemberExpression, MetaProperty, NewExpression, NewTargetExpression, NullLiteral, NumericLiteral, ObjectExpression, ObjectPattern, ParseResult, PatternTarget, Property, RegexLiteral, RestElement, ReturnStatement, SequenceExpression, SourceSpan, SpreadElement, Statement, StringLiteral, SuperExpression, SwitchCase, SwitchStatement, TaggedTemplateExpression, TemplateElement, TemplateLiteral, ThisExpression, ThrowStatement, TryStatement, UnaryExpression, UndefinedLiteral, UpdateExpression, UpdateTarget, VariableDeclaration, VariableDeclarationKind, VariableDeclarator, WhileStatement } from "./parse/parser.js";
@@ -0,0 +1 @@
1
+ export declare function validateBigIntData(value: unknown): asserts value is string;
@@ -0,0 +1,14 @@
1
+ export function validateBigIntData(value) {
2
+ if (typeof value !== "string" || value.length === 0)
3
+ throw new TypeError("Invalid BigInt snapshot value.");
4
+ if (value === "0")
5
+ return;
6
+ const start = value[0] === "-" ? 1 : 0;
7
+ if (start === value.length || value[start] === "0")
8
+ throw new TypeError("Invalid BigInt snapshot value.");
9
+ for (let index = start; index < value.length; index++) {
10
+ const code = value.charCodeAt(index);
11
+ if (code < 48 || code > 57)
12
+ throw new TypeError("Invalid BigInt snapshot value.");
13
+ }
14
+ }
@@ -58,6 +58,8 @@ function createDumpFile(snapshot) {
58
58
  return dumped;
59
59
  }
60
60
  function serializeDumpValue(value, path, state) {
61
+ if (typeof value === "bigint")
62
+ return { kind: "bigint", value: String(value) };
61
63
  if (typeof value === "symbol")
62
64
  return serializeSymbol(value, state.heapIds, state.heap);
63
65
  if (value === null || typeof value === "string" || typeof value === "boolean") {
@@ -8,6 +8,9 @@ import { type SandboxClosure, type SandboxPromise, type SandboxValue } from "../
8
8
  import { type SerializedArguments } from "./arguments.js";
9
9
  type Atom = boolean | null | number | string | {
10
10
  tag: "undefined";
11
+ } | {
12
+ tag: "bigint";
13
+ value: string;
11
14
  } | {
12
15
  tag: "number";
13
16
  value: "NaN" | "Infinity" | "-Infinity" | "-0";
@@ -1,4 +1,5 @@
1
1
  import { MAX_DATA_DEPTH } from "../graph-depth.js";
2
+ import { validateBigIntData } from "./bigint.js";
2
3
  import { serializeRegexProperties, restoreRegexProperties } from "./regexp-properties.js";
3
4
  import { wellKnownSymbols } from "../interp/symbols.js";
4
5
  import { symbolData, serializeSymbolProperties } from "./symbols.js";
@@ -29,6 +30,8 @@ export function encodeReplayData(value, options = {}) {
29
30
  return entry;
30
31
  if (entry === undefined)
31
32
  return { tag: "undefined" };
33
+ if (typeof entry === "bigint")
34
+ return { tag: "bigint", value: String(entry) };
32
35
  if (typeof entry === "symbol") {
33
36
  let id = symbols.get(entry);
34
37
  if (id === undefined) {
@@ -243,6 +246,11 @@ export function decodeReplayData(input, options = {}, parent) {
243
246
  }
244
247
  if (own(atom, "tag") === "undefined")
245
248
  return undefined;
249
+ if (own(atom, "tag") === "bigint") {
250
+ const value = own(atom, "value");
251
+ validateBigIntData(value);
252
+ return BigInt(value);
253
+ }
246
254
  if (atom.tag === "number") {
247
255
  switch (own(atom, "value")) {
248
256
  case "NaN":
@@ -328,7 +336,7 @@ export function decodeReplayData(input, options = {}, parent) {
328
336
  own(record(nodes[Number(payloadRecord.id)]), "kind") === "symbol";
329
337
  if (typeof payload !== "number" && typeof payload !== "string" && typeof payload !== "boolean" &&
330
338
  !symbolReference &&
331
- (payload === null || typeof payload !== "object" || own(record(payload), "tag") !== "number"))
339
+ (payload === null || typeof payload !== "object" || !["number", "bigint"].includes(String(own(record(payload), "tag")))))
332
340
  throw new TypeError("Invalid boxed primitive payload.");
333
341
  const result = createSandboxBox(child(payload));
334
342
  restored.set(id, result);
@@ -234,6 +234,8 @@ function deserializeValue(value, state) {
234
234
  if (Array.isArray(value)) {
235
235
  return value.map((entry) => deserializeValue(entry, state));
236
236
  }
237
+ if (value.kind === "bigint" && typeof value.value === "string")
238
+ return BigInt(value.value);
237
239
  if (isSerializedUndefinedValue(value)) {
238
240
  return undefined;
239
241
  }
@@ -105,7 +105,7 @@ export type RuntimePromiseValue = {
105
105
  id: SnapshotId;
106
106
  promise?: Promise<unknown>;
107
107
  };
108
- export type RuntimeSnapshotValue = symbol | SandboxBox | Date | Float32Array | boolean | null | number | string | undefined | RuntimeClosureValue | SandboxGenerator | SandboxCollectionIterator | SandboxRegExpIterator | RuntimePromiseValue | SandboxMap | SandboxRegex | SandboxSet | RuntimeSnapshotValue[] | {
108
+ export type RuntimeSnapshotValue = bigint | symbol | SandboxBox | Date | Float32Array | boolean | null | number | string | undefined | RuntimeClosureValue | SandboxGenerator | SandboxCollectionIterator | SandboxRegExpIterator | RuntimePromiseValue | SandboxMap | SandboxRegex | SandboxSet | RuntimeSnapshotValue[] | {
109
109
  [key: string]: RuntimeSnapshotValue;
110
110
  };
111
111
  export type RuntimeScopeFrame = {
@@ -116,6 +116,8 @@ function serializeValue(value, path, state) {
116
116
  : "-Infinity"
117
117
  };
118
118
  }
119
+ if (typeof value === "bigint")
120
+ return { kind: "bigint", value: String(value) };
119
121
  if (Array.isArray(value)) {
120
122
  const reference = serializeHeapReference(value, path, state);
121
123
  if (reference !== undefined) {
@@ -1,4 +1,5 @@
1
1
  import { replaceErrorStack, sandboxErrorNames } from "../error/shape.js";
2
+ import { validateBigIntData } from "./bigint.js";
2
3
  import { validateRegexProperties } from "./regexp-properties.js";
3
4
  import { wellKnownSymbols } from "../interp/symbols.js";
4
5
  import { types } from "node:util";
@@ -357,6 +358,15 @@ function validateValue(value, path, depth, state) {
357
358
  }
358
359
  function validateTaggedValue(record, path, state) {
359
360
  switch (record.kind) {
361
+ case "bigint":
362
+ requireString(record.value, `${path}.value`, state.limits);
363
+ try {
364
+ validateBigIntData(record.value);
365
+ }
366
+ catch {
367
+ fail("invalidValue", `${path}.value`, "invalid BigInt value");
368
+ }
369
+ return;
360
370
  case "undefined":
361
371
  return;
362
372
  case "number":
@@ -547,6 +557,15 @@ function validateBoxedRecord(record, path, heap) {
547
557
  if (typeof value === "number" || typeof value === "string" || typeof value === "boolean")
548
558
  return;
549
559
  const number = requireRecord(value, `${path}.value`);
560
+ if (number.kind === "bigint") {
561
+ try {
562
+ validateBigIntData(number.value);
563
+ }
564
+ catch {
565
+ fail("invalidValue", `${path}.value`, "invalid boxed BigInt payload");
566
+ }
567
+ return;
568
+ }
550
569
  if (number.kind === "ref") {
551
570
  const id = requireSafeInteger(number.id, `${path}.value.id`, 1);
552
571
  const target = requireRecord(heap[String(id)], `${path}.value`);