Parcourir la source

using type inferrence with Maps when initialization and declaration on same line

sanex3339 il y a 8 ans
Parent
commit
0df95f7424

+ 1 - 1
README.md

@@ -350,7 +350,7 @@ Type: `number` Default: `0.8` Min: `0` Max: `1`
 
 
 You can use this setting to adjust the probability (from 0 to 1) that a string literal will be inserted into the `stringArray`.
 You can use this setting to adjust the probability (from 0 to 1) that a string literal will be inserted into the `stringArray`.
 
 
-This setting is useful with large code size because repeatdely calls to the `stringArray` array can slightly slow down your code.
+This setting is useful with large code size because repeatdely calls to the string array can slightly slow down your code.
 
 
 `stringArrayThreshold: 0` equals to `stringArray: false`.
 `stringArrayThreshold: 0` equals to `stringArray: false`.
 
 

+ 2 - 2
src/Obfuscator.ts

@@ -29,7 +29,7 @@ export class Obfuscator implements IObfuscator {
     /**
     /**
      * @type {Map<string, NodeTransformers[]>}
      * @type {Map<string, NodeTransformers[]>}
      */
      */
-    private static readonly nodeControlFlowTransformersMap: Map <string, NodeTransformers[]> = new Map <string, NodeTransformers[]> ([
+    private static readonly nodeControlFlowTransformersMap: Map <string, NodeTransformers[]> = new Map([
         [NodeType.FunctionDeclaration, [NodeTransformers.FunctionControlFlowTransformer]],
         [NodeType.FunctionDeclaration, [NodeTransformers.FunctionControlFlowTransformer]],
         [NodeType.FunctionExpression, [NodeTransformers.FunctionControlFlowTransformer]]
         [NodeType.FunctionExpression, [NodeTransformers.FunctionControlFlowTransformer]]
     ]);
     ]);
@@ -37,7 +37,7 @@ export class Obfuscator implements IObfuscator {
     /**
     /**
      * @type {Map<string, NodeTransformers[]>}
      * @type {Map<string, NodeTransformers[]>}
      */
      */
-    private static readonly nodeObfuscatorsMap: Map <string, NodeTransformers[]> = new Map <string, NodeTransformers[]> ([
+    private static readonly nodeObfuscatorsMap: Map <string, NodeTransformers[]> = new Map([
         [NodeType.ArrowFunctionExpression, [NodeTransformers.FunctionObfuscator]],
         [NodeType.ArrowFunctionExpression, [NodeTransformers.FunctionObfuscator]],
         [NodeType.ClassDeclaration, [NodeTransformers.FunctionDeclarationObfuscator]],
         [NodeType.ClassDeclaration, [NodeTransformers.FunctionDeclarationObfuscator]],
         [NodeType.CatchClause, [NodeTransformers.CatchClauseObfuscator]],
         [NodeType.CatchClause, [NodeTransformers.CatchClauseObfuscator]],

+ 1 - 1
src/container/modules/node-transformers/NodeControlFlowTransformersModule.ts

@@ -14,7 +14,7 @@ export const nodeControlFlowTransformersModule: interfaces.ContainerModule = new
 
 
     bind<IControlFlowReplacer>(ServiceIdentifiers['Factory<IControlFlowReplacer>'])
     bind<IControlFlowReplacer>(ServiceIdentifiers['Factory<IControlFlowReplacer>'])
         .toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
         .toFactory<IControlFlowReplacer>((context: interfaces.Context) => {
-            const cache: Map <NodeControlFlowReplacers, IControlFlowReplacer> = new Map <NodeControlFlowReplacers, IControlFlowReplacer> ();
+            const cache: Map <NodeControlFlowReplacers, IControlFlowReplacer> = new Map();
 
 
             return (replacerName: NodeControlFlowReplacers) => {
             return (replacerName: NodeControlFlowReplacers) => {
                 if (cache.has(replacerName)) {
                 if (cache.has(replacerName)) {

+ 1 - 1
src/container/modules/node-transformers/NodeObfuscatorsModule.ts

@@ -29,7 +29,7 @@ export const nodeObfuscatorsModule: interfaces.ContainerModule = new ContainerMo
 
 
     bind<IObfuscatorReplacer>(ServiceIdentifiers['Factory<IObfuscatorReplacer>'])
     bind<IObfuscatorReplacer>(ServiceIdentifiers['Factory<IObfuscatorReplacer>'])
         .toFactory<IObfuscatorReplacer>((context: interfaces.Context) => {
         .toFactory<IObfuscatorReplacer>((context: interfaces.Context) => {
-            const cache: Map <NodeObfuscatorsReplacers, IObfuscatorReplacer> = new Map <NodeObfuscatorsReplacers, IObfuscatorReplacer> ();
+            const cache: Map <NodeObfuscatorsReplacers, IObfuscatorReplacer> = new Map();
 
 
             return (replacerName: NodeObfuscatorsReplacers) => {
             return (replacerName: NodeObfuscatorsReplacers) => {
                 if (cache.has(replacerName)) {
                 if (cache.has(replacerName)) {

+ 1 - 1
src/container/modules/node-transformers/NodeTransformersModule.ts

@@ -63,7 +63,7 @@ export const nodeTransformersModule: interfaces.ContainerModule = new ContainerM
     // node transformers factory
     // node transformers factory
     bind<INodeTransformer[]>(ServiceIdentifiers['Factory<INodeTransformer[]>'])
     bind<INodeTransformer[]>(ServiceIdentifiers['Factory<INodeTransformer[]>'])
         .toFactory<INodeTransformer[]>((context: interfaces.Context) => {
         .toFactory<INodeTransformer[]>((context: interfaces.Context) => {
-            const cache: Map <NodeTransformers, INodeTransformer> = new Map <NodeTransformers, INodeTransformer> ();
+            const cache: Map <NodeTransformers, INodeTransformer> = new Map();
 
 
             return (nodeTransformersMap: Map<string, NodeTransformers[]>) => (nodeType: string) => {
             return (nodeTransformersMap: Map<string, NodeTransformers[]>) => (nodeType: string) => {
                 const nodeTransformers: NodeTransformers[] = nodeTransformersMap.get(nodeType) || [];
                 const nodeTransformers: NodeTransformers[] = nodeTransformersMap.get(nodeType) || [];

+ 1 - 1
src/container/modules/stack-trace-analyzer/StackTraceAnalyzerModule.ts

@@ -32,7 +32,7 @@ export const stackTraceAnalyzerModule: interfaces.ContainerModule = new Containe
     // node transformers factory
     // node transformers factory
     bind<ICalleeDataExtractor>(ServiceIdentifiers['Factory<ICalleeDataExtractor>'])
     bind<ICalleeDataExtractor>(ServiceIdentifiers['Factory<ICalleeDataExtractor>'])
         .toFactory<ICalleeDataExtractor>((context: interfaces.Context) => {
         .toFactory<ICalleeDataExtractor>((context: interfaces.Context) => {
-            const cache: Map <CalleeDataExtractors, ICalleeDataExtractor> = new Map <CalleeDataExtractors, ICalleeDataExtractor> ();
+            const cache: Map <CalleeDataExtractors, ICalleeDataExtractor> = new Map();
 
 
             return (calleeDataExtractorName: CalleeDataExtractors) => {
             return (calleeDataExtractorName: CalleeDataExtractors) => {
                 if (cache.has(calleeDataExtractorName)) {
                 if (cache.has(calleeDataExtractorName)) {

+ 2 - 2
src/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.ts

@@ -30,7 +30,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
     /**
     /**
      * @type {Map <string, NodeControlFlowReplacers>}
      * @type {Map <string, NodeControlFlowReplacers>}
      */
      */
-    private static readonly controlFlowReplacersMap: Map <string, NodeControlFlowReplacers> = new Map <string, NodeControlFlowReplacers> ([
+    private static readonly controlFlowReplacersMap: Map <string, NodeControlFlowReplacers> = new Map([
         [NodeType.BinaryExpression, NodeControlFlowReplacers.BinaryExpressionControlFlowReplacer]
         [NodeType.BinaryExpression, NodeControlFlowReplacers.BinaryExpressionControlFlowReplacer]
     ]);
     ]);
 
 
@@ -52,7 +52,7 @@ export class FunctionControlFlowTransformer extends AbstractNodeTransformer {
     /**
     /**
      * @type {Map<ESTree.Node, IStorage<ICustomNode>>}
      * @type {Map<ESTree.Node, IStorage<ICustomNode>>}
      */
      */
-    private controlFlowData: Map <ESTree.Node, IStorage<ICustomNode>> = new Map <ESTree.Node, IStorage<ICustomNode>> ();
+    private controlFlowData: Map <ESTree.Node, IStorage<ICustomNode>> = new Map();
 
 
     /**
     /**
      * @type {TStatement[][]}
      * @type {TStatement[][]}

+ 1 - 1
src/node-transformers/node-control-flow-transformers/control-flow-replacers/BinaryExpressionControlFlowReplacer.ts

@@ -62,7 +62,7 @@ export class BinaryExpressionControlFlowReplacer extends AbstractControlFlowRepl
             storageKeysByBinaryOperator = <Map<ESTree.BinaryOperator, string[]>>binaryOperatorsDataByControlFlowStorageId
             storageKeysByBinaryOperator = <Map<ESTree.BinaryOperator, string[]>>binaryOperatorsDataByControlFlowStorageId
                 .get(controlFlowStorageId);
                 .get(controlFlowStorageId);
         } else {
         } else {
-            storageKeysByBinaryOperator = new Map();
+            storageKeysByBinaryOperator = new Map <ESTree.BinaryOperator, string[]> ();
         }
         }
 
 
         return storageKeysByBinaryOperator;
         return storageKeysByBinaryOperator;

+ 1 - 1
src/node-transformers/node-obfuscators/replacers/IdentifierReplacer.ts

@@ -12,7 +12,7 @@ export class IdentifierReplacer extends AbstractReplacer implements IObfuscatorR
     /**
     /**
      * @type {Map<string, string>}
      * @type {Map<string, string>}
      */
      */
-    private readonly namesMap: Map<string, string> = new Map<string, string>();
+    private readonly namesMap: Map<string, string> = new Map();
 
 
     /**
     /**
      * @param options
      * @param options