@atlaspack/packager-js 2.14.5-canary.18 → 2.14.5-canary.180
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 +307 -0
- package/lib/DevPackager.js +28 -3
- package/lib/ScopeHoistingPackager.js +324 -79
- package/lib/dev-prelude.js +6 -6
- package/lib/helpers.js +38 -3
- package/lib/index.js +5 -10
- package/lib/types/CJSOutputFormat.d.ts +7 -0
- package/lib/types/DevPackager.d.ts +15 -0
- package/lib/types/ESMOutputFormat.d.ts +7 -0
- package/lib/types/GlobalOutputFormat.d.ts +7 -0
- package/lib/types/ScopeHoistingPackager.d.ts +67 -0
- package/lib/types/helpers.d.ts +12 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/utils.d.ts +6 -0
- package/package.json +17 -11
- package/src/{CJSOutputFormat.js → CJSOutputFormat.ts} +0 -1
- package/src/{DevPackager.js → DevPackager.ts} +34 -7
- package/src/{ESMOutputFormat.js → ESMOutputFormat.ts} +2 -3
- package/src/{GlobalOutputFormat.js → GlobalOutputFormat.ts} +0 -1
- package/src/{ScopeHoistingPackager.js → ScopeHoistingPackager.ts} +383 -111
- package/src/dev-prelude.js +6 -6
- package/src/{helpers.js → helpers.ts} +37 -3
- package/src/{index.js → index.ts} +13 -20
- package/src/{utils.js → utils.ts} +1 -2
- package/tsconfig.json +4 -0
|
@@ -60,6 +60,13 @@ function _featureFlags() {
|
|
|
60
60
|
};
|
|
61
61
|
return data;
|
|
62
62
|
}
|
|
63
|
+
function _outdent() {
|
|
64
|
+
const data = require("outdent");
|
|
65
|
+
_outdent = function () {
|
|
66
|
+
return data;
|
|
67
|
+
};
|
|
68
|
+
return data;
|
|
69
|
+
}
|
|
63
70
|
var _ESMOutputFormat = require("./ESMOutputFormat");
|
|
64
71
|
var _CJSOutputFormat = require("./CJSOutputFormat");
|
|
65
72
|
var _GlobalOutputFormat = require("./GlobalOutputFormat");
|
|
@@ -70,7 +77,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
70
77
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
71
78
|
// General regex used to replace imports with the resolved code, references with resolutions,
|
|
72
79
|
// and count the number of newlines in the file for source maps.
|
|
73
|
-
//
|
|
74
80
|
// For conditional bundling the only difference in this regex is adding `importCond` where we have `importAsync` etc..
|
|
75
81
|
const REPLACEMENT_RE_CONDITIONAL = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require|importCond)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
76
82
|
const REPLACEMENT_RE = /\n|import\s+"([0-9a-f]{16,20}:.+?)";|(?:\$[0-9a-f]{16,20}\$exports)|(?:\$[0-9a-f]{16,20}\$(?:import|importAsync|require)\$[0-9a-f]+(?:\$[0-9a-f]+)?)/g;
|
|
@@ -80,6 +86,7 @@ const GLOBALS_BY_CONTEXT = {
|
|
|
80
86
|
'web-worker': new Set([...BUILTINS, ...Object.keys(_globals().default.worker)]),
|
|
81
87
|
'service-worker': new Set([...BUILTINS, ...Object.keys(_globals().default.serviceworker)]),
|
|
82
88
|
worklet: new Set([...BUILTINS]),
|
|
89
|
+
tesseract: new Set([...BUILTINS, ...Object.keys(_globals().default.worker)]),
|
|
83
90
|
node: new Set([...BUILTINS, ...Object.keys(_globals().default.node)]),
|
|
84
91
|
'electron-main': new Set([...BUILTINS, ...Object.keys(_globals().default.node)]),
|
|
85
92
|
'electron-renderer': new Set([...BUILTINS, ...Object.keys(_globals().default.node), ...Object.keys(_globals().default.browser)])
|
|
@@ -90,32 +97,37 @@ const OUTPUT_FORMATS = {
|
|
|
90
97
|
global: _GlobalOutputFormat.GlobalOutputFormat
|
|
91
98
|
};
|
|
92
99
|
class ScopeHoistingPackager {
|
|
100
|
+
// @ts-expect-error TS2564
|
|
101
|
+
|
|
93
102
|
exportedSymbols = new Map();
|
|
94
103
|
externals = new Map();
|
|
95
104
|
topLevelNames = new Map();
|
|
96
105
|
seenAssets = new Set();
|
|
97
106
|
wrappedAssets = new Set();
|
|
98
107
|
hoistedRequires = new Map();
|
|
108
|
+
seenHoistedRequires = new Set();
|
|
99
109
|
needsPrelude = false;
|
|
100
110
|
usedHelpers = new Set();
|
|
101
111
|
externalAssets = new Set();
|
|
102
|
-
|
|
103
|
-
constructor(options, bundleGraph, bundle, parcelRequireName, useAsyncBundleRuntime,
|
|
112
|
+
useBothScopeHoistingImprovements = (0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2') || (0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovement');
|
|
113
|
+
constructor(options, bundleGraph, bundle, parcelRequireName, useAsyncBundleRuntime, logger) {
|
|
104
114
|
this.options = options;
|
|
105
115
|
this.bundleGraph = bundleGraph;
|
|
106
116
|
this.bundle = bundle;
|
|
107
117
|
this.parcelRequireName = parcelRequireName;
|
|
108
118
|
this.useAsyncBundleRuntime = useAsyncBundleRuntime;
|
|
109
|
-
this.forceSkipWrapAssets = forceSkipWrapAssets ?? [];
|
|
110
119
|
this.logger = logger;
|
|
111
120
|
let OutputFormat = OUTPUT_FORMATS[this.bundle.env.outputFormat];
|
|
112
121
|
this.outputFormat = new OutputFormat(this);
|
|
113
|
-
this.isAsyncBundle = this.bundleGraph.hasParentBundleOfType(this.bundle, 'js') && !this.bundle.env.isIsolated() && this.bundle.bundleBehavior !== 'isolated';
|
|
122
|
+
this.isAsyncBundle = this.bundleGraph.hasParentBundleOfType(this.bundle, 'js') && !this.bundle.env.isIsolated() && this.bundle.bundleBehavior !== 'isolated' && this.bundle.bundleBehavior !== 'inlineIsolated';
|
|
114
123
|
this.globalNames = GLOBALS_BY_CONTEXT[bundle.env.context];
|
|
115
124
|
}
|
|
116
125
|
async package() {
|
|
117
126
|
var _sourceMap;
|
|
118
|
-
let
|
|
127
|
+
let {
|
|
128
|
+
wrapped: wrappedAssets,
|
|
129
|
+
constant: constantAssets
|
|
130
|
+
} = await this.loadAssets();
|
|
119
131
|
this.buildExportedSymbols();
|
|
120
132
|
|
|
121
133
|
// If building a library, the target is actually another bundler rather
|
|
@@ -132,9 +144,13 @@ class ScopeHoistingPackager {
|
|
|
132
144
|
}
|
|
133
145
|
let res = '';
|
|
134
146
|
let lineCount = 0;
|
|
147
|
+
// @ts-expect-error TS7034
|
|
135
148
|
let sourceMap = null;
|
|
136
149
|
let processAsset = asset => {
|
|
150
|
+
this.seenHoistedRequires.clear();
|
|
137
151
|
let [content, map, lines] = this.visitAsset(asset);
|
|
152
|
+
|
|
153
|
+
// @ts-expect-error TS7005
|
|
138
154
|
if (sourceMap && map) {
|
|
139
155
|
sourceMap.addSourceMap(map, lineCount);
|
|
140
156
|
} else if (this.bundle.env.sourceMap) {
|
|
@@ -143,6 +159,14 @@ class ScopeHoistingPackager {
|
|
|
143
159
|
res += content + '\n';
|
|
144
160
|
lineCount += lines + 1;
|
|
145
161
|
};
|
|
162
|
+
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') || this.useBothScopeHoistingImprovements) {
|
|
163
|
+
// Write out all constant modules used by this bundle
|
|
164
|
+
for (let asset of constantAssets) {
|
|
165
|
+
if (!this.seenAssets.has(asset.id)) {
|
|
166
|
+
processAsset(asset);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
146
170
|
|
|
147
171
|
// Hoist wrapped asset to the top of the bundle to ensure that they are registered
|
|
148
172
|
// before they are used.
|
|
@@ -165,16 +189,28 @@ class ScopeHoistingPackager {
|
|
|
165
189
|
let [prelude, preludeLines] = this.buildBundlePrelude();
|
|
166
190
|
res = prelude + res;
|
|
167
191
|
lineCount += preludeLines;
|
|
192
|
+
// @ts-expect-error TS2339
|
|
168
193
|
(_sourceMap = sourceMap) === null || _sourceMap === void 0 || _sourceMap.offsetLines(1, preludeLines);
|
|
169
194
|
let entries = this.bundle.getEntryAssets();
|
|
170
195
|
let mainEntry = this.bundle.getMainEntry();
|
|
171
196
|
if (this.isAsyncBundle) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
197
|
+
if (this.useBothScopeHoistingImprovements || (0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
198
|
+
// Generally speaking, async bundles should not be executed on load, as
|
|
199
|
+
// they're just collections of assets that other assets require.
|
|
200
|
+
// However, there are some special cases where a runtime asset needs to be
|
|
201
|
+
// injected, but no other asset will require it (mostly the bundle
|
|
202
|
+
// manifest).
|
|
203
|
+
// In this case, those assets need to be required on load.
|
|
204
|
+
entries = entries.filter(a => {
|
|
205
|
+
var _a$meta;
|
|
206
|
+
return (_a$meta = a.meta) === null || _a$meta === void 0 ? void 0 : _a$meta.runtimeAssetRequiringExecutionOnLoad;
|
|
207
|
+
});
|
|
208
|
+
} else {
|
|
209
|
+
entries = entries.filter(a => {
|
|
210
|
+
var _mainEntry;
|
|
211
|
+
return a.id !== ((_mainEntry = mainEntry) === null || _mainEntry === void 0 ? void 0 : _mainEntry.id);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
178
214
|
mainEntry = null;
|
|
179
215
|
}
|
|
180
216
|
let needsBundleQueue = this.shouldBundleQueue(this.bundle);
|
|
@@ -184,9 +220,14 @@ class ScopeHoistingPackager {
|
|
|
184
220
|
if (this.wrappedAssets.has(entry.id) && !this.isScriptEntry(entry)) {
|
|
185
221
|
var _entry$symbols$get;
|
|
186
222
|
let parcelRequire = `parcelRequire(${JSON.stringify(this.bundleGraph.getAssetPublicId(entry))});\n`;
|
|
223
|
+
|
|
224
|
+
// @ts-expect-error TS2345
|
|
187
225
|
let entryExports = (_entry$symbols$get = entry.symbols.get('*')) === null || _entry$symbols$get === void 0 ? void 0 : _entry$symbols$get.local;
|
|
188
|
-
if (entryExports && entry === mainEntry &&
|
|
226
|
+
if (entryExports && entry === mainEntry &&
|
|
227
|
+
// @ts-expect-error TS2345
|
|
228
|
+
this.exportedSymbols.has(entryExports)) {
|
|
189
229
|
(0, _assert().default)(!needsBundleQueue, 'Entry exports are not yet compaitble with async bundles');
|
|
230
|
+
// @ts-expect-error TS2731
|
|
190
231
|
res += `\nvar ${entryExports} = ${parcelRequire}`;
|
|
191
232
|
} else {
|
|
192
233
|
if (needsBundleQueue) {
|
|
@@ -218,6 +259,7 @@ class ScopeHoistingPackager {
|
|
|
218
259
|
}
|
|
219
260
|
res += (0, _utils2.replaceScriptDependencies)(this.bundleGraph, this.bundle, code, map, this.parcelRequireName);
|
|
220
261
|
if (sourceMap && map) {
|
|
262
|
+
// @ts-expect-error TS2339
|
|
221
263
|
sourceMap.addSourceMap(map, lineCount);
|
|
222
264
|
}
|
|
223
265
|
}
|
|
@@ -231,18 +273,18 @@ class ScopeHoistingPackager {
|
|
|
231
273
|
let hasHtmlReference = referencingBundles.some(b => b.type === 'html');
|
|
232
274
|
let hasConditionalReference = false;
|
|
233
275
|
let isConditionalBundle = false;
|
|
234
|
-
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')
|
|
276
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
235
277
|
// If the bundle has a conditional bundle reference (has an importCond)
|
|
236
278
|
hasConditionalReference = this.bundleGraph.getReferencedConditionalBundles(bundle).length > 0;
|
|
237
279
|
// If the bundle is a conditional bundle
|
|
238
280
|
isConditionalBundle = this.hasConditionalDependency();
|
|
239
281
|
}
|
|
240
|
-
return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && (hasHtmlReference || hasConditionalReference || isConditionalBundle);
|
|
282
|
+
return this.useAsyncBundleRuntime && bundle.type === 'js' && bundle.bundleBehavior !== 'inline' && bundle.bundleBehavior !== 'inlineIsolated' && bundle.env.outputFormat === 'esmodule' && !bundle.env.isIsolated() && bundle.bundleBehavior !== 'isolated' && (hasHtmlReference || hasConditionalReference || isConditionalBundle);
|
|
241
283
|
}
|
|
242
284
|
runWhenReady(bundle, codeToRun) {
|
|
243
285
|
let deps = this.bundleGraph.getReferencedBundles(bundle).filter(b => this.shouldBundleQueue(b)).map(b => b.publicId);
|
|
244
286
|
const conditions = [];
|
|
245
|
-
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')
|
|
287
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
246
288
|
const conditionSet = this.bundleGraph.getConditionalBundleMapping().get(bundle.id);
|
|
247
289
|
for (const [key, {
|
|
248
290
|
ifTrueBundles,
|
|
@@ -265,6 +307,7 @@ class ScopeHoistingPackager {
|
|
|
265
307
|
maxConcurrent: 32
|
|
266
308
|
});
|
|
267
309
|
let wrapped = [];
|
|
310
|
+
let constant = [];
|
|
268
311
|
this.bundle.traverseAssets(asset => {
|
|
269
312
|
queue.add(async () => {
|
|
270
313
|
let [code, map] = await Promise.all([asset.getCode(), this.bundle.env.sourceMap ? asset.getMapBuffer() : null]);
|
|
@@ -278,38 +321,91 @@ class ScopeHoistingPackager {
|
|
|
278
321
|
if (!asset.meta.isConstantModule || this.bundleGraph.getIncomingDependencies(asset).some(dep => dep.priority === 'lazy')) {
|
|
279
322
|
this.wrappedAssets.add(asset.id);
|
|
280
323
|
wrapped.push(asset);
|
|
324
|
+
} else if (((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') || this.useBothScopeHoistingImprovements) && asset.meta.isConstantModule) {
|
|
325
|
+
constant.push(asset);
|
|
281
326
|
}
|
|
282
327
|
}
|
|
283
328
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// due to the entry asset being wrapped.
|
|
298
|
-
if (this.forceSkipWrapAssets.length > 0 && this.forceSkipWrapAssets.some(p => p === _path().default.relative(this.options.projectRoot, asset.filePath))) {
|
|
299
|
-
this.logger.verbose({
|
|
300
|
-
message: `Force skipping wrapping of ${_path().default.relative(this.options.projectRoot, asset.filePath)}`
|
|
301
|
-
});
|
|
302
|
-
actions.skipChildren();
|
|
303
|
-
return;
|
|
329
|
+
if (this.useBothScopeHoistingImprovements) {
|
|
330
|
+
// Tracks which assets have been assigned to a wrap group
|
|
331
|
+
let assignedAssets = new Set();
|
|
332
|
+
|
|
333
|
+
// In V2 scope hoisting, we iterate from the main entry, rather than
|
|
334
|
+
// wrapping the entry assets
|
|
335
|
+
if (!(0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
336
|
+
// Make all entry assets wrapped, to avoid any top level hoisting
|
|
337
|
+
for (let entryAsset of this.bundle.getEntryAssets()) {
|
|
338
|
+
if (!this.wrappedAssets.has(entryAsset.id)) {
|
|
339
|
+
this.wrappedAssets.add(entryAsset.id);
|
|
340
|
+
wrapped.push(entryAsset);
|
|
341
|
+
}
|
|
304
342
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
343
|
+
}
|
|
344
|
+
let moduleGroupParents = [...wrapped];
|
|
345
|
+
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
346
|
+
// The main entry needs to be check to find assets that would have gone in
|
|
347
|
+
// the top level scope
|
|
348
|
+
let mainEntry = this.bundle.getMainEntry();
|
|
349
|
+
if (mainEntry && !this.wrappedAssets.has(mainEntry.id)) {
|
|
350
|
+
moduleGroupParents.unshift(mainEntry);
|
|
308
351
|
}
|
|
309
|
-
}
|
|
352
|
+
}
|
|
353
|
+
for (let moduleGroupParentAsset of moduleGroupParents) {
|
|
354
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
355
|
+
if (asset === moduleGroupParentAsset) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
359
|
+
actions.skipChildren();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (!asset.meta.isConstantModule && (assignedAssets.has(asset) || this.isReExported(asset))) {
|
|
363
|
+
wrapped.push(asset);
|
|
364
|
+
this.wrappedAssets.add(asset.id);
|
|
365
|
+
|
|
366
|
+
// This also needs to be added to the traversal so that we iterate
|
|
367
|
+
// it during this check.
|
|
368
|
+
moduleGroupParents.push(asset);
|
|
369
|
+
actions.skipChildren();
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
assignedAssets.add(asset);
|
|
373
|
+
}, moduleGroupParentAsset);
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
for (let wrappedAssetRoot of [...wrapped]) {
|
|
377
|
+
this.bundle.traverseAssets((asset, _, actions) => {
|
|
378
|
+
if (asset === wrappedAssetRoot) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (this.wrappedAssets.has(asset.id)) {
|
|
382
|
+
actions.skipChildren();
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
if (!asset.meta.isConstantModule) {
|
|
386
|
+
this.wrappedAssets.add(asset.id);
|
|
387
|
+
wrapped.push(asset);
|
|
388
|
+
}
|
|
389
|
+
}, wrappedAssetRoot);
|
|
390
|
+
}
|
|
310
391
|
}
|
|
392
|
+
|
|
393
|
+
// @ts-expect-error TS2769
|
|
311
394
|
this.assetOutputs = new Map(await queue.run());
|
|
312
|
-
return
|
|
395
|
+
return {
|
|
396
|
+
wrapped,
|
|
397
|
+
constant
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
isReExported(asset) {
|
|
401
|
+
let parentSymbols = this.bundleGraph.getIncomingDependencies(asset).map(dep => this.bundleGraph.getAssetWithDependency(dep)).flatMap(parent => {
|
|
402
|
+
if (parent == null) {
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
return this.bundleGraph.getExportedSymbols(parent, this.bundle);
|
|
406
|
+
});
|
|
407
|
+
let assetSymbols = this.bundleGraph.getExportedSymbols(asset, this.bundle);
|
|
408
|
+
return assetSymbols.some(assetSymbol => parentSymbols.some(parentSymbol => parentSymbol.symbol === assetSymbol.symbol));
|
|
313
409
|
}
|
|
314
410
|
buildExportedSymbols() {
|
|
315
411
|
if (!this.bundle.env.isLibrary || this.bundle.env.outputFormat !== 'esmodule') {
|
|
@@ -319,6 +415,7 @@ class ScopeHoistingPackager {
|
|
|
319
415
|
// TODO: handle ESM exports of wrapped entry assets...
|
|
320
416
|
let entry = this.bundle.getMainEntry();
|
|
321
417
|
if (entry && !this.wrappedAssets.has(entry.id)) {
|
|
418
|
+
// @ts-expect-error TS2345
|
|
322
419
|
let hasNamespace = entry.symbols.hasExportSymbol('*');
|
|
323
420
|
for (let {
|
|
324
421
|
asset,
|
|
@@ -334,11 +431,14 @@ class ScopeHoistingPackager {
|
|
|
334
431
|
if (hasNamespace && this.isAsyncBundle && exportAs !== '*') {
|
|
335
432
|
continue;
|
|
336
433
|
}
|
|
337
|
-
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
434
|
+
let symbols = (_this$exportedSymbols = this.exportedSymbols.get(
|
|
435
|
+
// @ts-expect-error TS2345
|
|
436
|
+
symbol === '*' ? (0, _nullthrows().default)((_entry$symbols$get2 = entry.symbols.get('*')) === null || _entry$symbols$get2 === void 0 ? void 0 : _entry$symbols$get2.local) : symbol)) === null || _this$exportedSymbols === void 0 ? void 0 : _this$exportedSymbols.exportAs;
|
|
338
437
|
if (!symbols) {
|
|
339
438
|
symbols = [];
|
|
340
439
|
this.exportedSymbols.set(symbol, {
|
|
341
440
|
asset,
|
|
441
|
+
// @ts-expect-error TS2322
|
|
342
442
|
exportSymbol,
|
|
343
443
|
local: symbol,
|
|
344
444
|
exportAs: symbols
|
|
@@ -347,6 +447,8 @@ class ScopeHoistingPackager {
|
|
|
347
447
|
if (exportAs === '*') {
|
|
348
448
|
exportAs = 'default';
|
|
349
449
|
}
|
|
450
|
+
|
|
451
|
+
// @ts-expect-error TS2345
|
|
350
452
|
symbols.push(exportAs);
|
|
351
453
|
} else if (symbol === null) {
|
|
352
454
|
// TODO `meta.exportsIdentifier[exportSymbol]` should be exported
|
|
@@ -395,6 +497,9 @@ class ScopeHoistingPackager {
|
|
|
395
497
|
} = (0, _nullthrows().default)(this.assetOutputs.get(asset.id));
|
|
396
498
|
return this.buildAsset(asset, code, map);
|
|
397
499
|
}
|
|
500
|
+
getAssetFilePath(asset) {
|
|
501
|
+
return _path().default.relative(this.options.projectRoot, asset.filePath);
|
|
502
|
+
}
|
|
398
503
|
buildAsset(asset, code, map) {
|
|
399
504
|
let shouldWrap = this.wrappedAssets.has(asset.id);
|
|
400
505
|
let deps = this.bundleGraph.getDependencies(asset);
|
|
@@ -420,6 +525,7 @@ class ScopeHoistingPackager {
|
|
|
420
525
|
let [code, map, lines] = this.visitAsset(resolved);
|
|
421
526
|
depCode += code + '\n';
|
|
422
527
|
if (sourceMap && map) {
|
|
528
|
+
// @ts-expect-error TS2551
|
|
423
529
|
sourceMap.addSourceMap(map, lineCount);
|
|
424
530
|
}
|
|
425
531
|
lineCount += lines + 1;
|
|
@@ -445,6 +551,7 @@ class ScopeHoistingPackager {
|
|
|
445
551
|
}
|
|
446
552
|
code += append;
|
|
447
553
|
let lineCount = 0;
|
|
554
|
+
// @ts-expect-error TS2552
|
|
448
555
|
let depContent = [];
|
|
449
556
|
if (depMap.size === 0 && replacements.size === 0) {
|
|
450
557
|
// If there are no dependencies or replacements, use a simple function to count the number of lines.
|
|
@@ -482,20 +589,51 @@ class ScopeHoistingPackager {
|
|
|
482
589
|
// after the dependency is declared. This handles the case where the resulting asset
|
|
483
590
|
// is wrapped, but the dependency in this asset is not marked as wrapped. This means
|
|
484
591
|
// that it was imported/required at the top-level, so its side effects should run immediately.
|
|
485
|
-
let
|
|
592
|
+
let res = '';
|
|
593
|
+
let lines = 0;
|
|
486
594
|
let map;
|
|
595
|
+
if (!(0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
596
|
+
[res, lines] = this.getHoistedParcelRequires(asset, dep, resolved);
|
|
597
|
+
}
|
|
487
598
|
if (this.bundle.hasAsset(resolved) && !this.seenAssets.has(resolved.id)) {
|
|
488
599
|
// If this asset is wrapped, we need to hoist the code for the dependency
|
|
489
600
|
// outside our parcelRequire.register wrapper. This is safe because all
|
|
490
601
|
// assets referenced by this asset will also be wrapped. Otherwise, inline the
|
|
491
602
|
// asset content where the import statement was.
|
|
492
|
-
if (
|
|
493
|
-
|
|
603
|
+
if (this.useBothScopeHoistingImprovements) {
|
|
604
|
+
if (!resolved.meta.isConstantModule && !this.wrappedAssets.has(resolved.id)) {
|
|
605
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
606
|
+
if (_utils().debugTools['asset-file-names-in-output']) {
|
|
607
|
+
let resolvedPath = this.getAssetFilePath(resolved);
|
|
608
|
+
res = (0, _outdent().outdent)`
|
|
609
|
+
/* Scope hoisted asset: ${resolvedPath} */
|
|
610
|
+
${depCode}
|
|
611
|
+
/* End: ${resolvedPath} */
|
|
612
|
+
${res}
|
|
613
|
+
`;
|
|
614
|
+
lines += 3 + depLines;
|
|
615
|
+
} else {
|
|
616
|
+
res = depCode + '\n' + res;
|
|
617
|
+
lines += 1 + depLines;
|
|
618
|
+
}
|
|
619
|
+
map = depMap;
|
|
620
|
+
}
|
|
494
621
|
} else {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
622
|
+
if (shouldWrap) {
|
|
623
|
+
depContent.push(this.visitAsset(resolved));
|
|
624
|
+
} else {
|
|
625
|
+
let [depCode, depMap, depLines] = this.visitAsset(resolved);
|
|
626
|
+
res = depCode + '\n' + res;
|
|
627
|
+
lines += 1 + depLines;
|
|
628
|
+
map = depMap;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
633
|
+
let [requiresCode, requiresLines] = this.getHoistedParcelRequires(asset, dep, resolved);
|
|
634
|
+
if (requiresCode) {
|
|
635
|
+
res = requiresCode + '\n' + res;
|
|
636
|
+
lines += requiresLines + 1;
|
|
499
637
|
}
|
|
500
638
|
}
|
|
501
639
|
|
|
@@ -506,6 +644,7 @@ class ScopeHoistingPackager {
|
|
|
506
644
|
sourceMap.offsetLines(lineCount + 1, lines);
|
|
507
645
|
}
|
|
508
646
|
if (map) {
|
|
647
|
+
// @ts-expect-error TS2551
|
|
509
648
|
sourceMap.addSourceMap(map, lineCount);
|
|
510
649
|
}
|
|
511
650
|
}
|
|
@@ -542,10 +681,15 @@ ${code}
|
|
|
542
681
|
});
|
|
543
682
|
`;
|
|
544
683
|
lineCount += 2;
|
|
684
|
+
if (_utils().debugTools['asset-file-names-in-output']) {
|
|
685
|
+
code = `/* ${this.getAssetFilePath(asset)} */\n` + code;
|
|
686
|
+
lineCount += 1;
|
|
687
|
+
}
|
|
545
688
|
for (let [depCode, map, lines] of depContent) {
|
|
546
689
|
if (!depCode) continue;
|
|
547
690
|
code += depCode + '\n';
|
|
548
691
|
if (sourceMap && map) {
|
|
692
|
+
// @ts-expect-error TS2551
|
|
549
693
|
sourceMap.addSourceMap(map, lineCount);
|
|
550
694
|
}
|
|
551
695
|
lineCount += lines + 1;
|
|
@@ -592,9 +736,12 @@ ${code}
|
|
|
592
736
|
for (let [imported, {
|
|
593
737
|
local
|
|
594
738
|
}] of dep.symbols) {
|
|
739
|
+
// @ts-expect-error TS2367
|
|
595
740
|
if (local === '*') {
|
|
596
741
|
continue;
|
|
597
742
|
}
|
|
743
|
+
|
|
744
|
+
// @ts-expect-error TS2345
|
|
598
745
|
let symbol = this.getSymbolResolution(asset, resolved, imported, dep);
|
|
599
746
|
replacements.set(local,
|
|
600
747
|
// If this was an internalized async asset, wrap in a Promise.resolve.
|
|
@@ -616,6 +763,7 @@ ${code}
|
|
|
616
763
|
// which will be provided to us by the wrapper.
|
|
617
764
|
if (this.wrappedAssets.has(asset.id) || this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry()) {
|
|
618
765
|
var _asset$symbols$get;
|
|
766
|
+
// @ts-expect-error TS2345
|
|
619
767
|
let exportsName = ((_asset$symbols$get = asset.symbols.get('*')) === null || _asset$symbols$get === void 0 ? void 0 : _asset$symbols$get.local) || `$${assetId}$exports`;
|
|
620
768
|
replacements.set(exportsName, 'module.exports');
|
|
621
769
|
}
|
|
@@ -648,8 +796,11 @@ ${code}
|
|
|
648
796
|
local
|
|
649
797
|
}] of dep.symbols) {
|
|
650
798
|
// If already imported, just add the already renamed variable to the mapping.
|
|
799
|
+
// @ts-expect-error TS2345
|
|
651
800
|
let renamed = external.get(imported);
|
|
801
|
+
// @ts-expect-error TS2367
|
|
652
802
|
if (renamed && local !== '*' && replacements) {
|
|
803
|
+
// @ts-expect-error TS2345
|
|
653
804
|
replacements.set(local, renamed);
|
|
654
805
|
continue;
|
|
655
806
|
}
|
|
@@ -662,16 +813,25 @@ ${code}
|
|
|
662
813
|
if (referencedBundle) {
|
|
663
814
|
var _entry$symbols$get3;
|
|
664
815
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
665
|
-
|
|
816
|
+
// @ts-expect-error TS2322
|
|
817
|
+
renamed =
|
|
818
|
+
// @ts-expect-error TS2345
|
|
819
|
+
((_entry$symbols$get3 = entry.symbols.get('*')) === null || _entry$symbols$get3 === void 0 ? void 0 : _entry$symbols$get3.local) ?? `$${String(entry.meta.id)}$exports`;
|
|
666
820
|
} else {
|
|
667
821
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
668
822
|
}
|
|
823
|
+
|
|
824
|
+
// @ts-expect-error TS2345
|
|
669
825
|
external.set('*', renamed);
|
|
670
826
|
}
|
|
827
|
+
|
|
828
|
+
// @ts-expect-error TS2367
|
|
671
829
|
if (local !== '*' && replacements) {
|
|
672
830
|
let replacement;
|
|
831
|
+
// @ts-expect-error TS2367
|
|
673
832
|
if (imported === '*') {
|
|
674
833
|
replacement = renamed;
|
|
834
|
+
// @ts-expect-error TS2367
|
|
675
835
|
} else if (imported === 'default') {
|
|
676
836
|
let needsDefaultInterop = true;
|
|
677
837
|
if (referencedBundle) {
|
|
@@ -685,32 +845,41 @@ ${code}
|
|
|
685
845
|
replacement = `${renamed}.default`;
|
|
686
846
|
}
|
|
687
847
|
} else {
|
|
848
|
+
// @ts-expect-error TS2345
|
|
688
849
|
replacement = this.getPropertyAccess(renamed, imported);
|
|
689
850
|
}
|
|
851
|
+
|
|
852
|
+
// @ts-expect-error TS2345
|
|
690
853
|
replacements.set(local, replacement);
|
|
691
854
|
}
|
|
692
855
|
} else {
|
|
693
856
|
let property;
|
|
694
857
|
if (referencedBundle) {
|
|
695
858
|
let entry = (0, _nullthrows().default)(referencedBundle.getMainEntry());
|
|
859
|
+
// @ts-expect-error TS2345
|
|
696
860
|
if (entry.symbols.hasExportSymbol('*')) {
|
|
697
861
|
// If importing * and the referenced module has a * export (e.g. CJS), use default instead.
|
|
698
862
|
// This mirrors the logic in buildExportedSymbols.
|
|
699
863
|
property = imported;
|
|
864
|
+
// @ts-expect-error TS2322
|
|
700
865
|
imported = (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.env.outputFormat) === 'esmodule' ? 'default' : '*';
|
|
701
866
|
} else {
|
|
867
|
+
// @ts-expect-error TS2367
|
|
702
868
|
if (imported === '*') {
|
|
703
869
|
let exportedSymbols = this.bundleGraph.getExportedSymbols(entry);
|
|
870
|
+
// @ts-expect-error TS2367
|
|
704
871
|
if (local === '*') {
|
|
705
872
|
// Re-export all symbols.
|
|
706
873
|
for (let exported of exportedSymbols) {
|
|
707
874
|
if (exported.symbol) {
|
|
875
|
+
// @ts-expect-error TS2345
|
|
708
876
|
external.set(exported.exportSymbol, exported.symbol);
|
|
709
877
|
}
|
|
710
878
|
}
|
|
711
879
|
continue;
|
|
712
880
|
}
|
|
713
881
|
}
|
|
882
|
+
// @ts-expect-error TS2322
|
|
714
883
|
renamed = this.bundleGraph.getSymbolResolution(entry, imported, this.bundle).symbol;
|
|
715
884
|
}
|
|
716
885
|
}
|
|
@@ -719,25 +888,37 @@ ${code}
|
|
|
719
888
|
// are deduplicated. We have to prefix the imported name with the bundle id so that
|
|
720
889
|
// local variables do not shadow it.
|
|
721
890
|
if (!renamed) {
|
|
891
|
+
// @ts-expect-error TS2345
|
|
722
892
|
if (this.exportedSymbols.has(local)) {
|
|
893
|
+
// @ts-expect-error TS2322
|
|
723
894
|
renamed = local;
|
|
895
|
+
// @ts-expect-error TS2367
|
|
724
896
|
} else if (imported === 'default' || imported === '*') {
|
|
725
897
|
renamed = this.getTopLevelName(`$${this.bundle.publicId}$${specifier}`);
|
|
726
898
|
} else {
|
|
727
|
-
renamed = this.getTopLevelName(
|
|
899
|
+
renamed = this.getTopLevelName(
|
|
900
|
+
// @ts-expect-error TS2731
|
|
901
|
+
`$${this.bundle.publicId}$${imported}`);
|
|
728
902
|
}
|
|
729
903
|
}
|
|
904
|
+
|
|
905
|
+
// @ts-expect-error TS2345
|
|
730
906
|
external.set(imported, renamed);
|
|
907
|
+
// @ts-expect-error TS2367
|
|
731
908
|
if (local !== '*' && replacements) {
|
|
732
909
|
let replacement = renamed;
|
|
910
|
+
// @ts-expect-error TS2367
|
|
733
911
|
if (property === '*') {
|
|
734
912
|
replacement = renamed;
|
|
913
|
+
// @ts-expect-error TS2367
|
|
735
914
|
} else if (property === 'default') {
|
|
736
915
|
replacement = `($parcel$interopDefault(${renamed}))`;
|
|
737
916
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
738
917
|
} else if (property) {
|
|
918
|
+
// @ts-expect-error TS2345
|
|
739
919
|
replacement = this.getPropertyAccess(renamed, property);
|
|
740
920
|
}
|
|
921
|
+
// @ts-expect-error TS2345
|
|
741
922
|
replacements.set(local, replacement);
|
|
742
923
|
}
|
|
743
924
|
}
|
|
@@ -759,6 +940,7 @@ ${code}
|
|
|
759
940
|
asset: resolvedAsset,
|
|
760
941
|
exportSymbol,
|
|
761
942
|
symbol
|
|
943
|
+
// @ts-expect-error TS2345
|
|
762
944
|
} = this.bundleGraph.getSymbolResolution(resolved, imported, this.bundle);
|
|
763
945
|
if (resolvedAsset.type !== 'js' || dep && this.bundleGraph.isDependencySkipped(dep)) {
|
|
764
946
|
// Graceful fallback for non-js imports or when trying to resolve a symbol
|
|
@@ -792,7 +974,13 @@ ${code}
|
|
|
792
974
|
|
|
793
975
|
// If this is an ESM default import of a CJS module with a `default` symbol,
|
|
794
976
|
// and no __esModule flag, we need to resolve to the namespace instead.
|
|
795
|
-
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') &&
|
|
977
|
+
let isDefaultInterop = exportSymbol === 'default' && staticExports && !isWrapped && ((dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Import' || (dep === null || dep === void 0 ? void 0 : dep.meta.kind) === 'Export') &&
|
|
978
|
+
// @ts-expect-error TS2345
|
|
979
|
+
resolvedAsset.symbols.hasExportSymbol('*') &&
|
|
980
|
+
// @ts-expect-error TS2345
|
|
981
|
+
resolvedAsset.symbols.hasExportSymbol('default') &&
|
|
982
|
+
// @ts-expect-error TS2345
|
|
983
|
+
!resolvedAsset.symbols.hasExportSymbol('__esModule');
|
|
796
984
|
|
|
797
985
|
// Find the namespace object for the resolved module. If wrapped and this
|
|
798
986
|
// is an inline require (not top-level), use a parcelRequire call, otherwise
|
|
@@ -808,7 +996,9 @@ ${code}
|
|
|
808
996
|
obj = `$${publicId}`;
|
|
809
997
|
} else {
|
|
810
998
|
var _resolvedAsset$symbol;
|
|
999
|
+
// @ts-expect-error TS2345
|
|
811
1000
|
obj = ((_resolvedAsset$symbol = resolvedAsset.symbols.get('*')) === null || _resolvedAsset$symbol === void 0 ? void 0 : _resolvedAsset$symbol.local) || `$${assetId}$exports`;
|
|
1001
|
+
// @ts-expect-error TS2345
|
|
812
1002
|
obj = (replacements === null || replacements === void 0 ? void 0 : replacements.get(obj)) || obj;
|
|
813
1003
|
}
|
|
814
1004
|
if (imported === '*' || exportSymbol === '*' || isDefaultInterop) {
|
|
@@ -817,6 +1007,7 @@ ${code}
|
|
|
817
1007
|
// Directly use module.exports for wrapped assets importing themselves.
|
|
818
1008
|
return 'module.exports';
|
|
819
1009
|
} else {
|
|
1010
|
+
// @ts-expect-error TS2322
|
|
820
1011
|
return obj;
|
|
821
1012
|
}
|
|
822
1013
|
} else if ((!staticExports || isWrapped || !symbol || isExternalCommonJS) && resolvedAsset !== parentAsset) {
|
|
@@ -825,15 +1016,20 @@ ${code}
|
|
|
825
1016
|
// than a direct reference. If importing default from a CJS module,
|
|
826
1017
|
// use a helper to check the __esModule flag at runtime.
|
|
827
1018
|
let kind = dep === null || dep === void 0 ? void 0 : dep.meta.kind;
|
|
828
|
-
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
1019
|
+
if ((!dep || kind === 'Import' || kind === 'Export') && exportSymbol === 'default' &&
|
|
1020
|
+
// @ts-expect-error TS2345
|
|
1021
|
+
resolvedAsset.symbols.hasExportSymbol('*') && this.needsDefaultInterop(resolvedAsset)) {
|
|
829
1022
|
this.usedHelpers.add('$parcel$interopDefault');
|
|
1023
|
+
// @ts-expect-error TS2731
|
|
830
1024
|
return `(/*@__PURE__*/$parcel$interopDefault(${obj}))`;
|
|
831
1025
|
} else {
|
|
1026
|
+
// @ts-expect-error TS2345
|
|
832
1027
|
return this.getPropertyAccess(obj, exportSymbol);
|
|
833
1028
|
}
|
|
834
1029
|
} else if (!symbol) {
|
|
835
1030
|
(0, _assert().default)(false, 'Asset was skipped or not found.');
|
|
836
1031
|
} else {
|
|
1032
|
+
// @ts-expect-error TS2322
|
|
837
1033
|
return (replacements === null || replacements === void 0 ? void 0 : replacements.get(symbol)) || symbol;
|
|
838
1034
|
}
|
|
839
1035
|
}
|
|
@@ -856,8 +1052,17 @@ ${code}
|
|
|
856
1052
|
}
|
|
857
1053
|
if (hoisted) {
|
|
858
1054
|
this.needsPrelude = true;
|
|
859
|
-
|
|
860
|
-
|
|
1055
|
+
if ((0, _featureFlags().getFeatureFlag)('applyScopeHoistingImprovementV2')) {
|
|
1056
|
+
let hoistedValues = [...hoisted.values()].filter(val => !this.seenHoistedRequires.has(val));
|
|
1057
|
+
for (let val of hoistedValues) {
|
|
1058
|
+
this.seenHoistedRequires.add(val);
|
|
1059
|
+
}
|
|
1060
|
+
res += '\n' + hoistedValues.join('\n');
|
|
1061
|
+
lineCount += hoisted.size;
|
|
1062
|
+
} else {
|
|
1063
|
+
res += '\n' + [...hoisted.values()].join('\n');
|
|
1064
|
+
lineCount += hoisted.size;
|
|
1065
|
+
}
|
|
861
1066
|
}
|
|
862
1067
|
return [res, lineCount];
|
|
863
1068
|
}
|
|
@@ -873,21 +1078,39 @@ ${code}
|
|
|
873
1078
|
// If the asset has a namespace export symbol, it is CommonJS.
|
|
874
1079
|
// If there's no __esModule flag, and default is a used symbol, we need
|
|
875
1080
|
// to insert an interop helper.
|
|
876
|
-
let defaultInterop =
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
//
|
|
880
|
-
|
|
881
|
-
//
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1081
|
+
let defaultInterop =
|
|
1082
|
+
// @ts-expect-error TS2345
|
|
1083
|
+
asset.symbols.hasExportSymbol('*') &&
|
|
1084
|
+
// @ts-expect-error TS2345
|
|
1085
|
+
usedSymbols.has('default') &&
|
|
1086
|
+
// @ts-expect-error TS2345
|
|
1087
|
+
!asset.symbols.hasExportSymbol('__esModule');
|
|
1088
|
+
let usedNamespace;
|
|
1089
|
+
if ((0, _featureFlags().getFeatureFlag)('inlineConstOptimisationFix') && asset.meta.isConstantModule) {
|
|
1090
|
+
// Only set usedNamespace if there is an incoming dependency in the current bundle that uses '*'
|
|
1091
|
+
usedNamespace = this.bundleGraph.getIncomingDependencies(asset).some(dep => this.bundle.hasDependency(dep) &&
|
|
1092
|
+
// @ts-expect-error TS2345
|
|
1093
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'));
|
|
1094
|
+
} else {
|
|
1095
|
+
usedNamespace =
|
|
1096
|
+
// If the asset has * in its used symbols, we might need the exports namespace.
|
|
1097
|
+
// The one case where this isn't true is in ESM library entries, where the only
|
|
1098
|
+
// dependency on * is the entry dependency. In this case, we will use ESM exports
|
|
1099
|
+
// instead of the namespace object.
|
|
1100
|
+
// @ts-expect-error TS2345
|
|
1101
|
+
usedSymbols.has('*') && (this.bundle.env.outputFormat !== 'esmodule' || !this.bundle.env.isLibrary || asset !== this.bundle.getMainEntry() || this.bundleGraph.getIncomingDependencies(asset).some(dep => !dep.isEntry && this.bundle.hasDependency(dep) &&
|
|
1102
|
+
// @ts-expect-error TS2345
|
|
1103
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep)).has('*'))) ||
|
|
1104
|
+
// If a symbol is imported (used) from a CJS asset but isn't listed in the symbols,
|
|
1105
|
+
// we fallback on the namespace object.
|
|
1106
|
+
// @ts-expect-error TS2345
|
|
1107
|
+
asset.symbols.hasExportSymbol('*') && [...usedSymbols].some(s => !asset.symbols.hasExportSymbol(s)) ||
|
|
1108
|
+
// If the exports has this asset's namespace (e.g. ESM output from CJS input),
|
|
1109
|
+
// include the namespace object for the default export.
|
|
1110
|
+
this.exportedSymbols.has(`$${assetId}$exports`) ||
|
|
1111
|
+
// CommonJS library bundle entries always need a namespace.
|
|
1112
|
+
this.bundle.env.isLibrary && this.bundle.env.outputFormat === 'commonjs' && asset === this.bundle.getMainEntry();
|
|
1113
|
+
}
|
|
891
1114
|
|
|
892
1115
|
// If the asset doesn't have static exports, should wrap, the namespace is used,
|
|
893
1116
|
// or we need default interop, then we need to synthesize a namespace object for
|
|
@@ -905,6 +1128,7 @@ ${code}
|
|
|
905
1128
|
// Insert the __esModule interop flag for this module if it has a `default` export
|
|
906
1129
|
// and the namespace symbol is used.
|
|
907
1130
|
// TODO: only if required by CJS?
|
|
1131
|
+
// @ts-expect-error TS2345
|
|
908
1132
|
if (asset.symbols.hasExportSymbol('default') && usedSymbols.has('*')) {
|
|
909
1133
|
prepend += `\n$parcel$defineInteropFlag($${assetId}$exports);\n`;
|
|
910
1134
|
prependLineCount += 2;
|
|
@@ -923,6 +1147,7 @@ ${code}
|
|
|
923
1147
|
for (let [imported, {
|
|
924
1148
|
local
|
|
925
1149
|
}] of dep.symbols) {
|
|
1150
|
+
// @ts-expect-error TS2367
|
|
926
1151
|
if (imported === '*' && local === '*') {
|
|
927
1152
|
if (!resolved) {
|
|
928
1153
|
// Re-exporting an external module. This should have already been handled in buildReplacements.
|
|
@@ -935,20 +1160,29 @@ ${code}
|
|
|
935
1160
|
// If the resolved asset has an exports object, use the $parcel$exportWildcard helper
|
|
936
1161
|
// to re-export all symbols. Otherwise, if there's no namespace object available, add
|
|
937
1162
|
// $parcel$export calls for each used symbol of the dependency.
|
|
938
|
-
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1163
|
+
if (isWrapped || resolved.meta.staticExports === false ||
|
|
1164
|
+
// @ts-expect-error TS2345
|
|
1165
|
+
(0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(resolved)).has('*') ||
|
|
939
1166
|
// an empty asset
|
|
940
|
-
!resolved.meta.hasCJSExports &&
|
|
1167
|
+
!resolved.meta.hasCJSExports &&
|
|
1168
|
+
// @ts-expect-error TS2345
|
|
1169
|
+
resolved.symbols.hasExportSymbol('*')) {
|
|
941
1170
|
let obj = this.getSymbolResolution(asset, resolved, '*', dep, replacements);
|
|
942
1171
|
append += `$parcel$exportWildcard($${assetId}$exports, ${obj});\n`;
|
|
943
1172
|
this.usedHelpers.add('$parcel$exportWildcard');
|
|
944
1173
|
} else {
|
|
945
1174
|
for (let symbol of (0, _nullthrows().default)(this.bundleGraph.getUsedSymbols(dep))) {
|
|
946
|
-
if (
|
|
1175
|
+
if (
|
|
1176
|
+
// @ts-expect-error TS2367
|
|
1177
|
+
symbol === 'default' ||
|
|
947
1178
|
// `export * as ...` does not include the default export
|
|
1179
|
+
// @ts-expect-error TS2367
|
|
948
1180
|
symbol === '__esModule') {
|
|
949
1181
|
continue;
|
|
950
1182
|
}
|
|
951
|
-
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1183
|
+
let resolvedSymbol = this.getSymbolResolution(asset, resolved,
|
|
1184
|
+
// @ts-expect-error TS2345
|
|
1185
|
+
symbol, undefined, replacements);
|
|
952
1186
|
let get = this.buildFunctionExpression([], resolvedSymbol);
|
|
953
1187
|
let set = asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolvedSymbol} = v`) : '';
|
|
954
1188
|
prepend += `$parcel$export($${assetId}$exports, ${JSON.stringify(symbol)}, ${get}${set});\n`;
|
|
@@ -965,6 +1199,7 @@ ${code}
|
|
|
965
1199
|
// re-exported symbols rather than only symbols declared in this asset.
|
|
966
1200
|
let incomingDeps = this.bundleGraph.getIncomingDependencies(asset);
|
|
967
1201
|
let usedExports = [...asset.symbols.exportSymbols()].filter(symbol => {
|
|
1202
|
+
// @ts-expect-error TS2367
|
|
968
1203
|
if (symbol === '*') {
|
|
969
1204
|
return false;
|
|
970
1205
|
}
|
|
@@ -979,6 +1214,8 @@ ${code}
|
|
|
979
1214
|
|
|
980
1215
|
// No used symbols available for the asset, make sure we keep all of them
|
|
981
1216
|
if (!symbols) return false;
|
|
1217
|
+
|
|
1218
|
+
// @ts-expect-error TS2345
|
|
982
1219
|
return !symbols.has(symbol) && !symbols.has('*');
|
|
983
1220
|
});
|
|
984
1221
|
return !unused;
|
|
@@ -990,7 +1227,9 @@ ${code}
|
|
|
990
1227
|
// additional assignments after each mutation of the original binding.
|
|
991
1228
|
prepend += `\n${usedExports.map(exp => {
|
|
992
1229
|
var _asset$symbols$get2;
|
|
993
|
-
let resolved = this.getSymbolResolution(asset, asset,
|
|
1230
|
+
let resolved = this.getSymbolResolution(asset, asset,
|
|
1231
|
+
// @ts-expect-error TS2345
|
|
1232
|
+
exp, undefined, replacements);
|
|
994
1233
|
let get = this.buildFunctionExpression([], resolved);
|
|
995
1234
|
let isEsmExport = !!((_asset$symbols$get2 = asset.symbols.get(exp)) !== null && _asset$symbols$get2 !== void 0 && (_asset$symbols$get2 = _asset$symbols$get2.meta) !== null && _asset$symbols$get2 !== void 0 && _asset$symbols$get2.isEsm);
|
|
996
1235
|
let set = !isEsmExport && asset.meta.hasCJSExports ? ', ' + this.buildFunctionExpression(['v'], `${resolved} = v`) : '';
|
|
@@ -1028,8 +1267,10 @@ ${code}
|
|
|
1028
1267
|
this.usedHelpers.add('$parcel$global');
|
|
1029
1268
|
}
|
|
1030
1269
|
for (let helper of this.usedHelpers) {
|
|
1270
|
+
// @ts-expect-error TS7053
|
|
1031
1271
|
let currentHelper = _helpers.helpers[helper];
|
|
1032
1272
|
if (typeof currentHelper === 'function') {
|
|
1273
|
+
// @ts-expect-error TS7053
|
|
1033
1274
|
currentHelper = _helpers.helpers[helper](this.bundle.env);
|
|
1034
1275
|
}
|
|
1035
1276
|
res += currentHelper;
|
|
@@ -1041,11 +1282,11 @@ ${code}
|
|
|
1041
1282
|
// Add the prelude if this is potentially the first JS bundle to load in a
|
|
1042
1283
|
// particular context (e.g. entry scripts in HTML, workers, etc.).
|
|
1043
1284
|
let parentBundles = this.bundleGraph.getParentBundles(this.bundle);
|
|
1044
|
-
let mightBeFirstJS = parentBundles.length === 0 || parentBundles.some(b => b.type !== 'js') || this.bundleGraph.getBundleGroupsContainingBundle(this.bundle).some(g => this.bundleGraph.isEntryBundleGroup(g)) || this.bundle.env.isIsolated() || this.bundle.bundleBehavior === 'isolated' ||
|
|
1285
|
+
let mightBeFirstJS = parentBundles.length === 0 || parentBundles.some(b => b.type !== 'js') || this.bundleGraph.getBundleGroupsContainingBundle(this.bundle).some(g => this.bundleGraph.isEntryBundleGroup(g)) || this.bundle.env.isIsolated() || this.bundle.bundleBehavior === 'isolated' || this.bundle.bundleBehavior === 'inlineIsolated' ||
|
|
1045
1286
|
// Conditional deps may be loaded before entrypoints on the server
|
|
1046
1287
|
this.hasConditionalDependency();
|
|
1047
1288
|
if (mightBeFirstJS) {
|
|
1048
|
-
let preludeCode = (0, _helpers.
|
|
1289
|
+
let preludeCode = ((0, _featureFlags().getFeatureFlag)('useNewPrelude') ? _helpers.preludeNew : _helpers.preludeOld)(this.parcelRequireName);
|
|
1049
1290
|
res += preludeCode;
|
|
1050
1291
|
if (enableSourceMaps) {
|
|
1051
1292
|
lines += (0, _utils().countLines)(preludeCode) - 1;
|
|
@@ -1068,7 +1309,7 @@ ${code}
|
|
|
1068
1309
|
}
|
|
1069
1310
|
|
|
1070
1311
|
// Add importScripts for sibling bundles in workers.
|
|
1071
|
-
if (this.bundle.env.isWorker() || this.bundle.env.isWorklet()) {
|
|
1312
|
+
if (this.bundle.env.isWorker() || this.bundle.env.isTesseract() || this.bundle.env.isWorklet()) {
|
|
1072
1313
|
let importScripts = '';
|
|
1073
1314
|
let bundles = this.bundleGraph.getReferencedBundles(this.bundle);
|
|
1074
1315
|
for (let b of bundles) {
|
|
@@ -1085,7 +1326,11 @@ ${code}
|
|
|
1085
1326
|
return [res, lines];
|
|
1086
1327
|
}
|
|
1087
1328
|
needsDefaultInterop(asset) {
|
|
1088
|
-
if (
|
|
1329
|
+
if (
|
|
1330
|
+
// @ts-expect-error TS2345
|
|
1331
|
+
asset.symbols.hasExportSymbol('*') &&
|
|
1332
|
+
// @ts-expect-error TS2345
|
|
1333
|
+
!asset.symbols.hasExportSymbol('default')) {
|
|
1089
1334
|
return true;
|
|
1090
1335
|
}
|
|
1091
1336
|
return false;
|