diff --git a/package.json b/package.json index 3c0c99d2..8c08a3cc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "commander": "8.2.0", "eslint-scope": "6.0.0", "fast-deep-equal": "3.1.3", - "inversify": "5.1.1", + "inversify": "6.0.1", "js-string-escape": "1.0.1", "md5": "2.3.0", "mkdirp": "1.0.4", diff --git a/src/code-transformers/AbstractCodeTransformer.ts b/src/code-transformers/AbstractCodeTransformer.ts index b6e96671..10fde172 100644 --- a/src/code-transformers/AbstractCodeTransformer.ts +++ b/src/code-transformers/AbstractCodeTransformer.ts @@ -29,7 +29,7 @@ export abstract class AbstractCodeTransformer implements ICodeTransformer { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { diff --git a/src/container/InversifyContainerFacade.ts b/src/container/InversifyContainerFacade.ts index 8c68664d..bacf2713 100644 --- a/src/container/InversifyContainerFacade.ts +++ b/src/container/InversifyContainerFacade.ts @@ -22,6 +22,7 @@ import { storagesModule } from './modules/storages/StoragesModule'; import { stringArrayTransformersModule } from './modules/node-transformers/StringArrayTransformersModule'; import { utilsModule } from './modules/utils/UtilsModule'; +import { TConstructor } from '../types/TConstructor'; import { TInputOptions } from '../types/options/TInputOptions'; import { ICodeTransformersRunner } from '../interfaces/code-transformers/ICodeTransformersRunner'; @@ -88,21 +89,21 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { } /** - * @param {interfaces.ServiceIdentifier>} serviceIdentifier - * @param {interfaces.ServiceIdentifier>[]} dependencies - * @returns {U} + * @param {interfaces.ServiceIdentifier[], U>>} serviceIdentifier + * @param {interfaces.ServiceIdentifier[], U>>} dependencies + * @returns {(context: interfaces.Context) => (bindingName: T) => U} */ public static getConstructorFactory ( - serviceIdentifier: interfaces.ServiceIdentifier>, - ...dependencies: interfaces.ServiceIdentifier>>[] + serviceIdentifier: interfaces.ServiceIdentifier[], U>>, + ...dependencies: interfaces.ServiceIdentifier[], U>>[] ): (context: interfaces.Context) => (bindingName: T) => U { return (context: interfaces.Context): (bindingName: T) => U => { - const cache: Map> = new Map(); + const cache: Map[], U>> = new Map(); const cachedDependencies: Record[] = []; return (bindingName: T): U => { dependencies.forEach(( - dependency: interfaces.ServiceIdentifier>>, + dependency: interfaces.ServiceIdentifier[], U>>, index: number ) => { if (!cachedDependencies[index]) { @@ -111,11 +112,11 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { }); if (cache.has(bindingName)) { - return new (>cache.get(bindingName))(...cachedDependencies); + return new ([], U>>cache.get(bindingName))(...cachedDependencies); } - const constructor: interfaces.Newable = context.container - .getNamed>( + const constructor = context.container + .getNamed[], U>>( serviceIdentifier, bindingName ); @@ -186,7 +187,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade { this.container .bind(ServiceIdentifiers.Factory__IObfuscationResult) - .toFactory((context: interfaces.Context) => { + .toFactory((context: interfaces.Context) => { return (obfuscatedCodeAsString: string, sourceMapAsString: string): IObfuscationResult => { const obfuscationResult: IObfuscationResult = context.container .get(ServiceIdentifiers.IObfuscationResult); diff --git a/src/container/modules/analyzers/AnalyzersModule.ts b/src/container/modules/analyzers/AnalyzersModule.ts index 3f728b28..ce76b198 100644 --- a/src/container/modules/analyzers/AnalyzersModule.ts +++ b/src/container/modules/analyzers/AnalyzersModule.ts @@ -60,7 +60,7 @@ export const analyzersModule: interfaces.ContainerModule = new ContainerModule(( // callee data extractor factory bind(ServiceIdentifiers.Factory__ICalleeDataExtractor) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory( ServiceIdentifiers.ICalleeDataExtractor )); diff --git a/src/container/modules/code-transformers/CodeTransformersModule.ts b/src/container/modules/code-transformers/CodeTransformersModule.ts index cbcf0dd2..7c2fb3d6 100644 --- a/src/container/modules/code-transformers/CodeTransformersModule.ts +++ b/src/container/modules/code-transformers/CodeTransformersModule.ts @@ -13,7 +13,7 @@ import { HashbangOperatorTransformer } from '../../../code-transformers/preparin export const codeTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // code transformers factory bind(ServiceIdentifiers.Factory__ICodeTransformer) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory(ServiceIdentifiers.ICodeTransformer)); // code transformer names groups builder diff --git a/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts b/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts index f1d36eef..de96a08d 100644 --- a/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts +++ b/src/container/modules/custom-code-helpers/CustomCodeHelpersModule.ts @@ -104,12 +104,12 @@ export const customCodeHelpersModule: interfaces.ContainerModule = new Container // customCodeHelper factory bind(ServiceIdentifiers.Factory__ICustomCodeHelper) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getFactory(ServiceIdentifiers.ICustomCodeHelper)); // customCodeHelperGroup factory bind(ServiceIdentifiers.Factory__ICustomCodeHelperGroup) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getFactory(ServiceIdentifiers.ICustomCodeHelperGroup)); // custom code helper formatter diff --git a/src/container/modules/custom-nodes/CustomNodesModule.ts b/src/container/modules/custom-nodes/CustomNodesModule.ts index 08584c19..1e058694 100644 --- a/src/container/modules/custom-nodes/CustomNodesModule.ts +++ b/src/container/modules/custom-nodes/CustomNodesModule.ts @@ -102,7 +102,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule // control flow customNode constructor factory bind(ServiceIdentifiers.Factory__IControlFlowCustomNode) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getConstructorFactory( ServiceIdentifiers.Newable__ICustomNode, ServiceIdentifiers.Factory__IIdentifierNamesGenerator, @@ -113,7 +113,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule // dead code injection customNode constructor factory bind(ServiceIdentifiers.Factory__IDeadCodeInjectionCustomNode) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getConstructorFactory( ServiceIdentifiers.Newable__ICustomNode, ServiceIdentifiers.Factory__IIdentifierNamesGenerator, @@ -124,7 +124,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule // object expression keys transformer customNode constructor factory bind(ServiceIdentifiers.Factory__IObjectExpressionKeysTransformerCustomNode) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getConstructorFactory( ServiceIdentifiers.Newable__ICustomNode, ServiceIdentifiers.Factory__IIdentifierNamesGenerator, @@ -135,7 +135,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule // string array customNode constructor factory bind(ServiceIdentifiers.Factory__IStringArrayCustomNode) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getConstructorFactory( ServiceIdentifiers.Newable__ICustomNode, ServiceIdentifiers.Factory__IIdentifierNamesGenerator, @@ -149,6 +149,6 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule // string array index node factory bind(ServiceIdentifiers.Factory__IStringArrayIndexNode) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory(ServiceIdentifiers.IStringArrayIndexNode)); }); diff --git a/src/container/modules/generators/GeneratorsModule.ts b/src/container/modules/generators/GeneratorsModule.ts index 72b11531..f65bd616 100644 --- a/src/container/modules/generators/GeneratorsModule.ts +++ b/src/container/modules/generators/GeneratorsModule.ts @@ -83,5 +83,5 @@ export const generatorsModule: interfaces.ContainerModule = new ContainerModule( }; } bind(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) - .toFactory(identifierNameGeneratorFactory()); + .toFactory(identifierNameGeneratorFactory()); }); diff --git a/src/container/modules/node-transformers/ControlFlowTransformersModule.ts b/src/container/modules/node-transformers/ControlFlowTransformersModule.ts index c8d8ecf1..376509db 100644 --- a/src/container/modules/node-transformers/ControlFlowTransformersModule.ts +++ b/src/container/modules/node-transformers/ControlFlowTransformersModule.ts @@ -44,6 +44,6 @@ export const controlFlowTransformersModule: interfaces.ContainerModule = new Con // control flow replacer factory bind(ServiceIdentifiers.Factory__IControlFlowReplacer) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory(ServiceIdentifiers.IControlFlowReplacer)); }); diff --git a/src/container/modules/node-transformers/ConvertingTransformersModule.ts b/src/container/modules/node-transformers/ConvertingTransformersModule.ts index 3a53fa00..cf9874df 100644 --- a/src/container/modules/node-transformers/ConvertingTransformersModule.ts +++ b/src/container/modules/node-transformers/ConvertingTransformersModule.ts @@ -79,7 +79,7 @@ export const convertingTransformersModule: interfaces.ContainerModule = new Cont // object expression extractor factory bind(ServiceIdentifiers.Factory__IObjectExpressionExtractor) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory( ServiceIdentifiers.IObjectExpressionExtractor )); diff --git a/src/container/modules/node-transformers/NodeTransformersModule.ts b/src/container/modules/node-transformers/NodeTransformersModule.ts index e0f9985b..05fb8020 100644 --- a/src/container/modules/node-transformers/NodeTransformersModule.ts +++ b/src/container/modules/node-transformers/NodeTransformersModule.ts @@ -12,7 +12,7 @@ import { NodeTransformerNamesGroupsBuilder } from '../../../node-transformers/No export const nodeTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => { // node transformers factory bind(ServiceIdentifiers.Factory__INodeTransformer) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory(ServiceIdentifiers.INodeTransformer)); // node transformer names groups builder diff --git a/src/container/modules/node-transformers/PreparingTransformersModule.ts b/src/container/modules/node-transformers/PreparingTransformersModule.ts index 75584878..57dd7f13 100644 --- a/src/container/modules/node-transformers/PreparingTransformersModule.ts +++ b/src/container/modules/node-transformers/PreparingTransformersModule.ts @@ -74,7 +74,7 @@ export const preparingTransformersModule: interfaces.ContainerModule = new Conta // obfuscating guards factory bind(ServiceIdentifiers.Factory__INodeGuard) - .toFactory(InversifyContainerFacade + .toFactory(InversifyContainerFacade .getCacheFactory( ServiceIdentifiers.INodeGuard )); diff --git a/src/container/modules/storages/StoragesModule.ts b/src/container/modules/storages/StoragesModule.ts index 3e022721..f0921478 100644 --- a/src/container/modules/storages/StoragesModule.ts +++ b/src/container/modules/storages/StoragesModule.ts @@ -2,6 +2,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ServiceIdentifiers } from '../../ServiceIdentifiers'; import { TControlFlowStorage } from '../../../types/storages/TControlFlowStorage'; +import { TConstructor } from '../../../types/TConstructor'; import { TCustomCodeHelperGroupStorage } from '../../../types/storages/TCustomCodeHelperGroupStorage'; import { IGlobalIdentifierNamesCacheStorage } from '../../../interfaces/storages/identifier-names-cache/IGlobalIdentifierNamesCacheStorage'; @@ -59,8 +60,10 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b bind(ServiceIdentifiers.Factory__TControlFlowStorage) .toFactory((context: interfaces.Context) => { return (): TControlFlowStorage => { - const constructor: interfaces.Newable = context.container - .get>(ServiceIdentifiers.Newable__TControlFlowStorage); + const constructor = context.container + .get>( + ServiceIdentifiers.Newable__TControlFlowStorage + ); const randomGenerator: IRandomGenerator = context.container .get(ServiceIdentifiers.IRandomGenerator); const options: IOptions = context.container diff --git a/src/custom-code-helpers/AbstractCustomCodeHelper.ts b/src/custom-code-helpers/AbstractCustomCodeHelper.ts index be1d24fd..d43325ca 100644 --- a/src/custom-code-helpers/AbstractCustomCodeHelper.ts +++ b/src/custom-code-helpers/AbstractCustomCodeHelper.ts @@ -63,7 +63,7 @@ export abstract class AbstractCustomCodeHelper < * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, diff --git a/src/custom-nodes/AbstractCustomNode.ts b/src/custom-nodes/AbstractCustomNode.ts index f083b441..99622731 100644 --- a/src/custom-nodes/AbstractCustomNode.ts +++ b/src/custom-nodes/AbstractCustomNode.ts @@ -45,7 +45,7 @@ export abstract class AbstractCustomNode < * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter, diff --git a/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts b/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts index 72915e05..a9583390 100644 --- a/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts +++ b/src/custom-nodes/string-array-nodes/AbstractStringArrayCallNode.ts @@ -62,7 +62,7 @@ export abstract class AbstractStringArrayCallNode extends AbstractCustomNode { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator) identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory, @inject(ServiceIdentifiers.Factory__IStringArrayIndexNode) diff --git a/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts b/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts index c08535ff..29734769 100644 --- a/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts +++ b/src/custom-nodes/string-array-nodes/string-array-index-nodes/AbstractStringArrayIndexNode.ts @@ -24,7 +24,7 @@ export abstract class AbstractStringArrayIndexNode implements IStringArrayIndexN * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { diff --git a/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts b/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts index 539878ba..b9e8325f 100644 --- a/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts +++ b/src/node-transformers/simplifying-transformers/AbstractStatementSimplifyTransformer.ts @@ -31,7 +31,7 @@ export abstract class AbstractStatementSimplifyTransformer extends AbstractNodeT * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { diff --git a/src/storages/ArrayStorage.ts b/src/storages/ArrayStorage.ts index d78856b7..a29d32c8 100644 --- a/src/storages/ArrayStorage.ts +++ b/src/storages/ArrayStorage.ts @@ -40,7 +40,7 @@ export abstract class ArrayStorage implements IArrayStorage { * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ - protected constructor ( + public constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { diff --git a/src/types/TConstructor.ts b/src/types/TConstructor.ts new file mode 100644 index 00000000..bf7d5141 --- /dev/null +++ b/src/types/TConstructor.ts @@ -0,0 +1 @@ +export type TConstructor = new (...args: TArgs) => TInstanceType; diff --git a/yarn.lock b/yarn.lock index 67521cca..de511566 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2683,10 +2683,10 @@ interpret@^2.2.0: resolved "https://registry.npmjs.org/interpret/-/interpret-2.2.0.tgz" integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw== -inversify@5.1.1: - version "5.1.1" - resolved "https://registry.yarnpkg.com/inversify/-/inversify-5.1.1.tgz#6fbd668c591337404e005a1946bfe0d802c08730" - integrity sha512-j8grHGDzv1v+8T1sAQ+3boTCntFPfvxLCkNcxB1J8qA0lUN+fAlSyYd+RXKvaPRL4AGyPxViutBEJHNXOyUdFQ== +inversify@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/inversify/-/inversify-6.0.1.tgz#b20d35425d5d8c5cd156120237aad0008d969f02" + integrity sha512-B3ex30927698TJENHR++8FfEaJGqoWOgI6ZY5Ht/nLUsFCwHn6akbwtnUAPCgUepAnTpe2qHxhDNjoKLyz6rgQ== is-arguments@^1.0.4: version "1.0.4"