@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
@@ -1943,6 +1943,10 @@ class DockerRunner {
1943
1943
  if (!fs3.existsSync(cfgPath)) {
1944
1944
  throw new Error(`Config file not found: ${cfgPath}`);
1945
1945
  }
1946
+ const statesDir = path3.join(specDir, "states");
1947
+ if (fs3.existsSync(statesDir)) {
1948
+ fs3.rmSync(statesDir, { recursive: true, force: true });
1949
+ }
1946
1950
  const args = [
1947
1951
  "run",
1948
1952
  "--rm",
@@ -1952,6 +1956,7 @@ class DockerRunner {
1952
1956
  "tlc",
1953
1957
  "-workers",
1954
1958
  `${options?.workers || 1}`,
1959
+ "-cleanup",
1955
1960
  `${specName}.tla`
1956
1961
  ];
1957
1962
  const result = await this.runCommand("docker", args, {
@@ -3579,17 +3584,25 @@ class HandlerExtractor {
3579
3584
  const assignments = [];
3580
3585
  const preconditions = [];
3581
3586
  const postconditions = [];
3587
+ let actualHandler = null;
3582
3588
  if (Node2.isArrowFunction(handlerArg) || Node2.isFunctionExpression(handlerArg)) {
3583
- this.extractAssignments(handlerArg, assignments);
3584
- this.extractVerificationConditions(handlerArg, preconditions, postconditions);
3585
- this.checkAsyncMutations(handlerArg, messageType);
3589
+ actualHandler = handlerArg;
3590
+ } else if (Node2.isIdentifier(handlerArg)) {
3591
+ actualHandler = this.resolveFunctionReference(handlerArg);
3592
+ }
3593
+ if (actualHandler) {
3594
+ this.extractAssignments(actualHandler, assignments);
3595
+ this.extractVerificationConditions(actualHandler, preconditions, postconditions);
3596
+ if (Node2.isArrowFunction(actualHandler) || Node2.isFunctionExpression(actualHandler)) {
3597
+ this.checkAsyncMutations(actualHandler, messageType);
3598
+ }
3586
3599
  }
3587
3600
  const line = callExpr.getStartLineNumber();
3588
3601
  const sourceFile = callExpr.getSourceFile();
3589
3602
  const handlerName = `${messageType}_handler`;
3590
3603
  let relationships;
3591
- if (Node2.isArrowFunction(handlerArg) || Node2.isFunctionExpression(handlerArg)) {
3592
- const detectedRelationships = this.relationshipExtractor.extractFromHandler(handlerArg, sourceFile, handlerName);
3604
+ if (actualHandler) {
3605
+ const detectedRelationships = this.relationshipExtractor.extractFromHandler(actualHandler, sourceFile, handlerName);
3593
3606
  if (detectedRelationships.length > 0) {
3594
3607
  relationships = detectedRelationships;
3595
3608
  }
@@ -3693,11 +3706,24 @@ class HandlerExtractor {
3693
3706
  }
3694
3707
  }
3695
3708
  }
3709
+ getUnaryOperatorText(operator) {
3710
+ if (typeof operator === "number") {
3711
+ if (operator === SyntaxKind.PlusPlusToken)
3712
+ return "++";
3713
+ if (operator === SyntaxKind.MinusMinusToken)
3714
+ return "--";
3715
+ return null;
3716
+ }
3717
+ if (operator && typeof operator === "object" && "getText" in operator) {
3718
+ return operator.getText();
3719
+ }
3720
+ return null;
3721
+ }
3696
3722
  extractUnaryExpressionAssignment(node, assignments) {
3697
3723
  if (!Node2.isPostfixUnaryExpression(node) && !Node2.isPrefixUnaryExpression(node))
3698
3724
  return;
3699
3725
  const operator = node.getOperatorToken();
3700
- const operatorText = operator.toString();
3726
+ const operatorText = this.getUnaryOperatorText(operator);
3701
3727
  if (operatorText !== "++" && operatorText !== "--")
3702
3728
  return;
3703
3729
  const operand = node.getOperand();
@@ -3789,7 +3815,7 @@ class HandlerExtractor {
3789
3815
  }
3790
3816
  extractVerificationConditions(funcNode, preconditions, postconditions) {
3791
3817
  const body = funcNode.getBody();
3792
- const statements = Node2.isBlock(body) ? body.getStatements() : [body];
3818
+ const statements = Node2.isBlock(body) ? body.getStatements() : body ? [body] : [];
3793
3819
  for (const statement of statements) {
3794
3820
  this.processStatementForConditions(statement, preconditions, postconditions);
3795
3821
  }
@@ -3909,10 +3935,14 @@ class HandlerExtractor {
3909
3935
  const handlers = [];
3910
3936
  try {
3911
3937
  const initializer = varDecl.getInitializer();
3912
- if (!this.isHandlerMapInitializer(initializer, varDecl)) {
3938
+ if (!initializer) {
3913
3939
  return handlers;
3914
3940
  }
3915
- const properties = initializer.getProperties();
3941
+ const objectLiteral = this.getHandlerMapObject(initializer, varDecl);
3942
+ if (!objectLiteral) {
3943
+ return handlers;
3944
+ }
3945
+ const properties = objectLiteral.getProperties();
3916
3946
  for (const prop of properties) {
3917
3947
  const handler = this.extractHandlerFromProperty(prop, context, filePath);
3918
3948
  if (handler) {
@@ -3922,12 +3952,16 @@ class HandlerExtractor {
3922
3952
  } catch (_error) {}
3923
3953
  return handlers;
3924
3954
  }
3925
- isHandlerMapInitializer(initializer, varDecl) {
3926
- if (!initializer || !Node2.isObjectLiteralExpression(initializer)) {
3927
- return false;
3955
+ getHandlerMapObject(initializer, varDecl) {
3956
+ if (Node2.isObjectLiteralExpression(initializer)) {
3957
+ if (this.isHandlerMapName(varDecl.getName())) {
3958
+ return initializer;
3959
+ }
3928
3960
  }
3929
- const varName = varDecl.getName().toLowerCase();
3930
- return /(handler|listener|callback|event)s?/.test(varName);
3961
+ return null;
3962
+ }
3963
+ isHandlerMapName(varName) {
3964
+ return /(handler|listener|callback|event)s?/.test(varName.toLowerCase());
3931
3965
  }
3932
3966
  extractHandlerFromProperty(prop, context, filePath) {
3933
3967
  if (!Node2.isPropertyAssignment(prop)) {
@@ -3938,13 +3972,29 @@ class HandlerExtractor {
3938
3972
  if (!messageType) {
3939
3973
  return null;
3940
3974
  }
3975
+ const value = prop.getInitializer();
3976
+ const assignments = [];
3977
+ const preconditions = [];
3978
+ const postconditions = [];
3979
+ if (value) {
3980
+ if (Node2.isArrowFunction(value) || Node2.isFunctionExpression(value)) {
3981
+ this.extractAssignments(value, assignments);
3982
+ this.extractVerificationConditions(value, preconditions, postconditions);
3983
+ } else if (Node2.isIdentifier(value)) {
3984
+ const referencedFunction = this.resolveFunctionReference(value);
3985
+ if (referencedFunction) {
3986
+ this.extractAssignments(referencedFunction, assignments);
3987
+ this.extractVerificationConditions(referencedFunction, preconditions, postconditions);
3988
+ }
3989
+ }
3990
+ }
3941
3991
  const line = prop.getStartLineNumber();
3942
3992
  return {
3943
3993
  messageType,
3944
3994
  node: context,
3945
- assignments: [],
3946
- preconditions: [],
3947
- postconditions: [],
3995
+ assignments,
3996
+ preconditions,
3997
+ postconditions,
3948
3998
  location: { file: filePath, line }
3949
3999
  };
3950
4000
  }
@@ -3957,6 +4007,26 @@ class HandlerExtractor {
3957
4007
  }
3958
4008
  return null;
3959
4009
  }
4010
+ resolveFunctionReference(identifier) {
4011
+ if (!Node2.isIdentifier(identifier)) {
4012
+ return null;
4013
+ }
4014
+ try {
4015
+ const definitions = identifier.getDefinitionNodes();
4016
+ for (const def of definitions) {
4017
+ if (Node2.isFunctionDeclaration(def)) {
4018
+ return def;
4019
+ }
4020
+ if (Node2.isVariableDeclaration(def)) {
4021
+ const initializer = def.getInitializer();
4022
+ if (initializer && (Node2.isArrowFunction(initializer) || Node2.isFunctionExpression(initializer))) {
4023
+ return initializer;
4024
+ }
4025
+ }
4026
+ }
4027
+ } catch (_error) {}
4028
+ return null;
4029
+ }
3960
4030
  extractTypeGuardHandlers(ifNode, context, filePath) {
3961
4031
  const handlers = [];
3962
4032
  try {
@@ -5323,4 +5393,4 @@ main().catch((error) => {
5323
5393
  process.exit(1);
5324
5394
  });
5325
5395
 
5326
- //# debugId=7CAD4356DD5A25CD64756E2164756E21
5396
+ //# debugId=10C305880072C68964756E2164756E21