@opencode/codemode 0.0.0-dev-19645 → 0.0.0-dev-19648

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.
@@ -90,7 +90,6 @@ export class RegExpObj extends Obj {
90
90
  constructor(proto, pattern, flags) {
91
91
  super(proto);
92
92
  this.regex = new RegExp(pattern, flags);
93
- define(this, "lastIndex", 0, { writable: true, enumerable: false, configurable: false });
94
93
  }
95
94
  }
96
95
  export class MapObj extends Obj {
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import { constructor, methods, prototypeFrom, receiver } from "../interpreter/native.js";
3
3
  import { syntaxError, typeError } from "../interpreter/model.js";
4
- import { define, defineAccessor, getOwn, Arr, Obj, RegExpObj, record, set } from "../interpreter/objects.js";
4
+ import { define, defineAccessor, Arr, Obj, RegExpObj, record } from "../interpreter/objects.js";
5
5
  import { coerceToNumber, coerceToString } from "./value.js";
6
6
  const flagProperties = [
7
7
  "hasIndices",
@@ -61,12 +61,6 @@ export const constructRegExp = (builtins, args, proto = builtins.RegExp) => {
61
61
  : `new RegExp(...) received ${JSON.stringify(pattern)}, which is not a valid regular expression pattern (${reason}). ${escapeRegexHint}`);
62
62
  }
63
63
  };
64
- const toLength = (value) => {
65
- const number = coerceToNumber(value);
66
- if (Number.isNaN(number) || number <= 0)
67
- return 0;
68
- return Math.min(Math.floor(number), Number.MAX_SAFE_INTEGER);
69
- };
70
64
  // RegExp constructs identically with or without new, like JS.
71
65
  export const regexpGlobal = (ctx) => {
72
66
  const builtins = ctx.builtins;
@@ -91,20 +85,18 @@ export const regexpGlobal = (ctx) => {
91
85
  const self = (thisValue, name) => receiver(RegExpObj, thisValue, `RegExp.prototype.${name}`);
92
86
  defineAccessor(proto, "source", (thisValue) => self(thisValue, "source").regex.source);
93
87
  defineAccessor(proto, "flags", (thisValue) => self(thisValue, "flags").regex.flags);
88
+ // The host regex holds the only lastIndex, so exec/test and the String methods share one counter.
89
+ defineAccessor(proto, "lastIndex", (thisValue) => self(thisValue, "lastIndex").regex.lastIndex, (thisValue, value) => {
90
+ self(thisValue, "lastIndex").regex.lastIndex = coerceToNumber(value);
91
+ });
94
92
  for (const name of flagProperties)
95
93
  defineAccessor(proto, name, (thisValue) => self(thisValue, name).regex[name]);
96
- // exec/test run the host regex from the program-visible lastIndex and write it back only when g or y is set.
97
94
  const run = (name) => [
98
95
  name,
99
96
  1,
100
97
  (thisValue, args) => {
101
98
  const value = self(thisValue, name);
102
- const input = coerceToString(args[0]);
103
- const stateful = value.regex.global || value.regex.sticky;
104
- value.regex.lastIndex = toLength(getOwn(value, "lastIndex"));
105
- const matched = value.regex.exec(input);
106
- if (stateful)
107
- set(value, "lastIndex", value.regex.lastIndex);
99
+ const matched = value.regex.exec(coerceToString(args[0]));
108
100
  if (name === "test")
109
101
  return matched !== null;
110
102
  return matched === null ? null : matchToValue(builtins, matched);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/codemode",
4
- "version": "0.0.0-dev-19645",
4
+ "version": "0.0.0-dev-19648",
5
5
  "description": "Effect-native confined code execution over schema-described tools",
6
6
  "type": "module",
7
7
  "license": "MIT",