js-confuser 1.7.1 → 1.7.2

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.
Files changed (123) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +12 -27
  3. package/dist/compiler.js +2 -8
  4. package/dist/constants.js +17 -10
  5. package/dist/index.js +7 -30
  6. package/dist/obfuscator.js +15 -62
  7. package/dist/options.js +21 -38
  8. package/dist/order.js +4 -7
  9. package/dist/parser.js +5 -13
  10. package/dist/precedence.js +6 -8
  11. package/dist/presets.js +4 -6
  12. package/dist/probability.js +13 -24
  13. package/dist/templates/bufferToString.js +100 -5
  14. package/dist/templates/crash.js +51 -9
  15. package/dist/templates/es5.js +125 -6
  16. package/dist/templates/functionLength.js +24 -6
  17. package/dist/templates/globals.js +9 -0
  18. package/dist/templates/template.js +71 -30
  19. package/dist/transforms/antiTooling.js +26 -22
  20. package/dist/transforms/calculator.js +18 -54
  21. package/dist/transforms/controlFlowFlattening/controlFlowFlattening.js +236 -333
  22. package/dist/transforms/controlFlowFlattening/expressionObfuscation.js +46 -25
  23. package/dist/transforms/deadCode.js +528 -27
  24. package/dist/transforms/dispatcher.js +106 -110
  25. package/dist/transforms/es5/antiClass.js +70 -44
  26. package/dist/transforms/es5/antiDestructuring.js +14 -38
  27. package/dist/transforms/es5/antiES6Object.js +39 -48
  28. package/dist/transforms/es5/antiSpreadOperator.js +5 -14
  29. package/dist/transforms/es5/antiTemplate.js +10 -19
  30. package/dist/transforms/es5/es5.js +7 -40
  31. package/dist/transforms/extraction/classExtraction.js +83 -0
  32. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +41 -80
  33. package/dist/transforms/extraction/objectExtraction.js +24 -56
  34. package/dist/transforms/finalizer.js +6 -20
  35. package/dist/transforms/flatten.js +51 -99
  36. package/dist/transforms/identifier/globalAnalysis.js +8 -26
  37. package/dist/transforms/identifier/globalConcealing.js +35 -54
  38. package/dist/transforms/identifier/movedDeclarations.js +66 -38
  39. package/dist/transforms/identifier/renameVariables.js +29 -68
  40. package/dist/transforms/identifier/variableAnalysis.js +21 -48
  41. package/dist/transforms/lock/antiDebug.js +20 -25
  42. package/dist/transforms/lock/integrity.js +48 -47
  43. package/dist/transforms/lock/lock.js +62 -113
  44. package/dist/transforms/minify.js +77 -108
  45. package/dist/transforms/opaquePredicates.js +11 -48
  46. package/dist/transforms/preparation.js +17 -50
  47. package/dist/transforms/renameLabels.js +5 -22
  48. package/dist/transforms/rgf.js +93 -69
  49. package/dist/transforms/shuffle.js +41 -46
  50. package/dist/transforms/stack.js +35 -98
  51. package/dist/transforms/string/encoding.js +73 -27
  52. package/dist/transforms/string/stringCompression.js +44 -68
  53. package/dist/transforms/string/stringConcealing.js +125 -134
  54. package/dist/transforms/string/stringEncoding.js +6 -26
  55. package/dist/transforms/string/stringSplitting.js +5 -30
  56. package/dist/transforms/transform.js +50 -100
  57. package/dist/traverse.js +11 -18
  58. package/dist/util/compare.js +27 -29
  59. package/dist/util/gen.js +32 -86
  60. package/dist/util/guard.js +0 -1
  61. package/dist/util/identifiers.js +9 -72
  62. package/dist/util/insert.js +27 -77
  63. package/dist/util/math.js +0 -3
  64. package/dist/util/object.js +3 -7
  65. package/dist/util/random.js +5 -36
  66. package/dist/util/scope.js +6 -3
  67. package/package.json +3 -3
  68. package/src/constants.ts +12 -0
  69. package/src/options.ts +13 -0
  70. package/src/order.ts +2 -2
  71. package/src/templates/bufferToString.ts +49 -11
  72. package/src/templates/functionLength.ts +21 -3
  73. package/src/templates/globals.ts +3 -0
  74. package/src/templates/template.ts +85 -25
  75. package/src/transforms/antiTooling.ts +33 -11
  76. package/src/transforms/controlFlowFlattening/controlFlowFlattening.ts +2 -2
  77. package/src/transforms/controlFlowFlattening/expressionObfuscation.ts +46 -10
  78. package/src/transforms/deadCode.ts +0 -16
  79. package/src/transforms/dispatcher.ts +91 -69
  80. package/src/transforms/es5/antiClass.ts +10 -1
  81. package/src/transforms/extraction/classExtraction.ts +168 -0
  82. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +9 -10
  83. package/src/transforms/extraction/objectExtraction.ts +4 -15
  84. package/src/transforms/flatten.ts +20 -5
  85. package/src/transforms/identifier/globalConcealing.ts +29 -65
  86. package/src/transforms/identifier/movedDeclarations.ts +90 -24
  87. package/src/transforms/minify.ts +27 -12
  88. package/src/transforms/rgf.ts +94 -5
  89. package/src/transforms/stack.ts +12 -3
  90. package/src/transforms/string/encoding.ts +85 -51
  91. package/src/transforms/string/stringCompression.ts +5 -8
  92. package/src/transforms/string/stringConcealing.ts +139 -113
  93. package/src/transforms/string/stringEncoding.ts +1 -2
  94. package/src/transforms/string/stringSplitting.ts +1 -2
  95. package/src/transforms/transform.ts +30 -1
  96. package/src/util/compare.ts +39 -5
  97. package/src/util/gen.ts +10 -3
  98. package/src/util/insert.ts +17 -0
  99. package/src/util/scope.ts +14 -2
  100. package/test/code/Cash.test.ts +10 -4
  101. package/test/code/StrictMode.src.js +65 -0
  102. package/test/code/StrictMode.test.js +37 -0
  103. package/test/compare.test.ts +62 -2
  104. package/test/options.test.ts +111 -55
  105. package/test/transforms/controlFlowFlattening/expressionObfuscation.test.ts +37 -18
  106. package/test/transforms/dispatcher.test.ts +55 -0
  107. package/test/transforms/extraction/classExtraction.test.ts +86 -0
  108. package/test/transforms/extraction/duplicateLiteralsRemoval.test.ts +8 -0
  109. package/test/transforms/extraction/objectExtraction.test.ts +2 -0
  110. package/test/transforms/identifier/globalConcealing.test.ts +19 -0
  111. package/test/transforms/identifier/movedDeclarations.test.ts +61 -0
  112. package/test/transforms/minify.test.ts +37 -0
  113. package/test/transforms/rgf.test.ts +50 -0
  114. package/dist/transforms/controlFlowFlattening/choiceFlowObfuscation.js +0 -62
  115. package/dist/transforms/controlFlowFlattening/controlFlowObfuscation.js +0 -159
  116. package/dist/transforms/controlFlowFlattening/switchCaseObfuscation.js +0 -106
  117. package/dist/transforms/eval.js +0 -84
  118. package/dist/transforms/hexadecimalNumbers.js +0 -63
  119. package/dist/transforms/hideInitializingCode.js +0 -270
  120. package/dist/transforms/identifier/nameRecycling.js +0 -218
  121. package/dist/transforms/label.js +0 -67
  122. package/dist/transforms/preparation/nameConflicts.js +0 -116
  123. package/dist/transforms/preparation/preparation.js +0 -188
@@ -8,18 +8,17 @@ exports.isEquivalent = isEquivalent;
8
8
  exports.isIndependent = isIndependent;
9
9
  exports.isInsideType = isInsideType;
10
10
  exports.isLoop = isLoop;
11
+ exports.isModuleSource = isModuleSource;
12
+ exports.isMoveable = isMoveable;
11
13
  exports.isPrimitive = isPrimitive;
12
14
  exports.isValidIdentifier = isValidIdentifier;
13
-
14
15
  var _traverse = require("../traverse");
15
-
16
16
  function isEquivalent(first, second) {
17
17
  var extra = {
18
18
  start: 1,
19
19
  end: 1,
20
20
  loc: 1
21
21
  };
22
-
23
22
  function removeExtra(obj) {
24
23
  if (typeof obj === "object") {
25
24
  for (var property in obj) {
@@ -34,88 +33,89 @@ function isEquivalent(first, second) {
34
33
  }
35
34
  }
36
35
  }
37
-
38
36
  return obj;
39
37
  }
40
-
41
38
  return JSON.stringify(removeExtra(first)) == JSON.stringify(removeExtra(second));
42
39
  }
43
40
  /**
44
41
  * Statements that allowed `break;` and `continue;` statements
45
42
  * @param object
46
43
  */
47
-
48
-
49
44
  function isLoop(object) {
50
45
  return ["SwitchStatement", "WhileStatement", "DoWhileStatement", "ForStatement", "ForInStatement", "ForOfStatement"].includes(object.type);
51
46
  }
52
-
53
47
  function isValidIdentifier(name) {
54
48
  if (typeof name !== "string") {
55
49
  return false;
56
50
  }
57
-
58
51
  if (name.includes(".") || name.includes(" ")) {
59
52
  return false;
60
53
  }
61
-
62
54
  var x = name.match(/^[A-Za-z$_][A-Za-z0-9$_]*/);
63
55
  return !!(x && x[0] == name);
64
56
  }
65
-
66
57
  function isInsideType(type, object, parents) {
67
58
  return [object, ...parents].some(x => x.type == type);
68
59
  }
69
-
70
60
  function isDirective(object, parents) {
71
61
  var dIndex = parents.findIndex(x => x.directive);
72
-
73
62
  if (dIndex == -1) {
74
63
  return false;
75
64
  }
76
-
77
65
  return parents[dIndex].expression == (parents[dIndex - 1] || object);
78
66
  }
79
-
67
+ function isModuleSource(object, parents) {
68
+ if (!parents[0]) {
69
+ return false;
70
+ }
71
+ if (parents[0].type == "ImportDeclaration" && parents[0].source == object) {
72
+ return true;
73
+ }
74
+ if (parents[0].type == "ImportExpression" && parents[0].source == object) {
75
+ return true;
76
+ }
77
+ if (parents[1] && parents[1].type == "CallExpression" && parents[1].arguments[0] === object && parents[1].callee.type == "Identifier") {
78
+ if (parents[1].callee.name == "require" || parents[1].callee.name == "import") {
79
+ return true;
80
+ }
81
+ }
82
+ return false;
83
+ }
84
+ function isMoveable(object, parents) {
85
+ return !isDirective(object, parents) && !isModuleSource(object, parents);
86
+ }
80
87
  function isIndependent(object, parents) {
81
88
  if (object.type == "Literal") {
82
89
  return true;
83
90
  }
84
-
85
- var parent = parents[0];
86
-
87
91
  if (object.type == "Identifier") {
88
- var set = new Set(["null", "undefined"]);
89
-
90
- if (set.has(object.name)) {
92
+ if (primitiveIdentifiers.has(object.name)) {
91
93
  return true;
92
94
  }
93
-
94
- if (parent.type == "Property") {
95
+ var parent = parents[0];
96
+ if (parent && parent.type == "Property") {
95
97
  if (!parent.computed && parent.key == object) {
96
98
  return true;
97
99
  }
98
100
  }
99
-
100
101
  return false;
101
102
  }
102
-
103
103
  if (object.type == "ArrayExpression" || object.type == "ObjectExpression" || object.type == "Property") {
104
104
  var allowIt = true;
105
105
  (0, _traverse.walk)(object, parents, ($object, $parents) => {
106
106
  if (object != $object) {
107
107
  if (!Array.isArray($object) && !isIndependent($object, $parents)) {
108
108
  allowIt = false;
109
+ return "EXIT";
109
110
  }
110
111
  }
111
112
  });
112
113
  return allowIt;
113
114
  }
114
-
115
115
  return false;
116
116
  }
117
-
118
117
  var primitiveIdentifiers = new Set(["undefined", "NaN"]);
118
+
119
119
  /**
120
120
  * booleans, numbers, string, null, undefined, NaN, infinity
121
121
  *
@@ -127,7 +127,6 @@ var primitiveIdentifiers = new Set(["undefined", "NaN"]);
127
127
  * @param node
128
128
  * @returns
129
129
  */
130
-
131
130
  function isPrimitive(node) {
132
131
  if (node.type == "Literal") {
133
132
  if (node.value === null) {
@@ -142,6 +141,5 @@ function isPrimitive(node) {
142
141
  } else if (node.type == "Identifier") {
143
142
  return primitiveIdentifiers.has(node.name);
144
143
  }
145
-
146
144
  return false;
147
145
  }
package/dist/util/gen.js CHANGED
@@ -37,6 +37,7 @@ exports.RestElement = RestElement;
37
37
  exports.ReturnStatement = ReturnStatement;
38
38
  exports.SequenceExpression = SequenceExpression;
39
39
  exports.SpreadElement = SpreadElement;
40
+ exports.Super = Super;
40
41
  exports.SwitchCase = SwitchCase;
41
42
  exports.SwitchDefaultCase = SwitchDefaultCase;
42
43
  exports.SwitchStatement = SwitchStatement;
@@ -49,25 +50,37 @@ exports.VariableDeclaration = VariableDeclaration;
49
50
  exports.VariableDeclarator = VariableDeclarator;
50
51
  exports.WhileStatement = WhileStatement;
51
52
  exports.WithStatement = WithStatement;
52
-
53
53
  var _assert = require("assert");
54
+ var _constants = require("../constants");
55
+ /**
56
+ * 0. First index is the Node.
57
+ * 1. Second index is the parents as an array.
58
+ */
59
+
60
+ /**
61
+ * Eval Callbacks are called once all transformations are done.
62
+ *
63
+ * - Called with object, and parents.
64
+ */
65
+
66
+ /**
67
+ * - 0. First index is the Node.
68
+ * - ...1 Parent nodes.
69
+ */
54
70
 
55
71
  function Literal(value) {
56
72
  if (typeof value === "undefined") {
57
73
  throw new Error("value is undefined");
58
74
  }
59
-
60
75
  if (typeof value == "number" && value < 0) {
61
76
  return UnaryExpression("-", Literal(Math.abs(value)));
62
77
  }
63
-
64
78
  (0, _assert.ok)(value === value, "NaN value is disallowed");
65
79
  return {
66
80
  type: "Literal",
67
81
  value: value
68
82
  };
69
83
  }
70
-
71
84
  function RegexLiteral(pattern, flags) {
72
85
  return {
73
86
  type: "Literal",
@@ -77,37 +90,30 @@ function RegexLiteral(pattern, flags) {
77
90
  }
78
91
  };
79
92
  }
80
-
81
93
  function Identifier(name) {
82
94
  if (!name) {
83
95
  throw new Error("name is null/empty");
84
96
  }
85
-
86
97
  if (name == "this") {
87
98
  throw new Error("Use ThisExpression");
88
99
  }
89
-
90
100
  if (name == "super") {
91
101
  throw new Error("Use Super");
92
102
  }
93
-
94
103
  return {
95
104
  type: "Identifier",
96
105
  name: name.toString()
97
106
  };
98
107
  }
99
-
100
108
  function BlockStatement(body) {
101
109
  if (!Array.isArray(body)) {
102
110
  throw new Error("not array");
103
111
  }
104
-
105
112
  return {
106
113
  type: "BlockStatement",
107
114
  body: body
108
115
  };
109
116
  }
110
-
111
117
  function LogicalExpression(operator, left, right) {
112
118
  return {
113
119
  type: "LogicalExpression",
@@ -116,12 +122,10 @@ function LogicalExpression(operator, left, right) {
116
122
  right
117
123
  };
118
124
  }
119
-
120
125
  function BinaryExpression(operator, left, right) {
121
126
  if (operator == "||" || operator == "&&") {
122
127
  throw new Error("invalid operator, use LogicalExpression");
123
128
  }
124
-
125
129
  return {
126
130
  type: "BinaryExpression",
127
131
  operator,
@@ -129,13 +133,11 @@ function BinaryExpression(operator, left, right) {
129
133
  right
130
134
  };
131
135
  }
132
-
133
136
  function ThisExpression() {
134
137
  return {
135
138
  type: "ThisExpression"
136
139
  };
137
140
  }
138
-
139
141
  function SwitchCase(test, consequent) {
140
142
  (0, _assert.ok)(test === null || test);
141
143
  (0, _assert.ok)(Array.isArray(consequent));
@@ -145,11 +147,9 @@ function SwitchCase(test, consequent) {
145
147
  consequent
146
148
  };
147
149
  }
148
-
149
150
  function SwitchDefaultCase(consequent) {
150
151
  return SwitchCase(null, consequent);
151
152
  }
152
-
153
153
  function LabeledStatement(label, body) {
154
154
  return {
155
155
  type: "LabeledStatement",
@@ -157,7 +157,6 @@ function LabeledStatement(label, body) {
157
157
  body: body
158
158
  };
159
159
  }
160
-
161
160
  function SwitchStatement(discriminant, cases) {
162
161
  return {
163
162
  type: "SwitchStatement",
@@ -165,26 +164,21 @@ function SwitchStatement(discriminant, cases) {
165
164
  cases: cases
166
165
  };
167
166
  }
168
-
169
167
  function BreakStatement(label) {
170
168
  return {
171
169
  type: "BreakStatement",
172
170
  label: label ? Identifier(label) : null
173
171
  };
174
172
  }
175
-
176
173
  function Property(key, value) {
177
174
  let computed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
178
175
  let kind = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "init";
179
-
180
176
  if (!key) {
181
177
  throw new Error("key is undefined");
182
178
  }
183
-
184
179
  if (!value) {
185
180
  throw new Error("value is undefined");
186
181
  }
187
-
188
182
  return {
189
183
  type: "Property",
190
184
  key: key,
@@ -195,39 +189,31 @@ function Property(key, value) {
195
189
  shorthand: false
196
190
  };
197
191
  }
198
-
199
192
  function ObjectExpression(properties) {
200
193
  if (!properties) {
201
194
  throw new Error("properties is null");
202
195
  }
203
-
204
196
  return {
205
197
  type: "ObjectExpression",
206
198
  properties: properties
207
199
  };
208
200
  }
209
-
210
201
  function VariableDeclarator(id) {
211
202
  let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
212
-
213
203
  if (typeof id === "string") {
214
204
  id = Identifier(id);
215
205
  }
216
-
217
206
  return {
218
207
  type: "VariableDeclarator",
219
208
  id,
220
209
  init
221
210
  };
222
211
  }
223
-
224
212
  function VariableDeclaration(declarations) {
225
213
  let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "var";
226
-
227
214
  if (!Array.isArray(declarations)) {
228
215
  declarations = [declarations];
229
216
  }
230
-
231
217
  (0, _assert.ok)(Array.isArray(declarations));
232
218
  (0, _assert.ok)(declarations.length);
233
219
  (0, _assert.ok)(!declarations.find(x => x.type == "ExpressionStatement"));
@@ -237,7 +223,6 @@ function VariableDeclaration(declarations) {
237
223
  kind: kind
238
224
  };
239
225
  }
240
-
241
226
  function ForStatement(variableDeclaration, test, update, body) {
242
227
  (0, _assert.ok)(variableDeclaration);
243
228
  (0, _assert.ok)(test);
@@ -250,7 +235,6 @@ function ForStatement(variableDeclaration, test, update, body) {
250
235
  body: BlockStatement(body)
251
236
  };
252
237
  }
253
-
254
238
  function WhileStatement(test, body) {
255
239
  (0, _assert.ok)(test);
256
240
  return {
@@ -259,26 +243,20 @@ function WhileStatement(test, body) {
259
243
  body: BlockStatement(body)
260
244
  };
261
245
  }
262
-
263
246
  function IfStatement(test, consequent) {
264
247
  let alternate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
265
-
266
248
  if (!test) {
267
249
  throw new Error("test is undefined");
268
250
  }
269
-
270
251
  if (!consequent) {
271
252
  throw new Error("consequent undefined, use empty array instead");
272
253
  }
273
-
274
254
  if (!Array.isArray(consequent)) {
275
255
  throw new Error("consequent needs to be array, found " + consequent.type);
276
256
  }
277
-
278
257
  if (alternate && !Array.isArray(alternate)) {
279
258
  throw new Error("alternate needs to be array, found " + alternate.type);
280
259
  }
281
-
282
260
  return {
283
261
  type: "IfStatement",
284
262
  test: test,
@@ -286,7 +264,6 @@ function IfStatement(test, consequent) {
286
264
  alternate: alternate ? BlockStatement(alternate) : null
287
265
  };
288
266
  }
289
-
290
267
  function FunctionExpression(params, body) {
291
268
  (0, _assert.ok)(Array.isArray(params), "params should be an array");
292
269
  return {
@@ -296,9 +273,11 @@ function FunctionExpression(params, body) {
296
273
  body: BlockStatement(body),
297
274
  generator: false,
298
275
  expression: false,
299
- async: false
276
+ async: false,
277
+ [_constants.predictableFunctionTag]: true
300
278
  };
301
279
  }
280
+
302
281
  /**
303
282
  * ```js
304
283
  * function name(p[0], p[1], p[2], ...p[4]){
@@ -310,17 +289,13 @@ function FunctionExpression(params, body) {
310
289
  * @param params
311
290
  * @param body
312
291
  */
313
-
314
-
315
292
  function FunctionDeclaration(name, params, body) {
316
293
  if (!body) {
317
294
  throw new Error("undefined body");
318
295
  }
319
-
320
296
  if (body && Array.isArray(body[0])) {
321
297
  throw new Error("nested array");
322
298
  }
323
-
324
299
  (0, _assert.ok)(Array.isArray(params), "params should be an array");
325
300
  return {
326
301
  type: "FunctionDeclaration",
@@ -329,29 +304,25 @@ function FunctionDeclaration(name, params, body) {
329
304
  body: BlockStatement(body),
330
305
  generator: false,
331
306
  expression: false,
332
- async: false
307
+ async: false,
308
+ [_constants.predictableFunctionTag]: true
333
309
  };
334
310
  }
335
-
336
311
  function DebuggerStatement() {
337
312
  return {
338
313
  type: "DebuggerStatement"
339
314
  };
340
315
  }
341
-
342
316
  function ReturnStatement() {
343
317
  let argument = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
344
-
345
318
  if (argument) {
346
319
  (0, _assert.ok)(argument.type, "Argument should be a node");
347
320
  }
348
-
349
321
  return {
350
322
  type: "ReturnStatement",
351
323
  argument: argument
352
324
  };
353
325
  }
354
-
355
326
  function AwaitExpression(argument) {
356
327
  (0, _assert.ok)(argument.type, "Argument should be a node");
357
328
  return {
@@ -359,7 +330,6 @@ function AwaitExpression(argument) {
359
330
  argument
360
331
  };
361
332
  }
362
-
363
333
  function ConditionalExpression(test, consequent, alternate) {
364
334
  (0, _assert.ok)(test);
365
335
  (0, _assert.ok)(consequent);
@@ -371,7 +341,6 @@ function ConditionalExpression(test, consequent, alternate) {
371
341
  alternate
372
342
  };
373
343
  }
374
-
375
344
  function ExpressionStatement(expression) {
376
345
  (0, _assert.ok)(expression.type);
377
346
  return {
@@ -379,7 +348,6 @@ function ExpressionStatement(expression) {
379
348
  expression: expression
380
349
  };
381
350
  }
382
-
383
351
  function UnaryExpression(operator, argument) {
384
352
  (0, _assert.ok)(typeof operator === "string");
385
353
  (0, _assert.ok)(argument.type);
@@ -389,7 +357,6 @@ function UnaryExpression(operator, argument) {
389
357
  argument
390
358
  };
391
359
  }
392
-
393
360
  function UpdateExpression(operator, argument) {
394
361
  let prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
395
362
  return {
@@ -399,41 +366,32 @@ function UpdateExpression(operator, argument) {
399
366
  prefix
400
367
  };
401
368
  }
402
-
403
369
  function SequenceExpression(expressions) {
404
370
  if (!expressions) {
405
371
  throw new Error("expressions undefined");
406
372
  }
407
-
408
373
  if (!expressions.length) {
409
374
  throw new Error("expressions length = 0");
410
375
  }
411
-
412
376
  return {
413
377
  type: "SequenceExpression",
414
378
  expressions: expressions
415
379
  };
416
380
  }
417
-
418
381
  function MemberExpression(object, property) {
419
382
  let computed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
420
-
421
383
  if (!object) {
422
384
  throw new Error("object undefined");
423
385
  }
424
-
425
386
  if (!property) {
426
387
  throw new Error("property undefined");
427
388
  }
428
-
429
389
  if (!computed && property.type == "Literal") {
430
390
  throw new Error("literal must be computed property");
431
391
  }
432
-
433
392
  if (object.name == "new" && property.name == "target") {
434
393
  throw new Error("new.target is a MetaProperty");
435
394
  }
436
-
437
395
  return {
438
396
  type: "MemberExpression",
439
397
  computed: computed,
@@ -441,7 +399,6 @@ function MemberExpression(object, property) {
441
399
  property: property
442
400
  };
443
401
  }
444
-
445
402
  function CallExpression(callee, args) {
446
403
  (0, _assert.ok)(Array.isArray(args), "args should be an array");
447
404
  return {
@@ -450,7 +407,6 @@ function CallExpression(callee, args) {
450
407
  arguments: args
451
408
  };
452
409
  }
453
-
454
410
  function NewExpression(callee, args) {
455
411
  return {
456
412
  type: "NewExpression",
@@ -458,7 +414,6 @@ function NewExpression(callee, args) {
458
414
  arguments: args
459
415
  };
460
416
  }
461
-
462
417
  function AssignmentExpression(operator, left, right) {
463
418
  return {
464
419
  type: "AssignmentExpression",
@@ -467,7 +422,6 @@ function AssignmentExpression(operator, left, right) {
467
422
  right: right
468
423
  };
469
424
  }
470
-
471
425
  function ArrayPattern(elements) {
472
426
  (0, _assert.ok)(Array.isArray(elements));
473
427
  return {
@@ -475,7 +429,6 @@ function ArrayPattern(elements) {
475
429
  elements: elements
476
430
  };
477
431
  }
478
-
479
432
  function ArrayExpression(elements) {
480
433
  (0, _assert.ok)(Array.isArray(elements));
481
434
  return {
@@ -483,7 +436,6 @@ function ArrayExpression(elements) {
483
436
  elements
484
437
  };
485
438
  }
486
-
487
439
  function AssignmentPattern(left, right) {
488
440
  (0, _assert.ok)(left);
489
441
  (0, _assert.ok)(right);
@@ -493,7 +445,6 @@ function AssignmentPattern(left, right) {
493
445
  right: right
494
446
  };
495
447
  }
496
-
497
448
  function AddComment(node, text) {
498
449
  if (node.leadingComments) {
499
450
  node.leadingComments.push({
@@ -508,23 +459,25 @@ function AddComment(node, text) {
508
459
  }]
509
460
  });
510
461
  }
511
-
512
462
  return node;
513
463
  }
514
-
515
- function MethodDefinition(identifier, functionExpression, kind) {
516
- let isStatic = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
464
+ function Super() {
465
+ return {
466
+ type: "Super"
467
+ };
468
+ }
469
+ function MethodDefinition(key, functionExpression, kind) {
470
+ let isStatic = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
517
471
  let computed = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
518
472
  return {
519
473
  type: "MethodDefinition",
520
- key: identifier,
474
+ key: key,
521
475
  computed: computed,
522
476
  value: functionExpression,
523
477
  kind: kind,
524
478
  static: isStatic
525
479
  };
526
480
  }
527
-
528
481
  function ClassDeclaration(id) {
529
482
  let superClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
530
483
  let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
@@ -538,7 +491,6 @@ function ClassDeclaration(id) {
538
491
  }
539
492
  };
540
493
  }
541
-
542
494
  function ClassExpression(id) {
543
495
  let superClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
544
496
  let body = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
@@ -552,14 +504,12 @@ function ClassExpression(id) {
552
504
  }
553
505
  };
554
506
  }
555
-
556
507
  function ThrowStatement(argument) {
557
508
  return {
558
509
  type: "ThrowStatement",
559
510
  argument: argument
560
511
  };
561
512
  }
562
-
563
513
  function WithStatement(object, body) {
564
514
  (0, _assert.ok)(object, "object");
565
515
  (0, _assert.ok)(object.type, "object should be node");
@@ -569,33 +519,30 @@ function WithStatement(object, body) {
569
519
  body: BlockStatement(body)
570
520
  };
571
521
  }
522
+
572
523
  /**
573
524
  * `fn(...args)`
574
525
  * @param argument
575
526
  * @returns
576
527
  */
577
-
578
-
579
528
  function SpreadElement(argument) {
580
529
  return {
581
530
  type: "SpreadElement",
582
531
  argument
583
532
  };
584
533
  }
534
+
585
535
  /**
586
536
  * `function fn(...params){}`
587
537
  * @param argument
588
538
  * @returns
589
539
  */
590
-
591
-
592
540
  function RestElement(argument) {
593
541
  return {
594
542
  type: "RestElement",
595
543
  argument
596
544
  };
597
545
  }
598
-
599
546
  function CatchClause() {
600
547
  let param = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
601
548
  let body = arguments.length > 1 ? arguments[1] : undefined;
@@ -605,7 +552,6 @@ function CatchClause() {
605
552
  body: BlockStatement(body)
606
553
  };
607
554
  }
608
-
609
555
  function TryStatement(body, handler, finallyBody) {
610
556
  (0, _assert.ok)(handler);
611
557
  (0, _assert.ok)(handler.type == "CatchClause");
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isStringLiteral = isStringLiteral;
7
-
8
7
  function isStringLiteral(node) {
9
8
  return node.type === "Literal" && typeof node.value === "string" && !node.regex;
10
9
  }