poe-code 13.0.8 → 13.0.9

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.
@@ -22,7 +22,7 @@ import {
22
22
  resolveFsConfig,
23
23
  splitFrontmatter,
24
24
  withBrokenPipeGuard
25
- } from "./chunks/chunk-ES7OFCHQ.js";
25
+ } from "./chunks/chunk-SUOXSVL2.js";
26
26
  import {
27
27
  Budget,
28
28
  SandboxError,
@@ -34,7 +34,7 @@ import {
34
34
  replaceErrorStack,
35
35
  restore,
36
36
  run
37
- } from "./chunks/chunk-YVTMQWCX.js";
37
+ } from "./chunks/chunk-XY2A4W6O.js";
38
38
  import "./chunks/chunk-ZRX5HT5L.js";
39
39
  import "./chunks/chunk-WVN5MMDR.js";
40
40
  import "./chunks/chunk-4YIDX44G.js";
@@ -3,7 +3,7 @@ import {
3
3
  createReplayableRandom,
4
4
  lint,
5
5
  run
6
- } from "./chunks/chunk-YVTMQWCX.js";
6
+ } from "./chunks/chunk-XY2A4W6O.js";
7
7
  import "./chunks/chunk-4YIDX44G.js";
8
8
  export {
9
9
  Budget,
@@ -29,7 +29,7 @@ import {
29
29
  runWithSpawnUsageAccumulator,
30
30
  splitFrontmatter,
31
31
  supportsSpawnMode
32
- } from "./chunks/chunk-ES7OFCHQ.js";
32
+ } from "./chunks/chunk-SUOXSVL2.js";
33
33
  import {
34
34
  Budget,
35
35
  FileSnapshotBackend,
@@ -51,7 +51,7 @@ import {
51
51
  registerPendingHostCallPolicy,
52
52
  restore,
53
53
  run
54
- } from "./chunks/chunk-YVTMQWCX.js";
54
+ } from "./chunks/chunk-XY2A4W6O.js";
55
55
  import "./chunks/chunk-ZRX5HT5L.js";
56
56
  import "./chunks/chunk-WVN5MMDR.js";
57
57
  import "./chunks/chunk-4YIDX44G.js";
@@ -2,7 +2,7 @@ import type { Expression } from "../../parse.js";
2
2
  import { Budget } from "../budget.js";
3
3
  import { CompileScope } from "../regex/compile-guard.js";
4
4
  import { type SandboxClosure, type SandboxValue } from "../values.js";
5
- type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "trim" | "trimEnd" | "trimStart";
5
+ type StringMethodName = "at" | "charAt" | "charCodeAt" | "codePointAt" | "concat" | "endsWith" | "includes" | "indexOf" | "isWellFormed" | "lastIndexOf" | "localeCompare" | "match" | "matchAll" | "normalize" | "padEnd" | "padStart" | "repeat" | "replace" | "replaceAll" | "slice" | "search" | "split" | "startsWith" | "substr" | "substring" | "toLowerCase" | "toUpperCase" | "trim" | "trimEnd" | "trimStart";
6
6
  export declare function getStringMember(value: string, property: string | number, budget: Budget): SandboxValue | undefined;
7
7
  export declare function isStringMethodName(property: string | number): property is StringMethodName;
8
8
  export declare function validateStringMethodArguments(_methodName: StringMethodName, _args: readonly Expression[]): void;
@@ -11,6 +11,7 @@ const stringMethodNames = new Set([
11
11
  "endsWith",
12
12
  "includes",
13
13
  "indexOf",
14
+ "isWellFormed",
14
15
  "lastIndexOf",
15
16
  "localeCompare",
16
17
  "match",
@@ -48,6 +49,7 @@ export function getStringMember(value, property, budget) {
48
49
  sandbox: true,
49
50
  name: `String#${property}`,
50
51
  ...(property === "localeCompare" ? { length: 1 } : {}),
52
+ ...(property === "isWellFormed" ? { length: 0 } : {}),
51
53
  call: (args, context) => callStringMethod(value, property, args, budget, context === undefined
52
54
  ? undefined
53
55
  : async (closure, closureArgs) => await closure.call(closureArgs, { ...context, thisValue: undefined }), context?.compilation)
@@ -65,6 +67,22 @@ export function isStringMethodName(property) {
65
67
  }
66
68
  export function validateStringMethodArguments(_methodName, _args) { }
67
69
  export function callStringMethod(value, methodName, args, budget, callClosure = async (closure, closureArgs) => await closure.call(closureArgs), parent) {
70
+ if (methodName === "isWellFormed") {
71
+ for (let index = 0; index < value.length; index++) {
72
+ const codeUnit = value.charCodeAt(index);
73
+ if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) {
74
+ const nextCodeUnit = value.charCodeAt(index + 1);
75
+ if (!(nextCodeUnit >= 0xdc00 && nextCodeUnit <= 0xdfff)) {
76
+ return false;
77
+ }
78
+ index++;
79
+ }
80
+ else if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) {
81
+ return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
68
86
  if (methodName === "replace" || methodName === "replaceAll") {
69
87
  return callReplaceLikeMethod(value, methodName, args, budget, callClosure);
70
88
  }
@@ -905,7 +905,8 @@ function isExpressionEndingPunctuator(value) {
905
905
  return value === ")" || value === "]" || value === "}" || value === "++" || value === "--";
906
906
  }
907
907
  function matchPunctuator(source, index) {
908
- return PUNCTUATORS.find((punctuator) => source.startsWith(punctuator, index));
908
+ return PUNCTUATORS.find((punctuator) => source.startsWith(punctuator, index) &&
909
+ (punctuator !== "?." || !isDecimalDigit(source[index + 2] ?? "")));
909
910
  }
910
911
  function shouldRejectRegexLiteral(previousToken, lastClosedControlParenthesis) {
911
912
  if (previousToken === undefined) {