@vercel/nft 0.26.3 → 0.26.5
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/out/analyze.js +223 -97
- package/out/analyze.js.map +1 -1
- package/out/cli.js +4 -4
- package/out/cli.js.map +1 -1
- package/out/fs.d.ts +1 -1
- package/out/fs.js +3 -3
- package/out/fs.js.map +1 -1
- package/out/node-file-trace.js +14 -8
- package/out/node-file-trace.js.map +1 -1
- package/out/resolve-dependency.js +62 -26
- package/out/resolve-dependency.js.map +1 -1
- package/out/utils/ast-helpers.js +8 -2
- package/out/utils/ast-helpers.js.map +1 -1
- package/out/utils/binary-locators.js +19 -19
- package/out/utils/binary-locators.js.map +1 -1
- package/out/utils/get-package-base.js +0 -1
- package/out/utils/get-package-base.js.map +1 -1
- package/out/utils/sharedlib-emit.js +2 -3
- package/out/utils/sharedlib-emit.js.map +1 -1
- package/out/utils/special-cases.js +88 -40
- package/out/utils/special-cases.js.map +1 -1
- package/out/utils/static-eval.js +54 -36
- package/out/utils/static-eval.js.map +1 -1
- package/out/utils/wrappers.js +200 -109
- package/out/utils/wrappers.js.map +1 -1
- package/package.json +18 -11
- package/readme.md +26 -22
package/out/utils/wrappers.js
CHANGED
|
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.handleWrappers = void 0;
|
|
4
4
|
const estree_walker_1 = require("estree-walker");
|
|
5
5
|
function isUndefinedOrVoid(node) {
|
|
6
|
-
return node.type === 'Identifier' && node.name === 'undefined' ||
|
|
6
|
+
return ((node.type === 'Identifier' && node.name === 'undefined') ||
|
|
7
|
+
(node.type === 'UnaryExpression' &&
|
|
8
|
+
node.operator === 'void' &&
|
|
9
|
+
node.argument.type === 'Literal' &&
|
|
10
|
+
node.argument.value === 0));
|
|
7
11
|
}
|
|
8
12
|
// Wrapper detection pretransforms to enable static analysis
|
|
9
13
|
function handleWrappers(ast) {
|
|
@@ -21,7 +25,8 @@ function handleWrappers(ast) {
|
|
|
21
25
|
ast.body[0].type === 'ExpressionStatement' &&
|
|
22
26
|
ast.body[0].expression.type === 'CallExpression' &&
|
|
23
27
|
ast.body[0].expression.callee.type === 'FunctionExpression' &&
|
|
24
|
-
(ast.body[0].expression.arguments.length === 1 ||
|
|
28
|
+
(ast.body[0].expression.arguments.length === 1 ||
|
|
29
|
+
ast.body[0].expression.arguments.length === 0))
|
|
25
30
|
wrapper = ast.body[0].expression;
|
|
26
31
|
else if (ast.body.length === 1 &&
|
|
27
32
|
ast.body[0].type === 'ExpressionStatement' &&
|
|
@@ -44,7 +49,8 @@ function handleWrappers(ast) {
|
|
|
44
49
|
// ->
|
|
45
50
|
// (function (define) { 'use strict' define(function () { ... }) })
|
|
46
51
|
// (typeof define === 'function' && define.amd ? define : function (factory) { module.exports = factory(require); })
|
|
47
|
-
if (wrapper.arguments[0] &&
|
|
52
|
+
if (wrapper.arguments[0] &&
|
|
53
|
+
wrapper.arguments[0].type === 'ConditionalExpression' &&
|
|
48
54
|
wrapper.arguments[0].test.type === 'LogicalExpression' &&
|
|
49
55
|
wrapper.arguments[0].test.operator === '&&' &&
|
|
50
56
|
wrapper.arguments[0].test.left.type === 'BinaryExpression' &&
|
|
@@ -64,23 +70,37 @@ function handleWrappers(ast) {
|
|
|
64
70
|
wrapper.arguments[0].alternate.params.length === 1 &&
|
|
65
71
|
wrapper.arguments[0].alternate.params[0].type === 'Identifier' &&
|
|
66
72
|
wrapper.arguments[0].alternate.body.body.length === 1 &&
|
|
67
|
-
wrapper.arguments[0].alternate.body.body[0].type ===
|
|
68
|
-
|
|
69
|
-
wrapper.arguments[0].alternate.body.body[0].expression.
|
|
70
|
-
|
|
71
|
-
wrapper.arguments[0].alternate.body.body[0].expression.left.
|
|
72
|
-
|
|
73
|
-
wrapper.arguments[0].alternate.body.body[0].expression.left.
|
|
74
|
-
|
|
75
|
-
wrapper.arguments[0].alternate.body.body[0].expression.
|
|
76
|
-
|
|
77
|
-
wrapper.arguments[0].alternate.body.body[0].expression.
|
|
73
|
+
wrapper.arguments[0].alternate.body.body[0].type ===
|
|
74
|
+
'ExpressionStatement' &&
|
|
75
|
+
wrapper.arguments[0].alternate.body.body[0].expression.type ===
|
|
76
|
+
'AssignmentExpression' &&
|
|
77
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.type ===
|
|
78
|
+
'MemberExpression' &&
|
|
79
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.object
|
|
80
|
+
.type === 'Identifier' &&
|
|
81
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.object
|
|
82
|
+
.name === 'module' &&
|
|
83
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.property
|
|
84
|
+
.type === 'Identifier' &&
|
|
85
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.property
|
|
86
|
+
.name === 'exports' &&
|
|
87
|
+
wrapper.arguments[0].alternate.body.body[0].expression.left.computed ===
|
|
88
|
+
false &&
|
|
89
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.type ===
|
|
90
|
+
'CallExpression' &&
|
|
91
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.callee
|
|
92
|
+
.type === 'Identifier' &&
|
|
93
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.callee
|
|
94
|
+
.name === wrapper.arguments[0].alternate.params[0].name &&
|
|
78
95
|
'body' in wrapper.callee &&
|
|
79
96
|
'body' in wrapper.callee.body &&
|
|
80
97
|
Array.isArray(wrapper.callee.body.body) &&
|
|
81
|
-
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments
|
|
82
|
-
|
|
83
|
-
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0]
|
|
98
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments
|
|
99
|
+
.length === 1 &&
|
|
100
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0]
|
|
101
|
+
.type === 'Identifier' &&
|
|
102
|
+
wrapper.arguments[0].alternate.body.body[0].expression.right.arguments[0]
|
|
103
|
+
.name === 'require') {
|
|
84
104
|
let body = wrapper.callee.body.body;
|
|
85
105
|
if (body[0].type === 'ExpressionStatement' &&
|
|
86
106
|
body[0].expression.type === 'Literal' &&
|
|
@@ -91,7 +111,8 @@ function handleWrappers(ast) {
|
|
|
91
111
|
body[0].type === 'ExpressionStatement' &&
|
|
92
112
|
body[0].expression.type === 'CallExpression' &&
|
|
93
113
|
body[0].expression.callee.type === 'Identifier' &&
|
|
94
|
-
body[0].expression.callee.name ===
|
|
114
|
+
body[0].expression.callee.name ===
|
|
115
|
+
wrapper.arguments[0].test.right.object.name &&
|
|
95
116
|
body[0].expression.arguments.length === 1 &&
|
|
96
117
|
body[0].expression.arguments[0].type === 'FunctionExpression' &&
|
|
97
118
|
body[0].expression.arguments[0].params.length === 1 &&
|
|
@@ -100,7 +121,7 @@ function handleWrappers(ast) {
|
|
|
100
121
|
const arg = body[0].expression.arguments[0];
|
|
101
122
|
arg.params = [];
|
|
102
123
|
try {
|
|
103
|
-
// @ts-ignore If it doesn't exist
|
|
124
|
+
// @ts-ignore If it doesn't exist that's ok
|
|
104
125
|
delete arg.scope.declarations.require;
|
|
105
126
|
}
|
|
106
127
|
catch (e) { }
|
|
@@ -122,33 +143,38 @@ function handleWrappers(ast) {
|
|
|
122
143
|
// "external": { exports: require('external') }
|
|
123
144
|
// },[24])(24)
|
|
124
145
|
// });
|
|
125
|
-
else if (wrapper.arguments[0] &&
|
|
146
|
+
else if (wrapper.arguments[0] &&
|
|
147
|
+
wrapper.arguments[0].type === 'FunctionExpression' &&
|
|
126
148
|
wrapper.arguments[0].params.length === 0 &&
|
|
127
149
|
(wrapper.arguments[0].body.body.length === 1 ||
|
|
128
|
-
wrapper.arguments[0].body.body.length === 2 &&
|
|
150
|
+
(wrapper.arguments[0].body.body.length === 2 &&
|
|
129
151
|
wrapper.arguments[0].body.body[0].type === 'VariableDeclaration' &&
|
|
130
152
|
wrapper.arguments[0].body.body[0].declarations.length === 3 &&
|
|
131
|
-
wrapper.arguments[0].body.body[0].declarations.every(decl => decl.init === null && decl.id.type === 'Identifier')) &&
|
|
132
|
-
wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]
|
|
153
|
+
wrapper.arguments[0].body.body[0].declarations.every((decl) => decl.init === null && decl.id.type === 'Identifier'))) &&
|
|
154
|
+
wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]
|
|
155
|
+
.type === 'ReturnStatement' &&
|
|
133
156
|
(browserifyReturn = wrapper.arguments[0].body.body[wrapper.arguments[0].body.body.length - 1]) &&
|
|
134
157
|
browserifyReturn.argument?.type === 'CallExpression' &&
|
|
135
158
|
browserifyReturn.argument.arguments.length &&
|
|
136
|
-
browserifyReturn.argument.arguments.every(arg => arg && arg.type === 'Literal' && typeof arg.value === 'number') &&
|
|
159
|
+
browserifyReturn.argument.arguments.every((arg) => arg && arg.type === 'Literal' && typeof arg.value === 'number') &&
|
|
137
160
|
browserifyReturn.argument.callee.type === 'CallExpression' &&
|
|
138
161
|
(browserifyReturn.argument.callee.callee.type === 'FunctionExpression' ||
|
|
139
|
-
browserifyReturn.argument.callee.callee.type === 'CallExpression' &&
|
|
140
|
-
browserifyReturn.argument.callee.callee.callee.type ===
|
|
141
|
-
|
|
162
|
+
(browserifyReturn.argument.callee.callee.type === 'CallExpression' &&
|
|
163
|
+
browserifyReturn.argument.callee.callee.callee.type ===
|
|
164
|
+
'FunctionExpression' &&
|
|
165
|
+
browserifyReturn.argument.callee.callee.arguments.length === 0)) &&
|
|
142
166
|
// (dont go deeper into browserify loader internals than this)
|
|
143
167
|
browserifyReturn.argument.callee.arguments.length === 3 &&
|
|
144
|
-
browserifyReturn.argument.callee.arguments[0].type ===
|
|
145
|
-
|
|
168
|
+
browserifyReturn.argument.callee.arguments[0].type ===
|
|
169
|
+
'ObjectExpression' &&
|
|
170
|
+
browserifyReturn.argument.callee.arguments[1].type ===
|
|
171
|
+
'ObjectExpression' &&
|
|
146
172
|
browserifyReturn.argument.callee.arguments[2].type === 'ArrayExpression') {
|
|
147
173
|
const modules = browserifyReturn.argument.callee.arguments[0].properties;
|
|
148
174
|
// verify modules is the expected data structure
|
|
149
175
|
// in the process, extract external requires
|
|
150
176
|
const externals = {};
|
|
151
|
-
if (modules.every(m => {
|
|
177
|
+
if (modules.every((m) => {
|
|
152
178
|
if (m.type !== 'Property' ||
|
|
153
179
|
m.computed !== false ||
|
|
154
180
|
m.key.type !== 'Literal' ||
|
|
@@ -165,8 +191,11 @@ function handleWrappers(ast) {
|
|
|
165
191
|
const moduleMap = m.value.elements[1].properties;
|
|
166
192
|
for (const prop of moduleMap) {
|
|
167
193
|
if (prop.type !== 'Property' ||
|
|
168
|
-
(prop.value.type !== 'Identifier' &&
|
|
169
|
-
|
|
194
|
+
(prop.value.type !== 'Identifier' &&
|
|
195
|
+
prop.value.type !== 'Literal' &&
|
|
196
|
+
!isUndefinedOrVoid(prop.value)) ||
|
|
197
|
+
!((prop.key.type === 'Literal' &&
|
|
198
|
+
typeof prop.key.value === 'string') ||
|
|
170
199
|
prop.key.type === 'Identifier') ||
|
|
171
200
|
prop.computed) {
|
|
172
201
|
return false;
|
|
@@ -180,7 +209,7 @@ function handleWrappers(ast) {
|
|
|
180
209
|
// @ts-ignore end can be undefined
|
|
181
210
|
end: prop.key.end,
|
|
182
211
|
value: prop.key.name,
|
|
183
|
-
raw: JSON.stringify(prop.key.name)
|
|
212
|
+
raw: JSON.stringify(prop.key.name),
|
|
184
213
|
};
|
|
185
214
|
}
|
|
186
215
|
else if (prop.key.type === 'Literal') {
|
|
@@ -193,7 +222,7 @@ function handleWrappers(ast) {
|
|
|
193
222
|
// if we have externals, inline them into the browserify cache for webpack to pick up
|
|
194
223
|
const externalIds = Object.keys(externals);
|
|
195
224
|
const cache = browserifyReturn.argument.callee.arguments[1];
|
|
196
|
-
cache.properties = externalIds.map(ext => {
|
|
225
|
+
cache.properties = externalIds.map((ext) => {
|
|
197
226
|
return {
|
|
198
227
|
type: 'Property',
|
|
199
228
|
method: false,
|
|
@@ -203,7 +232,8 @@ function handleWrappers(ast) {
|
|
|
203
232
|
key: externals[ext],
|
|
204
233
|
value: {
|
|
205
234
|
type: 'ObjectExpression',
|
|
206
|
-
properties: [
|
|
235
|
+
properties: [
|
|
236
|
+
{
|
|
207
237
|
type: 'Property',
|
|
208
238
|
kind: 'init',
|
|
209
239
|
method: false,
|
|
@@ -211,19 +241,20 @@ function handleWrappers(ast) {
|
|
|
211
241
|
computed: false,
|
|
212
242
|
key: {
|
|
213
243
|
type: 'Identifier',
|
|
214
|
-
name: 'exports'
|
|
244
|
+
name: 'exports',
|
|
215
245
|
},
|
|
216
246
|
value: {
|
|
217
247
|
type: 'CallExpression',
|
|
218
248
|
optional: false,
|
|
219
249
|
callee: {
|
|
220
250
|
type: 'Identifier',
|
|
221
|
-
name: 'require'
|
|
251
|
+
name: 'require',
|
|
222
252
|
},
|
|
223
|
-
arguments: [externals[ext]]
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
253
|
+
arguments: [externals[ext]],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
227
258
|
};
|
|
228
259
|
});
|
|
229
260
|
}
|
|
@@ -252,7 +283,8 @@ function handleWrappers(ast) {
|
|
|
252
283
|
// })(function () {
|
|
253
284
|
// // ...
|
|
254
285
|
// }
|
|
255
|
-
else if (wrapper.arguments[0] &&
|
|
286
|
+
else if (wrapper.arguments[0] &&
|
|
287
|
+
wrapper.arguments[0].type === 'FunctionExpression' &&
|
|
256
288
|
wrapper.arguments[0].params.length === 2 &&
|
|
257
289
|
wrapper.arguments[0].params[0].type === 'Identifier' &&
|
|
258
290
|
wrapper.arguments[0].params[1].type === 'Identifier' &&
|
|
@@ -286,15 +318,18 @@ function handleWrappers(ast) {
|
|
|
286
318
|
let callSite;
|
|
287
319
|
if (statement.consequent.body[0].type === 'VariableDeclaration' &&
|
|
288
320
|
statement.consequent.body[0].declarations[0].init &&
|
|
289
|
-
statement.consequent.body[0].declarations[0].init.type ===
|
|
321
|
+
statement.consequent.body[0].declarations[0].init.type ===
|
|
322
|
+
'CallExpression')
|
|
290
323
|
callSite = statement.consequent.body[0].declarations[0].init;
|
|
291
324
|
else if (statement.consequent.body[0].type === 'ExpressionStatement' &&
|
|
292
325
|
statement.consequent.body[0].expression.type === 'CallExpression')
|
|
293
326
|
callSite = statement.consequent.body[0].expression;
|
|
294
327
|
else if (statement.consequent.body[0].type === 'ExpressionStatement' &&
|
|
295
|
-
statement.consequent.body[0].expression.type ===
|
|
328
|
+
statement.consequent.body[0].expression.type ===
|
|
329
|
+
'AssignmentExpression' &&
|
|
296
330
|
statement.consequent.body[0].expression.operator === '=' &&
|
|
297
|
-
statement.consequent.body[0].expression.right.type ===
|
|
331
|
+
statement.consequent.body[0].expression.right.type ===
|
|
332
|
+
'CallExpression')
|
|
298
333
|
callSite = statement.consequent.body[0].expression.right;
|
|
299
334
|
if (callSite &&
|
|
300
335
|
callSite.callee.type === 'Identifier' &&
|
|
@@ -310,7 +345,7 @@ function handleWrappers(ast) {
|
|
|
310
345
|
const funcExpression = wrapper.arguments[0];
|
|
311
346
|
funcExpression.params = [];
|
|
312
347
|
try {
|
|
313
|
-
// @ts-ignore If scope doesn't exist
|
|
348
|
+
// @ts-ignore If scope doesn't exist that's ok
|
|
314
349
|
const scope = funcExpression.scope;
|
|
315
350
|
delete scope.declarations.require;
|
|
316
351
|
delete scope.declarations.exports;
|
|
@@ -320,7 +355,7 @@ function handleWrappers(ast) {
|
|
|
320
355
|
}
|
|
321
356
|
}
|
|
322
357
|
// Webpack wrapper
|
|
323
|
-
//
|
|
358
|
+
//
|
|
324
359
|
// module.exports = (function(e) {
|
|
325
360
|
// var t = {};
|
|
326
361
|
// function r(n) { /*...*/ }
|
|
@@ -351,7 +386,7 @@ function handleWrappers(ast) {
|
|
|
351
386
|
// OR !(function (){})() | (function () {})() variants
|
|
352
387
|
// OR { 0: function..., 'some-id': function () ... } registry variants
|
|
353
388
|
// OR Webpack 5 non-runtime variant:
|
|
354
|
-
//
|
|
389
|
+
//
|
|
355
390
|
// (function() {
|
|
356
391
|
// var exports = {};
|
|
357
392
|
// exports.id = 223;
|
|
@@ -361,33 +396,49 @@ function handleWrappers(ast) {
|
|
|
361
396
|
// ...
|
|
362
397
|
// })()
|
|
363
398
|
//
|
|
364
|
-
else if (wrapper.callee.type === 'FunctionExpression' &&
|
|
399
|
+
else if ((wrapper.callee.type === 'FunctionExpression' &&
|
|
365
400
|
wrapper.callee.body.body.length > 2 &&
|
|
366
401
|
wrapper.callee.body.body[0].type === 'VariableDeclaration' &&
|
|
367
402
|
wrapper.callee.body.body[0].declarations.length === 1 &&
|
|
368
|
-
wrapper.callee.body.body[0].declarations[0].type ===
|
|
403
|
+
wrapper.callee.body.body[0].declarations[0].type ===
|
|
404
|
+
'VariableDeclarator' &&
|
|
369
405
|
wrapper.callee.body.body[0].declarations[0].id.type === 'Identifier' &&
|
|
370
|
-
wrapper.callee.body.body[0].declarations[0].init &&
|
|
371
|
-
wrapper.callee.body.body[0].declarations[0].init.
|
|
372
|
-
|
|
373
|
-
wrapper.callee.body.body[0].declarations[0].init.
|
|
374
|
-
|
|
406
|
+
wrapper.callee.body.body[0].declarations[0].init &&
|
|
407
|
+
((wrapper.callee.body.body[0].declarations[0].init.type ===
|
|
408
|
+
'ObjectExpression' &&
|
|
409
|
+
wrapper.callee.body.body[0].declarations[0].init.properties.length ===
|
|
410
|
+
0) ||
|
|
411
|
+
(wrapper.callee.body.body[0].declarations[0].init.type ===
|
|
412
|
+
'CallExpression' &&
|
|
413
|
+
wrapper.callee.body.body[0].declarations[0].init.arguments
|
|
414
|
+
.length === 1)) &&
|
|
415
|
+
((wrapper.callee.body.body[1] &&
|
|
375
416
|
wrapper.callee.body.body[1].type === 'FunctionDeclaration' &&
|
|
376
417
|
wrapper.callee.body.body[1].params.length === 1 &&
|
|
377
|
-
wrapper.callee.body.body[1].body.body.length >= 3 ||
|
|
378
|
-
wrapper.callee.body.body[2] &&
|
|
418
|
+
wrapper.callee.body.body[1].body.body.length >= 3) ||
|
|
419
|
+
(wrapper.callee.body.body[2] &&
|
|
379
420
|
wrapper.callee.body.body[2].type === 'FunctionDeclaration' &&
|
|
380
421
|
wrapper.callee.body.body[2].params.length === 1 &&
|
|
381
|
-
wrapper.callee.body.body[2].body.body.length >= 3) &&
|
|
382
|
-
|
|
383
|
-
wrapper.arguments[0].
|
|
384
|
-
wrapper.arguments[0].elements.every(el => el && el.type === 'FunctionExpression') ||
|
|
385
|
-
wrapper.arguments[0].type === 'ObjectExpression' &&
|
|
422
|
+
wrapper.callee.body.body[2].body.body.length >= 3)) &&
|
|
423
|
+
wrapper.arguments[0] &&
|
|
424
|
+
((wrapper.arguments[0].type === 'ArrayExpression' &&
|
|
386
425
|
(webpackModuleObj = wrapper.arguments[0]) &&
|
|
387
|
-
wrapper.arguments[0].
|
|
388
|
-
wrapper.arguments[0].
|
|
389
|
-
wrapper.arguments[0].
|
|
390
|
-
|
|
426
|
+
wrapper.arguments[0].elements.length > 0 &&
|
|
427
|
+
wrapper.arguments[0].elements.every((el) => el && el.type === 'FunctionExpression')) ||
|
|
428
|
+
(wrapper.arguments[0].type === 'ObjectExpression' &&
|
|
429
|
+
(webpackModuleObj = wrapper.arguments[0]) &&
|
|
430
|
+
wrapper.arguments[0].properties &&
|
|
431
|
+
wrapper.arguments[0].properties.length > 0 &&
|
|
432
|
+
wrapper.arguments[0].properties.every((prop) => prop &&
|
|
433
|
+
prop.type === 'Property' &&
|
|
434
|
+
!prop.computed &&
|
|
435
|
+
prop.key &&
|
|
436
|
+
prop.key.type === 'Literal' &&
|
|
437
|
+
(typeof prop.key.value === 'string' ||
|
|
438
|
+
typeof prop.key.value === 'number') &&
|
|
439
|
+
prop.value &&
|
|
440
|
+
prop.value.type === 'FunctionExpression')))) ||
|
|
441
|
+
(wrapper.arguments.length === 0 &&
|
|
391
442
|
wrapper.callee.type === 'FunctionExpression' &&
|
|
392
443
|
wrapper.callee.params.length === 0 &&
|
|
393
444
|
wrapper.callee.body.type === 'BlockStatement' &&
|
|
@@ -396,45 +447,75 @@ function handleWrappers(ast) {
|
|
|
396
447
|
wrapper.callee.body.body[0].declarations.length === 1 &&
|
|
397
448
|
wrapper.callee.body.body[0].declarations[0].id.type === 'Identifier' &&
|
|
398
449
|
wrapper.callee.body.body[1].type === 'ExpressionStatement' &&
|
|
399
|
-
wrapper.callee.body.body[1].expression.type ===
|
|
450
|
+
wrapper.callee.body.body[1].expression.type ===
|
|
451
|
+
'AssignmentExpression' &&
|
|
400
452
|
wrapper.callee.body.body[2].type === 'ExpressionStatement' &&
|
|
401
|
-
wrapper.callee.body.body[2].expression.type ===
|
|
453
|
+
wrapper.callee.body.body[2].expression.type ===
|
|
454
|
+
'AssignmentExpression' &&
|
|
402
455
|
wrapper.callee.body.body[3].type === 'ExpressionStatement' &&
|
|
403
|
-
wrapper.callee.body.body[3].expression.type ===
|
|
404
|
-
|
|
405
|
-
wrapper.callee.body.body[3].expression.left.
|
|
406
|
-
|
|
407
|
-
wrapper.callee.body.body[3].expression.left.
|
|
408
|
-
|
|
409
|
-
wrapper.callee.body.body[3].expression.
|
|
410
|
-
|
|
456
|
+
wrapper.callee.body.body[3].expression.type ===
|
|
457
|
+
'AssignmentExpression' &&
|
|
458
|
+
wrapper.callee.body.body[3].expression.left.type ===
|
|
459
|
+
'MemberExpression' &&
|
|
460
|
+
wrapper.callee.body.body[3].expression.left.object.type ===
|
|
461
|
+
'Identifier' &&
|
|
462
|
+
wrapper.callee.body.body[3].expression.left.object.name ===
|
|
463
|
+
wrapper.callee.body.body[0].declarations[0].id.name &&
|
|
464
|
+
wrapper.callee.body.body[3].expression.left.property.type ===
|
|
465
|
+
'Identifier' &&
|
|
466
|
+
wrapper.callee.body.body[3].expression.left.property.name ===
|
|
467
|
+
'modules' &&
|
|
468
|
+
wrapper.callee.body.body[3].expression.right.type ===
|
|
469
|
+
'ObjectExpression' &&
|
|
470
|
+
wrapper.callee.body.body[3].expression.right.properties.every((prop) => prop &&
|
|
471
|
+
prop.type === 'Property' &&
|
|
472
|
+
!prop.computed &&
|
|
473
|
+
prop.key &&
|
|
474
|
+
prop.key.type === 'Literal' &&
|
|
475
|
+
(typeof prop.key.value === 'string' ||
|
|
476
|
+
typeof prop.key.value === 'number') &&
|
|
477
|
+
prop.value &&
|
|
478
|
+
prop.value.type === 'FunctionExpression') &&
|
|
411
479
|
(webpackModuleObj = wrapper.callee.body.body[3].expression.right) &&
|
|
412
|
-
(wrapper.callee.body.body[4].type === 'VariableDeclaration' &&
|
|
480
|
+
((wrapper.callee.body.body[4].type === 'VariableDeclaration' &&
|
|
413
481
|
wrapper.callee.body.body[4].declarations.length === 1 &&
|
|
414
482
|
wrapper.callee.body.body[4].declarations[0].init &&
|
|
415
|
-
wrapper.callee.body.body[4].declarations[0].init.type ===
|
|
416
|
-
|
|
417
|
-
wrapper.callee.body.body[4].declarations[0].init.callee.
|
|
418
|
-
|
|
483
|
+
wrapper.callee.body.body[4].declarations[0].init.type ===
|
|
484
|
+
'CallExpression' &&
|
|
485
|
+
wrapper.callee.body.body[4].declarations[0].init.callee.type ===
|
|
486
|
+
'Identifier' &&
|
|
487
|
+
wrapper.callee.body.body[4].declarations[0].init.callee.name ===
|
|
488
|
+
'require') ||
|
|
489
|
+
(wrapper.callee.body.body[5].type === 'VariableDeclaration' &&
|
|
419
490
|
wrapper.callee.body.body[5].declarations.length === 1 &&
|
|
420
491
|
wrapper.callee.body.body[5].declarations[0].init &&
|
|
421
|
-
wrapper.callee.body.body[5].declarations[0].init.type ===
|
|
422
|
-
|
|
423
|
-
wrapper.callee.body.body[5].declarations[0].init.callee.
|
|
492
|
+
wrapper.callee.body.body[5].declarations[0].init.type ===
|
|
493
|
+
'CallExpression' &&
|
|
494
|
+
wrapper.callee.body.body[5].declarations[0].init.callee.type ===
|
|
495
|
+
'Identifier' &&
|
|
496
|
+
wrapper.callee.body.body[5].declarations[0].init.callee.name ===
|
|
497
|
+
'require')))) {
|
|
424
498
|
const externalMap = new Map();
|
|
425
499
|
let modules;
|
|
426
500
|
if (webpackModuleObj.type === 'ArrayExpression')
|
|
427
|
-
modules = webpackModuleObj.elements.filter(el => el?.type === 'FunctionExpression').map((el, i) => [String(i), el]);
|
|
501
|
+
modules = webpackModuleObj.elements.filter((el) => el?.type === 'FunctionExpression').map((el, i) => [String(i), el]);
|
|
428
502
|
// Structure already checked in conditional above
|
|
429
503
|
else
|
|
430
|
-
modules = webpackModuleObj.properties.map(prop => [
|
|
504
|
+
modules = webpackModuleObj.properties.map((prop) => [
|
|
505
|
+
String(prop.key.value),
|
|
506
|
+
prop.value,
|
|
507
|
+
]);
|
|
431
508
|
for (const [k, m] of modules) {
|
|
432
|
-
const statement = m.body.body.length === 1
|
|
433
|
-
|
|
509
|
+
const statement = m.body.body.length === 1
|
|
510
|
+
? m.body.body[0]
|
|
511
|
+
: (m.body.body.length === 2 ||
|
|
512
|
+
(m.body.body.length === 3 &&
|
|
513
|
+
m.body.body[2].type === 'EmptyStatement')) &&
|
|
434
514
|
m.body.body[0].type === 'ExpressionStatement' &&
|
|
435
515
|
m.body.body[0].expression.type === 'Literal' &&
|
|
436
516
|
m.body.body[0].expression.value === 'use strict'
|
|
437
|
-
? m.body.body[1]
|
|
517
|
+
? m.body.body[1]
|
|
518
|
+
: null;
|
|
438
519
|
if (statement &&
|
|
439
520
|
statement.type === 'ExpressionStatement' &&
|
|
440
521
|
statement.expression.type === 'AssignmentExpression' &&
|
|
@@ -456,7 +537,9 @@ function handleWrappers(ast) {
|
|
|
456
537
|
}
|
|
457
538
|
}
|
|
458
539
|
for (const [, m] of modules) {
|
|
459
|
-
if ('params' in m &&
|
|
540
|
+
if ('params' in m &&
|
|
541
|
+
m.params.length === 3 &&
|
|
542
|
+
m.params[2].type === 'Identifier') {
|
|
460
543
|
const assignedVars = new Map();
|
|
461
544
|
(0, estree_walker_1.walk)(m.body, {
|
|
462
545
|
enter(_node, _maybeParent) {
|
|
@@ -475,12 +558,14 @@ function handleWrappers(ast) {
|
|
|
475
558
|
optional: false,
|
|
476
559
|
callee: {
|
|
477
560
|
type: 'Identifier',
|
|
478
|
-
name: 'require'
|
|
561
|
+
name: 'require',
|
|
479
562
|
},
|
|
480
|
-
arguments: [
|
|
563
|
+
arguments: [
|
|
564
|
+
{
|
|
481
565
|
type: 'Literal',
|
|
482
|
-
value: externalId
|
|
483
|
-
}
|
|
566
|
+
value: externalId,
|
|
567
|
+
},
|
|
568
|
+
],
|
|
484
569
|
};
|
|
485
570
|
const parent = maybeParent;
|
|
486
571
|
if ('right' in parent && parent.right === node) {
|
|
@@ -495,11 +580,13 @@ function handleWrappers(ast) {
|
|
|
495
580
|
else if ('callee' in parent && parent.callee === node) {
|
|
496
581
|
parent.callee = replacement;
|
|
497
582
|
}
|
|
498
|
-
else if ('arguments' in parent &&
|
|
499
|
-
parent.arguments
|
|
583
|
+
else if ('arguments' in parent &&
|
|
584
|
+
parent.arguments.some((arg) => arg === node)) {
|
|
585
|
+
parent.arguments = parent.arguments.map((arg) => arg === node ? replacement : arg);
|
|
500
586
|
}
|
|
501
587
|
else if ('init' in parent && parent.init === node) {
|
|
502
|
-
if (parent.type === 'VariableDeclarator' &&
|
|
588
|
+
if (parent.type === 'VariableDeclarator' &&
|
|
589
|
+
parent.id.type === 'Identifier')
|
|
503
590
|
assignedVars.set(parent.id.name, externalId);
|
|
504
591
|
parent.init = replacement;
|
|
505
592
|
}
|
|
@@ -514,7 +601,9 @@ function handleWrappers(ast) {
|
|
|
514
601
|
node.callee.property.name === 'n' &&
|
|
515
602
|
node.arguments.length === 1 &&
|
|
516
603
|
node.arguments[0].type === 'Identifier') {
|
|
517
|
-
if (maybeParent &&
|
|
604
|
+
if (maybeParent &&
|
|
605
|
+
'init' in maybeParent &&
|
|
606
|
+
maybeParent.init === node) {
|
|
518
607
|
const req = node.arguments[0];
|
|
519
608
|
const callExpression = {
|
|
520
609
|
type: 'CallExpression',
|
|
@@ -525,23 +614,24 @@ function handleWrappers(ast) {
|
|
|
525
614
|
optional: false,
|
|
526
615
|
object: {
|
|
527
616
|
type: 'Identifier',
|
|
528
|
-
name: 'Object'
|
|
617
|
+
name: 'Object',
|
|
529
618
|
},
|
|
530
619
|
property: {
|
|
531
620
|
type: 'Identifier',
|
|
532
|
-
name: 'assign'
|
|
533
|
-
}
|
|
621
|
+
name: 'assign',
|
|
622
|
+
},
|
|
534
623
|
},
|
|
535
624
|
arguments: [
|
|
536
625
|
{
|
|
537
626
|
type: 'ArrowFunctionExpression',
|
|
538
627
|
expression: true,
|
|
539
628
|
params: [],
|
|
540
|
-
body: req
|
|
629
|
+
body: req,
|
|
541
630
|
},
|
|
542
631
|
{
|
|
543
632
|
type: 'ObjectExpression',
|
|
544
|
-
properties: [
|
|
633
|
+
properties: [
|
|
634
|
+
{
|
|
545
635
|
type: 'Property',
|
|
546
636
|
kind: 'init',
|
|
547
637
|
method: false,
|
|
@@ -549,17 +639,18 @@ function handleWrappers(ast) {
|
|
|
549
639
|
shorthand: false,
|
|
550
640
|
key: {
|
|
551
641
|
type: 'Identifier',
|
|
552
|
-
name: 'a'
|
|
642
|
+
name: 'a',
|
|
553
643
|
},
|
|
554
|
-
value: req
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
644
|
+
value: req,
|
|
645
|
+
},
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
558
649
|
};
|
|
559
650
|
maybeParent.init = callExpression;
|
|
560
651
|
}
|
|
561
652
|
}
|
|
562
|
-
}
|
|
653
|
+
},
|
|
563
654
|
});
|
|
564
655
|
}
|
|
565
656
|
}
|