@cashscript/utils 0.11.0-next.4 → 0.11.0

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.
package/dist/artifact.js CHANGED
@@ -8,9 +8,10 @@ export function formatArtifact(artifact, format) {
8
8
  }
9
9
  const indent = (level) => ' '.repeat(level);
10
10
  function stringifyAsTs(obj, indentationLevel = 1) {
11
- // For strings, we use JSON.stringify, but we convert double quotes to single quotes
11
+ // For strings we use JSON.stringify to handle escaping, but we want to use single quotes instead of double quotes
12
+ // around string values inside objects, to match regular TS style
12
13
  if (typeof obj === 'string') {
13
- return JSON.stringify(obj).replace(/'/g, "\\'").replace(/"/g, "'");
14
+ return `'${JSON.stringify(obj).replace(/'/g, "\\'").replace(/\\"/g, '"').slice(1, -1)}'`;
14
15
  }
15
16
  // Numbers and booleans are just converted to strings
16
17
  if (typeof obj === 'number' || typeof obj === 'boolean') {
@@ -119,6 +119,6 @@ const unprovableOptimisations = [
119
119
  ['OP_DUP OP_OR', ''],
120
120
  ];
121
121
  // Note: we moved these optimisations into a single file, but kept the exact same order as before,
122
- // because the order in which oprimisations are applied can impact the output.
122
+ // because the order in which optimisations are applied can impact the output.
123
123
  export const optimisationReplacements = [...provableOptimisations, ...unprovableOptimisations];
124
124
  //# sourceMappingURL=optimisations.js.map
package/dist/script.js CHANGED
@@ -180,15 +180,18 @@ function replaceOps(script, locationData, logs, requires, constructorParamLength
180
180
  const scriptIndex = processedAsm === '' ? 0 : [...processedAsm.matchAll(/\s+/g)].length + 1;
181
181
  const patternLength = [...pattern.matchAll(/\s+/g)].length + 1;
182
182
  const replacementLength = replacement === '' ? 0 : [...replacement.matchAll(/\s+/g)].length + 1;
183
- // We get the locationdata entries for every opcode in the pattern
183
+ // We get the locationData entries for every opcode in the pattern
184
184
  const patternLocations = newLocationData.slice(scriptIndex, scriptIndex + patternLength);
185
185
  // We get the lowest start location and highest end location of the pattern
186
186
  const lowestStart = getLowestStartLocation(patternLocations);
187
187
  const highestEnd = getHighestEndLocation(patternLocations);
188
- // If any of the pattern locations have a position hint of END, we use that as the position hint
189
- const positionHint = patternLocations.some((location) => location.positionHint === PositionHint.END)
190
- ? PositionHint.END
191
- : PositionHint.START;
188
+ // Initially we set the position hint to END if any of the pattern locations have a position hint of END
189
+ // It turned out that this was not the correct approach in the case of OP_NOT OP_IF => OP_NOTIF,
190
+ // because OP_IF and OP_NOTIF are START opcodes, and OP_NOT is an END opcode.
191
+ // After reviewing the entire list of optimisations, we set the position hint to the last location's position hint
192
+ // which we believe to be the correct approach, but it is hard to reason about.
193
+ // We've also consulted with AI (o3-max) to help us reason about this, and it seems to be the correct approach.
194
+ const positionHint = patternLocations.at(-1)?.positionHint ?? PositionHint.START;
192
195
  // We merge the lowest start and highest end locations into a single location data entry
193
196
  const mergedLocation = {
194
197
  location: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashscript/utils",
3
- "version": "0.11.0-next.4",
3
+ "version": "0.11.0",
4
4
  "description": "CashScript utilities and types",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -52,5 +52,5 @@
52
52
  "jest": "^29.7.0",
53
53
  "typescript": "^5.7.3"
54
54
  },
55
- "gitHead": "68cdf30db455e3eef448a4feacfff0f5f26a36a7"
55
+ "gitHead": "47a9dbc781e009eea4704735a256ba05ae03f719"
56
56
  }