@fairfox/polly 0.13.2 → 0.14.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.
@@ -1874,6 +1874,39 @@ class HandlerExtractor {
1874
1874
  if (value !== undefined) {
1875
1875
  assignments.push({ field, value });
1876
1876
  }
1877
+ return;
1878
+ }
1879
+ const valueMatch = fieldPath.match(/\.value\.(.+)$/);
1880
+ if (valueMatch && valueMatch[1]) {
1881
+ const field = valueMatch[1];
1882
+ const value = this.extractValue(right);
1883
+ if (value !== undefined) {
1884
+ assignments.push({ field, value });
1885
+ }
1886
+ return;
1887
+ }
1888
+ if (fieldPath.endsWith(".value") && Node4.isObjectLiteralExpression(right)) {
1889
+ this.extractObjectLiteralAssignments(right, assignments);
1890
+ }
1891
+ }
1892
+ extractObjectLiteralAssignments(objectLiteral, assignments) {
1893
+ if (!Node4.isObjectLiteralExpression(objectLiteral))
1894
+ return;
1895
+ for (const prop of objectLiteral.getProperties()) {
1896
+ if (Node4.isPropertyAssignment(prop)) {
1897
+ const name = prop.getName();
1898
+ const initializer = prop.getInitializer();
1899
+ if (!name || !initializer)
1900
+ continue;
1901
+ const value = this.extractValue(initializer);
1902
+ if (value !== undefined) {
1903
+ assignments.push({ field: name, value });
1904
+ }
1905
+ }
1906
+ if (Node4.isShorthandPropertyAssignment(prop)) {
1907
+ const name = prop.getName();
1908
+ assignments.push({ field: name, value: "@" });
1909
+ }
1877
1910
  }
1878
1911
  }
1879
1912
  extractElementAccessAssignment(left, right, assignments) {
@@ -1883,9 +1916,9 @@ class HandlerExtractor {
1883
1916
  if (!Node4.isPropertyAccessExpression(expr))
1884
1917
  return;
1885
1918
  const fieldPath = this.getPropertyPath(expr);
1886
- if (!fieldPath.startsWith("state."))
1919
+ const field = this.extractFieldFromStatePath(fieldPath);
1920
+ if (!field)
1887
1921
  return;
1888
- const field = fieldPath.substring(6);
1889
1922
  const indexExpr = left.getArgumentExpression();
1890
1923
  const index = indexExpr ? indexExpr.getText() : "0";
1891
1924
  const value = this.extractValue(right);
@@ -1897,6 +1930,16 @@ class HandlerExtractor {
1897
1930
  });
1898
1931
  }
1899
1932
  }
1933
+ extractFieldFromStatePath(fieldPath) {
1934
+ if (fieldPath.startsWith("state.")) {
1935
+ return fieldPath.substring(6);
1936
+ }
1937
+ const valueMatch = fieldPath.match(/\.value\.(.+)$/);
1938
+ if (valueMatch && valueMatch[1]) {
1939
+ return valueMatch[1];
1940
+ }
1941
+ return null;
1942
+ }
1900
1943
  extractCompoundAssignment(node, assignments) {
1901
1944
  if (!Node4.isBinaryExpression(node))
1902
1945
  return;
@@ -1905,8 +1948,8 @@ class HandlerExtractor {
1905
1948
  const right = node.getRight();
1906
1949
  if (Node4.isPropertyAccessExpression(left)) {
1907
1950
  const fieldPath = this.getPropertyPath(left);
1908
- if (fieldPath.startsWith("state.")) {
1909
- const field = fieldPath.substring(6);
1951
+ const field = this.extractFieldFromStatePath(fieldPath);
1952
+ if (field) {
1910
1953
  const rightValue = right.getText();
1911
1954
  const tlaOp = operator.slice(0, -1);
1912
1955
  assignments.push({
@@ -1940,8 +1983,8 @@ class HandlerExtractor {
1940
1983
  if (!Node4.isPropertyAccessExpression(operand))
1941
1984
  return;
1942
1985
  const fieldPath = this.getPropertyPath(operand);
1943
- if (fieldPath.startsWith("state.")) {
1944
- const field = fieldPath.substring(6);
1986
+ const field = this.extractFieldFromStatePath(fieldPath);
1987
+ if (field) {
1945
1988
  const value = operatorText === "++" ? "@ + 1" : "@ - 1";
1946
1989
  assignments.push({ field, value });
1947
1990
  }
@@ -1956,8 +1999,8 @@ class HandlerExtractor {
1956
1999
  const object = expr.getExpression();
1957
2000
  if (Node4.isPropertyAccessExpression(object)) {
1958
2001
  const fieldPath = this.getPropertyPath(object);
1959
- if (fieldPath.startsWith("state.")) {
1960
- const field = fieldPath.substring(6);
2002
+ const field = this.extractFieldFromStatePath(fieldPath);
2003
+ if (field) {
1961
2004
  const args = node.getArguments().map((arg) => arg.getText());
1962
2005
  const tlaValue = this.translateArrayMethod(methodName, args, fieldPath);
1963
2006
  if (tlaValue) {
@@ -2597,8 +2640,8 @@ class HandlerExtractor {
2597
2640
  if (!Node4.isPropertyAccessExpression(left) && !Node4.isElementAccessExpression(left))
2598
2641
  return;
2599
2642
  const fieldPath = Node4.isPropertyAccessExpression(left) ? this.getPropertyPath(left) : this.getPropertyPath(left.getExpression());
2600
- if (fieldPath.startsWith("state.")) {
2601
- const field = fieldPath.substring(6);
2643
+ const field = this.extractFieldFromStatePath(fieldPath);
2644
+ if (field) {
2602
2645
  const line = node.getStartLineNumber();
2603
2646
  const afterAwait = node.getStart() > firstAwaitPos;
2604
2647
  mutations.push({ field, line, afterAwait });
@@ -2615,10 +2658,8 @@ class HandlerExtractor {
2615
2658
  if (!Node4.isPropertyAccessExpression(object))
2616
2659
  return;
2617
2660
  const fieldPath = this.getPropertyPath(object);
2618
- if (!fieldPath.startsWith("state."))
2619
- return;
2620
- if (["push", "pop", "shift", "unshift", "splice"].includes(methodName)) {
2621
- const field = fieldPath.substring(6);
2661
+ const field = this.extractFieldFromStatePath(fieldPath);
2662
+ if (field && ["push", "pop", "shift", "unshift", "splice"].includes(methodName)) {
2622
2663
  const line = node.getStartLineNumber();
2623
2664
  const afterAwait = node.getStart() > firstAwaitPos;
2624
2665
  mutations.push({ field, line, afterAwait });
@@ -5019,4 +5060,4 @@ main().catch((_error) => {
5019
5060
  process.exit(1);
5020
5061
  });
5021
5062
 
5022
- //# debugId=29B7FAEF737837BA64756E2164756E21
5063
+ //# debugId=7860F724A3DD29E164756E2164756E21