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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
# `1.5.0`
|
|
2
|
+
Hexadecimal Numbers
|
|
3
|
+
|
|
4
|
+
- The hexadecimal representation can now be used. [#29](https://github.com/MichaelXF/js-confuser/issues/29)
|
|
5
|
+
- New option `hexadecimalNumbers` to control this behavior.
|
|
6
|
+
|
|
7
|
+
### `hexadecimalNumbers`
|
|
8
|
+
|
|
9
|
+
Uses the hexadecimal representation (`50` -> `0x32`) for numbers. (`true/false`) -->
|
|
10
|
+
|
|
11
|
+
- Slight improvement to `Control Flow Flattening`
|
|
12
|
+
- Slight improvement to `Calculator`
|
|
13
|
+
|
|
14
|
+
# `1.4.3`
|
|
15
|
+
Minify Fix
|
|
16
|
+
|
|
17
|
+
- Fixed [#34](https://github.com/MichaelXF/js-confuser/issues/34)
|
|
18
|
+
- - Minify was removing `return` statements too aggressively, fixed in this version.
|
|
19
|
+
|
|
20
|
+
- Slight improvement to Control Flow Flattening
|
|
21
|
+
|
|
22
|
+
# `1.4.2`
|
|
23
|
+
Eval Fix
|
|
24
|
+
|
|
25
|
+
- Fixed [#31](https://github.com/MichaelXF/js-confuser/issues/31)
|
|
26
|
+
- - Eval and Integrity didn't work together, fixed in this version.
|
|
27
|
+
|
|
1
28
|
# `1.4.1`
|
|
2
29
|
AntiDebug Fix
|
|
3
30
|
|
package/README.md
CHANGED
|
@@ -115,6 +115,10 @@ JsConfuser.obfuscate(`<source code>`, {
|
|
|
115
115
|
|
|
116
116
|
Remove's whitespace from the final output. Enabled by default. (`true/false`)
|
|
117
117
|
|
|
118
|
+
### `hexadecimalNumbers`
|
|
119
|
+
|
|
120
|
+
Uses the hexadecimal representation (`50` -> `0x32`) for numbers. (`true/false`)
|
|
121
|
+
|
|
118
122
|
### `minify`
|
|
119
123
|
|
|
120
124
|
Minifies redundant code. (`true/false`)
|
|
@@ -528,6 +532,7 @@ function iVQoGQD(...iVQoGQD){
|
|
|
528
532
|
|
|
529
533
|
calculator: true,
|
|
530
534
|
compact: true,
|
|
535
|
+
hexadecimalNumbers: true,
|
|
531
536
|
controlFlowFlattening: 0.75,
|
|
532
537
|
deadCode: 0.2,
|
|
533
538
|
dispatcher: true,
|
|
@@ -562,6 +567,7 @@ function iVQoGQD(...iVQoGQD){
|
|
|
562
567
|
|
|
563
568
|
calculator: true,
|
|
564
569
|
compact: true,
|
|
570
|
+
hexadecimalNumbers: true,
|
|
565
571
|
controlFlowFlattening: 0.5,
|
|
566
572
|
deadCode: 0.025,
|
|
567
573
|
dispatcher: 0.75,
|
|
@@ -590,6 +596,7 @@ function iVQoGQD(...iVQoGQD){
|
|
|
590
596
|
|
|
591
597
|
calculator: true,
|
|
592
598
|
compact: true,
|
|
599
|
+
hexadecimalNumbers: true,
|
|
593
600
|
controlFlowFlattening: 0.25,
|
|
594
601
|
deadCode: 0.01,
|
|
595
602
|
dispatcher: 0.5,
|
package/dev.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
require("@babel/register")({
|
|
2
|
-
presets: [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
|
2
|
+
presets: ["@babel/preset-typescript"],
|
|
3
|
+
extensions: [".js", ".ts"],
|
|
4
|
+
cache: true,
|
|
5
|
+
retainLines: true,
|
|
7
6
|
});
|
|
8
7
|
|
|
9
8
|
module.exports = require("./dev.ts");
|
package/dist/compiler.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = compileJs;
|
|
7
6
|
exports.compileJsSync = compileJsSync;
|
|
7
|
+
exports.default = compileJs;
|
|
8
8
|
|
|
9
9
|
const escodegen = require("escodegen");
|
|
10
10
|
|
|
@@ -14,7 +14,8 @@ async function compileJs(tree, options) {
|
|
|
14
14
|
|
|
15
15
|
function compileJsSync(tree, options) {
|
|
16
16
|
var api = {
|
|
17
|
-
format: escodegen.FORMAT_MINIFY
|
|
17
|
+
format: { ...escodegen.FORMAT_MINIFY
|
|
18
|
+
}
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
if (!options.compact) {
|
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.reservedKeywords = exports.reservedIdentifiers = void 0;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Keywords disallowed for variable names in ES5 and under.
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.obfuscate = obfuscate;
|
|
7
|
-
exports.obfuscateAST = obfuscateAST;
|
|
8
6
|
Object.defineProperty(exports, "Obfuscator", {
|
|
9
7
|
enumerable: true,
|
|
10
8
|
get: function () {
|
|
@@ -17,13 +15,15 @@ Object.defineProperty(exports, "Transform", {
|
|
|
17
15
|
return _transform.default;
|
|
18
16
|
}
|
|
19
17
|
});
|
|
18
|
+
exports.default = exports.debugTransformations = exports.debugObfuscation = void 0;
|
|
19
|
+
exports.obfuscate = obfuscate;
|
|
20
|
+
exports.obfuscateAST = obfuscateAST;
|
|
20
21
|
Object.defineProperty(exports, "presets", {
|
|
21
22
|
enumerable: true,
|
|
22
23
|
get: function () {
|
|
23
24
|
return _presets.default;
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
exports.default = exports.debugObfuscation = exports.debugTransformations = void 0;
|
|
27
27
|
|
|
28
28
|
var _compiler = _interopRequireWildcard(require("./compiler"));
|
|
29
29
|
|
|
@@ -43,9 +43,9 @@ var _options = require("./options");
|
|
|
43
43
|
|
|
44
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
45
|
|
|
46
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
46
|
+
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); }
|
|
47
47
|
|
|
48
|
-
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; }
|
|
48
|
+
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; }
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* **JsConfuser**: Obfuscates JavaScript.
|
package/dist/obfuscator.js
CHANGED
|
@@ -67,6 +67,8 @@ var _antiTooling = _interopRequireDefault(require("./transforms/antiTooling"));
|
|
|
67
67
|
|
|
68
68
|
var _hideInitializingCode = _interopRequireDefault(require("./transforms/hideInitializingCode"));
|
|
69
69
|
|
|
70
|
+
var _hexadecimalNumbers = _interopRequireDefault(require("./transforms/hexadecimalNumbers"));
|
|
71
|
+
|
|
70
72
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
71
73
|
|
|
72
74
|
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; }
|
|
@@ -76,7 +78,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
76
78
|
*/
|
|
77
79
|
class Obfuscator extends _events.EventEmitter {
|
|
78
80
|
constructor(options) {
|
|
81
|
+
var _this;
|
|
82
|
+
|
|
79
83
|
super();
|
|
84
|
+
_this = this;
|
|
80
85
|
this.options = options;
|
|
81
86
|
|
|
82
87
|
_defineProperty(this, "varCount", void 0);
|
|
@@ -95,10 +100,14 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
95
100
|
this.push(new _preparation.default(this));
|
|
96
101
|
this.push(new _renameLabels.default(this));
|
|
97
102
|
|
|
98
|
-
const test = (map
|
|
103
|
+
const test = function (map) {
|
|
99
104
|
if ((0, _probability.isProbabilityMapProbable)(map)) {
|
|
105
|
+
for (var _len = arguments.length, transformers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
106
|
+
transformers[_key - 1] = arguments[_key];
|
|
107
|
+
}
|
|
108
|
+
|
|
100
109
|
// options.verbose && console.log("+ Added " + transformer.name);
|
|
101
|
-
transformers.forEach(Transformer =>
|
|
110
|
+
transformers.forEach(Transformer => _this.push(new Transformer(_this)));
|
|
102
111
|
} else {// options.verbose && console.log("- Skipped adding " + transformer.name);
|
|
103
112
|
}
|
|
104
113
|
}; // Optimization: Only add needed transformers. If a probability always return false, no need in running that extra code.
|
|
@@ -128,6 +137,7 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
128
137
|
test(options.stack, _stack.default);
|
|
129
138
|
test(true, _antiTooling.default);
|
|
130
139
|
test(options.hideInitializingCode, _hideInitializingCode.default);
|
|
140
|
+
test(options.hexadecimalNumbers, _hexadecimalNumbers.default);
|
|
131
141
|
|
|
132
142
|
if (options.lock && Object.keys(options.lock).filter(x => x == "domainLock" ? options.lock.domainLock && options.lock.domainLock.length : options.lock[x]).length) {
|
|
133
143
|
test(true, _lock.default);
|
|
@@ -153,7 +163,8 @@ class Obfuscator extends _events.EventEmitter {
|
|
|
153
163
|
this.state = "transform";
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
async apply(tree
|
|
166
|
+
async apply(tree) {
|
|
167
|
+
let debugMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
157
168
|
(0, _assert.ok)(tree.type == "Program", "The root node must be type 'Program'");
|
|
158
169
|
(0, _assert.ok)(Array.isArray(tree.body), "The root's body property must be an array");
|
|
159
170
|
(0, _assert.ok)(Array.isArray(this.array));
|
package/dist/options.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validateOptions = validateOptions;
|
|
7
6
|
exports.correctOptions = correctOptions;
|
|
7
|
+
exports.validateOptions = validateOptions;
|
|
8
8
|
|
|
9
9
|
var _assert = require("assert");
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ var _presets = _interopRequireDefault(require("./presets"));
|
|
|
12
12
|
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
|
|
15
|
-
const validProperties = new Set(["preset", "target", "indent", "compact", "minify", "es5", "renameVariables", "renameGlobals", "identifierGenerator", "nameRecycling", "controlFlowFlattening", "hideInitializingCode", "globalConcealing", "stringCompression", "stringConcealing", "stringEncoding", "stringSplitting", "duplicateLiteralsRemoval", "dispatcher", "eval", "rgf", "objectExtraction", "flatten", "deadCode", "calculator", "lock", "movedDeclarations", "opaquePredicates", "shuffle", "stack", "verbose", "globalVariables", "debugComments"]);
|
|
15
|
+
const validProperties = new Set(["preset", "target", "indent", "compact", "hexadecimalNumbers", "minify", "es5", "renameVariables", "renameGlobals", "identifierGenerator", "nameRecycling", "controlFlowFlattening", "hideInitializingCode", "globalConcealing", "stringCompression", "stringConcealing", "stringEncoding", "stringSplitting", "duplicateLiteralsRemoval", "dispatcher", "eval", "rgf", "objectExtraction", "flatten", "deadCode", "calculator", "lock", "movedDeclarations", "opaquePredicates", "shuffle", "stack", "verbose", "globalVariables", "debugComments"]);
|
|
16
16
|
const validOses = new Set(["windows", "linux", "osx", "ios", "android"]);
|
|
17
17
|
const validBrowsers = new Set(["firefox", "chrome", "iexplorer", "edge", "safari", "opera"]);
|
|
18
18
|
|
package/dist/order.js
CHANGED
|
@@ -39,4 +39,5 @@ exports.ObfuscateOrder = ObfuscateOrder;
|
|
|
39
39
|
ObfuscateOrder[ObfuscateOrder["ES5"] = 31] = "ES5";
|
|
40
40
|
ObfuscateOrder[ObfuscateOrder["StringEncoding"] = 32] = "StringEncoding";
|
|
41
41
|
ObfuscateOrder[ObfuscateOrder["AntiTooling"] = 34] = "AntiTooling";
|
|
42
|
+
ObfuscateOrder[ObfuscateOrder["HexadecimalNumbers"] = 35] = "HexadecimalNumbers";
|
|
42
43
|
})(ObfuscateOrder || (exports.ObfuscateOrder = ObfuscateOrder = {}));
|
package/dist/parser.js
CHANGED
|
@@ -9,9 +9,9 @@ exports.parseSync = parseSync;
|
|
|
9
9
|
|
|
10
10
|
var assert = _interopRequireWildcard(require("assert"));
|
|
11
11
|
|
|
12
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
12
|
+
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); }
|
|
13
13
|
|
|
14
|
-
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; }
|
|
14
|
+
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; }
|
|
15
15
|
|
|
16
16
|
const acorn = require("acorn");
|
|
17
17
|
/**
|
package/dist/precedence.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.OPERATOR_PRECEDENCE = exports.NEEDS_PARENTHESES = exports.EXPRESSIONS_PRECEDENCE = void 0;
|
|
7
7
|
const OPERATOR_PRECEDENCE = {
|
|
8
8
|
"||": 3,
|
|
9
9
|
"&&": 4,
|
package/dist/presets.js
CHANGED
|
@@ -33,6 +33,7 @@ const highPreset = {
|
|
|
33
33
|
preset: "high",
|
|
34
34
|
calculator: true,
|
|
35
35
|
compact: true,
|
|
36
|
+
hexadecimalNumbers: true,
|
|
36
37
|
controlFlowFlattening: 0.75,
|
|
37
38
|
deadCode: 0.2,
|
|
38
39
|
dispatcher: true,
|
|
@@ -69,6 +70,7 @@ const mediumPreset = {
|
|
|
69
70
|
preset: "medium",
|
|
70
71
|
calculator: true,
|
|
71
72
|
compact: true,
|
|
73
|
+
hexadecimalNumbers: true,
|
|
72
74
|
controlFlowFlattening: 0.5,
|
|
73
75
|
deadCode: 0.025,
|
|
74
76
|
dispatcher: 0.75,
|
|
@@ -96,6 +98,7 @@ const lowPreset = {
|
|
|
96
98
|
preset: "low",
|
|
97
99
|
calculator: true,
|
|
98
100
|
compact: true,
|
|
101
|
+
hexadecimalNumbers: true,
|
|
99
102
|
controlFlowFlattening: 0.25,
|
|
100
103
|
deadCode: 0.01,
|
|
101
104
|
dispatcher: 0.5,
|
package/dist/probability.js
CHANGED
|
@@ -16,7 +16,9 @@ var _object = require("./util/object");
|
|
|
16
16
|
* @param runner Custom function to determine return value
|
|
17
17
|
* @param customFnArgs Args given to user-implemented function, such as a variable name.
|
|
18
18
|
*/
|
|
19
|
-
function ComputeProbabilityMap(map
|
|
19
|
+
function ComputeProbabilityMap(map) {
|
|
20
|
+
let runner = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x => x;
|
|
21
|
+
|
|
20
22
|
if (!map) {
|
|
21
23
|
return runner();
|
|
22
24
|
}
|
|
@@ -30,6 +32,10 @@ function ComputeProbabilityMap(map, runner = x => x, ...customFnArgs) {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
if (typeof map === "function") {
|
|
35
|
+
for (var _len = arguments.length, customFnArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
36
|
+
customFnArgs[_key - 2] = arguments[_key];
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
return map(...customFnArgs);
|
|
34
40
|
}
|
|
35
41
|
|
|
@@ -19,6 +19,8 @@ var _assert = require("assert");
|
|
|
19
19
|
|
|
20
20
|
var _precedence = require("../precedence");
|
|
21
21
|
|
|
22
|
+
var _template = _interopRequireDefault(require("../templates/template"));
|
|
23
|
+
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
25
|
|
|
24
26
|
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; }
|
|
@@ -35,9 +37,15 @@ class Calculator extends _transform.default {
|
|
|
35
37
|
|
|
36
38
|
_defineProperty(this, "calculatorFn", void 0);
|
|
37
39
|
|
|
40
|
+
_defineProperty(this, "calculatorOpVar", void 0);
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "calculatorSetOpFn", void 0);
|
|
43
|
+
|
|
38
44
|
this.ops = Object.create(null);
|
|
39
45
|
this.statesUsed = new Set();
|
|
40
46
|
this.calculatorFn = this.getPlaceholder();
|
|
47
|
+
this.calculatorOpVar = this.getPlaceholder();
|
|
48
|
+
this.calculatorSetOpFn = this.getPlaceholder();
|
|
41
49
|
this.gen = this.getGenerator();
|
|
42
50
|
}
|
|
43
51
|
|
|
@@ -48,7 +56,6 @@ class Calculator extends _transform.default {
|
|
|
48
56
|
return;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
var opArg = this.getPlaceholder();
|
|
52
59
|
var leftArg = this.getPlaceholder();
|
|
53
60
|
var rightArg = this.getPlaceholder();
|
|
54
61
|
var switchCases = [];
|
|
@@ -58,7 +65,12 @@ class Calculator extends _transform.default {
|
|
|
58
65
|
var body = [(0, _gen.ReturnStatement)(factory(operator, (0, _gen.Identifier)(leftArg), (0, _gen.Identifier)(rightArg)))];
|
|
59
66
|
switchCases.push((0, _gen.SwitchCase)((0, _gen.Literal)(code), body));
|
|
60
67
|
});
|
|
61
|
-
var func = (0, _gen.FunctionDeclaration)(this.calculatorFn, [
|
|
68
|
+
var func = (0, _gen.FunctionDeclaration)(this.calculatorFn, [leftArg, rightArg].map(x => (0, _gen.Identifier)(x)), [(0, _gen.SwitchStatement)((0, _gen.Identifier)(this.calculatorOpVar), switchCases)]);
|
|
69
|
+
(0, _insert.prepend)(tree, (0, _gen.VariableDeclaration)((0, _gen.VariableDeclarator)(this.calculatorOpVar)));
|
|
70
|
+
(0, _insert.prepend)(tree, (0, _template.default)("function {name}(a){\n a = {b} + ({b}=a, 0);\n return a;\n }").single({
|
|
71
|
+
name: this.calculatorSetOpFn,
|
|
72
|
+
b: this.calculatorOpVar
|
|
73
|
+
}));
|
|
62
74
|
(0, _insert.prepend)(tree, func);
|
|
63
75
|
}
|
|
64
76
|
|
|
@@ -99,7 +111,7 @@ class Calculator extends _transform.default {
|
|
|
99
111
|
this.log(operator, "calc(".concat(newState, ", left, right)"));
|
|
100
112
|
}
|
|
101
113
|
|
|
102
|
-
this.replace(object, (0, _gen.CallExpression)((0, _gen.Identifier)(this.calculatorFn), [(0, _gen.Literal)(this.ops[operator]),
|
|
114
|
+
this.replace(object, (0, _gen.CallExpression)((0, _gen.Identifier)(this.calculatorFn), [object.left, object.right, (0, _random.choice)([(0, _gen.AssignmentExpression)("=", (0, _gen.Identifier)(this.calculatorOpVar), (0, _gen.Literal)(this.ops[operator])), (0, _gen.CallExpression)((0, _gen.Identifier)(this.calculatorSetOpFn), [(0, _gen.Literal)(this.ops[operator])])])]));
|
|
103
115
|
};
|
|
104
116
|
}
|
|
105
117
|
|
|
@@ -71,6 +71,8 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
transform(object, parents) {
|
|
74
|
+
var _this = this;
|
|
75
|
+
|
|
74
76
|
return () => {
|
|
75
77
|
if (object.body.length < 3) {
|
|
76
78
|
return;
|
|
@@ -193,20 +195,30 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
193
195
|
|
|
194
196
|
var resultVar = this.getPlaceholder();
|
|
195
197
|
var argVar = this.getPlaceholder();
|
|
198
|
+
var testVar = this.getPlaceholder();
|
|
199
|
+
var stringBankVar = this.getPlaceholder();
|
|
200
|
+
var stringBank = Object.create(null);
|
|
201
|
+
var stringBankByLabels = Object.create(null);
|
|
202
|
+
let stringBankGen = this.getGenerator();
|
|
203
|
+
var needsTestVar = false;
|
|
196
204
|
var needsResultAndArgVar = false;
|
|
205
|
+
var needsStringBankVar = false;
|
|
197
206
|
var fnToLabel = Object.create(null);
|
|
198
207
|
fnNames.forEach(fnName => {
|
|
199
208
|
fnToLabel[fnName] = this.getPlaceholder();
|
|
200
209
|
});
|
|
201
210
|
|
|
202
|
-
const flattenBody = (body
|
|
211
|
+
const flattenBody = function (body) {
|
|
212
|
+
let startingLabel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this.getPlaceholder();
|
|
203
213
|
var chunks = [];
|
|
204
214
|
var currentBody = [];
|
|
205
215
|
var currentLabel = startingLabel;
|
|
206
216
|
|
|
207
|
-
const finishCurrentChunk = (pointingLabel, newLabel
|
|
217
|
+
const finishCurrentChunk = function (pointingLabel, newLabel) {
|
|
218
|
+
let addGotoStatement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
219
|
+
|
|
208
220
|
if (!newLabel) {
|
|
209
|
-
newLabel =
|
|
221
|
+
newLabel = _this.getPlaceholder();
|
|
210
222
|
}
|
|
211
223
|
|
|
212
224
|
if (!pointingLabel) {
|
|
@@ -224,6 +236,25 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
224
236
|
label: currentLabel,
|
|
225
237
|
body: [...currentBody]
|
|
226
238
|
});
|
|
239
|
+
(0, _traverse.walk)(currentBody, [], (o, p) => {
|
|
240
|
+
if (o.type == "Literal" && typeof o.value == "string" && !o.regex && Math.random() / (Object.keys(stringBank).length / 2 + 1) > 0.5) {
|
|
241
|
+
needsStringBankVar = true;
|
|
242
|
+
|
|
243
|
+
if (!stringBankByLabels[currentLabel]) {
|
|
244
|
+
stringBankByLabels[currentLabel] = new Set();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
stringBankByLabels[currentLabel].add(o.value);
|
|
248
|
+
|
|
249
|
+
if (typeof stringBank[o.value] === "undefined") {
|
|
250
|
+
stringBank[o.value] = stringBankGen.generate();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return () => {
|
|
254
|
+
_this.replaceIdentifierOrLiteral(o, (0, _gen.MemberExpression)((0, _gen.Identifier)(stringBankVar), (0, _gen.Literal)(stringBank[o.value]), true), p);
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
});
|
|
227
258
|
currentLabel = newLabel;
|
|
228
259
|
currentBody = [];
|
|
229
260
|
};
|
|
@@ -241,7 +272,8 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
241
272
|
}
|
|
242
273
|
|
|
243
274
|
if (stmt.$callExpression && fnToLabel[stmt.$fnName]) {
|
|
244
|
-
var afterPath =
|
|
275
|
+
var afterPath = _this.getPlaceholder();
|
|
276
|
+
|
|
245
277
|
var args = [];
|
|
246
278
|
|
|
247
279
|
switch (stmt.$callExpression) {
|
|
@@ -298,10 +330,15 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
298
330
|
|
|
299
331
|
var isLoop = !isSwitchStatement;
|
|
300
332
|
var supportContinueStatement = isLoop;
|
|
301
|
-
|
|
302
|
-
var
|
|
303
|
-
|
|
304
|
-
var
|
|
333
|
+
|
|
334
|
+
var testPath = _this.getPlaceholder();
|
|
335
|
+
|
|
336
|
+
var updatePath = _this.getPlaceholder();
|
|
337
|
+
|
|
338
|
+
var bodyPath = _this.getPlaceholder();
|
|
339
|
+
|
|
340
|
+
var afterPath = _this.getPlaceholder();
|
|
341
|
+
|
|
305
342
|
var possible = true;
|
|
306
343
|
var toReplace = [];
|
|
307
344
|
(0, _traverse.walk)(control.body, [], (o, p) => {
|
|
@@ -327,15 +364,19 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
327
364
|
return;
|
|
328
365
|
}
|
|
329
366
|
|
|
330
|
-
toReplace.forEach(v =>
|
|
367
|
+
toReplace.forEach(v => _this.replace(v[0], v[1]));
|
|
331
368
|
|
|
332
369
|
if (isSwitchStatement) {
|
|
333
|
-
var switchVarName =
|
|
370
|
+
var switchVarName = _this.getPlaceholder();
|
|
371
|
+
|
|
334
372
|
currentBody.push((0, _gen.VariableDeclaration)((0, _gen.VariableDeclarator)(switchVarName, control.discriminant)));
|
|
335
|
-
|
|
373
|
+
|
|
374
|
+
var afterPath = _this.getPlaceholder();
|
|
375
|
+
|
|
336
376
|
finishCurrentChunk();
|
|
337
377
|
control.cases.forEach((switchCase, i) => {
|
|
338
|
-
var entryPath =
|
|
378
|
+
var entryPath = _this.getPlaceholder();
|
|
379
|
+
|
|
339
380
|
currentBody.push((0, _gen.IfStatement)((0, _gen.BinaryExpression)("===", (0, _gen.Identifier)(switchVarName), switchCase.test), [{
|
|
340
381
|
type: "GotoStatement",
|
|
341
382
|
label: entryPath
|
|
@@ -364,13 +405,18 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
364
405
|
|
|
365
406
|
|
|
366
407
|
finishCurrentChunk(isPostTest ? bodyPath : testPath, testPath);
|
|
367
|
-
currentBody.push((0, _gen.
|
|
408
|
+
currentBody.push((0, _gen.ExpressionStatement)((0, _gen.AssignmentExpression)("=", (0, _gen.Identifier)(testVar), control.test || (0, _gen.Literal)(true))));
|
|
409
|
+
needsTestVar = true;
|
|
410
|
+
finishCurrentChunk();
|
|
411
|
+
currentBody.push((0, _gen.IfStatement)((0, _gen.Identifier)(testVar), [{
|
|
368
412
|
type: "GotoStatement",
|
|
369
413
|
label: bodyPath
|
|
370
414
|
}])); // create new label called `bodyPath` and have test body point to afterPath (goto afterPath)
|
|
371
415
|
|
|
372
416
|
finishCurrentChunk(afterPath, bodyPath);
|
|
373
|
-
|
|
417
|
+
|
|
418
|
+
var innerBothPath = _this.getPlaceholder();
|
|
419
|
+
|
|
374
420
|
chunks.push(...flattenBody([...control.body.body, {
|
|
375
421
|
type: "GotoStatement",
|
|
376
422
|
label: updatePath
|
|
@@ -388,13 +434,20 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
388
434
|
}
|
|
389
435
|
|
|
390
436
|
if (stmt.type == "IfStatement" && stmt.consequent.type == "BlockStatement" && (!stmt.alternate || stmt.alternate.type == "BlockStatement")) {
|
|
437
|
+
finishCurrentChunk();
|
|
438
|
+
currentBody.push((0, _gen.ExpressionStatement)((0, _gen.AssignmentExpression)("=", (0, _gen.Identifier)(testVar), stmt.test)));
|
|
439
|
+
needsTestVar = true;
|
|
391
440
|
finishCurrentChunk();
|
|
392
441
|
var hasAlternate = !!stmt.alternate;
|
|
393
442
|
(0, _assert.ok)(!(hasAlternate && stmt.alternate.type !== "BlockStatement"));
|
|
394
|
-
|
|
395
|
-
var
|
|
396
|
-
|
|
397
|
-
|
|
443
|
+
|
|
444
|
+
var yesPath = _this.getPlaceholder();
|
|
445
|
+
|
|
446
|
+
var noPath = _this.getPlaceholder();
|
|
447
|
+
|
|
448
|
+
var afterPath = _this.getPlaceholder();
|
|
449
|
+
|
|
450
|
+
currentBody.push((0, _gen.IfStatement)((0, _gen.Identifier)(testVar), [{
|
|
398
451
|
type: "GotoStatement",
|
|
399
452
|
label: yesPath
|
|
400
453
|
}]));
|
|
@@ -574,6 +627,7 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
574
627
|
var made = 1;
|
|
575
628
|
var breaksInsertion = [];
|
|
576
629
|
var staticStateValues = [...labelToStates[chunk.label]];
|
|
630
|
+
var potentialBranches = new Set();
|
|
577
631
|
chunk.body.forEach((stmt, stmtIndex) => {
|
|
578
632
|
var addBreak = false;
|
|
579
633
|
(0, _traverse.walk)(stmt, [], (o, p) => {
|
|
@@ -603,6 +657,7 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
603
657
|
p[blockIndex].body.splice(childIndex + 1, 0, (0, _gen.BreakStatement)(switchLabel));
|
|
604
658
|
}
|
|
605
659
|
|
|
660
|
+
potentialBranches.add(o.label);
|
|
606
661
|
var mutatingStateValues = [...labelToStates[chunk.label]];
|
|
607
662
|
var nextStateValues = labelToStates[o.label];
|
|
608
663
|
(0, _assert.ok)(nextStateValues, o.label);
|
|
@@ -622,10 +677,21 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
622
677
|
breaksInsertion.reverse();
|
|
623
678
|
breaksInsertion.forEach(index => {
|
|
624
679
|
chunk.body.splice(index + 1, 0, (0, _gen.BreakStatement)(switchLabel));
|
|
625
|
-
});
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
for (var branch of Array.from(potentialBranches)) {
|
|
683
|
+
var strings = stringBankByLabels[branch];
|
|
684
|
+
|
|
685
|
+
if (strings) {
|
|
686
|
+
chunk.body.unshift((0, _gen.ExpressionStatement)((0, _gen.SequenceExpression)(Array.from(strings).map(strValue => {
|
|
687
|
+
return (0, _gen.AssignmentExpression)("=", (0, _gen.MemberExpression)((0, _gen.Identifier)(stringBankVar), (0, _gen.Literal)(stringBank[strValue]), true), (0, _gen.Literal)(strValue));
|
|
688
|
+
}))));
|
|
689
|
+
}
|
|
690
|
+
} // var c = Identifier("undefined");
|
|
626
691
|
// this.addComment(c, stateValues.join(", "));
|
|
627
692
|
// transitionStatements.push(c);
|
|
628
693
|
|
|
694
|
+
|
|
629
695
|
var caseObject = {
|
|
630
696
|
body: chunk.body,
|
|
631
697
|
state: state,
|
|
@@ -658,11 +724,19 @@ class ControlFlowFlattening extends _transform.default {
|
|
|
658
724
|
}));
|
|
659
725
|
var declarations = [];
|
|
660
726
|
|
|
727
|
+
if (needsTestVar) {
|
|
728
|
+
declarations.push((0, _gen.VariableDeclarator)(testVar));
|
|
729
|
+
}
|
|
730
|
+
|
|
661
731
|
if (needsResultAndArgVar) {
|
|
662
732
|
declarations.push((0, _gen.VariableDeclarator)(resultVar));
|
|
663
733
|
declarations.push((0, _gen.VariableDeclarator)(argVar));
|
|
664
734
|
}
|
|
665
735
|
|
|
736
|
+
if (needsStringBankVar) {
|
|
737
|
+
declarations.push((0, _gen.VariableDeclarator)(stringBankVar, (0, _gen.ObjectExpression)(stringBankByLabels[startLabel] ? Array.from(stringBankByLabels[startLabel]).map(strValue => (0, _gen.Property)((0, _gen.Literal)(stringBank[strValue]), (0, _gen.Literal)(strValue), false)) : [])));
|
|
738
|
+
}
|
|
739
|
+
|
|
666
740
|
declarations.push(...stateVars.map((stateVar, i) => {
|
|
667
741
|
return (0, _gen.VariableDeclarator)(stateVar, (0, _gen.Literal)(initStateValues[i]));
|
|
668
742
|
}));
|
|
@@ -25,7 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
|
|
26
26
|
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; }
|
|
27
27
|
|
|
28
|
-
const templates = [(0, _template.default)("\n function curCSS( elem, name, computed ) {\n var ret;\n \n computed = computed || getStyles( elem );\n \n if ( computed ) {\n ret = computed.getPropertyValue( name ) || computed[ name ];\n \n if ( ret === \"\" && !isAttached( elem ) ) {\n ret = redacted.style( elem, name );\n }\n }\n \n return ret !== undefined ?\n \n // Support: IE <=9 - 11+\n // IE returns zIndex value as an integer.\n ret + \"\" :\n ret;\n }"), (0, _template.default)("\n function Example() {\n var state = redacted.useState(false);\n return x(\n ErrorBoundary,\n null,\n x(\n DisplayName,\n null,\n )\n );\n }"), (0, _template.default)("\n const path = require('path');\nconst { version } = require('../../package');\nconst { version: dashboardPluginVersion } = require('@redacted/enterprise-plugin/package');\nconst { version: componentsVersion } = require('@redacted/components/package');\nconst { sdkVersion } = require('@redacted/enterprise-plugin');\nconst isStandaloneExecutable = require('../utils/isStandaloneExecutable');\nconst resolveLocalRedactedPath = require('./resolve-local-redacted-path');\n\nconst redactedPath = path.resolve(__dirname, '../redacted.js');"), (0, _template.default)("\nmodule.exports = async (resolveLocalRedactedPath = ()=>{throw new Error(\"No redacted path provided\")}) => {\n const cliParams = new Set(process.argv.slice(2));\n if (!cliParams.has('--version')) {\n if (cliParams.size !== 1) return false;\n if (!cliParams.has('-v')) return false;\n }\n\n const installationModePostfix = await (async (isStandaloneExecutable, redactedPath) => {\n if (isStandaloneExecutable) return ' (standalone)';\n if (redactedPath === (await resolveLocalRedactedPath())) return ' (local)';\n return '';\n })();\n\n return true;\n};"), (0, _template.default)("\nfunction setCookie(cname, cvalue, exdays) {\n var d = new Date();\n d.setTime(d.getTime() + (exdays*24*60*60*1000));\n var expires = \"expires=\"+ d.toUTCString();\n document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=/\";\n}"), (0, _template.default)("function getCookie(cname) {\n var name = cname + \"=\";\n var decodedCookie = decodeURIComponent(document.cookie);\n var ca = decodedCookie.split(';');\n for(var i = 0; i <ca.length; i++) {\n var c = ca[i];\n while (c.charAt(0) == ' ') {\n c = c.substring(1);\n }\n if (c.indexOf(name) == 0) {\n return c.substring(name.length, c.length);\n }\n }\n return \"\";\n}"), (0, _template.default)("function getLocalStorageValue(key, cb){\n if ( typeof key !== \"string\" ) {\n throw new Error(\"Invalid data key provided (not type string)\")\n }\n if ( !key ) {\n throw new Error(\"Invalid data key provided (empty string)\")\n }\n var value = window.localStorage.getItem(key)\n try {\n value = JSON.parse(value)\n } catch ( e ) {\n cb(new Error(\"Serialization error for data '\" + key + \"': \" + e.message))\n }\n\n cb(null, value)\n }"), (0, _template.default)("\n \n var __ = \"(c=ak(<~F$VU'9f)~><&85dBPL-module/from\";\n var s = \"q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?\";\n var g = \"return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)\";\n\n __.match(s + g);\n ")];
|
|
28
|
+
const templates = [(0, _template.default)("\n function curCSS( elem, name, computed ) {\n var ret;\n \n computed = computed || getStyles( elem );\n \n if ( computed ) {\n ret = computed.getPropertyValue( name ) || computed[ name ];\n \n if ( ret === \"\" && !isAttached( elem ) ) {\n ret = redacted.style( elem, name );\n }\n }\n \n return ret !== undefined ?\n \n // Support: IE <=9 - 11+\n // IE returns zIndex value as an integer.\n ret + \"\" :\n ret;\n }"), (0, _template.default)("\n function Example() {\n var state = redacted.useState(false);\n return x(\n ErrorBoundary,\n null,\n x(\n DisplayName,\n null,\n )\n );\n }"), (0, _template.default)("\n const path = require('path');\nconst { version } = require('../../package');\nconst { version: dashboardPluginVersion } = require('@redacted/enterprise-plugin/package');\nconst { version: componentsVersion } = require('@redacted/components/package');\nconst { sdkVersion } = require('@redacted/enterprise-plugin');\nconst isStandaloneExecutable = require('../utils/isStandaloneExecutable');\nconst resolveLocalRedactedPath = require('./resolve-local-redacted-path');\n\nconst redactedPath = path.resolve(__dirname, '../redacted.js');"), (0, _template.default)("\nmodule.exports = async (resolveLocalRedactedPath = ()=>{throw new Error(\"No redacted path provided\")}) => {\n const cliParams = new Set(process.argv.slice(2));\n if (!cliParams.has('--version')) {\n if (cliParams.size !== 1) return false;\n if (!cliParams.has('-v')) return false;\n }\n\n const installationModePostfix = await (async (isStandaloneExecutable, redactedPath) => {\n if (isStandaloneExecutable) return ' (standalone)';\n if (redactedPath === (await resolveLocalRedactedPath())) return ' (local)';\n return '';\n })();\n\n return true;\n};"), (0, _template.default)("\nfunction setCookie(cname, cvalue, exdays) {\n var d = new Date();\n d.setTime(d.getTime() + (exdays*24*60*60*1000));\n var expires = \"expires=\"+ d.toUTCString();\n document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=/\";\n}"), (0, _template.default)("function getCookie(cname) {\n var name = cname + \"=\";\n var decodedCookie = decodeURIComponent(document.cookie);\n var ca = decodedCookie.split(';');\n for(var i = 0; i <ca.length; i++) {\n var c = ca[i];\n while (c.charAt(0) == ' ') {\n c = c.substring(1);\n }\n if (c.indexOf(name) == 0) {\n return c.substring(name.length, c.length);\n }\n }\n return \"\";\n}"), (0, _template.default)("function getLocalStorageValue(key, cb){\n if ( typeof key !== \"string\" ) {\n throw new Error(\"Invalid data key provided (not type string)\")\n }\n if ( !key ) {\n throw new Error(\"Invalid data key provided (empty string)\")\n }\n var value = window.localStorage.getItem(key)\n try {\n value = JSON.parse(value)\n } catch ( e ) {\n cb(new Error(\"Serialization error for data '\" + key + \"': \" + e.message))\n }\n\n cb(null, value)\n }"), (0, _template.default)("\n \n var __ = \"(c=ak(<~F$VU'9f)~><&85dBPL-module/from\";\n var s = \"q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?\";\n var g = \"return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)\";\n\n __.match(s + g);\n "), (0, _template.default)("\n function vec_pack(vec) {\n return vec[1] * 67108864 + (vec[0] < 0 ? 33554432 | vec[0] : vec[0]);\n }\n \n function vec_unpack(number) {\n switch (((number & 33554432) !== 0) * 1 + (number < 0) * 2) {\n case 0:\n return [number % 33554432, Math.trunc(number / 67108864)];\n case 1:\n return [\n (number % 33554432) - 33554432,\n Math.trunc(number / 67108864) + 1,\n ];\n case 2:\n return [\n (((number + 33554432) % 33554432) + 33554432) % 33554432,\n Math.round(number / 67108864),\n ];\n case 3:\n return [number % 33554432, Math.trunc(number / 67108864)];\n }\n }\n \n let a = vec_pack([2, 4]);\n let b = vec_pack([1, 2]);\n \n let c = a + b; // Vector addition\n let d = c - b; // Vector subtraction\n let e = d * 2; // Scalar multiplication\n let f = e / 2; // Scalar division\n \n console.log(vec_unpack(c)); // [3, 6]\n console.log(vec_unpack(d)); // [2, 4]\n console.log(vec_unpack(e)); // [4, 8]\n console.log(vec_unpack(f)); // [2, 4]\n "), (0, _template.default)("\n function buildCharacterMap(str) {\n const characterMap = {};\n \n for (let char of str.replace(/[^w]/g, \"\").toLowerCase())\n characterMap[char] = characterMap[char] + 1 || 1;\n \n return characterMap;\n }\n \n function isAnagrams(stringA, stringB) {\n const stringAMap = buildCharMap(stringA);\n const stringBMap = buildCharMap(stringB);\n \n for (let char in stringAMap) {\n if (stringAMap[char] !== stringBMap[char]) {\n return false;\n }\n }\n \n if (Object.keys(stringAMap).length !== Object.keys(stringBMap).length) {\n return false;\n }\n \n return true;\n }\n \n /**\n * @param {TreeNode} root\n * @return {boolean}\n */\n function isBalanced(root) {\n const height = getHeightBalanced(root);\n return height !== Infinity;\n }\n \n function getHeightBalanced(node) {\n if (!node) {\n return -1;\n }\n \n const leftTreeHeight = getHeightBalanced(node.left);\n const rightTreeHeight = getHeightBalanced(node.right);\n \n const heightDiff = Math.abs(leftTreeHeight - rightTreeHeight);\n \n if (\n leftTreeHeight === Infinity ||\n rightTreeHeight === Infinity ||\n heightDiff > 1\n ) {\n return Infinity;\n }\n \n const currentHeight = Math.max(leftTreeHeight, rightTreeHeight) + 1;\n return currentHeight;\n }\n \n window[\"__GLOBAL__HELPERS__\"] = {\n buildCharacterMap,\n isAnagrams,\n isBalanced,\n getHeightBalanced,\n };\n ")];
|
|
29
29
|
/**
|
|
30
30
|
* Adds dead code to blocks.
|
|
31
31
|
*
|
|
@@ -255,7 +255,9 @@ class Dispatcher extends _transform.default {
|
|
|
255
255
|
(0, _insert.prepend)(object, (0, _gen.VariableDeclaration)((0, _gen.VariableDeclarator)(payloadArg, (0, _gen.ArrayExpression)([]))));
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
identifiers.forEach(
|
|
258
|
+
identifiers.forEach(_ref => {
|
|
259
|
+
let [o, p] = _ref;
|
|
260
|
+
|
|
259
261
|
if (o.type != "Identifier") {
|
|
260
262
|
return;
|
|
261
263
|
}
|
package/dist/transforms/eval.js
CHANGED
|
@@ -27,7 +27,7 @@ class Eval extends _transform.default {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
match(object, parents) {
|
|
30
|
-
return (0, _insert.isFunction)(object) && object.type != "ArrowFunctionExpression" && !object.$eval;
|
|
30
|
+
return (0, _insert.isFunction)(object) && object.type != "ArrowFunctionExpression" && !object.$eval && !object.$dispatcherSkip;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
transform(object, parents) {
|