StoragesModule.ts 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { ContainerModule, interfaces } from 'inversify';
  2. import { ServiceIdentifiers } from '../../ServiceIdentifiers';
  3. import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage';
  4. import { TConstructor } from '../../../types/TConstructor';
  5. import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage';
  6. import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage';
  7. import { ILiteralNodesCacheStorage } from '../../../interfaces/storages/string-array-transformers/ILiteralNodesCacheStorage';
  8. import { IOptions } from '../../../interfaces/options/IOptions';
  9. import { IPropertyIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IPropertyIdentifierNamesCacheStorage';
  10. import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
  11. import { IStringArrayScopeCallsWrappersDataStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayScopeCallsWrappersDataStorage';
  12. import { IStringArrayStorage } from '../../../interfaces/storages/string-array-transformers/IStringArrayStorage';
  13. import { IVisitedLexicalScopeNodesStackStorage } from '../../../interfaces/storages/string-array-transformers/IVisitedLexicalScopeNodesStackStorage';
  14. import { ControlFlowStorage } from '../../../storages/custom-nodes/ControlFlowStorage';
  15. import { CustomCodeHelperGroupStorage } from '../../../storages/custom-code-helpers/CustomCodeHelperGroupStorage';
  16. import { GlobalIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/GlobalIdentifierNamesCacheStorage';
  17. import { LiteralNodesCacheStorage } from '../../../storages/string-array-transformers/LiteralNodesCacheStorage';
  18. import { PropertyIdentifierNamesCacheStorage } from '../../../storages/identifier-names-cache/PropertyIdentifierNamesCacheStorage';
  19. import { StringArrayScopeCallsWrappersDataStorage } from '../../../storages/string-array-transformers/StringArrayScopeCallsWrappersDataStorage';
  20. import { StringArrayStorage } from '../../../storages/string-array-transformers/StringArrayStorage';
  21. import { VisitedLexicalScopeNodesStackStorage } from '../../../storages/string-array-transformers/VisitedLexicalScopeNodesStackStorage';
  22. export const storagesModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
  23. // storages
  24. bind<TCustomCodeHelperGroupStorage>(ServiceIdentifiers.TCustomNodeGroupStorage)
  25. .to(CustomCodeHelperGroupStorage)
  26. .inSingletonScope();
  27. bind<IGlobalIdentifierNamesCacheStorage>(ServiceIdentifiers.IGlobalIdentifierNamesCacheStorage)
  28. .to(GlobalIdentifierNamesCacheStorage)
  29. .inSingletonScope();
  30. bind<ILiteralNodesCacheStorage>(ServiceIdentifiers.ILiteralNodesCacheStorage)
  31. .to(LiteralNodesCacheStorage)
  32. .inSingletonScope();
  33. bind<IPropertyIdentifierNamesCacheStorage>(ServiceIdentifiers.IPropertyIdentifierNamesCacheStorage)
  34. .to(PropertyIdentifierNamesCacheStorage)
  35. .inSingletonScope();
  36. bind<IStringArrayStorage>(ServiceIdentifiers.IStringArrayStorage)
  37. .to(StringArrayStorage)
  38. .inSingletonScope();
  39. bind<IStringArrayScopeCallsWrappersDataStorage>(ServiceIdentifiers.IStringArrayScopeCallsWrappersDataStorage)
  40. .to(StringArrayScopeCallsWrappersDataStorage)
  41. .inSingletonScope();
  42. bind<IVisitedLexicalScopeNodesStackStorage>(ServiceIdentifiers.IVisitedLexicalScopeNodesStackStorage)
  43. .to(VisitedLexicalScopeNodesStackStorage)
  44. .inSingletonScope();
  45. bind<interfaces.Newable<TControlFlowStorage>>(ServiceIdentifiers.Newable__TControlFlowStorage)
  46. .toConstructor(ControlFlowStorage);
  47. // controlFlowStorage factory
  48. bind<TControlFlowStorage>(ServiceIdentifiers.Factory__TControlFlowStorage)
  49. .toFactory<TControlFlowStorage>((context: interfaces.Context) => {
  50. return (): TControlFlowStorage => {
  51. const constructor = context.container
  52. .get<TConstructor<[IRandomGenerator, IOptions], TControlFlowStorage>>(
  53. ServiceIdentifiers.Newable__TControlFlowStorage
  54. );
  55. const randomGenerator: IRandomGenerator = context.container
  56. .get<IRandomGenerator>(ServiceIdentifiers.IRandomGenerator);
  57. const options: IOptions = context.container
  58. .get<IOptions>(ServiceIdentifiers.IOptions);
  59. const storage: TControlFlowStorage = new constructor(randomGenerator, options);
  60. storage.initialize();
  61. return storage;
  62. };
  63. });
  64. });