@fairfox/polly 0.12.4 → 0.13.1

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 (33) hide show
  1. package/dist/src/background/index.js +118 -1
  2. package/dist/src/background/index.js.map +5 -4
  3. package/dist/src/background/message-router.js +118 -1
  4. package/dist/src/background/message-router.js.map +5 -4
  5. package/dist/src/index.d.ts +2 -0
  6. package/dist/src/index.js +203 -3
  7. package/dist/src/index.js.map +9 -6
  8. package/dist/src/shared/lib/constraints.d.ts +61 -0
  9. package/dist/src/shared/lib/context-helpers.js +118 -1
  10. package/dist/src/shared/lib/context-helpers.js.map +5 -4
  11. package/dist/src/shared/lib/message-bus.d.ts +22 -0
  12. package/dist/src/shared/lib/message-bus.js +118 -1
  13. package/dist/src/shared/lib/message-bus.js.map +5 -4
  14. package/dist/src/shared/lib/state.d.ts +8 -2
  15. package/dist/src/shared/lib/state.js +140 -3
  16. package/dist/src/shared/lib/state.js.map +6 -5
  17. package/dist/src/shared/lib/validation.d.ts +94 -0
  18. package/dist/src/shared/state/app-state.d.ts +4 -1
  19. package/dist/src/shared/state/app-state.js +140 -3
  20. package/dist/src/shared/state/app-state.js.map +6 -5
  21. package/dist/tools/analysis/src/extract/handlers.d.ts +19 -2
  22. package/dist/tools/teach/src/cli.js +83 -18
  23. package/dist/tools/teach/src/cli.js.map +3 -3
  24. package/dist/tools/teach/src/index.js +83 -18
  25. package/dist/tools/teach/src/index.js.map +3 -3
  26. package/dist/tools/verify/src/cli.js +88 -18
  27. package/dist/tools/verify/src/cli.js.map +4 -4
  28. package/dist/tools/verify/src/config.js +8 -2
  29. package/dist/tools/verify/src/config.js.map +3 -3
  30. package/dist/tools/verify/src/primitives/index.d.ts +21 -8
  31. package/dist/tools/visualize/src/cli.js +83 -18
  32. package/dist/tools/visualize/src/cli.js.map +3 -3
  33. package/package.json +1 -1
@@ -5667,17 +5667,25 @@ class HandlerExtractor {
5667
5667
  const assignments = [];
5668
5668
  const preconditions = [];
5669
5669
  const postconditions = [];
5670
+ let actualHandler = null;
5670
5671
  if (Node4.isArrowFunction(handlerArg) || Node4.isFunctionExpression(handlerArg)) {
5671
- this.extractAssignments(handlerArg, assignments);
5672
- this.extractVerificationConditions(handlerArg, preconditions, postconditions);
5673
- this.checkAsyncMutations(handlerArg, messageType);
5672
+ actualHandler = handlerArg;
5673
+ } else if (Node4.isIdentifier(handlerArg)) {
5674
+ actualHandler = this.resolveFunctionReference(handlerArg);
5675
+ }
5676
+ if (actualHandler) {
5677
+ this.extractAssignments(actualHandler, assignments);
5678
+ this.extractVerificationConditions(actualHandler, preconditions, postconditions);
5679
+ if (Node4.isArrowFunction(actualHandler) || Node4.isFunctionExpression(actualHandler)) {
5680
+ this.checkAsyncMutations(actualHandler, messageType);
5681
+ }
5674
5682
  }
5675
5683
  const line = callExpr.getStartLineNumber();
5676
5684
  const sourceFile = callExpr.getSourceFile();
5677
5685
  const handlerName = `${messageType}_handler`;
5678
5686
  let relationships;
5679
- if (Node4.isArrowFunction(handlerArg) || Node4.isFunctionExpression(handlerArg)) {
5680
- const detectedRelationships = this.relationshipExtractor.extractFromHandler(handlerArg, sourceFile, handlerName);
5687
+ if (actualHandler) {
5688
+ const detectedRelationships = this.relationshipExtractor.extractFromHandler(actualHandler, sourceFile, handlerName);
5681
5689
  if (detectedRelationships.length > 0) {
5682
5690
  relationships = detectedRelationships;
5683
5691
  }
@@ -5781,11 +5789,24 @@ class HandlerExtractor {
5781
5789
  }
5782
5790
  }
5783
5791
  }
5792
+ getUnaryOperatorText(operator) {
5793
+ if (typeof operator === "number") {
5794
+ if (operator === SyntaxKind.PlusPlusToken)
5795
+ return "++";
5796
+ if (operator === SyntaxKind.MinusMinusToken)
5797
+ return "--";
5798
+ return null;
5799
+ }
5800
+ if (operator && typeof operator === "object" && "getText" in operator) {
5801
+ return operator.getText();
5802
+ }
5803
+ return null;
5804
+ }
5784
5805
  extractUnaryExpressionAssignment(node, assignments) {
5785
5806
  if (!Node4.isPostfixUnaryExpression(node) && !Node4.isPrefixUnaryExpression(node))
5786
5807
  return;
5787
5808
  const operator = node.getOperatorToken();
5788
- const operatorText = operator.toString();
5809
+ const operatorText = this.getUnaryOperatorText(operator);
5789
5810
  if (operatorText !== "++" && operatorText !== "--")
5790
5811
  return;
5791
5812
  const operand = node.getOperand();
@@ -5877,7 +5898,7 @@ class HandlerExtractor {
5877
5898
  }
5878
5899
  extractVerificationConditions(funcNode, preconditions, postconditions) {
5879
5900
  const body = funcNode.getBody();
5880
- const statements = Node4.isBlock(body) ? body.getStatements() : [body];
5901
+ const statements = Node4.isBlock(body) ? body.getStatements() : body ? [body] : [];
5881
5902
  for (const statement of statements) {
5882
5903
  this.processStatementForConditions(statement, preconditions, postconditions);
5883
5904
  }
@@ -5997,10 +6018,14 @@ class HandlerExtractor {
5997
6018
  const handlers = [];
5998
6019
  try {
5999
6020
  const initializer = varDecl.getInitializer();
6000
- if (!this.isHandlerMapInitializer(initializer, varDecl)) {
6021
+ if (!initializer) {
6022
+ return handlers;
6023
+ }
6024
+ const objectLiteral = this.getHandlerMapObject(initializer, varDecl);
6025
+ if (!objectLiteral) {
6001
6026
  return handlers;
6002
6027
  }
6003
- const properties = initializer.getProperties();
6028
+ const properties = objectLiteral.getProperties();
6004
6029
  for (const prop of properties) {
6005
6030
  const handler = this.extractHandlerFromProperty(prop, context, filePath);
6006
6031
  if (handler) {
@@ -6010,12 +6035,16 @@ class HandlerExtractor {
6010
6035
  } catch (_error) {}
6011
6036
  return handlers;
6012
6037
  }
6013
- isHandlerMapInitializer(initializer, varDecl) {
6014
- if (!initializer || !Node4.isObjectLiteralExpression(initializer)) {
6015
- return false;
6038
+ getHandlerMapObject(initializer, varDecl) {
6039
+ if (Node4.isObjectLiteralExpression(initializer)) {
6040
+ if (this.isHandlerMapName(varDecl.getName())) {
6041
+ return initializer;
6042
+ }
6016
6043
  }
6017
- const varName = varDecl.getName().toLowerCase();
6018
- return /(handler|listener|callback|event)s?/.test(varName);
6044
+ return null;
6045
+ }
6046
+ isHandlerMapName(varName) {
6047
+ return /(handler|listener|callback|event)s?/.test(varName.toLowerCase());
6019
6048
  }
6020
6049
  extractHandlerFromProperty(prop, context, filePath) {
6021
6050
  if (!Node4.isPropertyAssignment(prop)) {
@@ -6026,13 +6055,29 @@ class HandlerExtractor {
6026
6055
  if (!messageType) {
6027
6056
  return null;
6028
6057
  }
6058
+ const value = prop.getInitializer();
6059
+ const assignments = [];
6060
+ const preconditions = [];
6061
+ const postconditions = [];
6062
+ if (value) {
6063
+ if (Node4.isArrowFunction(value) || Node4.isFunctionExpression(value)) {
6064
+ this.extractAssignments(value, assignments);
6065
+ this.extractVerificationConditions(value, preconditions, postconditions);
6066
+ } else if (Node4.isIdentifier(value)) {
6067
+ const referencedFunction = this.resolveFunctionReference(value);
6068
+ if (referencedFunction) {
6069
+ this.extractAssignments(referencedFunction, assignments);
6070
+ this.extractVerificationConditions(referencedFunction, preconditions, postconditions);
6071
+ }
6072
+ }
6073
+ }
6029
6074
  const line = prop.getStartLineNumber();
6030
6075
  return {
6031
6076
  messageType,
6032
6077
  node: context,
6033
- assignments: [],
6034
- preconditions: [],
6035
- postconditions: [],
6078
+ assignments,
6079
+ preconditions,
6080
+ postconditions,
6036
6081
  location: { file: filePath, line }
6037
6082
  };
6038
6083
  }
@@ -6045,6 +6090,26 @@ class HandlerExtractor {
6045
6090
  }
6046
6091
  return null;
6047
6092
  }
6093
+ resolveFunctionReference(identifier) {
6094
+ if (!Node4.isIdentifier(identifier)) {
6095
+ return null;
6096
+ }
6097
+ try {
6098
+ const definitions = identifier.getDefinitionNodes();
6099
+ for (const def of definitions) {
6100
+ if (Node4.isFunctionDeclaration(def)) {
6101
+ return def;
6102
+ }
6103
+ if (Node4.isVariableDeclaration(def)) {
6104
+ const initializer = def.getInitializer();
6105
+ if (initializer && (Node4.isArrowFunction(initializer) || Node4.isFunctionExpression(initializer))) {
6106
+ return initializer;
6107
+ }
6108
+ }
6109
+ }
6110
+ } catch (_error) {}
6111
+ return null;
6112
+ }
6048
6113
  extractTypeGuardHandlers(ifNode, context, filePath) {
6049
6114
  const handlers = [];
6050
6115
  try {
@@ -9599,4 +9664,4 @@ Goodbye!`);
9599
9664
  }
9600
9665
  main();
9601
9666
 
9602
- //# debugId=8B445D057C1E5F1464756E2164756E21
9667
+ //# debugId=EA44B00D786F888B64756E2164756E21