js-confuser 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +7 -0
- package/dev.js +4 -5
- package/dist/compiler.js +3 -2
- package/dist/constants.js +1 -1
- package/dist/index.js +5 -5
- package/dist/obfuscator.js +14 -3
- package/dist/options.js +2 -2
- package/dist/order.js +1 -0
- package/dist/parser.js +2 -2
- package/dist/precedence.js +1 -1
- package/dist/presets.js +3 -0
- package/dist/probability.js +7 -1
- package/dist/transforms/calculator.js +15 -3
- package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +93 -19
- package/dist/transforms/deadCode.js +1 -1
- package/dist/transforms/dispatcher.js +3 -1
- package/dist/transforms/eval.js +1 -1
- package/dist/transforms/flatten.js +2 -2
- package/dist/transforms/hexadecimalNumbers.js +38 -0
- package/dist/transforms/hideInitializingCode.js +8 -3
- package/dist/transforms/identifier/globalConcealing.js +3 -1
- package/dist/transforms/identifier/nameRecycling.js +2 -1
- package/dist/transforms/lock/integrity.js +2 -1
- package/dist/transforms/lock/lock.js +2 -2
- package/dist/transforms/minify.js +8 -3
- package/dist/transforms/rgf.js +11 -8
- package/dist/transforms/stack.js +2 -1
- package/dist/transforms/string/stringConcealing.js +3 -3
- package/dist/transforms/transform.js +32 -8
- package/dist/traverse.js +4 -2
- package/dist/types.js +5 -1
- package/dist/util/compare.js +4 -4
- package/dist/util/gen.js +66 -47
- package/dist/util/identifiers.js +4 -4
- package/dist/util/insert.js +25 -16
- package/dist/util/object.js +3 -1
- package/dist/util/random.js +5 -5
- package/dist/util/scope.js +1 -1
- package/package.json +11 -11
- package/samples/high.js +1 -198
- package/samples/low.js +1 -26
- package/samples/medium.js +1 -40
- package/src/compiler.ts +5 -1
- package/src/obfuscator.ts +2 -0
- package/src/options.ts +8 -0
- package/src/order.ts +2 -0
- package/src/presets.ts +3 -0
- package/src/transforms/calculator.ts +36 -5
- package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +119 -2
- package/src/transforms/deadCode.ts +102 -0
- package/src/transforms/eval.ts +2 -1
- package/src/transforms/hexadecimalNumbers.ts +31 -0
- package/src/transforms/minify.ts +9 -3
- package/src/transforms/transform.ts +10 -2
- package/test/transforms/eval.test.ts +28 -0
- package/test/transforms/hexadecimalNumbers.test.ts +62 -0
- package/test/transforms/minify.test.ts +38 -0
|
@@ -21,9 +21,9 @@ var _transform = _interopRequireDefault(require("./transform"));
|
|
|
21
21
|
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
|
|
24
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
25
25
|
|
|
26
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
27
|
|
|
28
28
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
29
29
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _transform = _interopRequireDefault(require("./transform"));
|
|
9
|
+
|
|
10
|
+
var _order = require("../order");
|
|
11
|
+
|
|
12
|
+
var _gen = require("../util/gen");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
class HexadecimalNumbers extends _transform.default {
|
|
17
|
+
constructor(o) {
|
|
18
|
+
super(o, _order.ObfuscateOrder.HexadecimalNumbers);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
match(object, parents) {
|
|
22
|
+
return object.type === "Literal" && typeof object.value === "number" && Math.floor(object.value) === object.value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
transform(object, parents) {
|
|
26
|
+
return () => {
|
|
27
|
+
// Technically, a Literal will never be negative because it's supposed to be inside a UnaryExpression with a "-" operator.
|
|
28
|
+
// This code handles it regardless
|
|
29
|
+
var isNegative = object.value < 0;
|
|
30
|
+
var hex = Math.abs(object.value).toString(16);
|
|
31
|
+
var newStr = (isNegative ? "-" : "") + "0x" + hex;
|
|
32
|
+
this.replace(object, (0, _gen.Identifier)(newStr));
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.default = HexadecimalNumbers;
|
|
@@ -131,14 +131,17 @@ class HideInitializingCode extends _transform.default {
|
|
|
131
131
|
var fnsToMake = (0, _random.getRandomInteger)(1, 5);
|
|
132
132
|
var numberLiteralsMade = 1;
|
|
133
133
|
|
|
134
|
-
function numberLiteral(num
|
|
134
|
+
function numberLiteral(num) {
|
|
135
|
+
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
136
|
+
|
|
135
137
|
if (depth > 6 || Math.random() > 0.8 / depth || Math.random() > 80 / numberLiteralsMade) {
|
|
136
138
|
return (0, _gen.Literal)(num);
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
numberLiteralsMade++;
|
|
140
142
|
|
|
141
|
-
function ternaryCall(name
|
|
143
|
+
function ternaryCall(name) {
|
|
144
|
+
let param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _random.getRandomInteger)(-250, 250);
|
|
142
145
|
return (0, _gen.ConditionalExpression)((0, _gen.BinaryExpression)("==", (0, _gen.UnaryExpression)("typeof", (0, _gen.Identifier)(name)), (0, _gen.Literal)("function")), (0, _gen.CallExpression)((0, _gen.Identifier)(name), [numberLiteral(param, depth + 1)]), (0, _gen.Identifier)(name));
|
|
143
146
|
}
|
|
144
147
|
|
|
@@ -232,7 +235,9 @@ class HideInitializingCode extends _transform.default {
|
|
|
232
235
|
return (0, _gen.ConditionalExpression)((0, _gen.BinaryExpression)("==", (0, _gen.UnaryExpression)("typeof", (0, _gen.Identifier)(name)), (0, _gen.Literal)("function")), (0, _gen.CallExpression)((0, _gen.MemberExpression)((0, _gen.Identifier)(name), (0, _gen.Identifier)("call"), false), [(0, _gen.ThisExpression)(), numberLiteral(param)]), (0, _gen.Identifier)(name));
|
|
233
236
|
}
|
|
234
237
|
|
|
235
|
-
function ternaryHell(expr
|
|
238
|
+
function ternaryHell(expr) {
|
|
239
|
+
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
240
|
+
|
|
236
241
|
if (!depth || depth > 5 || Math.random() > 0.99 / (depth / 2)) {
|
|
237
242
|
return expr;
|
|
238
243
|
}
|
|
@@ -155,7 +155,9 @@ class GlobalConcealing extends _transform.default {
|
|
|
155
155
|
|
|
156
156
|
used.add(state);
|
|
157
157
|
newNames[name] = state;
|
|
158
|
-
locations.forEach(
|
|
158
|
+
locations.forEach(_ref => {
|
|
159
|
+
let [node, parents] = _ref;
|
|
160
|
+
|
|
159
161
|
if (!parents.find(x => x.$dispatcherSkip)) {
|
|
160
162
|
// Do not replace
|
|
161
163
|
if (parents[0]) {
|
|
@@ -161,7 +161,8 @@ class NameRecycling extends _transform.default {
|
|
|
161
161
|
var newName = newNames[name];
|
|
162
162
|
|
|
163
163
|
if (newName) {
|
|
164
|
-
locations.forEach(
|
|
164
|
+
locations.forEach(_ref => {
|
|
165
|
+
let [object, parents] = _ref;
|
|
165
166
|
object.name = newName;
|
|
166
167
|
var declaratorIndex = parents.findIndex(p => p.type == "VariableDeclarator");
|
|
167
168
|
|
|
@@ -28,7 +28,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
28
28
|
* @param str
|
|
29
29
|
* @param seed
|
|
30
30
|
*/
|
|
31
|
-
function cyrb53(str
|
|
31
|
+
function cyrb53(str) {
|
|
32
|
+
let seed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
32
33
|
let h1 = 0xdeadbeef ^ seed,
|
|
33
34
|
h2 = 0x41c6ce57 ^ seed;
|
|
34
35
|
|
|
@@ -31,9 +31,9 @@ var _compare = require("../../util/compare");
|
|
|
31
31
|
|
|
32
32
|
var _assert = require("assert");
|
|
33
33
|
|
|
34
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
35
35
|
|
|
36
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
36
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
37
37
|
|
|
38
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
39
|
|
|
@@ -111,10 +111,15 @@ class Minify extends _transform.default {
|
|
|
111
111
|
// Unnecessary return
|
|
112
112
|
if (body.length && body[body.length - 1]) {
|
|
113
113
|
var last = body[body.length - 1];
|
|
114
|
-
var isUndefined = last.argument == null;
|
|
115
114
|
|
|
116
|
-
if (last.type == "ReturnStatement"
|
|
117
|
-
|
|
115
|
+
if (last.type == "ReturnStatement") {
|
|
116
|
+
var isUndefined = last.argument == null;
|
|
117
|
+
|
|
118
|
+
if (isUndefined) {
|
|
119
|
+
if ((0, _insert.getFunction)(object, parents).body == object) {
|
|
120
|
+
body.pop();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
118
123
|
}
|
|
119
124
|
} // Variable declaration grouping
|
|
120
125
|
// var a = 1;
|
package/dist/transforms/rgf.js
CHANGED
|
@@ -27,9 +27,9 @@ var _insert = require("../util/insert");
|
|
|
27
27
|
|
|
28
28
|
var _transform = _interopRequireDefault(require("./transform"));
|
|
29
29
|
|
|
30
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
31
|
|
|
32
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
33
|
|
|
34
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
35
|
|
|
@@ -122,11 +122,13 @@ class RGF extends _transform.default {
|
|
|
122
122
|
|
|
123
123
|
while (true) {
|
|
124
124
|
var hit = false;
|
|
125
|
-
collect.forEach(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
collect.forEach(_ref => {
|
|
126
|
+
let {
|
|
127
|
+
name,
|
|
128
|
+
references: references1,
|
|
129
|
+
location: location1
|
|
130
|
+
} = _ref;
|
|
131
|
+
|
|
130
132
|
if (!references1.size && name) {
|
|
131
133
|
collect.forEach(o => {
|
|
132
134
|
if (o.location[0] !== location1[0] && o.references.size && o.references.delete(name)) {
|
|
@@ -193,9 +195,10 @@ class RGF extends _transform.default {
|
|
|
193
195
|
var arrayExpression = (0, _gen.ArrayExpression)([]);
|
|
194
196
|
var variableDeclaration = (0, _gen.VariableDeclaration)([(0, _gen.VariableDeclarator)((0, _gen.Identifier)(referenceArray), arrayExpression)]);
|
|
195
197
|
(0, _insert.prepend)(contextObject, variableDeclaration);
|
|
196
|
-
queue.forEach(
|
|
198
|
+
queue.forEach(_ref2 => {
|
|
197
199
|
var _object$id2;
|
|
198
200
|
|
|
201
|
+
let [object, parents] = _ref2;
|
|
199
202
|
var name = object === null || object === void 0 ? void 0 : (_object$id2 = object.id) === null || _object$id2 === void 0 ? void 0 : _object$id2.name;
|
|
200
203
|
var hasName = !!name;
|
|
201
204
|
var params = object.params.map(x => x.name) || [];
|
package/dist/transforms/stack.js
CHANGED
|
@@ -136,7 +136,8 @@ class Stack extends _transform.default {
|
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
function numberLiteral(number
|
|
139
|
+
function numberLiteral(number) {
|
|
140
|
+
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
140
141
|
(0, _assert.ok)(number === number);
|
|
141
142
|
|
|
142
143
|
if (typeof number !== "number" || !Object.keys(deadValues).length || depth > 5 || Math.random() > (depth == 0 ? 0.9 : 0.8 / (depth * 2))) {
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isModuleSource = isModuleSource;
|
|
7
6
|
exports.default = void 0;
|
|
7
|
+
exports.isModuleSource = isModuleSource;
|
|
8
8
|
|
|
9
9
|
var _assert = require("assert");
|
|
10
10
|
|
|
@@ -168,8 +168,8 @@ class StringConcealing extends _transform.default {
|
|
|
168
168
|
callExpr = (0, _gen.CallExpression)((0, _gen.MemberExpression)((0, _gen.Identifier)(fnName), (0, _gen.Identifier)("apply"), false), [(0, _gen.ThisExpression)(), (0, _gen.ArrayExpression)([(0, _gen.Literal)(index)])]);
|
|
169
169
|
} // use `.call`
|
|
170
170
|
else if (Math.random() > 0.5) {
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
callExpr = (0, _gen.CallExpression)((0, _gen.MemberExpression)((0, _gen.Identifier)(fnName), (0, _gen.Identifier)("call"), false), [(0, _gen.ThisExpression)(), (0, _gen.Literal)(index)]);
|
|
172
|
+
}
|
|
173
173
|
|
|
174
174
|
var constantReference = parents.length && Math.random() > 0.5 / this.variablesMade;
|
|
175
175
|
|
|
@@ -85,7 +85,9 @@ class Transform {
|
|
|
85
85
|
/**
|
|
86
86
|
* Transformations to run at the same time (can cause conflicts so use sparingly)
|
|
87
87
|
*/
|
|
88
|
-
constructor(obfuscator
|
|
88
|
+
constructor(obfuscator) {
|
|
89
|
+
let priority = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
|
90
|
+
|
|
89
91
|
_defineProperty(this, "obfuscator", void 0);
|
|
90
92
|
|
|
91
93
|
_defineProperty(this, "options", void 0);
|
|
@@ -209,12 +211,21 @@ class Transform {
|
|
|
209
211
|
*/
|
|
210
212
|
|
|
211
213
|
|
|
212
|
-
getGenerator(
|
|
214
|
+
getGenerator() {
|
|
215
|
+
let offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
213
216
|
var count = offset;
|
|
217
|
+
var identifiers = new Set();
|
|
214
218
|
return {
|
|
215
219
|
generate: () => {
|
|
216
|
-
|
|
217
|
-
|
|
220
|
+
var retValue;
|
|
221
|
+
|
|
222
|
+
do {
|
|
223
|
+
count++;
|
|
224
|
+
retValue = this.generateIdentifier(-1, count);
|
|
225
|
+
} while (identifiers.has(retValue));
|
|
226
|
+
|
|
227
|
+
identifiers.add(retValue);
|
|
228
|
+
return retValue;
|
|
218
229
|
}
|
|
219
230
|
};
|
|
220
231
|
}
|
|
@@ -225,7 +236,10 @@ class Transform {
|
|
|
225
236
|
*/
|
|
226
237
|
|
|
227
238
|
|
|
228
|
-
generateIdentifier(
|
|
239
|
+
generateIdentifier() {
|
|
240
|
+
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
|
|
241
|
+
let count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
|
242
|
+
|
|
229
243
|
if (length == -1) {
|
|
230
244
|
length = (0, _random.getRandomInteger)(6, 8);
|
|
231
245
|
}
|
|
@@ -241,7 +255,9 @@ class Transform {
|
|
|
241
255
|
var identifier;
|
|
242
256
|
|
|
243
257
|
do {
|
|
244
|
-
identifier = (0, _probability.ComputeProbabilityMap)(this.options.identifierGenerator, (
|
|
258
|
+
identifier = (0, _probability.ComputeProbabilityMap)(this.options.identifierGenerator, function () {
|
|
259
|
+
let mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "randomized";
|
|
260
|
+
|
|
245
261
|
switch (mode) {
|
|
246
262
|
case "randomized":
|
|
247
263
|
var characters = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
|
|
@@ -352,8 +368,12 @@ class Transform {
|
|
|
352
368
|
*/
|
|
353
369
|
|
|
354
370
|
|
|
355
|
-
log(
|
|
371
|
+
log() {
|
|
356
372
|
if (this.options.verbose) {
|
|
373
|
+
for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
374
|
+
messages[_key] = arguments[_key];
|
|
375
|
+
}
|
|
376
|
+
|
|
357
377
|
console.log("[" + this.className + "]", ...messages);
|
|
358
378
|
}
|
|
359
379
|
}
|
|
@@ -363,8 +383,12 @@ class Transform {
|
|
|
363
383
|
*/
|
|
364
384
|
|
|
365
385
|
|
|
366
|
-
warn(
|
|
386
|
+
warn() {
|
|
367
387
|
if (this.options.verbose) {
|
|
388
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
389
|
+
messages[_key2] = arguments[_key2];
|
|
390
|
+
}
|
|
391
|
+
|
|
368
392
|
console.log("[ WARN " + this.className + " ]", ...messages);
|
|
369
393
|
}
|
|
370
394
|
}
|
package/dist/traverse.js
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.default = traverse;
|
|
6
7
|
exports.getBlock = getBlock;
|
|
7
8
|
exports.isBlock = isBlock;
|
|
8
9
|
exports.walk = walk;
|
|
9
|
-
exports.default = traverse;
|
|
10
10
|
|
|
11
11
|
var _identifiers = require("./util/identifiers");
|
|
12
12
|
|
|
@@ -39,7 +39,9 @@ function isBlock(object) {
|
|
|
39
39
|
return object && (object.type == "BlockStatement" || object.type == "Program");
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function walk(object, parents, onEnter
|
|
42
|
+
function walk(object, parents, onEnter) {
|
|
43
|
+
let seen = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Set();
|
|
44
|
+
|
|
43
45
|
if (typeof object === "object" && object) {
|
|
44
46
|
if (seen.has(object)) {
|
|
45
47
|
console.log(object);
|
package/dist/types.js
CHANGED
package/dist/util/compare.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isEquivalent = isEquivalent;
|
|
7
|
-
exports.isLoop = isLoop;
|
|
8
|
-
exports.isValidIdentifier = isValidIdentifier;
|
|
9
|
-
exports.isInsideType = isInsideType;
|
|
10
6
|
exports.isDirective = isDirective;
|
|
7
|
+
exports.isEquivalent = isEquivalent;
|
|
11
8
|
exports.isIndependent = isIndependent;
|
|
9
|
+
exports.isInsideType = isInsideType;
|
|
10
|
+
exports.isLoop = isLoop;
|
|
12
11
|
exports.isPrimitive = isPrimitive;
|
|
12
|
+
exports.isValidIdentifier = isValidIdentifier;
|
|
13
13
|
|
|
14
14
|
var _traverse = require("../traverse");
|
|
15
15
|
|
package/dist/util/gen.js
CHANGED
|
@@ -3,51 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
6
|
+
exports.AddComment = AddComment;
|
|
7
|
+
exports.ArrayExpression = ArrayExpression;
|
|
8
|
+
exports.ArrayPattern = ArrayPattern;
|
|
9
|
+
exports.AssignmentExpression = AssignmentExpression;
|
|
10
|
+
exports.AssignmentPattern = AssignmentPattern;
|
|
11
|
+
exports.AwaitExpression = AwaitExpression;
|
|
11
12
|
exports.BinaryExpression = BinaryExpression;
|
|
12
|
-
exports.
|
|
13
|
-
exports.SwitchCase = SwitchCase;
|
|
14
|
-
exports.SwitchDefaultCase = SwitchDefaultCase;
|
|
15
|
-
exports.LabeledStatement = LabeledStatement;
|
|
16
|
-
exports.SwitchStatement = SwitchStatement;
|
|
13
|
+
exports.BlockStatement = BlockStatement;
|
|
17
14
|
exports.BreakStatement = BreakStatement;
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.VariableDeclaration = VariableDeclaration;
|
|
22
|
-
exports.ForStatement = ForStatement;
|
|
23
|
-
exports.WhileStatement = WhileStatement;
|
|
24
|
-
exports.IfStatement = IfStatement;
|
|
25
|
-
exports.FunctionExpression = FunctionExpression;
|
|
26
|
-
exports.FunctionDeclaration = FunctionDeclaration;
|
|
27
|
-
exports.DebuggerStatement = DebuggerStatement;
|
|
28
|
-
exports.ReturnStatement = ReturnStatement;
|
|
29
|
-
exports.AwaitExpression = AwaitExpression;
|
|
15
|
+
exports.CallExpression = CallExpression;
|
|
16
|
+
exports.CatchClause = CatchClause;
|
|
17
|
+
exports.ClassDeclaration = ClassDeclaration;
|
|
30
18
|
exports.ConditionalExpression = ConditionalExpression;
|
|
19
|
+
exports.DebuggerStatement = DebuggerStatement;
|
|
31
20
|
exports.ExpressionStatement = ExpressionStatement;
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.
|
|
21
|
+
exports.ForStatement = ForStatement;
|
|
22
|
+
exports.FunctionDeclaration = FunctionDeclaration;
|
|
23
|
+
exports.FunctionExpression = FunctionExpression;
|
|
24
|
+
exports.Identifier = Identifier;
|
|
25
|
+
exports.IfStatement = IfStatement;
|
|
26
|
+
exports.LabeledStatement = LabeledStatement;
|
|
27
|
+
exports.Literal = Literal;
|
|
28
|
+
exports.LogicalExpression = LogicalExpression;
|
|
35
29
|
exports.MemberExpression = MemberExpression;
|
|
36
|
-
exports.CallExpression = CallExpression;
|
|
37
|
-
exports.NewExpression = NewExpression;
|
|
38
|
-
exports.AssignmentExpression = AssignmentExpression;
|
|
39
|
-
exports.ArrayPattern = ArrayPattern;
|
|
40
|
-
exports.ArrayExpression = ArrayExpression;
|
|
41
|
-
exports.AssignmentPattern = AssignmentPattern;
|
|
42
|
-
exports.AddComment = AddComment;
|
|
43
30
|
exports.MethodDefinition = MethodDefinition;
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
exports.
|
|
47
|
-
exports.
|
|
31
|
+
exports.NewExpression = NewExpression;
|
|
32
|
+
exports.ObjectExpression = ObjectExpression;
|
|
33
|
+
exports.Property = Property;
|
|
34
|
+
exports.RegexLiteral = RegexLiteral;
|
|
48
35
|
exports.RestElement = RestElement;
|
|
49
|
-
exports.
|
|
36
|
+
exports.ReturnStatement = ReturnStatement;
|
|
37
|
+
exports.SequenceExpression = SequenceExpression;
|
|
38
|
+
exports.SpreadElement = SpreadElement;
|
|
39
|
+
exports.SwitchCase = SwitchCase;
|
|
40
|
+
exports.SwitchDefaultCase = SwitchDefaultCase;
|
|
41
|
+
exports.SwitchStatement = SwitchStatement;
|
|
42
|
+
exports.ThisExpression = ThisExpression;
|
|
43
|
+
exports.ThrowStatement = ThrowStatement;
|
|
50
44
|
exports.TryStatement = TryStatement;
|
|
45
|
+
exports.UnaryExpression = UnaryExpression;
|
|
46
|
+
exports.UpdateExpression = UpdateExpression;
|
|
47
|
+
exports.VariableDeclaration = VariableDeclaration;
|
|
48
|
+
exports.VariableDeclarator = VariableDeclarator;
|
|
49
|
+
exports.WhileStatement = WhileStatement;
|
|
50
|
+
exports.WithStatement = WithStatement;
|
|
51
51
|
|
|
52
52
|
var _assert = require("assert");
|
|
53
53
|
|
|
@@ -172,7 +172,9 @@ function BreakStatement(label) {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
function Property(key, value
|
|
175
|
+
function Property(key, value) {
|
|
176
|
+
let computed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
177
|
+
|
|
176
178
|
if (!key) {
|
|
177
179
|
throw new Error("key is undefined");
|
|
178
180
|
}
|
|
@@ -203,7 +205,9 @@ function ObjectExpression(properties) {
|
|
|
203
205
|
};
|
|
204
206
|
}
|
|
205
207
|
|
|
206
|
-
function VariableDeclarator(id
|
|
208
|
+
function VariableDeclarator(id) {
|
|
209
|
+
let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
210
|
+
|
|
207
211
|
if (typeof id === "string") {
|
|
208
212
|
id = Identifier(id);
|
|
209
213
|
}
|
|
@@ -215,7 +219,9 @@ function VariableDeclarator(id, init = null) {
|
|
|
215
219
|
};
|
|
216
220
|
}
|
|
217
221
|
|
|
218
|
-
function VariableDeclaration(declarations
|
|
222
|
+
function VariableDeclaration(declarations) {
|
|
223
|
+
let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "var";
|
|
224
|
+
|
|
219
225
|
if (!Array.isArray(declarations)) {
|
|
220
226
|
declarations = [declarations];
|
|
221
227
|
}
|
|
@@ -252,7 +258,9 @@ function WhileStatement(test, body) {
|
|
|
252
258
|
};
|
|
253
259
|
}
|
|
254
260
|
|
|
255
|
-
function IfStatement(test, consequent
|
|
261
|
+
function IfStatement(test, consequent) {
|
|
262
|
+
let alternate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
263
|
+
|
|
256
264
|
if (!test) {
|
|
257
265
|
throw new Error("test is undefined");
|
|
258
266
|
}
|
|
@@ -329,7 +337,9 @@ function DebuggerStatement() {
|
|
|
329
337
|
};
|
|
330
338
|
}
|
|
331
339
|
|
|
332
|
-
function ReturnStatement(
|
|
340
|
+
function ReturnStatement() {
|
|
341
|
+
let argument = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
342
|
+
|
|
333
343
|
if (argument) {
|
|
334
344
|
(0, _assert.ok)(argument.type, "Argument should be a node");
|
|
335
345
|
}
|
|
@@ -378,7 +388,8 @@ function UnaryExpression(operator, argument) {
|
|
|
378
388
|
};
|
|
379
389
|
}
|
|
380
390
|
|
|
381
|
-
function UpdateExpression(operator, argument
|
|
391
|
+
function UpdateExpression(operator, argument) {
|
|
392
|
+
let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
382
393
|
return {
|
|
383
394
|
type: "UpdateExpression",
|
|
384
395
|
operator,
|
|
@@ -402,7 +413,9 @@ function SequenceExpression(expressions) {
|
|
|
402
413
|
};
|
|
403
414
|
}
|
|
404
415
|
|
|
405
|
-
function MemberExpression(object, property
|
|
416
|
+
function MemberExpression(object, property) {
|
|
417
|
+
let computed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
418
|
+
|
|
406
419
|
if (!object) {
|
|
407
420
|
throw new Error("object undefined");
|
|
408
421
|
}
|
|
@@ -497,7 +510,9 @@ function AddComment(node, text) {
|
|
|
497
510
|
return node;
|
|
498
511
|
}
|
|
499
512
|
|
|
500
|
-
function MethodDefinition(identifier, functionExpression, kind
|
|
513
|
+
function MethodDefinition(identifier, functionExpression, kind) {
|
|
514
|
+
let isStatic = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
|
|
515
|
+
let computed = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
501
516
|
return {
|
|
502
517
|
type: "MethodDefinition",
|
|
503
518
|
key: identifier,
|
|
@@ -508,7 +523,9 @@ function MethodDefinition(identifier, functionExpression, kind, isStatic = true,
|
|
|
508
523
|
};
|
|
509
524
|
}
|
|
510
525
|
|
|
511
|
-
function ClassDeclaration(id
|
|
526
|
+
function ClassDeclaration(id) {
|
|
527
|
+
let superClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
528
|
+
let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
512
529
|
return {
|
|
513
530
|
type: "ClassDeclaration",
|
|
514
531
|
id: id,
|
|
@@ -563,7 +580,9 @@ function RestElement(argument) {
|
|
|
563
580
|
};
|
|
564
581
|
}
|
|
565
582
|
|
|
566
|
-
function CatchClause(
|
|
583
|
+
function CatchClause() {
|
|
584
|
+
let param = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
585
|
+
let body = arguments.length > 1 ? arguments[1] : undefined;
|
|
567
586
|
return {
|
|
568
587
|
type: "CatchClause",
|
|
569
588
|
param: param,
|
package/dist/util/identifiers.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.getIdentifierInfo = getIdentifierInfo;
|
|
6
|
+
exports.containsLexicallyBoundVariables = containsLexicallyBoundVariables;
|
|
8
7
|
exports.getDefiningIdentifier = getDefiningIdentifier;
|
|
9
|
-
exports.isFunctionParameter = isFunctionParameter;
|
|
10
8
|
exports.getFunctionParameters = getFunctionParameters;
|
|
11
|
-
exports.
|
|
9
|
+
exports.getIdentifierInfo = getIdentifierInfo;
|
|
10
|
+
exports.isFunctionParameter = isFunctionParameter;
|
|
11
|
+
exports.validateChain = validateChain;
|
|
12
12
|
|
|
13
13
|
var _assert = require("assert");
|
|
14
14
|
|
package/dist/util/insert.js
CHANGED
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.isContext = isContext;
|
|
6
|
+
exports.append = append;
|
|
7
|
+
exports.clone = clone;
|
|
8
|
+
exports.deleteDeclaration = deleteDeclaration;
|
|
9
|
+
exports.deleteDirect = deleteDirect;
|
|
10
|
+
exports.getBlockBody = getBlockBody;
|
|
12
11
|
exports.getContexts = getContexts;
|
|
13
|
-
exports.getLexContext = getLexContext;
|
|
14
12
|
exports.getDefiningContext = getDefiningContext;
|
|
15
|
-
exports.
|
|
16
|
-
exports.getBlockBody = getBlockBody;
|
|
13
|
+
exports.getFunction = getFunction;
|
|
17
14
|
exports.getIndexDirect = getIndexDirect;
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.clone = clone;
|
|
15
|
+
exports.getLexContext = getLexContext;
|
|
16
|
+
exports.getReferencingContexts = getReferencingContexts;
|
|
17
|
+
exports.getVarContext = getVarContext;
|
|
18
|
+
exports.isContext = isContext;
|
|
23
19
|
exports.isForInitialize = isForInitialize;
|
|
20
|
+
exports.isFunction = isFunction;
|
|
21
|
+
exports.isLexContext = isLexContext;
|
|
22
|
+
exports.isVarContext = isVarContext;
|
|
23
|
+
exports.prepend = prepend;
|
|
24
24
|
|
|
25
25
|
var _assert = require("assert");
|
|
26
26
|
|
|
@@ -250,9 +250,13 @@ function deleteDirect(object, parent) {
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
function prepend(block
|
|
253
|
+
function prepend(block) {
|
|
254
254
|
(0, _assert.ok)(!Array.isArray(block), "block should not be array");
|
|
255
255
|
|
|
256
|
+
for (var _len = arguments.length, nodes = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
257
|
+
nodes[_key - 1] = arguments[_key];
|
|
258
|
+
}
|
|
259
|
+
|
|
256
260
|
if (block.type == "Program") {
|
|
257
261
|
var decs = 0;
|
|
258
262
|
block.body.forEach((stmt, i) => {
|
|
@@ -268,8 +272,13 @@ function prepend(block, ...nodes) {
|
|
|
268
272
|
}
|
|
269
273
|
}
|
|
270
274
|
|
|
271
|
-
function append(block
|
|
275
|
+
function append(block) {
|
|
272
276
|
(0, _assert.ok)(!Array.isArray(block), "block should not be array");
|
|
277
|
+
|
|
278
|
+
for (var _len2 = arguments.length, nodes = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
279
|
+
nodes[_key2 - 1] = arguments[_key2];
|
|
280
|
+
}
|
|
281
|
+
|
|
273
282
|
getBlockBody(block).push(...nodes);
|
|
274
283
|
}
|
|
275
284
|
|