Skip to content

Commit 7c23e9f

Browse files
committed
Applying optimize-js for obfuscated code
1 parent 3809f54 commit 7c23e9f

File tree

9 files changed

+194
-172
lines changed

9 files changed

+194
-172
lines changed

dist/index.js

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

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "0.8.0-dev.0",
3+
"version": "0.8.0-dev.1",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",
@@ -29,6 +29,7 @@
2929
"estraverse": "^4.2.0",
3030
"format-unicorn": "^1.1.0",
3131
"mkdirp": "^0.5.1",
32+
"optimize-js": "^1.0.1",
3233
"source-map-support": "^0.4.2"
3334
},
3435
"devDependencies": {
@@ -52,6 +53,7 @@
5253
"coveralls": "^2.11.14",
5354
"istanbul": "1.1.0-alpha.1",
5455
"mocha": "^3.0.2",
56+
"optimize-js-plugin": "0.0.4",
5557
"sinon": "^2.0.0-pre.3",
5658
"ts-loader": "^0.8.2",
5759
"ts-node": "^1.3.0",

src/JavaScriptObfuscatorInternal.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Obfuscator } from "./Obfuscator";
1212
import { Options } from "./options/Options";
1313
import { SourceMapCorrector } from "./SourceMapCorrector";
1414

15+
const optimizeJs = require('optimize-js');
16+
1517
export class JavaScriptObfuscatorInternal {
1618
/**
1719
* @type {GenerateOptions}
@@ -67,6 +69,10 @@ export class JavaScriptObfuscatorInternal {
6769

6870
const generatorOutput: IGeneratorOutput = escodegen.generate(astTree, escodegenParams);
6971

72+
if (options.optimize) {
73+
generatorOutput.code = optimizeJs(generatorOutput.code);
74+
}
75+
7076
generatorOutput.map = generatorOutput.map ? generatorOutput.map.toString() : '';
7177

7278
return generatorOutput;

src/interfaces/IObfuscatorOptions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IObfuscatorOptions {
66
debugProtectionInterval?: boolean;
77
disableConsoleOutput?: boolean;
88
encodeUnicodeLiterals?: boolean;
9+
optimize?: boolean;
910
reservedNames?: string[];
1011
rotateUnicodeArray?: boolean;
1112
selfDefending?: boolean;

src/interfaces/IOptions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface IOptions {
66
readonly debugProtectionInterval: boolean;
77
readonly disableConsoleOutput: boolean;
88
readonly encodeUnicodeLiterals: boolean;
9+
readonly optimize: boolean;
910
readonly reservedNames: string[];
1011
readonly rotateUnicodeArray: boolean;
1112
readonly selfDefending: boolean;

src/options/Options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ export class Options implements IOptions {
7272
@IsBoolean()
7373
public readonly encodeUnicodeLiterals: boolean;
7474

75+
/**
76+
* @type {boolean}
77+
*/
78+
@IsBoolean()
79+
public readonly optimize: boolean;
80+
7581
/**
7682
* @type {string[]}
7783
*/

src/preset-options/DefaultPreset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const DEFAULT_PRESET: IObfuscatorOptions = Object.freeze({
99
disableConsoleOutput: true,
1010
domainLock: [],
1111
encodeUnicodeLiterals: false,
12+
optimize: true,
1213
reservedNames: [],
1314
rotateUnicodeArray: true,
1415
selfDefending: true,

src/preset-options/NoCustomNodesPreset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const NO_CUSTOM_NODES_PRESET: IObfuscatorOptions = Object.freeze({
99
disableConsoleOutput: false,
1010
domainLock: [],
1111
encodeUnicodeLiterals: false,
12+
optimize: false,
1213
reservedNames: [],
1314
rotateUnicodeArray: false,
1415
selfDefending: false,

webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var fs = require("fs"),
44
nodeExternals = require('webpack-node-externals'),
5-
webpack = require('webpack');
5+
webpack = require('webpack'),
6+
OptimizeJSPlugin = require('optimize-js-plugin');
67

78
function getLicenseText () {
89
return "/*\nCopyright (C) 2016 Timofey Kachalov <sanex3339@yandex.ru>\n\n" +
@@ -31,7 +32,10 @@ module.exports = {
3132
raw: true,
3233
entryOnly: false
3334
}
34-
)
35+
),
36+
/*new OptimizeJSPlugin({
37+
sourceMap: true
38+
})*/
3539
],
3640
output: {
3741
path: './dist',

0 commit comments

Comments
 (0)