webpack 4.1.0 → 4.4.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/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,311 +1,328 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const AMDRequireItemDependency = require("./AMDRequireItemDependency");
|
8
|
-
const AMDRequireContextDependency = require("./AMDRequireContextDependency");
|
9
|
-
const ConstDependency = require("./ConstDependency");
|
10
|
-
const AMDDefineDependency = require("./AMDDefineDependency");
|
11
|
-
const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
|
12
|
-
const LocalModuleDependency = require("./LocalModuleDependency");
|
13
|
-
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
14
|
-
const LocalModulesHelpers = require("./LocalModulesHelpers");
|
15
|
-
|
16
|
-
const isBoundFunctionExpression = expr => {
|
17
|
-
if (expr.type !== "CallExpression") return false;
|
18
|
-
if (expr.callee.type !== "MemberExpression") return false;
|
19
|
-
if (expr.callee.computed) return false;
|
20
|
-
if (expr.callee.object.type !== "FunctionExpression") return false;
|
21
|
-
if (expr.callee.property.type !== "Identifier") return false;
|
22
|
-
if (expr.callee.property.name !== "bind") return false;
|
23
|
-
return true;
|
24
|
-
};
|
25
|
-
|
26
|
-
function isUnboundFunctionExpression(expr) {
|
27
|
-
if (expr.type === "FunctionExpression") return true;
|
28
|
-
if (expr.type === "ArrowFunctionExpression") return true;
|
29
|
-
return false;
|
30
|
-
}
|
31
|
-
|
32
|
-
function isCallable(expr) {
|
33
|
-
if (isUnboundFunctionExpression(expr)) return true;
|
34
|
-
if (isBoundFunctionExpression(expr)) return true;
|
35
|
-
return false;
|
36
|
-
}
|
37
|
-
|
38
|
-
class AMDDefineDependencyParserPlugin {
|
39
|
-
constructor(options) {
|
40
|
-
this.options = options;
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
})
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
const
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
}
|
112
|
-
|
113
|
-
if (param.
|
114
|
-
param.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
identifiers
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
parser.
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
()
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const AMDRequireItemDependency = require("./AMDRequireItemDependency");
|
8
|
+
const AMDRequireContextDependency = require("./AMDRequireContextDependency");
|
9
|
+
const ConstDependency = require("./ConstDependency");
|
10
|
+
const AMDDefineDependency = require("./AMDDefineDependency");
|
11
|
+
const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
|
12
|
+
const LocalModuleDependency = require("./LocalModuleDependency");
|
13
|
+
const ContextDependencyHelpers = require("./ContextDependencyHelpers");
|
14
|
+
const LocalModulesHelpers = require("./LocalModulesHelpers");
|
15
|
+
|
16
|
+
const isBoundFunctionExpression = expr => {
|
17
|
+
if (expr.type !== "CallExpression") return false;
|
18
|
+
if (expr.callee.type !== "MemberExpression") return false;
|
19
|
+
if (expr.callee.computed) return false;
|
20
|
+
if (expr.callee.object.type !== "FunctionExpression") return false;
|
21
|
+
if (expr.callee.property.type !== "Identifier") return false;
|
22
|
+
if (expr.callee.property.name !== "bind") return false;
|
23
|
+
return true;
|
24
|
+
};
|
25
|
+
|
26
|
+
function isUnboundFunctionExpression(expr) {
|
27
|
+
if (expr.type === "FunctionExpression") return true;
|
28
|
+
if (expr.type === "ArrowFunctionExpression") return true;
|
29
|
+
return false;
|
30
|
+
}
|
31
|
+
|
32
|
+
function isCallable(expr) {
|
33
|
+
if (isUnboundFunctionExpression(expr)) return true;
|
34
|
+
if (isBoundFunctionExpression(expr)) return true;
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
|
38
|
+
class AMDDefineDependencyParserPlugin {
|
39
|
+
constructor(options) {
|
40
|
+
this.options = options;
|
41
|
+
}
|
42
|
+
|
43
|
+
apply(parser) {
|
44
|
+
parser.hooks.call
|
45
|
+
.for("define")
|
46
|
+
.tap(
|
47
|
+
"AMDDefineDependencyParserPlugin",
|
48
|
+
this.processCallDefine.bind(this, parser)
|
49
|
+
);
|
50
|
+
}
|
51
|
+
|
52
|
+
processArray(parser, expr, param, identifiers, namedModule) {
|
53
|
+
if (param.isArray()) {
|
54
|
+
param.items.forEach((param, idx) => {
|
55
|
+
if (
|
56
|
+
param.isString() &&
|
57
|
+
["require", "module", "exports"].includes(param.string)
|
58
|
+
)
|
59
|
+
identifiers[idx] = param.string;
|
60
|
+
const result = this.processItem(parser, expr, param, namedModule);
|
61
|
+
if (result === undefined) {
|
62
|
+
this.processContext(parser, expr, param);
|
63
|
+
}
|
64
|
+
});
|
65
|
+
return true;
|
66
|
+
} else if (param.isConstArray()) {
|
67
|
+
const deps = [];
|
68
|
+
param.array.forEach((request, idx) => {
|
69
|
+
let dep;
|
70
|
+
let localModule;
|
71
|
+
if (request === "require") {
|
72
|
+
identifiers[idx] = request;
|
73
|
+
dep = "__webpack_require__";
|
74
|
+
} else if (["exports", "module"].includes(request)) {
|
75
|
+
identifiers[idx] = request;
|
76
|
+
dep = request;
|
77
|
+
} else if (
|
78
|
+
(localModule = LocalModulesHelpers.getLocalModule(
|
79
|
+
parser.state,
|
80
|
+
request
|
81
|
+
))
|
82
|
+
) {
|
83
|
+
// eslint-disable-line no-cond-assign
|
84
|
+
dep = new LocalModuleDependency(localModule);
|
85
|
+
dep.loc = expr.loc;
|
86
|
+
parser.state.current.addDependency(dep);
|
87
|
+
} else {
|
88
|
+
dep = this.newRequireItemDependency(request);
|
89
|
+
dep.loc = expr.loc;
|
90
|
+
dep.optional = !!parser.scope.inTry;
|
91
|
+
parser.state.current.addDependency(dep);
|
92
|
+
}
|
93
|
+
deps.push(dep);
|
94
|
+
});
|
95
|
+
const dep = this.newRequireArrayDependency(deps, param.range);
|
96
|
+
dep.loc = expr.loc;
|
97
|
+
dep.optional = !!parser.scope.inTry;
|
98
|
+
parser.state.current.addDependency(dep);
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
processItem(parser, expr, param, namedModule) {
|
103
|
+
if (param.isConditional()) {
|
104
|
+
param.options.forEach(param => {
|
105
|
+
const result = this.processItem(parser, expr, param);
|
106
|
+
if (result === undefined) {
|
107
|
+
this.processContext(parser, expr, param);
|
108
|
+
}
|
109
|
+
});
|
110
|
+
return true;
|
111
|
+
} else if (param.isString()) {
|
112
|
+
let dep, localModule;
|
113
|
+
if (param.string === "require") {
|
114
|
+
dep = new ConstDependency("__webpack_require__", param.range);
|
115
|
+
} else if (["require", "exports", "module"].includes(param.string)) {
|
116
|
+
dep = new ConstDependency(param.string, param.range);
|
117
|
+
} else if (
|
118
|
+
(localModule = LocalModulesHelpers.getLocalModule(
|
119
|
+
parser.state,
|
120
|
+
param.string,
|
121
|
+
namedModule
|
122
|
+
))
|
123
|
+
) {
|
124
|
+
// eslint-disable-line no-cond-assign
|
125
|
+
dep = new LocalModuleDependency(localModule, param.range);
|
126
|
+
} else {
|
127
|
+
dep = this.newRequireItemDependency(param.string, param.range);
|
128
|
+
}
|
129
|
+
dep.loc = expr.loc;
|
130
|
+
dep.optional = !!parser.scope.inTry;
|
131
|
+
parser.state.current.addDependency(dep);
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
processContext(parser, expr, param) {
|
136
|
+
const dep = ContextDependencyHelpers.create(
|
137
|
+
AMDRequireContextDependency,
|
138
|
+
param.range,
|
139
|
+
param,
|
140
|
+
expr,
|
141
|
+
this.options
|
142
|
+
);
|
143
|
+
if (!dep) return;
|
144
|
+
dep.loc = expr.loc;
|
145
|
+
dep.optional = !!parser.scope.inTry;
|
146
|
+
parser.state.current.addDependency(dep);
|
147
|
+
return true;
|
148
|
+
}
|
149
|
+
|
150
|
+
processCallDefine(parser, expr) {
|
151
|
+
let array, fn, obj, namedModule;
|
152
|
+
switch (expr.arguments.length) {
|
153
|
+
case 1:
|
154
|
+
if (isCallable(expr.arguments[0])) {
|
155
|
+
// define(f() {…})
|
156
|
+
fn = expr.arguments[0];
|
157
|
+
} else if (expr.arguments[0].type === "ObjectExpression") {
|
158
|
+
// define({…})
|
159
|
+
obj = expr.arguments[0];
|
160
|
+
} else {
|
161
|
+
// define(expr)
|
162
|
+
// unclear if function or object
|
163
|
+
obj = fn = expr.arguments[0];
|
164
|
+
}
|
165
|
+
break;
|
166
|
+
case 2:
|
167
|
+
if (expr.arguments[0].type === "Literal") {
|
168
|
+
namedModule = expr.arguments[0].value;
|
169
|
+
// define("…", …)
|
170
|
+
if (isCallable(expr.arguments[1])) {
|
171
|
+
// define("…", f() {…})
|
172
|
+
fn = expr.arguments[1];
|
173
|
+
} else if (expr.arguments[1].type === "ObjectExpression") {
|
174
|
+
// define("…", {…})
|
175
|
+
obj = expr.arguments[1];
|
176
|
+
} else {
|
177
|
+
// define("…", expr)
|
178
|
+
// unclear if function or object
|
179
|
+
obj = fn = expr.arguments[1];
|
180
|
+
}
|
181
|
+
} else {
|
182
|
+
array = expr.arguments[0];
|
183
|
+
if (isCallable(expr.arguments[1])) {
|
184
|
+
// define([…], f() {})
|
185
|
+
fn = expr.arguments[1];
|
186
|
+
} else if (expr.arguments[1].type === "ObjectExpression") {
|
187
|
+
// define([…], {…})
|
188
|
+
obj = expr.arguments[1];
|
189
|
+
} else {
|
190
|
+
// define([…], expr)
|
191
|
+
// unclear if function or object
|
192
|
+
obj = fn = expr.arguments[1];
|
193
|
+
}
|
194
|
+
}
|
195
|
+
break;
|
196
|
+
case 3:
|
197
|
+
// define("…", […], f() {…})
|
198
|
+
namedModule = expr.arguments[0].value;
|
199
|
+
array = expr.arguments[1];
|
200
|
+
if (isCallable(expr.arguments[2])) {
|
201
|
+
// define("…", […], f() {})
|
202
|
+
fn = expr.arguments[2];
|
203
|
+
} else if (expr.arguments[2].type === "ObjectExpression") {
|
204
|
+
// define("…", […], {…})
|
205
|
+
obj = expr.arguments[2];
|
206
|
+
} else {
|
207
|
+
// define("…", […], expr)
|
208
|
+
// unclear if function or object
|
209
|
+
obj = fn = expr.arguments[2];
|
210
|
+
}
|
211
|
+
break;
|
212
|
+
default:
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
let fnParams = null;
|
216
|
+
let fnParamsOffset = 0;
|
217
|
+
if (fn) {
|
218
|
+
if (isUnboundFunctionExpression(fn)) fnParams = fn.params;
|
219
|
+
else if (isBoundFunctionExpression(fn)) {
|
220
|
+
fnParams = fn.callee.object.params;
|
221
|
+
fnParamsOffset = fn.arguments.length - 1;
|
222
|
+
if (fnParamsOffset < 0) fnParamsOffset = 0;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
let fnRenames = parser.scope.renames.createChild();
|
226
|
+
let identifiers;
|
227
|
+
if (array) {
|
228
|
+
identifiers = {};
|
229
|
+
const param = parser.evaluateExpression(array);
|
230
|
+
const result = this.processArray(
|
231
|
+
parser,
|
232
|
+
expr,
|
233
|
+
param,
|
234
|
+
identifiers,
|
235
|
+
namedModule
|
236
|
+
);
|
237
|
+
if (!result) return;
|
238
|
+
if (fnParams)
|
239
|
+
fnParams = fnParams.slice(fnParamsOffset).filter((param, idx) => {
|
240
|
+
if (identifiers[idx]) {
|
241
|
+
fnRenames.set(param.name, identifiers[idx]);
|
242
|
+
return false;
|
243
|
+
}
|
244
|
+
return true;
|
245
|
+
});
|
246
|
+
} else {
|
247
|
+
identifiers = ["require", "exports", "module"];
|
248
|
+
if (fnParams)
|
249
|
+
fnParams = fnParams.slice(fnParamsOffset).filter((param, idx) => {
|
250
|
+
if (identifiers[idx]) {
|
251
|
+
fnRenames.set(param.name, identifiers[idx]);
|
252
|
+
return false;
|
253
|
+
}
|
254
|
+
return true;
|
255
|
+
});
|
256
|
+
}
|
257
|
+
let inTry;
|
258
|
+
if (fn && isUnboundFunctionExpression(fn)) {
|
259
|
+
inTry = parser.scope.inTry;
|
260
|
+
parser.inScope(fnParams, () => {
|
261
|
+
parser.scope.renames = fnRenames;
|
262
|
+
parser.scope.inTry = inTry;
|
263
|
+
if (fn.body.type === "BlockStatement") {
|
264
|
+
parser.walkStatement(fn.body);
|
265
|
+
} else {
|
266
|
+
parser.walkExpression(fn.body);
|
267
|
+
}
|
268
|
+
});
|
269
|
+
} else if (fn && isBoundFunctionExpression(fn)) {
|
270
|
+
inTry = parser.scope.inTry;
|
271
|
+
parser.inScope(
|
272
|
+
fn.callee.object.params.filter(
|
273
|
+
i => !["require", "module", "exports"].includes(i.name)
|
274
|
+
),
|
275
|
+
() => {
|
276
|
+
parser.scope.renames = fnRenames;
|
277
|
+
parser.scope.inTry = inTry;
|
278
|
+
if (fn.callee.object.body.type === "BlockStatement")
|
279
|
+
parser.walkStatement(fn.callee.object.body);
|
280
|
+
else parser.walkExpression(fn.callee.object.body);
|
281
|
+
}
|
282
|
+
);
|
283
|
+
if (fn.arguments) parser.walkExpressions(fn.arguments);
|
284
|
+
} else if (fn || obj) {
|
285
|
+
parser.walkExpression(fn || obj);
|
286
|
+
}
|
287
|
+
|
288
|
+
const dep = this.newDefineDependency(
|
289
|
+
expr.range,
|
290
|
+
array ? array.range : null,
|
291
|
+
fn ? fn.range : null,
|
292
|
+
obj ? obj.range : null,
|
293
|
+
namedModule ? namedModule : null
|
294
|
+
);
|
295
|
+
dep.loc = expr.loc;
|
296
|
+
if (namedModule) {
|
297
|
+
dep.localModule = LocalModulesHelpers.addLocalModule(
|
298
|
+
parser.state,
|
299
|
+
namedModule
|
300
|
+
);
|
301
|
+
}
|
302
|
+
parser.state.current.addDependency(dep);
|
303
|
+
return true;
|
304
|
+
}
|
305
|
+
|
306
|
+
newDefineDependency(
|
307
|
+
range,
|
308
|
+
arrayRange,
|
309
|
+
functionRange,
|
310
|
+
objectRange,
|
311
|
+
namedModule
|
312
|
+
) {
|
313
|
+
return new AMDDefineDependency(
|
314
|
+
range,
|
315
|
+
arrayRange,
|
316
|
+
functionRange,
|
317
|
+
objectRange,
|
318
|
+
namedModule
|
319
|
+
);
|
320
|
+
}
|
321
|
+
newRequireArrayDependency(depsArray, range) {
|
322
|
+
return new AMDRequireArrayDependency(depsArray, range);
|
323
|
+
}
|
324
|
+
newRequireItemDependency(request, range) {
|
325
|
+
return new AMDRequireItemDependency(request, range);
|
326
|
+
}
|
327
|
+
}
|
328
|
+
module.exports = AMDDefineDependencyParserPlugin;
|