Skip to content

Commit ed09424

Browse files
author
sanex3339
committed
Changed file log messages
1 parent ae111ea commit ed09424

File tree

18 files changed

+141
-153
lines changed

18 files changed

+141
-153
lines changed

dist/index.browser.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.cli.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ASTParserFacade.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import acornImportMeta from 'acorn-import-meta';
33
import * as ESTree from 'estree';
44
import chalk, { Chalk } from 'chalk';
55

6-
import { IASTParserFacadeInputData } from './interfaces/IASTParserFacadeInputData';
7-
86
/**
97
* Facade over AST parser `acorn`
108
*/
@@ -28,23 +26,23 @@ export class ASTParserFacade {
2826
];
2927

3028
/**
31-
* @param {string} inputData
29+
* @param {string} sourceCode
3230
* @param {Options} config
3331
* @returns {Program}
3432
*/
35-
public static parse (inputData: IASTParserFacadeInputData, config: acorn.Options): ESTree.Program | never {
33+
public static parse (sourceCode: string, config: acorn.Options): ESTree.Program | never {
3634
const sourceTypeLength: number = ASTParserFacade.sourceTypes.length;
3735

3836
for (let i: number = 0; i < sourceTypeLength; i++) {
3937
try {
40-
return ASTParserFacade.parseType(inputData, config, ASTParserFacade.sourceTypes[i]);
38+
return ASTParserFacade.parseType(sourceCode, config, ASTParserFacade.sourceTypes[i]);
4139
} catch (error) {
4240
if (i < sourceTypeLength - 1) {
4341
continue;
4442
}
4543

4644
throw new Error(ASTParserFacade.processParsingError(
47-
inputData,
45+
sourceCode,
4846
error.message,
4947
error.loc
5048
));
@@ -55,17 +53,16 @@ export class ASTParserFacade {
5553
}
5654

5755
/**
58-
* @param {IASTParserFacadeInputData} inputData
56+
* @param {string} sourceCode
5957
* @param {acorn.Options} inputConfig
6058
* @param {acorn.Options["sourceType"]} sourceType
6159
* @returns {Program}
6260
*/
6361
private static parseType (
64-
inputData: IASTParserFacadeInputData,
62+
sourceCode: string,
6563
inputConfig: acorn.Options,
6664
sourceType: acorn.Options['sourceType']
6765
): ESTree.Program {
68-
const { sourceCode } = inputData;
6966
const comments: ESTree.Comment[] = [];
7067
const config: acorn.Options = {
7168
...inputConfig,
@@ -85,33 +82,27 @@ export class ASTParserFacade {
8582
}
8683

8784
/**
88-
* @param {IASTParserFacadeInputData} inputData
85+
* @param {string} sourceCode
8986
* @param {string} errorMessage
9087
* @param {Position | null} position
9188
* @returns {never}
9289
*/
9390
private static processParsingError (
94-
inputData: IASTParserFacadeInputData,
91+
sourceCode: string,
9592
errorMessage: string,
9693
position: ESTree.Position | null
9794
): never {
9895
if (!position || !position.line || !position.column) {
9996
throw new Error(errorMessage);
10097
}
10198

102-
const { sourceCode, inputFilePath } = inputData;
103-
10499
const sourceCodeLines: string[] = sourceCode.split(/\r?\n/);
105100
const errorLine: string | undefined = sourceCodeLines[position.line - 1];
106101

107102
if (!errorLine) {
108103
throw new Error(errorMessage);
109104
}
110105

111-
const formattedInputFilePath: string = inputFilePath
112-
? `${inputFilePath}, `
113-
: '';
114-
115106
const startErrorIndex: number = Math.max(0, position.column - ASTParserFacade.nearestSymbolsCount);
116107
const endErrorIndex: number = Math.min(errorLine.length, position.column + ASTParserFacade.nearestSymbolsCount);
117108

@@ -121,7 +112,7 @@ export class ASTParserFacade {
121112
}...`;
122113

123114
throw new Error(
124-
`ERROR in ${formattedInputFilePath}line ${position.line}: ${errorMessage}\n${formattedPointer} ${formattedCodeSlice}`
115+
`ERROR at line ${position.line}: ${errorMessage}\n${formattedPointer} ${formattedCodeSlice}`
125116
);
126117
}
127118
}

src/JavaScriptObfuscator.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as ESTree from 'estree';
77

88
import { TObfuscatedCodeFactory } from './types/container/source-code/TObfuscatedCodeFactory';
99

10-
import { IASTParserFacadeInputData } from './interfaces/IASTParserFacadeInputData';
1110
import { IGeneratorOutput } from './interfaces/IGeneratorOutput';
1211
import { IJavaScriptObfuscator } from './interfaces/IJavaScriptObfsucator';
1312
import { ILogger } from './interfaces/logger/ILogger';
@@ -150,12 +149,7 @@ export class JavaScriptObfuscator implements IJavaScriptObfuscator {
150149
* @returns {Program}
151150
*/
152151
private parseCode (sourceCode: string): ESTree.Program {
153-
const inputData: IASTParserFacadeInputData = {
154-
sourceCode,
155-
inputFilePath: this.options.inputFilePath
156-
};
157-
158-
return ASTParserFacade.parse(inputData, JavaScriptObfuscator.parseOptions);
152+
return ASTParserFacade.parse(sourceCode, JavaScriptObfuscator.parseOptions);
159153
}
160154

161155
/**

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import { StringArrayEncodingSanitizer } from './sanitizers/StringArrayEncodingSa
2121

2222
import { CLIUtils } from './utils/CLIUtils';
2323
import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade';
24+
import { Logger } from '../logger/Logger';
2425
import { ObfuscatedCodeWriter } from './utils/ObfuscatedCodeWriter';
2526
import { SourceCodeReader } from './utils/SourceCodeReader';
2627
import { Utils } from '../utils/Utils';
28+
import { LoggingPrefix } from '../enums/logger/LoggingPrefix';
2729

2830
export class JavaScriptObfuscatorCLI implements IInitializable {
2931
/**
@@ -103,14 +105,12 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
103105
const configFileLocation: string = configFilePath ? path.resolve(configFilePath, '.') : '';
104106
const configFileOptions: TInputOptions = configFileLocation ? CLIUtils.getUserConfig(configFileLocation) : {};
105107
const inputFileName: string = path.basename(inputCodePath);
106-
const inputFilePath: string = inputCodePath;
107108

108109
return {
109110
...DEFAULT_PRESET,
110111
...configFileOptions,
111112
...inputCLIOptions,
112-
inputFileName,
113-
inputFilePath
113+
inputFileName
114114
};
115115
}
116116

@@ -367,7 +367,23 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
367367
sourceCodeData.forEach(({ filePath, content }: IFileData, index: number) => {
368368
const outputCodePath: string = this.obfuscatedCodeWriter.getOutputCodePath(filePath);
369369

370-
this.processSourceCode(content, filePath, outputCodePath, index);
370+
try {
371+
Logger.log(
372+
Logger.colorInfo,
373+
LoggingPrefix.CLI,
374+
`Obfuscating file: ${filePath}...`
375+
);
376+
377+
this.processSourceCode(content, filePath, outputCodePath, index);
378+
} catch (error) {
379+
Logger.log(
380+
Logger.colorInfo,
381+
LoggingPrefix.CLI,
382+
`Error in file: ${filePath}...`
383+
);
384+
385+
throw error;
386+
}
371387
});
372388
}
373389

src/cli/utils/SourceCodeReader.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import { TInputCLIOptions } from '../../types/options/TInputCLIOptions';
66

77
import { IFileData } from '../../interfaces/cli/IFileData';
88

9-
import { LoggingPrefix } from '../../enums/logger/LoggingPrefix';
10-
119
import { JavaScriptObfuscatorCLI } from '../JavaScriptObfuscatorCLI';
12-
import { Logger } from '../../logger/Logger';
1310

1411
export class SourceCodeReader {
1512
/**
@@ -104,28 +101,13 @@ export class SourceCodeReader {
104101
&& !SourceCodeReader.isExcludedPath(filePath, excludePatterns);
105102
}
106103

107-
/**
108-
* @param {string} filePath
109-
*/
110-
private static logFilePath (filePath: string): void {
111-
const normalizedFilePath: string = path.normalize(filePath);
112-
113-
Logger.log(
114-
Logger.colorInfo,
115-
LoggingPrefix.CLI,
116-
`Obfuscating file: ${normalizedFilePath}...`
117-
);
118-
}
119-
120104
/**
121105
* @param {string} filePath
122106
* @returns {string}
123107
*/
124108
private static readFile (filePath: string): IFileData {
125-
SourceCodeReader.logFilePath(filePath);
126-
127109
return {
128-
filePath,
110+
filePath: path.normalize(filePath),
129111
content: fs.readFileSync(filePath, JavaScriptObfuscatorCLI.encoding)
130112
};
131113
}

src/interfaces/IASTParserFacadeInputData.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/interfaces/options/IOptions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export interface IOptions {
2020
readonly identifiersDictionary: string[];
2121
readonly identifiersPrefix: string;
2222
readonly inputFileName: string;
23-
readonly inputFilePath: string;
2423
readonly log: boolean;
2524
readonly renameGlobals: boolean;
2625
readonly reservedNames: string[];

src/node/NodeUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class NodeUtils {
3636
*/
3737
public static convertCodeToStructure (code: string): ESTree.Statement[] {
3838
const structure: ESTree.Program = ASTParserFacade.parse(
39-
{ sourceCode: code },
39+
code,
4040
{
4141
ecmaVersion,
4242
sourceType: 'script'

0 commit comments

Comments
 (0)