Kaynağa Gözat

Types refactoring

sanex3339 8 yıl önce
ebeveyn
işleme
848a31d92b

+ 6 - 9
src/cli/JavaScriptObfuscatorCLI.ts

@@ -2,6 +2,7 @@ import * as commander from 'commander';
 import * as path from 'path';
 
 import { TInputOptions } from '../types/options/TInputOptions';
+import { TObject } from '../types/TObject';
 
 import { IObfuscationResult } from '../interfaces/IObfuscationResult';
 
@@ -51,23 +52,19 @@ export class JavaScriptObfuscatorCLI {
     }
 
     /**
-     * @param {Object} options
+     * @param {TObject} options
      * @returns {TInputOptions}
      */
-    private static sanitizeOptions (options: Object): TInputOptions {
+    private static sanitizeOptions (options: TObject): TInputOptions {
         const filteredOptions: TInputOptions = {};
         const availableOptions: string[] = Object.keys(DEFAULT_PRESET);
 
         for (const option in options) {
-            if (!options.hasOwnProperty(option)) {
+            if (!options.hasOwnProperty(option) || !availableOptions.includes(option)) {
                 continue;
             }
 
-            if (!availableOptions.includes(option)) {
-                continue;
-            }
-
-            (<any>filteredOptions)[option] = (<any>options)[option];
+            filteredOptions[option] = options[option];
         }
 
         return filteredOptions;
@@ -253,7 +250,7 @@ export class JavaScriptObfuscatorCLI {
 
     private processData (): void {
         const options: TInputOptions = this.buildOptions();
-        const outputCodePath: string = CLIUtils.getOutputCodePath((<any>this.commands).output, this.inputPath);
+        const outputCodePath: string = CLIUtils.getOutputCodePath(this.commands.output, this.inputPath);
 
         if (options.sourceMap) {
             this.processDataWithSourceMap(outputCodePath, options);

+ 4 - 2
src/cli/utils/CLIUtils.ts

@@ -2,6 +2,8 @@ import * as fs from 'fs';
 import * as mkdirp from 'mkdirp';
 import * as path from 'path';
 
+import { TObject } from '../../types/TObject';
+
 import { IPackageConfig } from '../../interfaces/IPackageConfig';
 
 export class CLIUtils {
@@ -75,9 +77,9 @@ export class CLIUtils {
 
     /**
      * @param {string} configPath
-     * @returns {Object}
+     * @returns {TObject}
      */
-    public static getUserConfig (configPath: string): Object {
+    public static getUserConfig (configPath: string): TObject {
         let config: Object;
 
         try {

+ 5 - 1
src/node/NodeUtils.ts

@@ -45,6 +45,10 @@ export class NodeUtils {
      * @returns {T}
      */
     public static clone <T extends ESTree.Node> (astTree: T): T {
+        /**
+         * @param {T} node
+         * @returns {T}
+         */
         const cloneRecursive: (node: T) => T = (node: T) => {
             if (node === null) {
                 return node;
@@ -89,7 +93,7 @@ export class NodeUtils {
         structure = NodeUtils.addXVerbatimPropertyToLiterals(structure);
         structure = NodeUtils.parentize(structure);
 
-        return <TStatement[]>structure.body;
+        return structure.body;
     }
 
     /**

+ 1 - 0
src/types/TObject.d.ts

@@ -0,0 +1 @@
+export type TObject = {[key: string]: any};

+ 3 - 1
src/types/options/TInputOptions.d.ts

@@ -1,3 +1,5 @@
+import { TObject } from '../TObject';
+
 import { IOptions } from '../../interfaces/options/IOptions';
 
-export type TInputOptions = Partial<Pick<IOptions, keyof IOptions>>;
+export type TInputOptions = Partial<Pick<IOptions, keyof IOptions>> & TObject;