@rollup/wasm-node 4.64.9 → 5.0.0-1
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/LICENSE.md +3 -304
- package/dist/ast-types.d.ts +896 -0
- package/dist/bin/rollup +21 -22
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +3 -3
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +1817 -1952
- package/dist/es/shared/parseAst.js +3567 -235
- package/dist/es/shared/watch.js +1765 -9600
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +3 -3
- package/dist/native.js +25 -7
- package/dist/parseAst.d.ts +13 -1
- package/dist/parseAst.js +8 -2
- package/dist/rollup.android-arm-eabi.node +0 -0
- package/dist/rollup.android-arm64.node +0 -0
- package/dist/rollup.d.ts +157 -105
- package/dist/rollup.darwin-arm64.node +0 -0
- package/dist/rollup.darwin-x64.node +0 -0
- package/dist/rollup.freebsd-arm64.node +0 -0
- package/dist/rollup.freebsd-x64.node +0 -0
- package/dist/rollup.js +2 -3
- package/dist/rollup.linux-arm-gnueabihf.node +0 -0
- package/dist/rollup.linux-arm-musleabihf.node +0 -0
- package/dist/rollup.linux-arm64-gnu.node +0 -0
- package/dist/rollup.linux-arm64-musl.node +0 -0
- package/dist/rollup.linux-loong64-gnu.node +0 -0
- package/dist/rollup.linux-loong64-musl.node +0 -0
- package/dist/rollup.linux-ppc64-gnu.node +0 -0
- package/dist/rollup.linux-ppc64-musl.node +0 -0
- package/dist/rollup.linux-riscv64-gnu.node +0 -0
- package/dist/rollup.linux-riscv64-musl.node +0 -0
- package/dist/rollup.linux-s390x-gnu.node +0 -0
- package/dist/rollup.linux-x64-gnu.node +0 -0
- package/dist/rollup.linux-x64-musl.node +0 -0
- package/dist/rollup.openbsd-x64.node +0 -0
- package/dist/rollup.openharmony-arm64.node +0 -0
- package/dist/rollup.win32-arm64-msvc.node +0 -0
- package/dist/rollup.win32-ia32-msvc.node +0 -0
- package/dist/rollup.win32-x64-gnu.node +0 -0
- package/dist/rollup.win32-x64-msvc.node +0 -0
- package/dist/shared/index.js +1775 -9597
- package/dist/shared/loadConfigFile.js +9 -9
- package/dist/shared/node-entry.js +2 -4
- package/dist/shared/parseAst.js +3595 -253
- package/dist/shared/rollup.js +1670 -1783
- package/dist/shared/watch-cli.js +10 -9
- package/dist/shared/watch.js +7 -11
- package/dist/wasm-node/bindings_wasm.js +31 -3
- package/dist/wasm-node/bindings_wasm_bg.wasm +0 -0
- package/package.json +19 -22
- package/dist/shared/fsevents-importer.js +0 -37
package/dist/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js
|
|
4
|
-
|
|
3
|
+
Rollup.js v5.0.0-1
|
|
4
|
+
Sun, 18 Oct 2026 06:06:25 GMT - commit ed75a6895d5bc62fdbff91b9d48e22e6e281e3bc
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
|
|
12
12
|
const parseAst_js = require('./parseAst.js');
|
|
13
13
|
const process$1 = require('node:process');
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const native_js = require('../native.js');
|
|
14
|
+
const sp = require('node:path');
|
|
15
|
+
const path = require('path');
|
|
17
16
|
const node_perf_hooks = require('node:perf_hooks');
|
|
17
|
+
const native_js = require('../native.js');
|
|
18
18
|
const promises = require('node:fs/promises');
|
|
19
19
|
|
|
20
20
|
function _interopNamespaceDefault(e) {
|
|
@@ -42,7 +42,7 @@ function _mergeNamespaces(n, m) {
|
|
|
42
42
|
|
|
43
43
|
const promises__namespace = /*#__PURE__*/_interopNamespaceDefault(promises);
|
|
44
44
|
|
|
45
|
-
var version = "
|
|
45
|
+
var version = "5.0.0-1";
|
|
46
46
|
const package_ = {
|
|
47
47
|
version: version};
|
|
48
48
|
|
|
@@ -409,10 +409,10 @@ function generateAssetFileName(name, names, source, originalFileName, originalFi
|
|
|
409
409
|
type: 'asset'
|
|
410
410
|
})
|
|
411
411
|
: outputOptions.assetFileNames, 'output.assetFileNames', {
|
|
412
|
-
ext: () =>
|
|
413
|
-
extname: () =>
|
|
412
|
+
ext: () => sp.extname(emittedName).slice(1),
|
|
413
|
+
extname: () => sp.extname(emittedName),
|
|
414
414
|
hash: size => sourceHash.slice(0, Math.min(Math.max(0, size || DEFAULT_HASH_SIZE), MAX_HASH_SIZE)),
|
|
415
|
-
name: () => emittedName.slice(0, Math.max(0, emittedName.length -
|
|
415
|
+
name: () => emittedName.slice(0, Math.max(0, emittedName.length - sp.extname(emittedName).length))
|
|
416
416
|
}), bundle);
|
|
417
417
|
}
|
|
418
418
|
function reserveFileNameInBundle(fileName, { bundle }, log) {
|
|
@@ -577,7 +577,9 @@ class FileEmitter {
|
|
|
577
577
|
code: prebuiltChunk.code,
|
|
578
578
|
dynamicImports: [],
|
|
579
579
|
exports: prebuiltChunk.exports || [],
|
|
580
|
+
facadeModuleAttributes: {},
|
|
580
581
|
facadeModuleId: null,
|
|
582
|
+
facadeModuleRawId: null,
|
|
581
583
|
fileName: prebuiltChunk.fileName,
|
|
582
584
|
implicitlyLoadedBefore: [],
|
|
583
585
|
importedBindings: {},
|
|
@@ -802,6 +804,48 @@ function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
|
802
804
|
};
|
|
803
805
|
}
|
|
804
806
|
|
|
807
|
+
const ATTRIBUTES_MARKER_LENGTH = '&attributes='.length;
|
|
808
|
+
function generateIdByRawIdAndAttributes(rawId, attributes) {
|
|
809
|
+
if (!attributes || Object.keys(attributes).length === 0) {
|
|
810
|
+
return rawId;
|
|
811
|
+
}
|
|
812
|
+
const sortedAttributes = Object.fromEntries(Object.entries(attributes).sort(([firstKey], [secondKey]) => firstKey < secondKey ? -1 : firstKey > secondKey ? 1 : 0));
|
|
813
|
+
return `${rawId}${rawId.includes('?') ? '&' : '?'}attributes=${encodeURIComponent(JSON.stringify(sortedAttributes))}`;
|
|
814
|
+
}
|
|
815
|
+
function normalizeModuleId(moduleId) {
|
|
816
|
+
if (typeof moduleId === 'object') {
|
|
817
|
+
return generateIdByRawIdAndAttributes(moduleId.rawId, moduleId.attributes);
|
|
818
|
+
}
|
|
819
|
+
return moduleId;
|
|
820
|
+
}
|
|
821
|
+
function normalizeModuleIdToObject(moduleId) {
|
|
822
|
+
if (typeof moduleId === 'object') {
|
|
823
|
+
return {
|
|
824
|
+
...moduleId,
|
|
825
|
+
id: generateIdByRawIdAndAttributes(moduleId.rawId, moduleId.attributes)
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
const { rawId, attributes } = getRawIdAndAttributes(moduleId);
|
|
829
|
+
return { attributes, id: moduleId, rawId };
|
|
830
|
+
}
|
|
831
|
+
function getRawIdAndAttributes(id) {
|
|
832
|
+
const attributesMarkerIndex = Math.max(id.lastIndexOf('?attributes='), id.lastIndexOf('&attributes='));
|
|
833
|
+
if (attributesMarkerIndex === -1) {
|
|
834
|
+
return { rawId: id };
|
|
835
|
+
}
|
|
836
|
+
try {
|
|
837
|
+
const rawId = id.slice(0, attributesMarkerIndex);
|
|
838
|
+
const attributes = JSON.parse(decodeURIComponent(id.slice(attributesMarkerIndex + ATTRIBUTES_MARKER_LENGTH)));
|
|
839
|
+
if (generateIdByRawIdAndAttributes(rawId, attributes) === id) {
|
|
840
|
+
return { attributes, rawId };
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
catch {
|
|
844
|
+
// fall through to treat the id as opaque
|
|
845
|
+
}
|
|
846
|
+
return { rawId: id };
|
|
847
|
+
}
|
|
848
|
+
|
|
805
849
|
const ANONYMOUS_PLUGIN_PREFIX = 'at position ';
|
|
806
850
|
const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = 'at output position ';
|
|
807
851
|
|
|
@@ -886,6 +930,20 @@ function getCacheForUncacheablePlugin(pluginName) {
|
|
|
886
930
|
}
|
|
887
931
|
|
|
888
932
|
const rollupVersion$2 = package_.version;
|
|
933
|
+
function getNormalizedImporter(importer, deprecatedImporterAttributes, pluginName, options) {
|
|
934
|
+
const normalizedImporter = normalizeModuleIdToObject(importer);
|
|
935
|
+
const hasDeprecatedImporterAttributes = !!deprecatedImporterAttributes && Object.keys(deprecatedImporterAttributes).length > 0;
|
|
936
|
+
if (typeof importer === 'string' &&
|
|
937
|
+
!normalizedImporter.attributes &&
|
|
938
|
+
hasDeprecatedImporterAttributes) {
|
|
939
|
+
parseAst_js.warnDeprecation('The "importerAttributes" option is deprecated. Provide a UniqueModuleId for "importer" instead.', parseAst_js.URL_THIS_RESOLVE, true, options, pluginName);
|
|
940
|
+
return normalizeModuleIdToObject({
|
|
941
|
+
attributes: deprecatedImporterAttributes,
|
|
942
|
+
rawId: importer
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
return normalizedImporter;
|
|
946
|
+
}
|
|
889
947
|
function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, existingPluginNames) {
|
|
890
948
|
const { logLevel, onLog } = options;
|
|
891
949
|
let cacheable = true;
|
|
@@ -927,16 +985,23 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
927
985
|
getWatchFiles: () => Object.keys(graph.watchFiles),
|
|
928
986
|
info: getLogHandler(parseAst_js.LOGLEVEL_INFO, 'PLUGIN_LOG', onLog, plugin.name, logLevel),
|
|
929
987
|
load(resolvedId) {
|
|
930
|
-
return graph.moduleLoader.preloadModule(
|
|
988
|
+
return graph.moduleLoader.preloadModule({
|
|
989
|
+
...resolvedId,
|
|
990
|
+
...normalizeModuleIdToObject(resolvedId.id)
|
|
991
|
+
});
|
|
931
992
|
},
|
|
932
993
|
meta: {
|
|
933
994
|
rollupVersion: rollupVersion$2,
|
|
934
995
|
watchMode: graph.watchMode
|
|
935
996
|
},
|
|
936
997
|
parse: parseAst_js.parseAst,
|
|
937
|
-
|
|
998
|
+
parseAndWalk: parseAst_js.parseAndWalk,
|
|
999
|
+
resolve(source, importer, { attributes, custom, importerAttributes: deprecatedImporterAttributes, isEntry, skipSelf } = parseAst_js.BLANK) {
|
|
938
1000
|
skipSelf ??= true;
|
|
939
|
-
|
|
1001
|
+
const { id: importerId, attributes: importerAttributes, rawId: importerRawId } = importer
|
|
1002
|
+
? getNormalizedImporter(importer, deprecatedImporterAttributes, plugin.name, options)
|
|
1003
|
+
: parseAst_js.BLANK;
|
|
1004
|
+
return graph.moduleLoader.resolveId(source, importerId, custom, isEntry, attributes || parseAst_js.EMPTY_OBJECT, importerAttributes || parseAst_js.EMPTY_OBJECT, importerRawId, skipSelf ? [{ importer: importerId, plugin, source }] : null);
|
|
940
1005
|
},
|
|
941
1006
|
setAssetSource: fileEmitter.setAssetSource,
|
|
942
1007
|
warn: getLogHandler(parseAst_js.LOGLEVEL_WARN, 'PLUGIN_WARNING', onLog, plugin.name, logLevel)
|
|
@@ -947,35 +1012,6 @@ function getDefaultExportFromCjs (x) {
|
|
|
947
1012
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
948
1013
|
}
|
|
949
1014
|
|
|
950
|
-
function getAugmentedNamespace(n) {
|
|
951
|
-
if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
|
|
952
|
-
var f = n.default;
|
|
953
|
-
if (typeof f == "function") {
|
|
954
|
-
var a = function a () {
|
|
955
|
-
var isInstance = false;
|
|
956
|
-
try {
|
|
957
|
-
isInstance = this instanceof a;
|
|
958
|
-
} catch (e) {}
|
|
959
|
-
if (isInstance) {
|
|
960
|
-
return Reflect.construct(f, arguments, this.constructor);
|
|
961
|
-
}
|
|
962
|
-
return f.apply(this, arguments);
|
|
963
|
-
};
|
|
964
|
-
a.prototype = f.prototype;
|
|
965
|
-
} else a = {};
|
|
966
|
-
Object.defineProperty(a, '__esModule', {value: true});
|
|
967
|
-
Object.keys(n).forEach(function (k) {
|
|
968
|
-
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
969
|
-
Object.defineProperty(a, k, d.get ? d : {
|
|
970
|
-
enumerable: true,
|
|
971
|
-
get: function () {
|
|
972
|
-
return n[k];
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
});
|
|
976
|
-
return a;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
1015
|
var utils = {};
|
|
980
1016
|
|
|
981
1017
|
var constants;
|
|
@@ -3490,7 +3526,7 @@ function getMatcherString$1(glob, cwd) {
|
|
|
3490
3526
|
if (glob.startsWith('**') || parseAst_js.isAbsolute(glob)) {
|
|
3491
3527
|
return parseAst_js.normalize(glob);
|
|
3492
3528
|
}
|
|
3493
|
-
const resolved =
|
|
3529
|
+
const resolved = sp.resolve(cwd, glob);
|
|
3494
3530
|
return parseAst_js.normalize(resolved);
|
|
3495
3531
|
}
|
|
3496
3532
|
function patternToIdFilter(pattern) {
|
|
@@ -4000,7 +4036,7 @@ function mergeInputOptions(config, overrides, plugins, log, onLog) {
|
|
|
4000
4036
|
const getExternal = (config, overrides) => {
|
|
4001
4037
|
const configExternal = config.external;
|
|
4002
4038
|
return typeof configExternal === 'function'
|
|
4003
|
-
? (source, importer, isResolved) => configExternal(source, importer, isResolved) || overrides.external.includes(source)
|
|
4039
|
+
? (source, importer, isResolved, options) => configExternal(source, importer, isResolved, options) || overrides.external.includes(source)
|
|
4004
4040
|
: [...ensureArray$1(configExternal), ...overrides.external];
|
|
4005
4041
|
};
|
|
4006
4042
|
const getObjectOption = (config, overrides, name, objectifyValue = objectifyOption) => {
|
|
@@ -6553,88 +6589,6 @@ class IncludedTopLevelPathTracker {
|
|
|
6553
6589
|
}
|
|
6554
6590
|
}
|
|
6555
6591
|
|
|
6556
|
-
/** @import { Node } from 'estree' */
|
|
6557
|
-
|
|
6558
|
-
/**
|
|
6559
|
-
* @param {Node} node
|
|
6560
|
-
* @param {Node} parent
|
|
6561
|
-
* @returns {boolean}
|
|
6562
|
-
*/
|
|
6563
|
-
function is_reference(node, parent) {
|
|
6564
|
-
if (node.type === 'MemberExpression') {
|
|
6565
|
-
return !node.computed && is_reference(node.object, node);
|
|
6566
|
-
}
|
|
6567
|
-
|
|
6568
|
-
if (node.type !== 'Identifier') return false;
|
|
6569
|
-
|
|
6570
|
-
switch (parent?.type) {
|
|
6571
|
-
// disregard `bar` in `foo.bar`
|
|
6572
|
-
case 'MemberExpression':
|
|
6573
|
-
return parent.computed || node === parent.object;
|
|
6574
|
-
|
|
6575
|
-
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
6576
|
-
case 'MethodDefinition':
|
|
6577
|
-
return parent.computed;
|
|
6578
|
-
|
|
6579
|
-
// disregard the `meta` in `import.meta`
|
|
6580
|
-
case 'MetaProperty':
|
|
6581
|
-
return parent.meta === node;
|
|
6582
|
-
|
|
6583
|
-
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
6584
|
-
case 'PropertyDefinition':
|
|
6585
|
-
return parent.computed || node === parent.value;
|
|
6586
|
-
|
|
6587
|
-
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
6588
|
-
case 'Property':
|
|
6589
|
-
return parent.computed || node === parent.value;
|
|
6590
|
-
|
|
6591
|
-
// disregard the `bar` in `export { foo as bar }` or
|
|
6592
|
-
// the foo in `import { foo as bar }`
|
|
6593
|
-
case 'ExportSpecifier':
|
|
6594
|
-
case 'ImportSpecifier':
|
|
6595
|
-
return node === parent.local;
|
|
6596
|
-
|
|
6597
|
-
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
6598
|
-
case 'LabeledStatement':
|
|
6599
|
-
case 'BreakStatement':
|
|
6600
|
-
case 'ContinueStatement':
|
|
6601
|
-
return false;
|
|
6602
|
-
|
|
6603
|
-
default:
|
|
6604
|
-
return true;
|
|
6605
|
-
}
|
|
6606
|
-
}
|
|
6607
|
-
|
|
6608
|
-
function createInclusionContext() {
|
|
6609
|
-
return {
|
|
6610
|
-
brokenFlow: false,
|
|
6611
|
-
hasBreak: false,
|
|
6612
|
-
hasContinue: false,
|
|
6613
|
-
includedCallArguments: new Set(),
|
|
6614
|
-
includedLabels: new Set()
|
|
6615
|
-
};
|
|
6616
|
-
}
|
|
6617
|
-
function createHasEffectsContext() {
|
|
6618
|
-
return {
|
|
6619
|
-
accessed: new EntityPathTracker(),
|
|
6620
|
-
assigned: new EntityPathTracker(),
|
|
6621
|
-
brokenFlow: false,
|
|
6622
|
-
called: new DiscriminatedPathTracker(),
|
|
6623
|
-
hasBreak: false,
|
|
6624
|
-
hasContinue: false,
|
|
6625
|
-
ignore: {
|
|
6626
|
-
breaks: false,
|
|
6627
|
-
continues: false,
|
|
6628
|
-
labels: new Set(),
|
|
6629
|
-
returnYield: false,
|
|
6630
|
-
this: false
|
|
6631
|
-
},
|
|
6632
|
-
includedLabels: new Set(),
|
|
6633
|
-
instantiated: new DiscriminatedPathTracker(),
|
|
6634
|
-
replacedVariableInits: new Map()
|
|
6635
|
-
};
|
|
6636
|
-
}
|
|
6637
|
-
|
|
6638
6592
|
function isFlagSet(flags, flag) {
|
|
6639
6593
|
return (flags & flag) !== 0;
|
|
6640
6594
|
}
|
|
@@ -6742,355 +6696,69 @@ const NODE_INTERACTION_UNKNOWN_CALL = {
|
|
|
6742
6696
|
withNew: false
|
|
6743
6697
|
};
|
|
6744
6698
|
|
|
6745
|
-
const
|
|
6746
|
-
|
|
6747
|
-
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
6699
|
+
const RESERVED_NAMES = new Set([
|
|
6700
|
+
'await',
|
|
6701
|
+
'break',
|
|
6702
|
+
'case',
|
|
6703
|
+
'catch',
|
|
6704
|
+
'class',
|
|
6705
|
+
'const',
|
|
6706
|
+
'continue',
|
|
6707
|
+
'debugger',
|
|
6708
|
+
'default',
|
|
6709
|
+
'delete',
|
|
6710
|
+
'do',
|
|
6711
|
+
'else',
|
|
6712
|
+
'enum',
|
|
6713
|
+
'eval',
|
|
6714
|
+
'export',
|
|
6715
|
+
'extends',
|
|
6716
|
+
'false',
|
|
6717
|
+
'finally',
|
|
6718
|
+
'for',
|
|
6719
|
+
'function',
|
|
6720
|
+
'if',
|
|
6721
|
+
'implements',
|
|
6722
|
+
'import',
|
|
6723
|
+
'in',
|
|
6724
|
+
'instanceof',
|
|
6725
|
+
'interface',
|
|
6726
|
+
'let',
|
|
6727
|
+
'NaN',
|
|
6728
|
+
'new',
|
|
6729
|
+
'null',
|
|
6730
|
+
'package',
|
|
6731
|
+
'private',
|
|
6732
|
+
'protected',
|
|
6733
|
+
'public',
|
|
6734
|
+
'return',
|
|
6735
|
+
'static',
|
|
6736
|
+
'super',
|
|
6737
|
+
'switch',
|
|
6738
|
+
'this',
|
|
6739
|
+
'throw',
|
|
6740
|
+
'true',
|
|
6741
|
+
'try',
|
|
6742
|
+
'typeof',
|
|
6743
|
+
'undefined',
|
|
6744
|
+
'var',
|
|
6745
|
+
'void',
|
|
6746
|
+
'while',
|
|
6747
|
+
'with',
|
|
6748
|
+
'yield'
|
|
6749
|
+
]);
|
|
6757
6750
|
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
this.isTargetOfAssignment = true;
|
|
6764
|
-
}
|
|
6765
|
-
constructor(name) {
|
|
6766
|
-
super();
|
|
6767
|
-
this.name = name;
|
|
6768
|
-
this.alwaysRendered = false;
|
|
6769
|
-
this.forbiddenNames = null;
|
|
6770
|
-
this.globalName = null;
|
|
6771
|
-
this.initReached = false;
|
|
6772
|
-
this.isId = false;
|
|
6773
|
-
this.kind = null;
|
|
6774
|
-
this.renderBaseName = null;
|
|
6775
|
-
this.renderName = null;
|
|
6776
|
-
this.isReassigned = false;
|
|
6777
|
-
// Unlike isReassigned, set eagerly during binding for every assignment,
|
|
6778
|
-
// including ones that are never included
|
|
6779
|
-
this.isTargetOfAssignment = false;
|
|
6780
|
-
this.onlyFunctionCallUsed = true;
|
|
6781
|
-
}
|
|
6782
|
-
/**
|
|
6783
|
-
* Binds identifiers that reference this variable to this variable.
|
|
6784
|
-
* Necessary to be able to change variable names.
|
|
6785
|
-
*/
|
|
6786
|
-
addReference(_identifier) { }
|
|
6787
|
-
/**
|
|
6788
|
-
* Check if the identifier variable is only used as function call
|
|
6789
|
-
* @returns true if the variable is only used as function call
|
|
6790
|
-
*/
|
|
6791
|
-
getOnlyFunctionCallUsed() {
|
|
6792
|
-
return this.onlyFunctionCallUsed;
|
|
6793
|
-
}
|
|
6794
|
-
/**
|
|
6795
|
-
* Collect the places where the identifier variable is used
|
|
6796
|
-
* @param usedPlace Where the variable is used
|
|
6797
|
-
*/
|
|
6798
|
-
addUsedPlace(usedPlace) {
|
|
6799
|
-
const isFunctionCall = usedPlace.parent.type === parseAst_js.CallExpression &&
|
|
6800
|
-
usedPlace.parent.callee === usedPlace;
|
|
6801
|
-
if (!isFunctionCall && usedPlace.parent.type !== parseAst_js.ExportDefaultDeclaration) {
|
|
6802
|
-
this.onlyFunctionCallUsed = false;
|
|
6803
|
-
}
|
|
6804
|
-
}
|
|
6805
|
-
/**
|
|
6806
|
-
* Prevent this variable from being renamed to this name to avoid name
|
|
6807
|
-
* collisions
|
|
6808
|
-
*/
|
|
6809
|
-
forbidName(name) {
|
|
6810
|
-
(this.forbiddenNames ||= new Set()).add(name);
|
|
6811
|
-
}
|
|
6812
|
-
getBaseVariableName() {
|
|
6813
|
-
return (this.renderedLikeHoisted?.getBaseVariableName() ||
|
|
6814
|
-
this.renderBaseName ||
|
|
6815
|
-
this.renderName ||
|
|
6816
|
-
this.name);
|
|
6817
|
-
}
|
|
6818
|
-
getName(getPropertyAccess, useOriginalName) {
|
|
6819
|
-
if (this.globalName) {
|
|
6820
|
-
return this.globalName;
|
|
6821
|
-
}
|
|
6822
|
-
if (useOriginalName?.(this)) {
|
|
6823
|
-
return this.name;
|
|
6824
|
-
}
|
|
6825
|
-
if (this.renderedLikeHoisted) {
|
|
6826
|
-
return this.renderedLikeHoisted.getName(getPropertyAccess, useOriginalName);
|
|
6827
|
-
}
|
|
6828
|
-
const name = this.renderName || this.name;
|
|
6829
|
-
return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
|
|
6830
|
-
}
|
|
6831
|
-
hasEffectsOnInteractionAtPath(path, { type }, _context) {
|
|
6832
|
-
return type !== INTERACTION_ACCESSED || path.length > 0;
|
|
6833
|
-
}
|
|
6834
|
-
/**
|
|
6835
|
-
* Marks this variable as being part of the bundle, which is usually the case
|
|
6836
|
-
* when one of its identifiers becomes part of the bundle. Returns true if it
|
|
6837
|
-
* has not been included previously. Once a variable is included, it should
|
|
6838
|
-
* take care all its declarations are included.
|
|
6839
|
-
*/
|
|
6840
|
-
includePath(path, context) {
|
|
6841
|
-
this.included = true;
|
|
6842
|
-
this.renderedLikeHoisted?.includePath(path, context);
|
|
6843
|
-
}
|
|
6844
|
-
/**
|
|
6845
|
-
* Links the rendered name of this variable to another variable and includes
|
|
6846
|
-
* this variable if the other variable is included.
|
|
6847
|
-
*/
|
|
6848
|
-
renderLikeHoisted(variable) {
|
|
6849
|
-
this.renderedLikeHoisted = variable;
|
|
6850
|
-
}
|
|
6851
|
-
markCalledFromTryStatement() { }
|
|
6852
|
-
addReassignedValue(_value) { }
|
|
6853
|
-
setRenderNames(baseName, name) {
|
|
6854
|
-
this.renderBaseName = baseName;
|
|
6855
|
-
this.renderName = name;
|
|
6856
|
-
}
|
|
6857
|
-
}
|
|
6858
|
-
|
|
6859
|
-
/** Synthetic import name for source phase imports, similar to '*' for namespaces */
|
|
6860
|
-
const SOURCE_PHASE_IMPORT = '*source';
|
|
6861
|
-
class ExternalVariable extends Variable {
|
|
6862
|
-
constructor(module, name) {
|
|
6863
|
-
super(name);
|
|
6864
|
-
this.referenced = false;
|
|
6865
|
-
this.module = module;
|
|
6866
|
-
this.isNamespace = name === '*';
|
|
6867
|
-
this.isSourcePhase = name === SOURCE_PHASE_IMPORT;
|
|
6868
|
-
}
|
|
6869
|
-
addReference(identifier) {
|
|
6870
|
-
this.referenced = true;
|
|
6871
|
-
if (this.name === 'default' || this.name === '*') {
|
|
6872
|
-
this.module.suggestName(identifier.name);
|
|
6873
|
-
}
|
|
6874
|
-
}
|
|
6875
|
-
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
6876
|
-
return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
|
|
6877
|
-
}
|
|
6878
|
-
includePath(path, context) {
|
|
6879
|
-
super.includePath(path, context);
|
|
6880
|
-
this.module.used = true;
|
|
6881
|
-
}
|
|
6882
|
-
}
|
|
6883
|
-
|
|
6884
|
-
function cacheObjectGetters(object, getterProperties) {
|
|
6885
|
-
for (const property of getterProperties) {
|
|
6886
|
-
const propertyGetter = Object.getOwnPropertyDescriptor(object, property).get;
|
|
6887
|
-
Object.defineProperty(object, property, {
|
|
6888
|
-
get() {
|
|
6889
|
-
const value = propertyGetter.call(object);
|
|
6890
|
-
// This replaces the getter with a fixed value for subsequent calls
|
|
6891
|
-
Object.defineProperty(object, property, { value });
|
|
6892
|
-
return value;
|
|
6893
|
-
}
|
|
6894
|
-
});
|
|
6895
|
-
}
|
|
6896
|
-
}
|
|
6897
|
-
|
|
6898
|
-
const RESERVED_NAMES = new Set([
|
|
6899
|
-
'await',
|
|
6900
|
-
'break',
|
|
6901
|
-
'case',
|
|
6902
|
-
'catch',
|
|
6903
|
-
'class',
|
|
6904
|
-
'const',
|
|
6905
|
-
'continue',
|
|
6906
|
-
'debugger',
|
|
6907
|
-
'default',
|
|
6908
|
-
'delete',
|
|
6909
|
-
'do',
|
|
6910
|
-
'else',
|
|
6911
|
-
'enum',
|
|
6912
|
-
'eval',
|
|
6913
|
-
'export',
|
|
6914
|
-
'extends',
|
|
6915
|
-
'false',
|
|
6916
|
-
'finally',
|
|
6917
|
-
'for',
|
|
6918
|
-
'function',
|
|
6919
|
-
'if',
|
|
6920
|
-
'implements',
|
|
6921
|
-
'import',
|
|
6922
|
-
'in',
|
|
6923
|
-
'instanceof',
|
|
6924
|
-
'interface',
|
|
6925
|
-
'let',
|
|
6926
|
-
'NaN',
|
|
6927
|
-
'new',
|
|
6928
|
-
'null',
|
|
6929
|
-
'package',
|
|
6930
|
-
'private',
|
|
6931
|
-
'protected',
|
|
6932
|
-
'public',
|
|
6933
|
-
'return',
|
|
6934
|
-
'static',
|
|
6935
|
-
'super',
|
|
6936
|
-
'switch',
|
|
6937
|
-
'this',
|
|
6938
|
-
'throw',
|
|
6939
|
-
'true',
|
|
6940
|
-
'try',
|
|
6941
|
-
'typeof',
|
|
6942
|
-
'undefined',
|
|
6943
|
-
'var',
|
|
6944
|
-
'void',
|
|
6945
|
-
'while',
|
|
6946
|
-
'with',
|
|
6947
|
-
'yield'
|
|
6948
|
-
]);
|
|
6949
|
-
|
|
6950
|
-
const illegalCharacters = /[^\w$]/g;
|
|
6951
|
-
const illegalCharacter = /[^\w$]/;
|
|
6952
|
-
const startsWithDigit = (value) => /\d/.test(value[0]);
|
|
6953
|
-
const needsEscape = (value) => startsWithDigit(value) || RESERVED_NAMES.has(value) || value === 'arguments';
|
|
6954
|
-
function isLegal(value) {
|
|
6955
|
-
if (needsEscape(value)) {
|
|
6956
|
-
return false;
|
|
6957
|
-
}
|
|
6958
|
-
return !illegalCharacter.test(value);
|
|
6959
|
-
}
|
|
6960
|
-
function makeLegal(value) {
|
|
6961
|
-
value = value
|
|
6962
|
-
.replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
|
|
6963
|
-
.replace(illegalCharacters, '_');
|
|
6964
|
-
if (needsEscape(value))
|
|
6965
|
-
value = `_${value}`;
|
|
6966
|
-
return value || '_';
|
|
6967
|
-
}
|
|
6968
|
-
const VALID_IDENTIFIER_REGEXP = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
|
|
6969
|
-
const NUMBER_REGEXP = /^(?:0|[1-9]\d*)$/;
|
|
6970
|
-
function stringifyObjectKeyIfNeeded(key) {
|
|
6971
|
-
if (VALID_IDENTIFIER_REGEXP.test(key)) {
|
|
6972
|
-
return key === '__proto__' ? '["__proto__"]' : key;
|
|
6973
|
-
}
|
|
6974
|
-
if (NUMBER_REGEXP.test(key) && +key <= Number.MAX_SAFE_INTEGER) {
|
|
6975
|
-
return key;
|
|
6976
|
-
}
|
|
6977
|
-
return JSON.stringify(key);
|
|
6978
|
-
}
|
|
6979
|
-
function stringifyIdentifierIfNeeded(key) {
|
|
6980
|
-
if (VALID_IDENTIFIER_REGEXP.test(key)) {
|
|
6981
|
-
return key;
|
|
6982
|
-
}
|
|
6983
|
-
return JSON.stringify(key);
|
|
6984
|
-
}
|
|
6985
|
-
|
|
6986
|
-
class ExternalModule {
|
|
6987
|
-
constructor(options, id, moduleSideEffects, meta, renormalizeRenderPath, attributes) {
|
|
6988
|
-
this.options = options;
|
|
6989
|
-
this.id = id;
|
|
6990
|
-
this.renormalizeRenderPath = renormalizeRenderPath;
|
|
6991
|
-
this.dynamicImporters = [];
|
|
6992
|
-
this.execIndex = Infinity;
|
|
6993
|
-
this.exportedVariables = new Map();
|
|
6994
|
-
this.importers = [];
|
|
6995
|
-
this.reexported = false;
|
|
6996
|
-
this.used = false;
|
|
6997
|
-
this.declarations = new Map();
|
|
6998
|
-
this.importersByExportedName = new Map();
|
|
6999
|
-
this.mostCommonSuggestion = 0;
|
|
7000
|
-
this.nameSuggestions = new Map();
|
|
7001
|
-
this.suggestedVariableName = makeLegal(id.split(/[/\\]/).pop());
|
|
7002
|
-
const { importers, dynamicImporters } = this;
|
|
7003
|
-
this.info = {
|
|
7004
|
-
ast: null,
|
|
7005
|
-
attributes,
|
|
7006
|
-
code: null,
|
|
7007
|
-
dynamicallyImportedIdResolutions: parseAst_js.EMPTY_ARRAY,
|
|
7008
|
-
dynamicallyImportedIds: parseAst_js.EMPTY_ARRAY,
|
|
7009
|
-
get dynamicImporters() {
|
|
7010
|
-
return dynamicImporters.sort();
|
|
7011
|
-
},
|
|
7012
|
-
exportedBindings: null,
|
|
7013
|
-
exports: null,
|
|
7014
|
-
hasDefaultExport: null,
|
|
7015
|
-
id,
|
|
7016
|
-
implicitlyLoadedAfterOneOf: parseAst_js.EMPTY_ARRAY,
|
|
7017
|
-
implicitlyLoadedBefore: parseAst_js.EMPTY_ARRAY,
|
|
7018
|
-
importedIdResolutions: parseAst_js.EMPTY_ARRAY,
|
|
7019
|
-
importedIds: parseAst_js.EMPTY_ARRAY,
|
|
7020
|
-
get importers() {
|
|
7021
|
-
return importers.sort();
|
|
7022
|
-
},
|
|
7023
|
-
isEntry: false,
|
|
7024
|
-
isExternal: true,
|
|
7025
|
-
isIncluded: null,
|
|
7026
|
-
meta,
|
|
7027
|
-
moduleSideEffects,
|
|
7028
|
-
safeVariableNames: null,
|
|
7029
|
-
syntheticNamedExports: false
|
|
7030
|
-
};
|
|
7031
|
-
}
|
|
7032
|
-
cacheInfoGetters() {
|
|
7033
|
-
cacheObjectGetters(this.info, ['dynamicImporters', 'importers']);
|
|
7034
|
-
}
|
|
7035
|
-
getVariableForExportName(name, { importChain }) {
|
|
7036
|
-
const declaration = this.declarations.get(name);
|
|
7037
|
-
for (const module of importChain) {
|
|
7038
|
-
getOrCreate(this.importersByExportedName, name, getNewSet).add(module);
|
|
7039
|
-
}
|
|
7040
|
-
if (declaration)
|
|
7041
|
-
return [declaration];
|
|
7042
|
-
const externalVariable = new ExternalVariable(this, name);
|
|
7043
|
-
this.declarations.set(name, externalVariable);
|
|
7044
|
-
this.exportedVariables.set(externalVariable, name);
|
|
7045
|
-
return [externalVariable];
|
|
7046
|
-
}
|
|
7047
|
-
suggestName(name) {
|
|
7048
|
-
const value = (this.nameSuggestions.get(name) ?? 0) + 1;
|
|
7049
|
-
this.nameSuggestions.set(name, value);
|
|
7050
|
-
if (value > this.mostCommonSuggestion) {
|
|
7051
|
-
this.mostCommonSuggestion = value;
|
|
7052
|
-
this.suggestedVariableName = name;
|
|
7053
|
-
}
|
|
7054
|
-
}
|
|
7055
|
-
warnUnusedImports() {
|
|
7056
|
-
const unused = [...this.declarations]
|
|
7057
|
-
.filter(([name, declaration]) => name !== '*' && !declaration.included && !this.reexported && !declaration.referenced)
|
|
7058
|
-
.map(([name]) => name);
|
|
7059
|
-
if (unused.length === 0)
|
|
7060
|
-
return;
|
|
7061
|
-
const importersSet = new Set();
|
|
7062
|
-
for (const name of unused) {
|
|
7063
|
-
const importersOfName = this.importersByExportedName.get(name);
|
|
7064
|
-
for (const importer of this.importers) {
|
|
7065
|
-
if (!importersOfName?.has(importer))
|
|
7066
|
-
continue;
|
|
7067
|
-
importersSet.add(importer);
|
|
7068
|
-
}
|
|
7069
|
-
}
|
|
7070
|
-
const importersArray = [...importersSet];
|
|
7071
|
-
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logUnusedExternalImports(this.id, unused, importersArray));
|
|
7072
|
-
}
|
|
7073
|
-
}
|
|
7074
|
-
|
|
7075
|
-
function markModuleAndImpureDependenciesAsExecuted(baseModule) {
|
|
7076
|
-
baseModule.isExecuted = true;
|
|
7077
|
-
const modules = [baseModule];
|
|
7078
|
-
const visitedModules = new Set();
|
|
7079
|
-
for (const module of modules) {
|
|
7080
|
-
for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
|
|
7081
|
-
if (!(dependency instanceof ExternalModule) &&
|
|
7082
|
-
!dependency.isExecuted &&
|
|
7083
|
-
(dependency.info.moduleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
|
|
7084
|
-
!visitedModules.has(dependency.id)) {
|
|
7085
|
-
dependency.isExecuted = true;
|
|
7086
|
-
visitedModules.add(dependency.id);
|
|
7087
|
-
modules.push(dependency);
|
|
7088
|
-
}
|
|
7089
|
-
}
|
|
6751
|
+
function getSafeName(baseName, usedNames, forbiddenNames) {
|
|
6752
|
+
let safeName = baseName;
|
|
6753
|
+
let count = 1;
|
|
6754
|
+
while (usedNames.has(safeName) || RESERVED_NAMES.has(safeName) || forbiddenNames?.has(safeName)) {
|
|
6755
|
+
safeName = `${baseName}$${toBase64(count++)}`;
|
|
7090
6756
|
}
|
|
6757
|
+
usedNames.add(safeName);
|
|
6758
|
+
return safeName;
|
|
7091
6759
|
}
|
|
7092
6760
|
|
|
7093
|
-
// This file is generated by scripts/generate-child-node-keys.
|
|
6761
|
+
// This file is generated by scripts/generate-child-node-keys.ts.
|
|
7094
6762
|
// Do not edit this file directly.
|
|
7095
6763
|
const childNodeKeys = {
|
|
7096
6764
|
ArrayExpression: ['elements'],
|
|
@@ -7184,10 +6852,40 @@ const childNodeKeys = {
|
|
|
7184
6852
|
YieldExpression: ['argument']
|
|
7185
6853
|
};
|
|
7186
6854
|
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
6855
|
+
function createInclusionContext() {
|
|
6856
|
+
return {
|
|
6857
|
+
brokenFlow: false,
|
|
6858
|
+
hasBreak: false,
|
|
6859
|
+
hasContinue: false,
|
|
6860
|
+
includedCallArguments: new Set(),
|
|
6861
|
+
includedLabels: new Set()
|
|
6862
|
+
};
|
|
6863
|
+
}
|
|
6864
|
+
function createHasEffectsContext() {
|
|
6865
|
+
return {
|
|
6866
|
+
accessed: new EntityPathTracker(),
|
|
6867
|
+
assigned: new EntityPathTracker(),
|
|
6868
|
+
brokenFlow: false,
|
|
6869
|
+
called: new DiscriminatedPathTracker(),
|
|
6870
|
+
hasBreak: false,
|
|
6871
|
+
hasContinue: false,
|
|
6872
|
+
ignore: {
|
|
6873
|
+
breaks: false,
|
|
6874
|
+
continues: false,
|
|
6875
|
+
labels: new Set(),
|
|
6876
|
+
returnYield: false,
|
|
6877
|
+
this: false
|
|
6878
|
+
},
|
|
6879
|
+
includedLabels: new Set(),
|
|
6880
|
+
instantiated: new DiscriminatedPathTracker(),
|
|
6881
|
+
replacedVariableInits: new Map()
|
|
6882
|
+
};
|
|
6883
|
+
}
|
|
6884
|
+
|
|
6885
|
+
const INCLUDE_PARAMETERS = 'variables';
|
|
6886
|
+
const IS_SKIPPED_CHAIN = Symbol('IS_SKIPPED_CHAIN');
|
|
6887
|
+
class NodeBase extends ExpressionEntity {
|
|
6888
|
+
/**
|
|
7191
6889
|
* Nodes can apply custom deoptimizations once they become part of the
|
|
7192
6890
|
* executed code. To do this, they must initialize this as false, implement
|
|
7193
6891
|
* applyDeoptimizations and call this from include and hasEffects if they have
|
|
@@ -7298,44 +6996,6 @@ class NodeBase extends ExpressionEntity {
|
|
|
7298
6996
|
this.scope.context.magicString.addSourcemapLocation(this.start);
|
|
7299
6997
|
this.scope.context.magicString.addSourcemapLocation(this.end);
|
|
7300
6998
|
}
|
|
7301
|
-
parseNode(esTreeNode) {
|
|
7302
|
-
for (const [key, value] of Object.entries(esTreeNode)) {
|
|
7303
|
-
// Skip properties defined on the class already.
|
|
7304
|
-
// This way, we can override this function to add custom initialisation and then call super.parseNode
|
|
7305
|
-
// Note: this doesn't skip properties with defined getters/setters which we use to pack wrap booleans
|
|
7306
|
-
// in bitfields. Those are still assigned from the value in the esTreeNode.
|
|
7307
|
-
if (this.hasOwnProperty(key))
|
|
7308
|
-
continue;
|
|
7309
|
-
if (key.charCodeAt(0) === 95 /* _ */) {
|
|
7310
|
-
if (key === parseAst_js.ANNOTATION_KEY) {
|
|
7311
|
-
this.annotations = value;
|
|
7312
|
-
}
|
|
7313
|
-
else if (key === parseAst_js.INVALID_ANNOTATION_KEY) {
|
|
7314
|
-
this.invalidAnnotations = value;
|
|
7315
|
-
}
|
|
7316
|
-
}
|
|
7317
|
-
else if (typeof value !== 'object' || value === null) {
|
|
7318
|
-
this[key] = value;
|
|
7319
|
-
}
|
|
7320
|
-
else if (Array.isArray(value)) {
|
|
7321
|
-
this[key] = new Array(value.length);
|
|
7322
|
-
let index = 0;
|
|
7323
|
-
for (const child of value) {
|
|
7324
|
-
this[key][index++] =
|
|
7325
|
-
child === null
|
|
7326
|
-
? null
|
|
7327
|
-
: new (this.scope.context.getNodeConstructor(child.type))(this, this.scope).parseNode(child);
|
|
7328
|
-
}
|
|
7329
|
-
}
|
|
7330
|
-
else {
|
|
7331
|
-
this[key] = new (this.scope.context.getNodeConstructor(value.type))(this, this.scope).parseNode(value);
|
|
7332
|
-
}
|
|
7333
|
-
}
|
|
7334
|
-
// extend child keys for unknown node types
|
|
7335
|
-
childNodeKeys[esTreeNode.type] ||= createChildNodeKeysForNode(esTreeNode);
|
|
7336
|
-
this.initialise();
|
|
7337
|
-
return this;
|
|
7338
|
-
}
|
|
7339
6999
|
removeAnnotations(code) {
|
|
7340
7000
|
if (this.annotations) {
|
|
7341
7001
|
for (const annotation of this.annotations) {
|
|
@@ -7384,51 +7044,736 @@ class NodeBase extends ExpressionEntity {
|
|
|
7384
7044
|
value.deoptimizePath(UNKNOWN_PATH);
|
|
7385
7045
|
}
|
|
7386
7046
|
}
|
|
7387
|
-
this.scope.context.requestTreeshakingPass();
|
|
7047
|
+
this.scope.context.requestTreeshakingPass();
|
|
7048
|
+
}
|
|
7049
|
+
}
|
|
7050
|
+
function onlyIncludeSelf() {
|
|
7051
|
+
this.included = true;
|
|
7052
|
+
if (!this.deoptimized)
|
|
7053
|
+
this.applyDeoptimizations();
|
|
7054
|
+
}
|
|
7055
|
+
function onlyIncludeSelfNoDeoptimize() {
|
|
7056
|
+
this.included = true;
|
|
7057
|
+
}
|
|
7058
|
+
function doNotDeoptimize() {
|
|
7059
|
+
this.deoptimized = true;
|
|
7060
|
+
}
|
|
7061
|
+
|
|
7062
|
+
function isObjectExpressionNode(node) {
|
|
7063
|
+
return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
|
|
7064
|
+
}
|
|
7065
|
+
function isArrowFunctionExpressionNode(node) {
|
|
7066
|
+
return node instanceof NodeBase && node.type === parseAst_js.ArrowFunctionExpression;
|
|
7067
|
+
}
|
|
7068
|
+
function isFunctionExpressionNode(node) {
|
|
7069
|
+
return node instanceof NodeBase && node.type === parseAst_js.FunctionExpression;
|
|
7070
|
+
}
|
|
7071
|
+
function isIdentifierNode(node) {
|
|
7072
|
+
return node instanceof NodeBase && node.type === parseAst_js.Identifier;
|
|
7073
|
+
}
|
|
7074
|
+
|
|
7075
|
+
// To avoid infinite recursions
|
|
7076
|
+
const MAX_PATH_DEPTH = 6;
|
|
7077
|
+
// If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
|
|
7078
|
+
// most MAX_PATH_DEPTH long. The last element is always UnknownKey
|
|
7079
|
+
const limitConcatenatedPathDepth = (path1, path2) => {
|
|
7080
|
+
const { length: length1 } = path1;
|
|
7081
|
+
const { length: length2 } = path2;
|
|
7082
|
+
return length1 === 0
|
|
7083
|
+
? path2
|
|
7084
|
+
: length2 === 0
|
|
7085
|
+
? path1
|
|
7086
|
+
: length1 + length2 > MAX_PATH_DEPTH
|
|
7087
|
+
? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
|
|
7088
|
+
: [...path1, ...path2];
|
|
7089
|
+
};
|
|
7090
|
+
|
|
7091
|
+
class Variable extends ExpressionEntity {
|
|
7092
|
+
markReassigned() {
|
|
7093
|
+
this.isReassigned = true;
|
|
7094
|
+
}
|
|
7095
|
+
markTargetOfAssignment() {
|
|
7096
|
+
this.isTargetOfAssignment = true;
|
|
7097
|
+
}
|
|
7098
|
+
constructor(name) {
|
|
7099
|
+
super();
|
|
7100
|
+
this.name = name;
|
|
7101
|
+
this.alwaysRendered = false;
|
|
7102
|
+
this.forbiddenNames = null;
|
|
7103
|
+
this.globalName = null;
|
|
7104
|
+
this.initReached = false;
|
|
7105
|
+
this.isId = false;
|
|
7106
|
+
this.kind = null;
|
|
7107
|
+
this.renderBaseName = null;
|
|
7108
|
+
this.renderName = null;
|
|
7109
|
+
this.isReassigned = false;
|
|
7110
|
+
// Unlike isReassigned, set eagerly during binding for every assignment,
|
|
7111
|
+
// including ones that are never included
|
|
7112
|
+
this.isTargetOfAssignment = false;
|
|
7113
|
+
this.onlyFunctionCallUsed = true;
|
|
7114
|
+
}
|
|
7115
|
+
/**
|
|
7116
|
+
* Binds identifiers that reference this variable to this variable.
|
|
7117
|
+
* Necessary to be able to change variable names.
|
|
7118
|
+
*/
|
|
7119
|
+
addReference(_identifier) { }
|
|
7120
|
+
/**
|
|
7121
|
+
* Check if the identifier variable is only used as function call
|
|
7122
|
+
* @returns true if the variable is only used as function call
|
|
7123
|
+
*/
|
|
7124
|
+
getOnlyFunctionCallUsed() {
|
|
7125
|
+
return this.onlyFunctionCallUsed;
|
|
7126
|
+
}
|
|
7127
|
+
/**
|
|
7128
|
+
* Collect the places where the identifier variable is used
|
|
7129
|
+
* @param usedPlace Where the variable is used
|
|
7130
|
+
*/
|
|
7131
|
+
addUsedPlace(usedPlace) {
|
|
7132
|
+
const isFunctionCall = usedPlace.parent.type === parseAst_js.CallExpression && usedPlace.parent.callee === usedPlace;
|
|
7133
|
+
if (!isFunctionCall && usedPlace.parent.type !== parseAst_js.ExportDefaultDeclaration) {
|
|
7134
|
+
this.onlyFunctionCallUsed = false;
|
|
7135
|
+
}
|
|
7136
|
+
}
|
|
7137
|
+
/**
|
|
7138
|
+
* Prevent this variable from being renamed to this name to avoid name
|
|
7139
|
+
* collisions
|
|
7140
|
+
*/
|
|
7141
|
+
forbidName(name) {
|
|
7142
|
+
(this.forbiddenNames ||= new Set()).add(name);
|
|
7143
|
+
}
|
|
7144
|
+
getBaseVariableName() {
|
|
7145
|
+
return (this.renderedLikeHoisted?.getBaseVariableName() ||
|
|
7146
|
+
this.renderBaseName ||
|
|
7147
|
+
this.renderName ||
|
|
7148
|
+
this.name);
|
|
7149
|
+
}
|
|
7150
|
+
getName(getPropertyAccess, useOriginalName) {
|
|
7151
|
+
if (this.globalName) {
|
|
7152
|
+
return this.globalName;
|
|
7153
|
+
}
|
|
7154
|
+
if (useOriginalName?.(this)) {
|
|
7155
|
+
return this.name;
|
|
7156
|
+
}
|
|
7157
|
+
if (this.renderedLikeHoisted) {
|
|
7158
|
+
return this.renderedLikeHoisted.getName(getPropertyAccess, useOriginalName);
|
|
7159
|
+
}
|
|
7160
|
+
const name = this.renderName || this.name;
|
|
7161
|
+
return this.renderBaseName ? `${this.renderBaseName}${getPropertyAccess(name)}` : name;
|
|
7162
|
+
}
|
|
7163
|
+
hasEffectsOnInteractionAtPath(path, { type }, _context) {
|
|
7164
|
+
return type !== INTERACTION_ACCESSED || path.length > 0;
|
|
7165
|
+
}
|
|
7166
|
+
/**
|
|
7167
|
+
* Marks this variable as being part of the bundle, which is usually the case
|
|
7168
|
+
* when one of its identifiers becomes part of the bundle. Returns true if it
|
|
7169
|
+
* has not been included previously. Once a variable is included, it should
|
|
7170
|
+
* take care all its declarations are included.
|
|
7171
|
+
*/
|
|
7172
|
+
includePath(path, context) {
|
|
7173
|
+
this.included = true;
|
|
7174
|
+
this.renderedLikeHoisted?.includePath(path, context);
|
|
7175
|
+
}
|
|
7176
|
+
/**
|
|
7177
|
+
* Links the rendered name of this variable to another variable and includes
|
|
7178
|
+
* this variable if the other variable is included.
|
|
7179
|
+
*/
|
|
7180
|
+
renderLikeHoisted(variable) {
|
|
7181
|
+
this.renderedLikeHoisted = variable;
|
|
7182
|
+
}
|
|
7183
|
+
markCalledFromTryStatement() { }
|
|
7184
|
+
addReassignedValue(_value) { }
|
|
7185
|
+
setRenderNames(baseName, name) {
|
|
7186
|
+
this.renderBaseName = baseName;
|
|
7187
|
+
this.renderName = name;
|
|
7188
|
+
}
|
|
7189
|
+
}
|
|
7190
|
+
|
|
7191
|
+
class LocalVariable extends Variable {
|
|
7192
|
+
constructor(name, declarator, init,
|
|
7193
|
+
/** if this is non-empty, the actual init is this path of this.init */
|
|
7194
|
+
initPath, context, kind) {
|
|
7195
|
+
super(name);
|
|
7196
|
+
this.init = init;
|
|
7197
|
+
this.initPath = initPath;
|
|
7198
|
+
this.kind = kind;
|
|
7199
|
+
this.calledFromTryStatement = false;
|
|
7200
|
+
this.additionalInitializers = null;
|
|
7201
|
+
// A possibly incomplete list of functions assigned to this variable; only used
|
|
7202
|
+
// to retain call arguments of assigned try-catch helpers, never for value queries
|
|
7203
|
+
this.assignedFunctions = null;
|
|
7204
|
+
this.includedPathTracker = new IncludedFullPathTracker();
|
|
7205
|
+
this.expressionsToBeDeoptimized = [];
|
|
7206
|
+
this.declarations = declarator ? [declarator] : [];
|
|
7207
|
+
this.deoptimizationTracker = context.deoptimizationTracker;
|
|
7208
|
+
this.module = context.module;
|
|
7209
|
+
}
|
|
7210
|
+
addDeclaration(identifier, init) {
|
|
7211
|
+
this.declarations.push(identifier);
|
|
7212
|
+
this.markInitializersForDeoptimization().push(init);
|
|
7213
|
+
}
|
|
7214
|
+
consolidateInitializers() {
|
|
7215
|
+
if (this.additionalInitializers) {
|
|
7216
|
+
for (const initializer of this.additionalInitializers) {
|
|
7217
|
+
initializer.deoptimizePath(UNKNOWN_PATH);
|
|
7218
|
+
}
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
7222
|
+
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
7223
|
+
deoptimizeInteraction(interaction);
|
|
7224
|
+
return;
|
|
7225
|
+
}
|
|
7226
|
+
recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
7227
|
+
this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
|
|
7228
|
+
}, undefined);
|
|
7229
|
+
}
|
|
7230
|
+
deoptimizePath(path) {
|
|
7231
|
+
if (this.isReassigned ||
|
|
7232
|
+
this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
7233
|
+
return;
|
|
7234
|
+
}
|
|
7235
|
+
if (path.length === 0) {
|
|
7236
|
+
this.markReassigned();
|
|
7237
|
+
const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
|
|
7238
|
+
this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
|
|
7239
|
+
for (const expression of expressionsToBeDeoptimized) {
|
|
7240
|
+
expression.deoptimizeCache();
|
|
7241
|
+
}
|
|
7242
|
+
this.init.deoptimizePath([...this.initPath, UnknownKey]);
|
|
7243
|
+
}
|
|
7244
|
+
else {
|
|
7245
|
+
this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
|
|
7246
|
+
}
|
|
7247
|
+
}
|
|
7248
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
7249
|
+
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
7250
|
+
return UnknownValue;
|
|
7251
|
+
}
|
|
7252
|
+
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
7253
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
7254
|
+
return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
|
|
7255
|
+
}, UnknownValue);
|
|
7256
|
+
}
|
|
7257
|
+
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
7258
|
+
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
7259
|
+
return UNKNOWN_RETURN_EXPRESSION;
|
|
7260
|
+
}
|
|
7261
|
+
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
7262
|
+
this.expressionsToBeDeoptimized.push(origin);
|
|
7263
|
+
return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
|
|
7264
|
+
}, UNKNOWN_RETURN_EXPRESSION);
|
|
7265
|
+
}
|
|
7266
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
7267
|
+
if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
7268
|
+
return true;
|
|
7269
|
+
}
|
|
7270
|
+
switch (interaction.type) {
|
|
7271
|
+
case INTERACTION_ACCESSED: {
|
|
7272
|
+
if (this.isReassigned)
|
|
7273
|
+
return true;
|
|
7274
|
+
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
7275
|
+
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
7276
|
+
}
|
|
7277
|
+
case INTERACTION_ASSIGNED: {
|
|
7278
|
+
if (this.included)
|
|
7279
|
+
return true;
|
|
7280
|
+
if (path.length === 0)
|
|
7281
|
+
return false;
|
|
7282
|
+
// if (this.isReassigned || this.init.included) return true;
|
|
7283
|
+
if (this.isReassigned)
|
|
7284
|
+
return true;
|
|
7285
|
+
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
7286
|
+
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
7287
|
+
}
|
|
7288
|
+
case INTERACTION_CALLED: {
|
|
7289
|
+
if (this.isReassigned)
|
|
7290
|
+
return true;
|
|
7291
|
+
return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
|
|
7292
|
+
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
7293
|
+
}
|
|
7294
|
+
}
|
|
7295
|
+
}
|
|
7296
|
+
includePath(path, context) {
|
|
7297
|
+
if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
|
|
7298
|
+
this.module.scope.context.requestTreeshakingPass();
|
|
7299
|
+
if (!this.included) {
|
|
7300
|
+
// This will reduce the number of tree-shaking passes by eagerly
|
|
7301
|
+
// including inits. By pushing this here instead of directly including
|
|
7302
|
+
// we avoid deep call stacks.
|
|
7303
|
+
this.module.scope.context.newlyIncludedVariableInits.add(this.init);
|
|
7304
|
+
}
|
|
7305
|
+
super.includePath(path, context);
|
|
7306
|
+
for (const declaration of this.declarations) {
|
|
7307
|
+
// If node is a default export, it can save a tree-shaking run to include the full declaration now
|
|
7308
|
+
if (!declaration.included)
|
|
7309
|
+
declaration.include(context, false);
|
|
7310
|
+
let node = declaration.parent;
|
|
7311
|
+
while (!node.included) {
|
|
7312
|
+
// We do not want to properly include parents in case they are part of a dead branch
|
|
7313
|
+
// in which case .include() might pull in more dead code
|
|
7314
|
+
node.includeNode(context);
|
|
7315
|
+
if (node.type === parseAst_js.Program)
|
|
7316
|
+
break;
|
|
7317
|
+
node = node.parent;
|
|
7318
|
+
}
|
|
7319
|
+
}
|
|
7320
|
+
// We need to make sure we include the correct path of the init
|
|
7321
|
+
if (path.length > 0) {
|
|
7322
|
+
this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
|
|
7323
|
+
this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
|
|
7324
|
+
}
|
|
7325
|
+
}
|
|
7326
|
+
}
|
|
7327
|
+
includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
|
|
7328
|
+
if (this.isReassigned) {
|
|
7329
|
+
// The value may still be one of the assigned functions, whose try-catch
|
|
7330
|
+
// helpers need their call arguments retained
|
|
7331
|
+
includeInteraction(interaction, context);
|
|
7332
|
+
if (path.length === 0) {
|
|
7333
|
+
this.includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context);
|
|
7334
|
+
}
|
|
7335
|
+
return;
|
|
7336
|
+
}
|
|
7337
|
+
if (context.includedCallArguments.has(this.init) ||
|
|
7338
|
+
path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
7339
|
+
includeInteraction(interaction, context);
|
|
7340
|
+
return;
|
|
7341
|
+
}
|
|
7342
|
+
context.includedCallArguments.add(this.init);
|
|
7343
|
+
this.init.includeCallArgumentsWhenCalledAtPath([...this.initPath, ...path], interaction, context);
|
|
7344
|
+
context.includedCallArguments.delete(this.init);
|
|
7345
|
+
}
|
|
7346
|
+
includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context) {
|
|
7347
|
+
if (this.initPath.length === 0) {
|
|
7348
|
+
this.includeCallArgumentsOfTryCatchHelper(this.init, interaction, context);
|
|
7349
|
+
}
|
|
7350
|
+
for (const assignedFunction of this.assignedFunctions ?? parseAst_js.EMPTY_ARRAY) {
|
|
7351
|
+
this.includeCallArgumentsOfTryCatchHelper(assignedFunction, interaction, context);
|
|
7352
|
+
}
|
|
7353
|
+
}
|
|
7354
|
+
includeCallArgumentsOfTryCatchHelper(value, interaction, context) {
|
|
7355
|
+
if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
|
|
7356
|
+
if (value.scope.hasParameterCalledFromTryStatement()) {
|
|
7357
|
+
value.scope.includeCallArguments(interaction, context);
|
|
7358
|
+
}
|
|
7359
|
+
}
|
|
7360
|
+
}
|
|
7361
|
+
addReassignedValue(value) {
|
|
7362
|
+
if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
|
|
7363
|
+
(this.assignedFunctions ??= []).push(value);
|
|
7364
|
+
}
|
|
7365
|
+
}
|
|
7366
|
+
markCalledFromTryStatement() {
|
|
7367
|
+
this.calledFromTryStatement = true;
|
|
7368
|
+
}
|
|
7369
|
+
markInitializersForDeoptimization() {
|
|
7370
|
+
if (this.additionalInitializers === null) {
|
|
7371
|
+
this.additionalInitializers = [this.init];
|
|
7372
|
+
this.init = UNKNOWN_EXPRESSION;
|
|
7373
|
+
this.markReassigned();
|
|
7374
|
+
}
|
|
7375
|
+
return this.additionalInitializers;
|
|
7376
|
+
}
|
|
7377
|
+
}
|
|
7378
|
+
|
|
7379
|
+
class Scope {
|
|
7380
|
+
constructor() {
|
|
7381
|
+
this.children = [];
|
|
7382
|
+
this.variables = new Map();
|
|
7383
|
+
}
|
|
7384
|
+
/*
|
|
7385
|
+
Redeclaration rules:
|
|
7386
|
+
- var can redeclare var
|
|
7387
|
+
- in function scopes, function and var can redeclare function and var
|
|
7388
|
+
- var is hoisted across scopes, function remains in the scope it is declared
|
|
7389
|
+
- var and function can redeclare function parameters, but parameters cannot redeclare parameters
|
|
7390
|
+
- function cannot redeclare catch scope parameters
|
|
7391
|
+
- var can redeclare catch scope parameters in a way
|
|
7392
|
+
- if the parameter is an identifier and not a pattern
|
|
7393
|
+
- then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
|
|
7394
|
+
- const, let, class, and function except in the cases above cannot redeclare anything
|
|
7395
|
+
*/
|
|
7396
|
+
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
7397
|
+
const name = identifier.name;
|
|
7398
|
+
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
7399
|
+
if (existingVariable) {
|
|
7400
|
+
if (kind === 'var' && existingVariable.kind === 'var') {
|
|
7401
|
+
existingVariable.addDeclaration(identifier, init);
|
|
7402
|
+
return existingVariable;
|
|
7403
|
+
}
|
|
7404
|
+
context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
7405
|
+
}
|
|
7406
|
+
const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
|
|
7407
|
+
this.variables.set(name, newVariable);
|
|
7408
|
+
return newVariable;
|
|
7409
|
+
}
|
|
7410
|
+
addHoistedVariable(name, variable) {
|
|
7411
|
+
(this.hoistedVariables ||= new Map()).set(name, variable);
|
|
7412
|
+
}
|
|
7413
|
+
contains(name) {
|
|
7414
|
+
return this.variables.has(name);
|
|
7415
|
+
}
|
|
7416
|
+
findVariable(_name) {
|
|
7417
|
+
/* istanbul ignore next */
|
|
7418
|
+
throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
|
|
7419
|
+
}
|
|
7420
|
+
}
|
|
7421
|
+
|
|
7422
|
+
class ChildScope extends Scope {
|
|
7423
|
+
constructor(parent, context) {
|
|
7424
|
+
super();
|
|
7425
|
+
this.parent = parent;
|
|
7426
|
+
this.context = context;
|
|
7427
|
+
this.accessedOutsideVariables = new Map();
|
|
7428
|
+
parent.children.push(this);
|
|
7429
|
+
}
|
|
7430
|
+
addAccessedDynamicImport(importExpression) {
|
|
7431
|
+
(this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
|
|
7432
|
+
if (this.parent instanceof ChildScope) {
|
|
7433
|
+
this.parent.addAccessedDynamicImport(importExpression);
|
|
7434
|
+
}
|
|
7435
|
+
}
|
|
7436
|
+
addAccessedGlobals(globals, accessedGlobalsByScope) {
|
|
7437
|
+
const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
|
|
7438
|
+
for (const name of globals) {
|
|
7439
|
+
accessedGlobals.add(name);
|
|
7440
|
+
}
|
|
7441
|
+
accessedGlobalsByScope.set(this, accessedGlobals);
|
|
7442
|
+
if (this.parent instanceof ChildScope) {
|
|
7443
|
+
this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7446
|
+
addNamespaceMemberAccess(name, variable) {
|
|
7447
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
7448
|
+
this.parent.addNamespaceMemberAccess(name, variable);
|
|
7449
|
+
}
|
|
7450
|
+
addReturnExpression(expression) {
|
|
7451
|
+
if (this.parent instanceof ChildScope) {
|
|
7452
|
+
this.parent.addReturnExpression(expression);
|
|
7453
|
+
}
|
|
7454
|
+
}
|
|
7455
|
+
addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
7456
|
+
for (const variable of this.accessedOutsideVariables.values()) {
|
|
7457
|
+
if (variable.included) {
|
|
7458
|
+
usedNames.add(variable.getBaseVariableName());
|
|
7459
|
+
// In system format, exported variables are assigned via `exports(name, value)`.
|
|
7460
|
+
// Any scope that references such a variable must treat `exports` as used so
|
|
7461
|
+
// that a nested binding of the same name does not shadow the system wrapper's
|
|
7462
|
+
// `exports` argument.
|
|
7463
|
+
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
7464
|
+
usedNames.add('exports');
|
|
7465
|
+
}
|
|
7466
|
+
}
|
|
7467
|
+
}
|
|
7468
|
+
const accessedGlobals = accessedGlobalsByScope.get(this);
|
|
7469
|
+
if (accessedGlobals) {
|
|
7470
|
+
for (const name of accessedGlobals) {
|
|
7471
|
+
usedNames.add(name);
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
}
|
|
7475
|
+
contains(name) {
|
|
7476
|
+
return this.variables.has(name) || this.parent.contains(name);
|
|
7477
|
+
}
|
|
7478
|
+
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
7479
|
+
const usedNames = new Set();
|
|
7480
|
+
this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
|
|
7481
|
+
if (this.accessedDynamicImports) {
|
|
7482
|
+
for (const importExpression of this.accessedDynamicImports) {
|
|
7483
|
+
if (importExpression.inlineNamespace) {
|
|
7484
|
+
usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
|
|
7485
|
+
}
|
|
7486
|
+
}
|
|
7487
|
+
}
|
|
7488
|
+
for (const [name, variable] of this.variables) {
|
|
7489
|
+
if (variable.included || variable.alwaysRendered) {
|
|
7490
|
+
variable.setRenderNames(null, getSafeName(name, usedNames, variable.forbiddenNames));
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7493
|
+
for (const scope of this.children) {
|
|
7494
|
+
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
7495
|
+
}
|
|
7496
|
+
}
|
|
7497
|
+
findLexicalBoundary() {
|
|
7498
|
+
return this.parent.findLexicalBoundary();
|
|
7499
|
+
}
|
|
7500
|
+
findGlobal(name) {
|
|
7501
|
+
const variable = this.parent.findVariable(name);
|
|
7502
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
7503
|
+
return variable;
|
|
7504
|
+
}
|
|
7505
|
+
findVariable(name) {
|
|
7506
|
+
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
7507
|
+
if (knownVariable) {
|
|
7508
|
+
return knownVariable;
|
|
7509
|
+
}
|
|
7510
|
+
const variable = this.parent.findVariable(name);
|
|
7511
|
+
this.accessedOutsideVariables.set(name, variable);
|
|
7512
|
+
return variable;
|
|
7513
|
+
}
|
|
7514
|
+
}
|
|
7515
|
+
|
|
7516
|
+
function checkEffectForNodes(nodes, context) {
|
|
7517
|
+
for (const node of nodes) {
|
|
7518
|
+
if (node.hasEffects(context)) {
|
|
7519
|
+
return true;
|
|
7520
|
+
}
|
|
7521
|
+
}
|
|
7522
|
+
return false;
|
|
7523
|
+
}
|
|
7524
|
+
|
|
7525
|
+
/** @import { Node } from 'estree' */
|
|
7526
|
+
|
|
7527
|
+
/**
|
|
7528
|
+
* @param {Node} node
|
|
7529
|
+
* @param {Node} parent
|
|
7530
|
+
* @returns {boolean}
|
|
7531
|
+
*/
|
|
7532
|
+
function is_reference(node, parent) {
|
|
7533
|
+
if (node.type === 'MemberExpression') {
|
|
7534
|
+
return !node.computed && is_reference(node.object, node);
|
|
7535
|
+
}
|
|
7536
|
+
|
|
7537
|
+
if (node.type !== 'Identifier') return false;
|
|
7538
|
+
|
|
7539
|
+
switch (parent?.type) {
|
|
7540
|
+
// disregard `bar` in `foo.bar`
|
|
7541
|
+
case 'MemberExpression':
|
|
7542
|
+
return parent.computed || node === parent.object;
|
|
7543
|
+
|
|
7544
|
+
// disregard the `foo` in `class {foo(){}}` but keep it in `class {[foo](){}}`
|
|
7545
|
+
case 'MethodDefinition':
|
|
7546
|
+
return parent.computed;
|
|
7547
|
+
|
|
7548
|
+
// disregard the `meta` in `import.meta`
|
|
7549
|
+
case 'MetaProperty':
|
|
7550
|
+
return parent.meta === node;
|
|
7551
|
+
|
|
7552
|
+
// disregard the `foo` in `class {foo=bar}` but keep it in `class {[foo]=bar}` and `class {bar=foo}`
|
|
7553
|
+
case 'PropertyDefinition':
|
|
7554
|
+
return parent.computed || node === parent.value;
|
|
7555
|
+
|
|
7556
|
+
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
|
|
7557
|
+
case 'Property':
|
|
7558
|
+
return parent.computed || node === parent.value;
|
|
7559
|
+
|
|
7560
|
+
// disregard the `bar` in `export { foo as bar }` or
|
|
7561
|
+
// the foo in `import { foo as bar }`
|
|
7562
|
+
case 'ExportSpecifier':
|
|
7563
|
+
case 'ImportSpecifier':
|
|
7564
|
+
return node === parent.local;
|
|
7565
|
+
|
|
7566
|
+
// disregard the `foo` in `foo: while (...) { ... break foo; ... continue foo;}`
|
|
7567
|
+
case 'LabeledStatement':
|
|
7568
|
+
case 'BreakStatement':
|
|
7569
|
+
case 'ContinueStatement':
|
|
7570
|
+
return false;
|
|
7571
|
+
|
|
7572
|
+
default:
|
|
7573
|
+
return true;
|
|
7574
|
+
}
|
|
7575
|
+
}
|
|
7576
|
+
|
|
7577
|
+
const PureFunctionKey = Symbol('PureFunction');
|
|
7578
|
+
const getPureFunctions = ({ treeshake }) => {
|
|
7579
|
+
const pureFunctions = Object.create(null);
|
|
7580
|
+
for (const functionName of treeshake ? treeshake.manualPureFunctions : []) {
|
|
7581
|
+
let currentFunctions = pureFunctions;
|
|
7582
|
+
for (const pathSegment of functionName.split('.')) {
|
|
7583
|
+
currentFunctions = currentFunctions[pathSegment] ||= Object.create(null);
|
|
7584
|
+
}
|
|
7585
|
+
currentFunctions[PureFunctionKey] = true;
|
|
7586
|
+
}
|
|
7587
|
+
return pureFunctions;
|
|
7588
|
+
};
|
|
7589
|
+
|
|
7590
|
+
/** Synthetic import name for source phase imports, similar to '*' for namespaces */
|
|
7591
|
+
const SOURCE_PHASE_IMPORT = '*source';
|
|
7592
|
+
class ExternalVariable extends Variable {
|
|
7593
|
+
constructor(module, name) {
|
|
7594
|
+
super(name);
|
|
7595
|
+
this.referenced = false;
|
|
7596
|
+
this.module = module;
|
|
7597
|
+
this.isNamespace = name === '*';
|
|
7598
|
+
this.isSourcePhase = name === SOURCE_PHASE_IMPORT;
|
|
7599
|
+
}
|
|
7600
|
+
addReference(identifier) {
|
|
7601
|
+
this.referenced = true;
|
|
7602
|
+
if (this.name === 'default' || this.name === '*') {
|
|
7603
|
+
this.module.suggestName(identifier.name);
|
|
7604
|
+
}
|
|
7605
|
+
}
|
|
7606
|
+
hasEffectsOnInteractionAtPath(path, { type }) {
|
|
7607
|
+
return type !== INTERACTION_ACCESSED || path.length > (this.isNamespace ? 1 : 0);
|
|
7608
|
+
}
|
|
7609
|
+
includePath(path, context) {
|
|
7610
|
+
super.includePath(path, context);
|
|
7611
|
+
this.module.used = true;
|
|
7612
|
+
}
|
|
7613
|
+
}
|
|
7614
|
+
|
|
7615
|
+
function cacheObjectGetters(object, getterProperties) {
|
|
7616
|
+
for (const property of getterProperties) {
|
|
7617
|
+
const propertyGetter = Object.getOwnPropertyDescriptor(object, property).get;
|
|
7618
|
+
Object.defineProperty(object, property, {
|
|
7619
|
+
get() {
|
|
7620
|
+
const value = propertyGetter.call(object);
|
|
7621
|
+
// This replaces the getter with a fixed value for subsequent calls
|
|
7622
|
+
Object.defineProperty(object, property, { value });
|
|
7623
|
+
return value;
|
|
7624
|
+
}
|
|
7625
|
+
});
|
|
7626
|
+
}
|
|
7627
|
+
}
|
|
7628
|
+
|
|
7629
|
+
const illegalCharacters = /[^\w$]/g;
|
|
7630
|
+
const illegalCharacter = /[^\w$]/;
|
|
7631
|
+
const startsWithDigit = (value) => /\d/.test(value[0]);
|
|
7632
|
+
const needsEscape = (value) => startsWithDigit(value) || RESERVED_NAMES.has(value) || value === 'arguments';
|
|
7633
|
+
function isLegal(value) {
|
|
7634
|
+
if (needsEscape(value)) {
|
|
7635
|
+
return false;
|
|
7636
|
+
}
|
|
7637
|
+
return !illegalCharacter.test(value);
|
|
7638
|
+
}
|
|
7639
|
+
function makeLegal(value) {
|
|
7640
|
+
value = value
|
|
7641
|
+
.replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
|
|
7642
|
+
.replace(illegalCharacters, '_');
|
|
7643
|
+
if (needsEscape(value))
|
|
7644
|
+
value = `_${value}`;
|
|
7645
|
+
return value || '_';
|
|
7646
|
+
}
|
|
7647
|
+
const VALID_IDENTIFIER_REGEXP = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
|
|
7648
|
+
const NUMBER_REGEXP = /^(?:0|[1-9]\d*)$/;
|
|
7649
|
+
function stringifyObjectKeyIfNeeded(key) {
|
|
7650
|
+
if (VALID_IDENTIFIER_REGEXP.test(key)) {
|
|
7651
|
+
return key === '__proto__' ? '["__proto__"]' : key;
|
|
7652
|
+
}
|
|
7653
|
+
if (NUMBER_REGEXP.test(key) && +key <= Number.MAX_SAFE_INTEGER) {
|
|
7654
|
+
return key;
|
|
7655
|
+
}
|
|
7656
|
+
return JSON.stringify(key);
|
|
7657
|
+
}
|
|
7658
|
+
function stringifyIdentifierIfNeeded(key) {
|
|
7659
|
+
if (VALID_IDENTIFIER_REGEXP.test(key)) {
|
|
7660
|
+
return key;
|
|
7661
|
+
}
|
|
7662
|
+
return JSON.stringify(key);
|
|
7663
|
+
}
|
|
7664
|
+
|
|
7665
|
+
class ExternalModule {
|
|
7666
|
+
constructor(options, id, rawId, moduleSideEffects, meta, renormalizeRenderPath, attributes) {
|
|
7667
|
+
this.options = options;
|
|
7668
|
+
this.id = id;
|
|
7669
|
+
this.rawId = rawId;
|
|
7670
|
+
this.renormalizeRenderPath = renormalizeRenderPath;
|
|
7671
|
+
this.dynamicImporters = [];
|
|
7672
|
+
this.execIndex = Infinity;
|
|
7673
|
+
this.exportedVariables = new Map();
|
|
7674
|
+
this.importers = [];
|
|
7675
|
+
this.reexported = false;
|
|
7676
|
+
this.used = false;
|
|
7677
|
+
this.declarations = new Map();
|
|
7678
|
+
this.importersByExportedName = new Map();
|
|
7679
|
+
this.mostCommonSuggestion = 0;
|
|
7680
|
+
this.nameSuggestions = new Map();
|
|
7681
|
+
const nameAttributes = new URLSearchParams(attributes);
|
|
7682
|
+
nameAttributes.sort();
|
|
7683
|
+
const attributesString = nameAttributes.toString();
|
|
7684
|
+
const attributesSuffix = attributesString ? `?${attributesString}` : '';
|
|
7685
|
+
this.suggestedVariableName = makeLegal(`${rawId.split(/[/\\]/).pop()}${attributesSuffix}`);
|
|
7686
|
+
const { importers, dynamicImporters } = this;
|
|
7687
|
+
this.info = {
|
|
7688
|
+
ast: null,
|
|
7689
|
+
attributes,
|
|
7690
|
+
code: null,
|
|
7691
|
+
dynamicallyImportedIdResolutions: parseAst_js.EMPTY_ARRAY,
|
|
7692
|
+
dynamicallyImportedIds: parseAst_js.EMPTY_ARRAY,
|
|
7693
|
+
get dynamicImporters() {
|
|
7694
|
+
return dynamicImporters.sort();
|
|
7695
|
+
},
|
|
7696
|
+
exportedBindings: null,
|
|
7697
|
+
exports: null,
|
|
7698
|
+
hasDefaultExport: null,
|
|
7699
|
+
id,
|
|
7700
|
+
implicitlyLoadedAfterOneOf: parseAst_js.EMPTY_ARRAY,
|
|
7701
|
+
implicitlyLoadedBefore: parseAst_js.EMPTY_ARRAY,
|
|
7702
|
+
importedIdResolutions: parseAst_js.EMPTY_ARRAY,
|
|
7703
|
+
importedIds: parseAst_js.EMPTY_ARRAY,
|
|
7704
|
+
get importers() {
|
|
7705
|
+
return importers.sort();
|
|
7706
|
+
},
|
|
7707
|
+
isEntry: false,
|
|
7708
|
+
isExternal: true,
|
|
7709
|
+
isIncluded: null,
|
|
7710
|
+
meta,
|
|
7711
|
+
moduleSideEffects,
|
|
7712
|
+
rawId,
|
|
7713
|
+
safeVariableNames: null,
|
|
7714
|
+
syntheticNamedExports: false
|
|
7715
|
+
};
|
|
7716
|
+
}
|
|
7717
|
+
cacheInfoGetters() {
|
|
7718
|
+
cacheObjectGetters(this.info, ['dynamicImporters', 'importers']);
|
|
7719
|
+
}
|
|
7720
|
+
getVariableForExportName(name, { importChain }) {
|
|
7721
|
+
const declaration = this.declarations.get(name);
|
|
7722
|
+
for (const module of importChain) {
|
|
7723
|
+
getOrCreate(this.importersByExportedName, name, getNewSet).add(module);
|
|
7724
|
+
}
|
|
7725
|
+
if (declaration)
|
|
7726
|
+
return [declaration];
|
|
7727
|
+
const externalVariable = new ExternalVariable(this, name);
|
|
7728
|
+
this.declarations.set(name, externalVariable);
|
|
7729
|
+
this.exportedVariables.set(externalVariable, name);
|
|
7730
|
+
return [externalVariable];
|
|
7731
|
+
}
|
|
7732
|
+
suggestName(name) {
|
|
7733
|
+
const value = (this.nameSuggestions.get(name) ?? 0) + 1;
|
|
7734
|
+
this.nameSuggestions.set(name, value);
|
|
7735
|
+
if (value > this.mostCommonSuggestion) {
|
|
7736
|
+
this.mostCommonSuggestion = value;
|
|
7737
|
+
this.suggestedVariableName = name;
|
|
7738
|
+
}
|
|
7739
|
+
}
|
|
7740
|
+
warnUnusedImports() {
|
|
7741
|
+
const unused = [...this.declarations]
|
|
7742
|
+
.filter(([name, declaration]) => name !== '*' && !declaration.included && !this.reexported && !declaration.referenced)
|
|
7743
|
+
.map(([name]) => name);
|
|
7744
|
+
if (unused.length === 0)
|
|
7745
|
+
return;
|
|
7746
|
+
const importersSet = new Set();
|
|
7747
|
+
for (const name of unused) {
|
|
7748
|
+
const importersOfName = this.importersByExportedName.get(name);
|
|
7749
|
+
for (const importer of this.importers) {
|
|
7750
|
+
if (!importersOfName?.has(importer))
|
|
7751
|
+
continue;
|
|
7752
|
+
importersSet.add(importer);
|
|
7753
|
+
}
|
|
7754
|
+
}
|
|
7755
|
+
const importersArray = [...importersSet];
|
|
7756
|
+
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logUnusedExternalImports(this.id, unused, importersArray));
|
|
7757
|
+
}
|
|
7758
|
+
}
|
|
7759
|
+
|
|
7760
|
+
function markModuleAndImpureDependenciesAsExecuted(baseModule) {
|
|
7761
|
+
baseModule.isExecuted = true;
|
|
7762
|
+
const modules = [baseModule];
|
|
7763
|
+
const visitedModules = new Set();
|
|
7764
|
+
for (const module of modules) {
|
|
7765
|
+
for (const dependency of [...module.dependencies, ...module.implicitlyLoadedBefore]) {
|
|
7766
|
+
if (!(dependency instanceof ExternalModule) &&
|
|
7767
|
+
!dependency.isExecuted &&
|
|
7768
|
+
(dependency.info.moduleSideEffects || module.implicitlyLoadedBefore.has(dependency)) &&
|
|
7769
|
+
!visitedModules.has(dependency.id)) {
|
|
7770
|
+
dependency.isExecuted = true;
|
|
7771
|
+
visitedModules.add(dependency.id);
|
|
7772
|
+
modules.push(dependency);
|
|
7773
|
+
}
|
|
7774
|
+
}
|
|
7388
7775
|
}
|
|
7389
7776
|
}
|
|
7390
|
-
function createChildNodeKeysForNode(esTreeNode) {
|
|
7391
|
-
return Object.keys(esTreeNode).filter(key => typeof esTreeNode[key] === 'object' && key.charCodeAt(0) !== 95 /* _ */);
|
|
7392
|
-
}
|
|
7393
|
-
function onlyIncludeSelf() {
|
|
7394
|
-
this.included = true;
|
|
7395
|
-
if (!this.deoptimized)
|
|
7396
|
-
this.applyDeoptimizations();
|
|
7397
|
-
}
|
|
7398
|
-
function onlyIncludeSelfNoDeoptimize() {
|
|
7399
|
-
this.included = true;
|
|
7400
|
-
}
|
|
7401
|
-
function doNotDeoptimize() {
|
|
7402
|
-
this.deoptimized = true;
|
|
7403
|
-
}
|
|
7404
|
-
|
|
7405
|
-
function isObjectExpressionNode(node) {
|
|
7406
|
-
return node instanceof NodeBase && node.type === parseAst_js.ObjectExpression;
|
|
7407
|
-
}
|
|
7408
|
-
function isPropertyNode(node) {
|
|
7409
|
-
return node instanceof NodeBase && node.type === parseAst_js.Property;
|
|
7410
|
-
}
|
|
7411
|
-
function isArrowFunctionExpressionNode(node) {
|
|
7412
|
-
return node instanceof NodeBase && node.type === parseAst_js.ArrowFunctionExpression;
|
|
7413
|
-
}
|
|
7414
|
-
function isFunctionExpressionNode(node) {
|
|
7415
|
-
return node instanceof NodeBase && node.type === parseAst_js.FunctionExpression;
|
|
7416
|
-
}
|
|
7417
|
-
function isCallExpressionNode(node) {
|
|
7418
|
-
return node instanceof NodeBase && node.type === parseAst_js.CallExpression;
|
|
7419
|
-
}
|
|
7420
|
-
function isMemberExpressionNode(node) {
|
|
7421
|
-
return node instanceof NodeBase && node.type === parseAst_js.MemberExpression;
|
|
7422
|
-
}
|
|
7423
|
-
function isAwaitExpressionNode(node) {
|
|
7424
|
-
return node instanceof NodeBase && node.type === parseAst_js.AwaitExpression;
|
|
7425
|
-
}
|
|
7426
|
-
function isIdentifierNode(node) {
|
|
7427
|
-
return node instanceof NodeBase && node.type === parseAst_js.Identifier;
|
|
7428
|
-
}
|
|
7429
|
-
function isExpressionStatementNode(node) {
|
|
7430
|
-
return node instanceof NodeBase && node.type === parseAst_js.ExpressionStatement;
|
|
7431
|
-
}
|
|
7432
7777
|
|
|
7433
7778
|
function assembleMemberDescriptions(memberDescriptions, inheritedDescriptions = null) {
|
|
7434
7779
|
return Object.create(inheritedDescriptions, memberDescriptions);
|
|
@@ -8711,7 +9056,7 @@ const knownGlobals = {
|
|
|
8711
9056
|
[ValueProperties]: {
|
|
8712
9057
|
deoptimizeArgumentsOnCall: ({ args: [, target, parameter] }) => {
|
|
8713
9058
|
if (isObjectExpressionNode(parameter)) {
|
|
8714
|
-
const hasSpreadElement = parameter.properties.some(property =>
|
|
9059
|
+
const hasSpreadElement = parameter.properties.some(property => property.type !== parseAst_js.Property);
|
|
8715
9060
|
if (!hasSpreadElement) {
|
|
8716
9061
|
for (const property of parameter.properties) {
|
|
8717
9062
|
property.deoptimizeArgumentsOnInteractionAtPath({
|
|
@@ -9447,248 +9792,44 @@ class GlobalVariable extends Variable {
|
|
|
9447
9792
|
// are also covered via other means, we keep them for completeness
|
|
9448
9793
|
case INTERACTION_ACCESSED:
|
|
9449
9794
|
case INTERACTION_ASSIGNED: {
|
|
9450
|
-
if (!getGlobalAtPath([this.name, ...path].slice(0, -1))) {
|
|
9451
|
-
super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9452
|
-
}
|
|
9453
|
-
return;
|
|
9454
|
-
}
|
|
9455
|
-
case INTERACTION_CALLED: {
|
|
9456
|
-
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9457
|
-
if (globalAtPath) {
|
|
9458
|
-
globalAtPath.deoptimizeArgumentsOnCall(interaction);
|
|
9459
|
-
}
|
|
9460
|
-
else {
|
|
9461
|
-
super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9462
|
-
}
|
|
9463
|
-
return;
|
|
9464
|
-
}
|
|
9465
|
-
}
|
|
9466
|
-
}
|
|
9467
|
-
getLiteralValueAtPath(path, _recursionTracker, _origin) {
|
|
9468
|
-
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9469
|
-
return globalAtPath ? globalAtPath.getLiteralValue() : UnknownValue;
|
|
9470
|
-
}
|
|
9471
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9472
|
-
switch (interaction.type) {
|
|
9473
|
-
case INTERACTION_ACCESSED: {
|
|
9474
|
-
if (path.length === 0) {
|
|
9475
|
-
// Technically, "undefined" is a global variable of sorts
|
|
9476
|
-
return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
|
|
9477
|
-
}
|
|
9478
|
-
return !getGlobalAtPath([this.name, ...path].slice(0, -1));
|
|
9479
|
-
}
|
|
9480
|
-
case INTERACTION_ASSIGNED: {
|
|
9481
|
-
return true;
|
|
9482
|
-
}
|
|
9483
|
-
case INTERACTION_CALLED: {
|
|
9484
|
-
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9485
|
-
return !globalAtPath || globalAtPath.hasEffectsWhenCalled(interaction, context);
|
|
9486
|
-
}
|
|
9487
|
-
}
|
|
9488
|
-
}
|
|
9489
|
-
}
|
|
9490
|
-
|
|
9491
|
-
// To avoid infinite recursions
|
|
9492
|
-
const MAX_PATH_DEPTH = 6;
|
|
9493
|
-
// If a path is longer than MAX_PATH_DEPTH, it is truncated so that it is at
|
|
9494
|
-
// most MAX_PATH_DEPTH long. The last element is always UnknownKey
|
|
9495
|
-
const limitConcatenatedPathDepth = (path1, path2) => {
|
|
9496
|
-
const { length: length1 } = path1;
|
|
9497
|
-
const { length: length2 } = path2;
|
|
9498
|
-
return length1 === 0
|
|
9499
|
-
? path2
|
|
9500
|
-
: length2 === 0
|
|
9501
|
-
? path1
|
|
9502
|
-
: length1 + length2 > MAX_PATH_DEPTH
|
|
9503
|
-
? [...path1, ...path2.slice(0, MAX_PATH_DEPTH - 1 - path1.length), 'UnknownKey']
|
|
9504
|
-
: [...path1, ...path2];
|
|
9505
|
-
};
|
|
9506
|
-
|
|
9507
|
-
class LocalVariable extends Variable {
|
|
9508
|
-
constructor(name, declarator, init,
|
|
9509
|
-
/** if this is non-empty, the actual init is this path of this.init */
|
|
9510
|
-
initPath, context, kind) {
|
|
9511
|
-
super(name);
|
|
9512
|
-
this.init = init;
|
|
9513
|
-
this.initPath = initPath;
|
|
9514
|
-
this.kind = kind;
|
|
9515
|
-
this.calledFromTryStatement = false;
|
|
9516
|
-
this.additionalInitializers = null;
|
|
9517
|
-
// A possibly incomplete list of functions assigned to this variable; only used
|
|
9518
|
-
// to retain call arguments of assigned try-catch helpers, never for value queries
|
|
9519
|
-
this.assignedFunctions = null;
|
|
9520
|
-
this.includedPathTracker = new IncludedFullPathTracker();
|
|
9521
|
-
this.expressionsToBeDeoptimized = [];
|
|
9522
|
-
this.declarations = declarator ? [declarator] : [];
|
|
9523
|
-
this.deoptimizationTracker = context.deoptimizationTracker;
|
|
9524
|
-
this.module = context.module;
|
|
9525
|
-
}
|
|
9526
|
-
addDeclaration(identifier, init) {
|
|
9527
|
-
this.declarations.push(identifier);
|
|
9528
|
-
this.markInitializersForDeoptimization().push(init);
|
|
9529
|
-
}
|
|
9530
|
-
consolidateInitializers() {
|
|
9531
|
-
if (this.additionalInitializers) {
|
|
9532
|
-
for (const initializer of this.additionalInitializers) {
|
|
9533
|
-
initializer.deoptimizePath(UNKNOWN_PATH);
|
|
9534
|
-
}
|
|
9535
|
-
}
|
|
9536
|
-
}
|
|
9537
|
-
deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker) {
|
|
9538
|
-
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
9539
|
-
deoptimizeInteraction(interaction);
|
|
9540
|
-
return;
|
|
9541
|
-
}
|
|
9542
|
-
recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
9543
|
-
this.init.deoptimizeArgumentsOnInteractionAtPath(interaction, [...this.initPath, ...path], recursionTracker);
|
|
9544
|
-
}, undefined);
|
|
9545
|
-
}
|
|
9546
|
-
deoptimizePath(path) {
|
|
9547
|
-
if (this.isReassigned ||
|
|
9548
|
-
this.deoptimizationTracker.trackEntityAtPathAndGetIfTracked(path, this)) {
|
|
9549
|
-
return;
|
|
9550
|
-
}
|
|
9551
|
-
if (path.length === 0) {
|
|
9552
|
-
this.markReassigned();
|
|
9553
|
-
const expressionsToBeDeoptimized = this.expressionsToBeDeoptimized;
|
|
9554
|
-
this.expressionsToBeDeoptimized = parseAst_js.EMPTY_ARRAY;
|
|
9555
|
-
for (const expression of expressionsToBeDeoptimized) {
|
|
9556
|
-
expression.deoptimizeCache();
|
|
9557
|
-
}
|
|
9558
|
-
this.init.deoptimizePath([...this.initPath, UnknownKey]);
|
|
9559
|
-
}
|
|
9560
|
-
else {
|
|
9561
|
-
this.init.deoptimizePath(limitConcatenatedPathDepth(this.initPath, path));
|
|
9562
|
-
}
|
|
9563
|
-
}
|
|
9564
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
9565
|
-
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
9566
|
-
return UnknownValue;
|
|
9567
|
-
}
|
|
9568
|
-
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
9569
|
-
this.expressionsToBeDeoptimized.push(origin);
|
|
9570
|
-
return this.init.getLiteralValueAtPath([...this.initPath, ...path], recursionTracker, origin);
|
|
9571
|
-
}, UnknownValue);
|
|
9572
|
-
}
|
|
9573
|
-
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
9574
|
-
if (this.isReassigned || path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
9575
|
-
return UNKNOWN_RETURN_EXPRESSION;
|
|
9576
|
-
}
|
|
9577
|
-
return recursionTracker.withTrackedEntityAtPath(path, this.init, () => {
|
|
9578
|
-
this.expressionsToBeDeoptimized.push(origin);
|
|
9579
|
-
return this.init.getReturnExpressionWhenCalledAtPath([...this.initPath, ...path], interaction, recursionTracker, origin);
|
|
9580
|
-
}, UNKNOWN_RETURN_EXPRESSION);
|
|
9581
|
-
}
|
|
9582
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9583
|
-
if (path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
9584
|
-
return true;
|
|
9585
|
-
}
|
|
9586
|
-
switch (interaction.type) {
|
|
9587
|
-
case INTERACTION_ACCESSED: {
|
|
9588
|
-
if (this.isReassigned)
|
|
9589
|
-
return true;
|
|
9590
|
-
return (!context.accessed.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9591
|
-
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
9592
|
-
}
|
|
9593
|
-
case INTERACTION_ASSIGNED: {
|
|
9594
|
-
if (this.included)
|
|
9595
|
-
return true;
|
|
9596
|
-
if (path.length === 0)
|
|
9597
|
-
return false;
|
|
9598
|
-
// if (this.isReassigned || this.init.included) return true;
|
|
9599
|
-
if (this.isReassigned)
|
|
9600
|
-
return true;
|
|
9601
|
-
return (!context.assigned.trackEntityAtPathAndGetIfTracked(path, this) &&
|
|
9602
|
-
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
9603
|
-
}
|
|
9604
|
-
case INTERACTION_CALLED: {
|
|
9605
|
-
if (this.isReassigned)
|
|
9606
|
-
return true;
|
|
9607
|
-
return (!(interaction.withNew ? context.instantiated : context.called).trackEntityAtPathAndGetIfTracked(path, interaction.args, this) &&
|
|
9608
|
-
this.init.hasEffectsOnInteractionAtPath([...this.initPath, ...path], interaction, context));
|
|
9609
|
-
}
|
|
9610
|
-
}
|
|
9611
|
-
}
|
|
9612
|
-
includePath(path, context) {
|
|
9613
|
-
if (!this.includedPathTracker.includePathAndGetIfIncluded(path)) {
|
|
9614
|
-
this.module.scope.context.requestTreeshakingPass();
|
|
9615
|
-
if (!this.included) {
|
|
9616
|
-
// This will reduce the number of tree-shaking passes by eagerly
|
|
9617
|
-
// including inits. By pushing this here instead of directly including
|
|
9618
|
-
// we avoid deep call stacks.
|
|
9619
|
-
this.module.scope.context.newlyIncludedVariableInits.add(this.init);
|
|
9620
|
-
}
|
|
9621
|
-
super.includePath(path, context);
|
|
9622
|
-
for (const declaration of this.declarations) {
|
|
9623
|
-
// If node is a default export, it can save a tree-shaking run to include the full declaration now
|
|
9624
|
-
if (!declaration.included)
|
|
9625
|
-
declaration.include(context, false);
|
|
9626
|
-
let node = declaration.parent;
|
|
9627
|
-
while (!node.included) {
|
|
9628
|
-
// We do not want to properly include parents in case they are part of a dead branch
|
|
9629
|
-
// in which case .include() might pull in more dead code
|
|
9630
|
-
node.includeNode(context);
|
|
9631
|
-
if (node.type === parseAst_js.Program)
|
|
9632
|
-
break;
|
|
9633
|
-
node = node.parent;
|
|
9634
|
-
}
|
|
9635
|
-
}
|
|
9636
|
-
// We need to make sure we include the correct path of the init
|
|
9637
|
-
if (path.length > 0) {
|
|
9638
|
-
this.init.includePath(limitConcatenatedPathDepth(this.initPath, path), context);
|
|
9639
|
-
this.additionalInitializers?.forEach(initializer => initializer.includePath(UNKNOWN_PATH, context));
|
|
9640
|
-
}
|
|
9641
|
-
}
|
|
9642
|
-
}
|
|
9643
|
-
includeCallArgumentsWhenCalledAtPath(path, interaction, context) {
|
|
9644
|
-
if (this.isReassigned) {
|
|
9645
|
-
// The value may still be one of the assigned functions, whose try-catch
|
|
9646
|
-
// helpers need their call arguments retained
|
|
9647
|
-
includeInteraction(interaction, context);
|
|
9648
|
-
if (path.length === 0) {
|
|
9649
|
-
this.includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context);
|
|
9650
|
-
}
|
|
9651
|
-
return;
|
|
9652
|
-
}
|
|
9653
|
-
if (context.includedCallArguments.has(this.init) ||
|
|
9654
|
-
path.length + this.initPath.length > MAX_PATH_DEPTH) {
|
|
9655
|
-
includeInteraction(interaction, context);
|
|
9656
|
-
return;
|
|
9657
|
-
}
|
|
9658
|
-
context.includedCallArguments.add(this.init);
|
|
9659
|
-
this.init.includeCallArgumentsWhenCalledAtPath([...this.initPath, ...path], interaction, context);
|
|
9660
|
-
context.includedCallArguments.delete(this.init);
|
|
9661
|
-
}
|
|
9662
|
-
includeCallArgumentsOfAssignedTryCatchHelpers(interaction, context) {
|
|
9663
|
-
if (this.initPath.length === 0) {
|
|
9664
|
-
this.includeCallArgumentsOfTryCatchHelper(this.init, interaction, context);
|
|
9665
|
-
}
|
|
9666
|
-
for (const assignedFunction of this.assignedFunctions ?? parseAst_js.EMPTY_ARRAY) {
|
|
9667
|
-
this.includeCallArgumentsOfTryCatchHelper(assignedFunction, interaction, context);
|
|
9668
|
-
}
|
|
9669
|
-
}
|
|
9670
|
-
includeCallArgumentsOfTryCatchHelper(value, interaction, context) {
|
|
9671
|
-
if (isArrowFunctionExpressionNode(value) || isFunctionExpressionNode(value)) {
|
|
9672
|
-
if (value.scope.hasParameterCalledFromTryStatement()) {
|
|
9673
|
-
value.scope.includeCallArguments(interaction, context);
|
|
9795
|
+
if (!getGlobalAtPath([this.name, ...path].slice(0, -1))) {
|
|
9796
|
+
super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9797
|
+
}
|
|
9798
|
+
return;
|
|
9799
|
+
}
|
|
9800
|
+
case INTERACTION_CALLED: {
|
|
9801
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9802
|
+
if (globalAtPath) {
|
|
9803
|
+
globalAtPath.deoptimizeArgumentsOnCall(interaction);
|
|
9804
|
+
}
|
|
9805
|
+
else {
|
|
9806
|
+
super.deoptimizeArgumentsOnInteractionAtPath(interaction, path, recursionTracker);
|
|
9807
|
+
}
|
|
9808
|
+
return;
|
|
9674
9809
|
}
|
|
9675
9810
|
}
|
|
9676
9811
|
}
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
}
|
|
9681
|
-
}
|
|
9682
|
-
markCalledFromTryStatement() {
|
|
9683
|
-
this.calledFromTryStatement = true;
|
|
9812
|
+
getLiteralValueAtPath(path, _recursionTracker, _origin) {
|
|
9813
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9814
|
+
return globalAtPath ? globalAtPath.getLiteralValue() : UnknownValue;
|
|
9684
9815
|
}
|
|
9685
|
-
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9816
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
9817
|
+
switch (interaction.type) {
|
|
9818
|
+
case INTERACTION_ACCESSED: {
|
|
9819
|
+
if (path.length === 0) {
|
|
9820
|
+
// Technically, "undefined" is a global variable of sorts
|
|
9821
|
+
return this.name !== 'undefined' && !getGlobalAtPath([this.name]);
|
|
9822
|
+
}
|
|
9823
|
+
return !getGlobalAtPath([this.name, ...path].slice(0, -1));
|
|
9824
|
+
}
|
|
9825
|
+
case INTERACTION_ASSIGNED: {
|
|
9826
|
+
return true;
|
|
9827
|
+
}
|
|
9828
|
+
case INTERACTION_CALLED: {
|
|
9829
|
+
const globalAtPath = getGlobalAtPath([this.name, ...path]);
|
|
9830
|
+
return !globalAtPath || globalAtPath.hasEffectsWhenCalled(interaction, context);
|
|
9831
|
+
}
|
|
9690
9832
|
}
|
|
9691
|
-
return this.additionalInitializers;
|
|
9692
9833
|
}
|
|
9693
9834
|
}
|
|
9694
9835
|
|
|
@@ -9994,163 +10135,7 @@ class Identifier extends IdentifierBase {
|
|
|
9994
10135
|
}
|
|
9995
10136
|
}
|
|
9996
10137
|
|
|
9997
|
-
|
|
9998
|
-
let safeName = baseName;
|
|
9999
|
-
let count = 1;
|
|
10000
|
-
while (usedNames.has(safeName) || RESERVED_NAMES.has(safeName) || forbiddenNames?.has(safeName)) {
|
|
10001
|
-
safeName = `${baseName}$${toBase64(count++)}`;
|
|
10002
|
-
}
|
|
10003
|
-
usedNames.add(safeName);
|
|
10004
|
-
return safeName;
|
|
10005
|
-
}
|
|
10006
|
-
|
|
10007
|
-
class Scope {
|
|
10008
|
-
constructor() {
|
|
10009
|
-
this.children = [];
|
|
10010
|
-
this.variables = new Map();
|
|
10011
|
-
}
|
|
10012
|
-
/*
|
|
10013
|
-
Redeclaration rules:
|
|
10014
|
-
- var can redeclare var
|
|
10015
|
-
- in function scopes, function and var can redeclare function and var
|
|
10016
|
-
- var is hoisted across scopes, function remains in the scope it is declared
|
|
10017
|
-
- var and function can redeclare function parameters, but parameters cannot redeclare parameters
|
|
10018
|
-
- function cannot redeclare catch scope parameters
|
|
10019
|
-
- var can redeclare catch scope parameters in a way
|
|
10020
|
-
- if the parameter is an identifier and not a pattern
|
|
10021
|
-
- then the variable is still declared in the hoisted outer scope, but the initializer is assigned to the parameter
|
|
10022
|
-
- const, let, class, and function except in the cases above cannot redeclare anything
|
|
10023
|
-
*/
|
|
10024
|
-
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
10025
|
-
const name = identifier.name;
|
|
10026
|
-
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
10027
|
-
if (existingVariable) {
|
|
10028
|
-
if (kind === 'var' && existingVariable.kind === 'var') {
|
|
10029
|
-
existingVariable.addDeclaration(identifier, init);
|
|
10030
|
-
return existingVariable;
|
|
10031
|
-
}
|
|
10032
|
-
context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
10033
|
-
}
|
|
10034
|
-
const newVariable = new LocalVariable(identifier.name, identifier, init, destructuredInitPath, context, kind);
|
|
10035
|
-
this.variables.set(name, newVariable);
|
|
10036
|
-
return newVariable;
|
|
10037
|
-
}
|
|
10038
|
-
addHoistedVariable(name, variable) {
|
|
10039
|
-
(this.hoistedVariables ||= new Map()).set(name, variable);
|
|
10040
|
-
}
|
|
10041
|
-
contains(name) {
|
|
10042
|
-
return this.variables.has(name);
|
|
10043
|
-
}
|
|
10044
|
-
findVariable(_name) {
|
|
10045
|
-
/* istanbul ignore next */
|
|
10046
|
-
throw new Error('Internal Error: findVariable needs to be implemented by a subclass');
|
|
10047
|
-
}
|
|
10048
|
-
}
|
|
10049
|
-
|
|
10050
|
-
class ChildScope extends Scope {
|
|
10051
|
-
constructor(parent, context) {
|
|
10052
|
-
super();
|
|
10053
|
-
this.parent = parent;
|
|
10054
|
-
this.context = context;
|
|
10055
|
-
this.accessedOutsideVariables = new Map();
|
|
10056
|
-
parent.children.push(this);
|
|
10057
|
-
}
|
|
10058
|
-
addAccessedDynamicImport(importExpression) {
|
|
10059
|
-
(this.accessedDynamicImports || (this.accessedDynamicImports = new Set())).add(importExpression);
|
|
10060
|
-
if (this.parent instanceof ChildScope) {
|
|
10061
|
-
this.parent.addAccessedDynamicImport(importExpression);
|
|
10062
|
-
}
|
|
10063
|
-
}
|
|
10064
|
-
addAccessedGlobals(globals, accessedGlobalsByScope) {
|
|
10065
|
-
const accessedGlobals = accessedGlobalsByScope.get(this) || new Set();
|
|
10066
|
-
for (const name of globals) {
|
|
10067
|
-
accessedGlobals.add(name);
|
|
10068
|
-
}
|
|
10069
|
-
accessedGlobalsByScope.set(this, accessedGlobals);
|
|
10070
|
-
if (this.parent instanceof ChildScope) {
|
|
10071
|
-
this.parent.addAccessedGlobals(globals, accessedGlobalsByScope);
|
|
10072
|
-
}
|
|
10073
|
-
}
|
|
10074
|
-
addNamespaceMemberAccess(name, variable) {
|
|
10075
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
10076
|
-
this.parent.addNamespaceMemberAccess(name, variable);
|
|
10077
|
-
}
|
|
10078
|
-
addReturnExpression(expression) {
|
|
10079
|
-
if (this.parent instanceof ChildScope) {
|
|
10080
|
-
this.parent.addReturnExpression(expression);
|
|
10081
|
-
}
|
|
10082
|
-
}
|
|
10083
|
-
addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
10084
|
-
for (const variable of this.accessedOutsideVariables.values()) {
|
|
10085
|
-
if (variable.included) {
|
|
10086
|
-
usedNames.add(variable.getBaseVariableName());
|
|
10087
|
-
// In system format, exported variables are assigned via `exports(name, value)`.
|
|
10088
|
-
// Any scope that references such a variable must treat `exports` as used so
|
|
10089
|
-
// that a nested binding of the same name does not shadow the system wrapper's
|
|
10090
|
-
// `exports` argument.
|
|
10091
|
-
if (format === 'system' && exportNamesByVariable.has(variable)) {
|
|
10092
|
-
usedNames.add('exports');
|
|
10093
|
-
}
|
|
10094
|
-
}
|
|
10095
|
-
}
|
|
10096
|
-
const accessedGlobals = accessedGlobalsByScope.get(this);
|
|
10097
|
-
if (accessedGlobals) {
|
|
10098
|
-
for (const name of accessedGlobals) {
|
|
10099
|
-
usedNames.add(name);
|
|
10100
|
-
}
|
|
10101
|
-
}
|
|
10102
|
-
}
|
|
10103
|
-
contains(name) {
|
|
10104
|
-
return this.variables.has(name) || this.parent.contains(name);
|
|
10105
|
-
}
|
|
10106
|
-
deconflict(format, exportNamesByVariable, accessedGlobalsByScope) {
|
|
10107
|
-
const usedNames = new Set();
|
|
10108
|
-
this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
|
|
10109
|
-
if (this.accessedDynamicImports) {
|
|
10110
|
-
for (const importExpression of this.accessedDynamicImports) {
|
|
10111
|
-
if (importExpression.inlineNamespace) {
|
|
10112
|
-
usedNames.add(importExpression.inlineNamespace.getBaseVariableName());
|
|
10113
|
-
}
|
|
10114
|
-
}
|
|
10115
|
-
}
|
|
10116
|
-
for (const [name, variable] of this.variables) {
|
|
10117
|
-
if (variable.included || variable.alwaysRendered) {
|
|
10118
|
-
variable.setRenderNames(null, getSafeName(name, usedNames, variable.forbiddenNames));
|
|
10119
|
-
}
|
|
10120
|
-
}
|
|
10121
|
-
for (const scope of this.children) {
|
|
10122
|
-
scope.deconflict(format, exportNamesByVariable, accessedGlobalsByScope);
|
|
10123
|
-
}
|
|
10124
|
-
}
|
|
10125
|
-
findLexicalBoundary() {
|
|
10126
|
-
return this.parent.findLexicalBoundary();
|
|
10127
|
-
}
|
|
10128
|
-
findGlobal(name) {
|
|
10129
|
-
const variable = this.parent.findVariable(name);
|
|
10130
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
10131
|
-
return variable;
|
|
10132
|
-
}
|
|
10133
|
-
findVariable(name) {
|
|
10134
|
-
const knownVariable = this.variables.get(name) || this.accessedOutsideVariables.get(name);
|
|
10135
|
-
if (knownVariable) {
|
|
10136
|
-
return knownVariable;
|
|
10137
|
-
}
|
|
10138
|
-
const variable = this.parent.findVariable(name);
|
|
10139
|
-
this.accessedOutsideVariables.set(name, variable);
|
|
10140
|
-
return variable;
|
|
10141
|
-
}
|
|
10142
|
-
}
|
|
10143
|
-
|
|
10144
|
-
function checkEffectForNodes(nodes, context) {
|
|
10145
|
-
for (const node of nodes) {
|
|
10146
|
-
if (node.hasEffects(context)) {
|
|
10147
|
-
return true;
|
|
10148
|
-
}
|
|
10149
|
-
}
|
|
10150
|
-
return false;
|
|
10151
|
-
}
|
|
10152
|
-
|
|
10153
|
-
class MethodBase extends NodeBase {
|
|
10138
|
+
class PropertyBase extends NodeBase {
|
|
10154
10139
|
constructor() {
|
|
10155
10140
|
super(...arguments);
|
|
10156
10141
|
this.accessedValue = null;
|
|
@@ -10227,10 +10212,10 @@ class MethodBase extends NodeBase {
|
|
|
10227
10212
|
return this.accessedValue;
|
|
10228
10213
|
}
|
|
10229
10214
|
}
|
|
10230
|
-
|
|
10231
|
-
|
|
10215
|
+
PropertyBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
10216
|
+
PropertyBase.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
10232
10217
|
|
|
10233
|
-
class MethodDefinition extends
|
|
10218
|
+
class MethodDefinition extends PropertyBase {
|
|
10234
10219
|
hasEffects(context) {
|
|
10235
10220
|
return super.hasEffects(context) || checkEffectForNodes(this.decorators, context);
|
|
10236
10221
|
}
|
|
@@ -10249,95 +10234,33 @@ class PropertyDefinition extends NodeBase {
|
|
|
10249
10234
|
deoptimizePath(path) {
|
|
10250
10235
|
this.value?.deoptimizePath(path);
|
|
10251
10236
|
}
|
|
10252
|
-
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
10253
|
-
return this.value
|
|
10254
|
-
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
10255
|
-
: UnknownValue;
|
|
10256
|
-
}
|
|
10257
|
-
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
10258
|
-
return this.value
|
|
10259
|
-
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
10260
|
-
: UNKNOWN_RETURN_EXPRESSION;
|
|
10261
|
-
}
|
|
10262
|
-
hasEffects(context) {
|
|
10263
|
-
return (this.key.hasEffects(context) ||
|
|
10264
|
-
(this.static && !!this.value?.hasEffects(context)) ||
|
|
10265
|
-
checkEffectForNodes(this.decorators, context));
|
|
10266
|
-
}
|
|
10267
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
10268
|
-
return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
10269
|
-
}
|
|
10270
|
-
includeNode(context) {
|
|
10271
|
-
this.included = true;
|
|
10272
|
-
this.value?.includePath(UNKNOWN_PATH, context);
|
|
10273
|
-
for (const decorator of this.decorators) {
|
|
10274
|
-
decorator.includePath(UNKNOWN_PATH, context);
|
|
10275
|
-
}
|
|
10276
|
-
}
|
|
10277
|
-
}
|
|
10278
|
-
PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
10279
|
-
|
|
10280
|
-
class BlockScope extends ChildScope {
|
|
10281
|
-
constructor(parent) {
|
|
10282
|
-
super(parent, parent.context);
|
|
10283
|
-
}
|
|
10284
|
-
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
10285
|
-
if (kind === 'var') {
|
|
10286
|
-
const name = identifier.name;
|
|
10287
|
-
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
10288
|
-
if (existingVariable) {
|
|
10289
|
-
if (existingVariable.kind === 'var' ||
|
|
10290
|
-
(kind === 'var' && existingVariable.kind === 'parameter')) {
|
|
10291
|
-
existingVariable.addDeclaration(identifier, init);
|
|
10292
|
-
return existingVariable;
|
|
10293
|
-
}
|
|
10294
|
-
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
10295
|
-
}
|
|
10296
|
-
const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
10297
|
-
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
10298
|
-
// We cannot call deoptimizePath here.
|
|
10299
|
-
declaredVariable.markInitializersForDeoptimization();
|
|
10300
|
-
// We add the variable to this and all parent scopes to reliably detect conflicts
|
|
10301
|
-
this.addHoistedVariable(name, declaredVariable);
|
|
10302
|
-
return declaredVariable;
|
|
10303
|
-
}
|
|
10304
|
-
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
10305
|
-
}
|
|
10306
|
-
}
|
|
10307
|
-
|
|
10308
|
-
class StaticBlock extends NodeBase {
|
|
10309
|
-
createScope(parentScope) {
|
|
10310
|
-
this.scope = new BlockScope(parentScope);
|
|
10237
|
+
getLiteralValueAtPath(path, recursionTracker, origin) {
|
|
10238
|
+
return this.value
|
|
10239
|
+
? this.value.getLiteralValueAtPath(path, recursionTracker, origin)
|
|
10240
|
+
: UnknownValue;
|
|
10241
|
+
}
|
|
10242
|
+
getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin) {
|
|
10243
|
+
return this.value
|
|
10244
|
+
? this.value.getReturnExpressionWhenCalledAtPath(path, interaction, recursionTracker, origin)
|
|
10245
|
+
: UNKNOWN_RETURN_EXPRESSION;
|
|
10311
10246
|
}
|
|
10312
10247
|
hasEffects(context) {
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
}
|
|
10317
|
-
return false;
|
|
10248
|
+
return (this.key.hasEffects(context) ||
|
|
10249
|
+
(this.static && !!this.value?.hasEffects(context)) ||
|
|
10250
|
+
checkEffectForNodes(this.decorators, context));
|
|
10318
10251
|
}
|
|
10319
|
-
|
|
10320
|
-
this.
|
|
10321
|
-
for (const node of this.body) {
|
|
10322
|
-
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
10323
|
-
node.include(context, includeChildrenRecursively);
|
|
10324
|
-
}
|
|
10252
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
10253
|
+
return !this.value || this.value.hasEffectsOnInteractionAtPath(path, interaction, context);
|
|
10325
10254
|
}
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
else {
|
|
10332
|
-
super.render(code, options);
|
|
10255
|
+
includeNode(context) {
|
|
10256
|
+
this.included = true;
|
|
10257
|
+
this.value?.includePath(UNKNOWN_PATH, context);
|
|
10258
|
+
for (const decorator of this.decorators) {
|
|
10259
|
+
decorator.includePath(UNKNOWN_PATH, context);
|
|
10333
10260
|
}
|
|
10334
10261
|
}
|
|
10335
10262
|
}
|
|
10336
|
-
|
|
10337
|
-
StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
10338
|
-
function isStaticBlock(statement) {
|
|
10339
|
-
return statement.type === parseAst_js.StaticBlock;
|
|
10340
|
-
}
|
|
10263
|
+
PropertyDefinition.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
10341
10264
|
|
|
10342
10265
|
class ClassNode extends NodeBase {
|
|
10343
10266
|
constructor() {
|
|
@@ -10409,7 +10332,7 @@ class ClassNode extends NodeBase {
|
|
|
10409
10332
|
applyDeoptimizations() {
|
|
10410
10333
|
this.deoptimized = true;
|
|
10411
10334
|
for (const definition of this.body.body) {
|
|
10412
|
-
if (
|
|
10335
|
+
if (definition.type !== parseAst_js.StaticBlock &&
|
|
10413
10336
|
!(definition.static ||
|
|
10414
10337
|
(definition instanceof MethodDefinition && definition.kind === 'constructor'))) {
|
|
10415
10338
|
// Calls to methods are not tracked, ensure that the return value is deoptimized
|
|
@@ -10455,7 +10378,7 @@ class ClassNode extends NodeBase {
|
|
|
10455
10378
|
const staticProperties = [];
|
|
10456
10379
|
const dynamicMethods = [];
|
|
10457
10380
|
for (const definition of this.body.body) {
|
|
10458
|
-
if (
|
|
10381
|
+
if (definition.type === parseAst_js.StaticBlock)
|
|
10459
10382
|
continue;
|
|
10460
10383
|
const properties = definition.static ? staticProperties : dynamicMethods;
|
|
10461
10384
|
const definitionKind = definition.kind;
|
|
@@ -10503,12 +10426,6 @@ class ClassDeclaration extends ClassNode {
|
|
|
10503
10426
|
this.id.variable.isId = true;
|
|
10504
10427
|
}
|
|
10505
10428
|
}
|
|
10506
|
-
parseNode(esTreeNode) {
|
|
10507
|
-
if (esTreeNode.id !== null) {
|
|
10508
|
-
this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
|
|
10509
|
-
}
|
|
10510
|
-
return super.parseNode(esTreeNode);
|
|
10511
|
-
}
|
|
10512
10429
|
render(code, options) {
|
|
10513
10430
|
const { exportNamesByVariable, format, snippets: { _, getPropertyAccess } } = options;
|
|
10514
10431
|
if (this.id) {
|
|
@@ -11088,6 +11005,34 @@ class FunctionScope extends ReturnValueScope {
|
|
|
11088
11005
|
}
|
|
11089
11006
|
}
|
|
11090
11007
|
|
|
11008
|
+
class BlockScope extends ChildScope {
|
|
11009
|
+
constructor(parent) {
|
|
11010
|
+
super(parent, parent.context);
|
|
11011
|
+
}
|
|
11012
|
+
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
11013
|
+
if (kind === 'var') {
|
|
11014
|
+
const name = identifier.name;
|
|
11015
|
+
const existingVariable = this.hoistedVariables?.get(name) || this.variables.get(name);
|
|
11016
|
+
if (existingVariable) {
|
|
11017
|
+
if (existingVariable.kind === 'var' ||
|
|
11018
|
+
(kind === 'var' && existingVariable.kind === 'parameter')) {
|
|
11019
|
+
existingVariable.addDeclaration(identifier, init);
|
|
11020
|
+
return existingVariable;
|
|
11021
|
+
}
|
|
11022
|
+
return context.error(parseAst_js.logRedeclarationError(name), identifier.start);
|
|
11023
|
+
}
|
|
11024
|
+
const declaredVariable = this.parent.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
11025
|
+
// Necessary to make sure the init is deoptimized for conditional declarations.
|
|
11026
|
+
// We cannot call deoptimizePath here.
|
|
11027
|
+
declaredVariable.markInitializersForDeoptimization();
|
|
11028
|
+
// We add the variable to this and all parent scopes to reliably detect conflicts
|
|
11029
|
+
this.addHoistedVariable(name, declaredVariable);
|
|
11030
|
+
return declaredVariable;
|
|
11031
|
+
}
|
|
11032
|
+
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
11033
|
+
}
|
|
11034
|
+
}
|
|
11035
|
+
|
|
11091
11036
|
class ExpressionStatement extends NodeBase {
|
|
11092
11037
|
initialise() {
|
|
11093
11038
|
super.initialise();
|
|
@@ -11184,66 +11129,6 @@ class BlockStatement extends NodeBase {
|
|
|
11184
11129
|
BlockStatement.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
11185
11130
|
BlockStatement.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
11186
11131
|
|
|
11187
|
-
class RestElement extends NodeBase {
|
|
11188
|
-
constructor() {
|
|
11189
|
-
super(...arguments);
|
|
11190
|
-
this.declarationInit = null;
|
|
11191
|
-
}
|
|
11192
|
-
addExportedVariables(variables, exportNamesByVariable) {
|
|
11193
|
-
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
11194
|
-
}
|
|
11195
|
-
declare(kind, destructuredInitPath, init) {
|
|
11196
|
-
this.declarationInit = init;
|
|
11197
|
-
return this.argument.declare(kind, getIncludedPatternPath$1(destructuredInitPath), init);
|
|
11198
|
-
}
|
|
11199
|
-
deoptimizeAssignment(destructuredInitPath, init) {
|
|
11200
|
-
this.argument.deoptimizeAssignment(getIncludedPatternPath$1(destructuredInitPath), init);
|
|
11201
|
-
}
|
|
11202
|
-
deoptimizePath(path) {
|
|
11203
|
-
if (path.length === 0) {
|
|
11204
|
-
this.argument.deoptimizePath(EMPTY_PATH);
|
|
11205
|
-
}
|
|
11206
|
-
}
|
|
11207
|
-
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
11208
|
-
return (path.length > 0 ||
|
|
11209
|
-
this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
|
|
11210
|
-
}
|
|
11211
|
-
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
11212
|
-
return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath$1(destructuredInitPath), init);
|
|
11213
|
-
}
|
|
11214
|
-
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
11215
|
-
const included = this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath$1(destructuredInitPath), init);
|
|
11216
|
-
if (!this.included && included) {
|
|
11217
|
-
this.includeNode(context);
|
|
11218
|
-
}
|
|
11219
|
-
return this.included;
|
|
11220
|
-
}
|
|
11221
|
-
include(context, includeChildrenRecursively) {
|
|
11222
|
-
if (!this.included)
|
|
11223
|
-
this.includeNode(context);
|
|
11224
|
-
// This should just include the identifier, its properties should be
|
|
11225
|
-
// included where the variable is used.
|
|
11226
|
-
this.argument.include(context, includeChildrenRecursively);
|
|
11227
|
-
}
|
|
11228
|
-
markDeclarationReached() {
|
|
11229
|
-
this.argument.markDeclarationReached();
|
|
11230
|
-
}
|
|
11231
|
-
setAssignedValue(value) {
|
|
11232
|
-
this.argument.setAssignedValue(value);
|
|
11233
|
-
}
|
|
11234
|
-
applyDeoptimizations() {
|
|
11235
|
-
this.deoptimized = true;
|
|
11236
|
-
if (this.declarationInit !== null) {
|
|
11237
|
-
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
11238
|
-
this.scope.context.requestTreeshakingPass();
|
|
11239
|
-
}
|
|
11240
|
-
}
|
|
11241
|
-
}
|
|
11242
|
-
RestElement.prototype.includeNode = onlyIncludeSelf;
|
|
11243
|
-
const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
11244
|
-
? destructuredInitPath
|
|
11245
|
-
: [...destructuredInitPath, UnknownKey];
|
|
11246
|
-
|
|
11247
11132
|
class FunctionBase extends NodeBase {
|
|
11248
11133
|
constructor() {
|
|
11249
11134
|
super(...arguments);
|
|
@@ -11344,11 +11229,12 @@ class FunctionBase extends NodeBase {
|
|
|
11344
11229
|
*/
|
|
11345
11230
|
onlyFunctionCallUsed() {
|
|
11346
11231
|
let variable = null;
|
|
11347
|
-
|
|
11348
|
-
|
|
11232
|
+
const { parent } = this;
|
|
11233
|
+
if (parent.type === parseAst_js.VariableDeclarator) {
|
|
11234
|
+
variable = parent.id.variable ?? null;
|
|
11349
11235
|
}
|
|
11350
|
-
if (
|
|
11351
|
-
variable =
|
|
11236
|
+
else if (parent.type === parseAst_js.ExportDefaultDeclaration) {
|
|
11237
|
+
variable = parent.variable;
|
|
11352
11238
|
}
|
|
11353
11239
|
return variable?.getOnlyFunctionCallUsed() ?? false;
|
|
11354
11240
|
}
|
|
@@ -11385,18 +11271,6 @@ class FunctionBase extends NodeBase {
|
|
|
11385
11271
|
this.annotationNoSideEffects = this.annotations.some(comment => comment.type === 'noSideEffects');
|
|
11386
11272
|
}
|
|
11387
11273
|
}
|
|
11388
|
-
parseNode(esTreeNode) {
|
|
11389
|
-
const { body, params } = esTreeNode;
|
|
11390
|
-
const { scope } = this;
|
|
11391
|
-
const { bodyScope, context } = scope;
|
|
11392
|
-
// We need to ensure that parameters are declared before the body is parsed
|
|
11393
|
-
// so that the scope already knows all parameters and can detect conflicts
|
|
11394
|
-
// when parsing the body.
|
|
11395
|
-
const parameters = (this.params = params.map((parameter) => new (context.getNodeConstructor(parameter.type))(this, scope).parseNode(parameter)));
|
|
11396
|
-
scope.addParameterVariables(parameters.map(parameter => parameter.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION)), parameters[parameters.length - 1] instanceof RestElement);
|
|
11397
|
-
this.body = new (context.getNodeConstructor(body.type))(this, bodyScope).parseNode(body);
|
|
11398
|
-
return super.parseNode(esTreeNode);
|
|
11399
|
-
}
|
|
11400
11274
|
}
|
|
11401
11275
|
FunctionBase.prototype.preventChildBlockScope = true;
|
|
11402
11276
|
FunctionBase.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
@@ -11510,12 +11384,6 @@ class FunctionDeclaration extends FunctionNode {
|
|
|
11510
11384
|
// call super.onlyFunctionCallUsed for export default anonymous function
|
|
11511
11385
|
return this.id?.variable.getOnlyFunctionCallUsed() ?? super.onlyFunctionCallUsed();
|
|
11512
11386
|
}
|
|
11513
|
-
parseNode(esTreeNode) {
|
|
11514
|
-
if (esTreeNode.id !== null) {
|
|
11515
|
-
this.id = new Identifier(this, this.scope.parent).parseNode(esTreeNode.id);
|
|
11516
|
-
}
|
|
11517
|
-
return super.parseNode(esTreeNode);
|
|
11518
|
-
}
|
|
11519
11387
|
}
|
|
11520
11388
|
|
|
11521
11389
|
// The header ends at the first non-white-space after "default"
|
|
@@ -11890,11 +11758,6 @@ class Literal extends NodeBase {
|
|
|
11890
11758
|
super.initialise();
|
|
11891
11759
|
this.members = getLiteralMembersForValue(this.value);
|
|
11892
11760
|
}
|
|
11893
|
-
parseNode(esTreeNode) {
|
|
11894
|
-
this.value = esTreeNode.value;
|
|
11895
|
-
this.regex = esTreeNode.regex;
|
|
11896
|
-
return super.parseNode(esTreeNode);
|
|
11897
|
-
}
|
|
11898
11761
|
render() {
|
|
11899
11762
|
if (typeof this.value === 'string') {
|
|
11900
11763
|
this.scope.context.addIndentExclusionRange([this.start + 1, this.end - 1]);
|
|
@@ -12392,23 +12255,32 @@ class MetaProperty extends NodeBase {
|
|
|
12392
12255
|
render(code, renderOptions) {
|
|
12393
12256
|
const { format, pluginDriver, snippets } = renderOptions;
|
|
12394
12257
|
const { scope: { context: { module } }, meta: { name }, metaProperty, parent, preliminaryChunkId, referenceId, start, end } = this;
|
|
12395
|
-
const { id: moduleId, info: { attributes } } = module;
|
|
12258
|
+
const { id: moduleId, rawId: moduleRawId, info: { attributes: moduleAttributes } } = module;
|
|
12396
12259
|
if (name !== IMPORT)
|
|
12397
12260
|
return;
|
|
12398
12261
|
const chunkId = preliminaryChunkId;
|
|
12399
12262
|
if (referenceId) {
|
|
12400
12263
|
const fileName = pluginDriver.getFileName(referenceId);
|
|
12401
|
-
const relativePath = parseAst_js.normalize(
|
|
12264
|
+
const relativePath = parseAst_js.normalize(sp.relative(sp.dirname(chunkId), fileName));
|
|
12402
12265
|
const isUrlObject = !!metaProperty?.startsWith(FILE_OBJ_PREFIX);
|
|
12403
12266
|
const replacement = pluginDriver.hookFirstSync('resolveFileUrl', [
|
|
12404
|
-
{
|
|
12267
|
+
{
|
|
12268
|
+
chunkId,
|
|
12269
|
+
fileName,
|
|
12270
|
+
format,
|
|
12271
|
+
moduleAttributes,
|
|
12272
|
+
moduleId,
|
|
12273
|
+
moduleRawId,
|
|
12274
|
+
referenceId,
|
|
12275
|
+
relativePath
|
|
12276
|
+
}
|
|
12405
12277
|
]) || relativeUrlMechanisms[format](relativePath, isUrlObject);
|
|
12406
12278
|
code.overwrite(parent.start, parent.end, replacement, { contentOnly: true });
|
|
12407
12279
|
return;
|
|
12408
12280
|
}
|
|
12409
12281
|
let replacement = pluginDriver.hookFirstSync('resolveImportMeta', [
|
|
12410
12282
|
metaProperty,
|
|
12411
|
-
{
|
|
12283
|
+
{ chunkId, format, moduleAttributes, moduleId, moduleRawId }
|
|
12412
12284
|
]);
|
|
12413
12285
|
if (!replacement) {
|
|
12414
12286
|
replacement = importMetaMechanisms[format]?.(metaProperty, { chunkId, snippets });
|
|
@@ -12795,9 +12667,14 @@ class ExternalChunk {
|
|
|
12795
12667
|
return this.fileName;
|
|
12796
12668
|
}
|
|
12797
12669
|
const { paths } = this.options;
|
|
12670
|
+
const rawId = this.moduleInfo.rawId;
|
|
12798
12671
|
return (this.fileName =
|
|
12799
|
-
(typeof paths === 'function'
|
|
12800
|
-
|
|
12672
|
+
(typeof paths === 'function'
|
|
12673
|
+
? paths(rawId, {
|
|
12674
|
+
attributes: this.moduleInfo.attributes
|
|
12675
|
+
})
|
|
12676
|
+
: paths[rawId]) ||
|
|
12677
|
+
(this.renormalizeRenderPath ? parseAst_js.normalize(sp.relative(this.inputBase, rawId)) : rawId));
|
|
12801
12678
|
}
|
|
12802
12679
|
getImportAttributes(snippets) {
|
|
12803
12680
|
return (this.importAttributes ||= formatAttributes(['es', 'cjs'].includes(this.options.format) &&
|
|
@@ -13408,7 +13285,7 @@ function setupNamespace(name, root, globals, { _, getPropertyAccess, s }, compac
|
|
|
13408
13285
|
}
|
|
13409
13286
|
parts[0] =
|
|
13410
13287
|
(typeof globals === 'function'
|
|
13411
|
-
? globals(parts[0])
|
|
13288
|
+
? globals(parts[0], { attributes: {} })
|
|
13412
13289
|
: isReserved
|
|
13413
13290
|
? parts[0]
|
|
13414
13291
|
: globals[parts[0]]) || parts[0];
|
|
@@ -13430,7 +13307,7 @@ function assignToDeepVariable(deepName, root, globals, assignment, { _, getPrope
|
|
|
13430
13307
|
}
|
|
13431
13308
|
parts[0] =
|
|
13432
13309
|
(typeof globals === 'function'
|
|
13433
|
-
? globals(parts[0])
|
|
13310
|
+
? globals(parts[0], { attributes: {} })
|
|
13434
13311
|
: isReserved
|
|
13435
13312
|
? parts[0]
|
|
13436
13313
|
: globals[parts[0]]) || parts[0];
|
|
@@ -13827,24 +13704,24 @@ function ensureArray(thing) {
|
|
|
13827
13704
|
return [thing];
|
|
13828
13705
|
}
|
|
13829
13706
|
|
|
13830
|
-
const normalizePathRegExp = new RegExp(`\\${
|
|
13707
|
+
const normalizePathRegExp = new RegExp(`\\${path.win32.sep}`, 'g');
|
|
13831
13708
|
const normalizePath = function normalizePath(filename) {
|
|
13832
|
-
return filename.replace(normalizePathRegExp,
|
|
13709
|
+
return filename.replace(normalizePathRegExp, path.posix.sep);
|
|
13833
13710
|
};
|
|
13834
13711
|
|
|
13835
13712
|
function getMatcherString(id, resolutionBase) {
|
|
13836
|
-
if (resolutionBase === false ||
|
|
13713
|
+
if (resolutionBase === false || path.isAbsolute(id) || id.startsWith('**')) {
|
|
13837
13714
|
return normalizePath(id);
|
|
13838
13715
|
}
|
|
13839
13716
|
// resolve('') is valid and will default to process.cwd()
|
|
13840
|
-
const basePath = normalizePath(
|
|
13717
|
+
const basePath = normalizePath(path.resolve(resolutionBase || ''))
|
|
13841
13718
|
// escape all possible (posix + win) path characters that might interfere with regex
|
|
13842
13719
|
.replace(/[-^$*+?.()|[\]{}]/g, '\\$&');
|
|
13843
13720
|
// Note that we use posix.join because:
|
|
13844
13721
|
// 1. the basePath has been normalized to use /
|
|
13845
13722
|
// 2. the incoming glob (id) matcher, also uses /
|
|
13846
13723
|
// otherwise Node will force backslash (\) on windows
|
|
13847
|
-
return
|
|
13724
|
+
return path.posix.join(basePath, normalizePath(id));
|
|
13848
13725
|
}
|
|
13849
13726
|
const createFilter = function createFilter(include, exclude, options) {
|
|
13850
13727
|
const resolutionBase = options && options.resolve;
|
|
@@ -13902,7 +13779,7 @@ class ArrayPattern extends NodeBase {
|
|
|
13902
13779
|
}
|
|
13903
13780
|
declare(kind, destructuredInitPath, init) {
|
|
13904
13781
|
const variables = [];
|
|
13905
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13782
|
+
const includedPatternPath = getIncludedPatternPath$1(destructuredInitPath);
|
|
13906
13783
|
for (const element of this.elements) {
|
|
13907
13784
|
if (element !== null) {
|
|
13908
13785
|
variables.push(...element.declare(kind, includedPatternPath, init));
|
|
@@ -13911,7 +13788,7 @@ class ArrayPattern extends NodeBase {
|
|
|
13911
13788
|
return variables;
|
|
13912
13789
|
}
|
|
13913
13790
|
deoptimizeAssignment(destructuredInitPath, init) {
|
|
13914
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13791
|
+
const includedPatternPath = getIncludedPatternPath$1(destructuredInitPath);
|
|
13915
13792
|
for (const element of this.elements) {
|
|
13916
13793
|
element?.deoptimizeAssignment(includedPatternPath, init);
|
|
13917
13794
|
}
|
|
@@ -13923,7 +13800,7 @@ class ArrayPattern extends NodeBase {
|
|
|
13923
13800
|
}
|
|
13924
13801
|
}
|
|
13925
13802
|
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
13926
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13803
|
+
const includedPatternPath = getIncludedPatternPath$1(destructuredInitPath);
|
|
13927
13804
|
for (const element of this.elements) {
|
|
13928
13805
|
if (element?.hasEffectsWhenDestructuring(context, includedPatternPath, init)) {
|
|
13929
13806
|
return true;
|
|
@@ -13941,7 +13818,7 @@ class ArrayPattern extends NodeBase {
|
|
|
13941
13818
|
}
|
|
13942
13819
|
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
13943
13820
|
let included = false;
|
|
13944
|
-
const includedPatternPath = getIncludedPatternPath(destructuredInitPath);
|
|
13821
|
+
const includedPatternPath = getIncludedPatternPath$1(destructuredInitPath);
|
|
13945
13822
|
for (const element of [...this.elements].reverse()) {
|
|
13946
13823
|
if (element) {
|
|
13947
13824
|
if (included && !element.included) {
|
|
@@ -13986,7 +13863,7 @@ class ArrayPattern extends NodeBase {
|
|
|
13986
13863
|
}
|
|
13987
13864
|
}
|
|
13988
13865
|
ArrayPattern.prototype.includeNode = onlyIncludeSelf;
|
|
13989
|
-
const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
13866
|
+
const getIncludedPatternPath$1 = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
13990
13867
|
? destructuredInitPath
|
|
13991
13868
|
: [...destructuredInitPath, UnknownInteger];
|
|
13992
13869
|
|
|
@@ -14033,8 +13910,7 @@ class ArrowFunctionExpression extends FunctionBase {
|
|
|
14033
13910
|
return false;
|
|
14034
13911
|
}
|
|
14035
13912
|
onlyFunctionCallUsed() {
|
|
14036
|
-
const isIIFE = this.parent.type === parseAst_js.CallExpression &&
|
|
14037
|
-
this.parent.callee === this;
|
|
13913
|
+
const isIIFE = this.parent.type === parseAst_js.CallExpression && this.parent.callee === this;
|
|
14038
13914
|
return isIIFE || super.onlyFunctionCallUsed();
|
|
14039
13915
|
}
|
|
14040
13916
|
include(context, includeChildrenRecursively) {
|
|
@@ -14336,10 +14212,15 @@ function markTopLevelAwait(node) {
|
|
|
14336
14212
|
if (node.scope.context.usesTopLevelAwait)
|
|
14337
14213
|
return;
|
|
14338
14214
|
let parent = node.parent;
|
|
14339
|
-
|
|
14340
|
-
|
|
14215
|
+
while (parent) {
|
|
14216
|
+
const { type } = parent;
|
|
14217
|
+
if (type === parseAst_js.ArrowFunctionExpression ||
|
|
14218
|
+
type === parseAst_js.FunctionExpression ||
|
|
14219
|
+
type === parseAst_js.FunctionDeclaration) {
|
|
14341
14220
|
return;
|
|
14342
|
-
|
|
14221
|
+
}
|
|
14222
|
+
parent = parent.parent;
|
|
14223
|
+
}
|
|
14343
14224
|
node.scope.context.usesTopLevelAwait = true;
|
|
14344
14225
|
}
|
|
14345
14226
|
|
|
@@ -14426,10 +14307,9 @@ const binaryOperators = {
|
|
|
14426
14307
|
'>>': (left, right) => left >> right,
|
|
14427
14308
|
'>>>': (left, right) => left >>> right,
|
|
14428
14309
|
'^': (left, right) => left ^ right,
|
|
14310
|
+
in: () => UnknownValue,
|
|
14311
|
+
instanceof: () => UnknownValue,
|
|
14429
14312
|
'|': (left, right) => left | right
|
|
14430
|
-
// We use the fallback for cases where we return something unknown
|
|
14431
|
-
// in: () => UnknownValue,
|
|
14432
|
-
// instanceof: () => UnknownValue,
|
|
14433
14313
|
};
|
|
14434
14314
|
const UNASSIGNED$1 = Symbol('Unassigned');
|
|
14435
14315
|
class BinaryExpression extends NodeBase {
|
|
@@ -14447,7 +14327,9 @@ class BinaryExpression extends NodeBase {
|
|
|
14447
14327
|
if (typeof leftValue === 'symbol')
|
|
14448
14328
|
return UnknownValue;
|
|
14449
14329
|
// Optimize `'export' in namespace`
|
|
14450
|
-
if (this.operator === 'in' &&
|
|
14330
|
+
if (this.operator === 'in' &&
|
|
14331
|
+
'variable' in this.right &&
|
|
14332
|
+
this.right.variable instanceof NamespaceVariable) {
|
|
14451
14333
|
const [variable] = this.right.variable.context.traceExport(String(leftValue));
|
|
14452
14334
|
if (variable instanceof ExternalVariable)
|
|
14453
14335
|
return UnknownValue;
|
|
@@ -14458,14 +14340,13 @@ class BinaryExpression extends NodeBase {
|
|
|
14458
14340
|
const rightValue = this.right.getLiteralValueAtPath(EMPTY_PATH, recursionTracker, origin);
|
|
14459
14341
|
if (typeof rightValue === 'symbol')
|
|
14460
14342
|
return UnknownValue;
|
|
14461
|
-
|
|
14462
|
-
if (!operatorFunction)
|
|
14463
|
-
return UnknownValue;
|
|
14464
|
-
return operatorFunction(leftValue, rightValue);
|
|
14343
|
+
return binaryOperators[this.operator](leftValue, rightValue);
|
|
14465
14344
|
}
|
|
14466
14345
|
getRenderedLiteralValue() {
|
|
14467
14346
|
// Only optimize `'export' in ns`
|
|
14468
|
-
if (this.operator
|
|
14347
|
+
if (!(this.operator === 'in' &&
|
|
14348
|
+
'variable' in this.right &&
|
|
14349
|
+
this.right.variable instanceof NamespaceVariable)) {
|
|
14469
14350
|
return UnknownValue;
|
|
14470
14351
|
}
|
|
14471
14352
|
if (this.renderedLiteralValue !== UNASSIGNED$1)
|
|
@@ -14804,16 +14685,6 @@ class CatchClause extends NodeBase {
|
|
|
14804
14685
|
createScope(parentScope) {
|
|
14805
14686
|
this.scope = new ParameterScope(parentScope, true);
|
|
14806
14687
|
}
|
|
14807
|
-
parseNode(esTreeNode) {
|
|
14808
|
-
const { body, param, type } = esTreeNode;
|
|
14809
|
-
this.type = type;
|
|
14810
|
-
if (param) {
|
|
14811
|
-
this.param = new (this.scope.context.getNodeConstructor(param.type))(this, this.scope).parseNode(param);
|
|
14812
|
-
this.param.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
|
|
14813
|
-
}
|
|
14814
|
-
this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
|
|
14815
|
-
return super.parseNode(esTreeNode);
|
|
14816
|
-
}
|
|
14817
14688
|
}
|
|
14818
14689
|
CatchClause.prototype.preventChildBlockScope = true;
|
|
14819
14690
|
CatchClause.prototype.includeNode = onlyIncludeSelf;
|
|
@@ -14864,14 +14735,6 @@ class ClassBody extends NodeBase {
|
|
|
14864
14735
|
definition.include(context, includeChildrenRecursively);
|
|
14865
14736
|
}
|
|
14866
14737
|
}
|
|
14867
|
-
parseNode(esTreeNode) {
|
|
14868
|
-
const body = (this.body = new Array(esTreeNode.body.length));
|
|
14869
|
-
let index = 0;
|
|
14870
|
-
for (const definition of esTreeNode.body) {
|
|
14871
|
-
body[index++] = new (this.scope.context.getNodeConstructor(definition.type))(this, definition.static ? this.scope : this.scope.instanceScope).parseNode(definition);
|
|
14872
|
-
}
|
|
14873
|
-
return super.parseNode(esTreeNode);
|
|
14874
|
-
}
|
|
14875
14738
|
}
|
|
14876
14739
|
ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
14877
14740
|
ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
@@ -15402,12 +15265,6 @@ class FunctionExpression extends FunctionNode {
|
|
|
15402
15265
|
createScope(parentScope) {
|
|
15403
15266
|
super.createScope((this.idScope = new ChildScope(parentScope, parentScope.context)));
|
|
15404
15267
|
}
|
|
15405
|
-
parseNode(esTreeNode) {
|
|
15406
|
-
if (esTreeNode.id !== null) {
|
|
15407
|
-
this.id = new Identifier(this, this.idScope).parseNode(esTreeNode.id);
|
|
15408
|
-
}
|
|
15409
|
-
return super.parseNode(esTreeNode);
|
|
15410
|
-
}
|
|
15411
15268
|
onlyFunctionCallUsed() {
|
|
15412
15269
|
const isIIFE = this.parent.type === parseAst_js.CallExpression &&
|
|
15413
15270
|
this.parent.callee === this &&
|
|
@@ -15423,17 +15280,6 @@ class FunctionExpression extends FunctionNode {
|
|
|
15423
15280
|
}
|
|
15424
15281
|
}
|
|
15425
15282
|
|
|
15426
|
-
class TrackingScope extends BlockScope {
|
|
15427
|
-
constructor() {
|
|
15428
|
-
super(...arguments);
|
|
15429
|
-
this.hoistedDeclarations = [];
|
|
15430
|
-
}
|
|
15431
|
-
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
15432
|
-
this.hoistedDeclarations.push(identifier);
|
|
15433
|
-
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
15434
|
-
}
|
|
15435
|
-
}
|
|
15436
|
-
|
|
15437
15283
|
const unset = Symbol('unset');
|
|
15438
15284
|
class IfStatement extends NodeBase {
|
|
15439
15285
|
constructor() {
|
|
@@ -15478,13 +15324,6 @@ class IfStatement extends NodeBase {
|
|
|
15478
15324
|
}
|
|
15479
15325
|
}
|
|
15480
15326
|
}
|
|
15481
|
-
parseNode(esTreeNode) {
|
|
15482
|
-
this.consequent = new (this.scope.context.getNodeConstructor(esTreeNode.consequent.type))(this, (this.consequentScope = new TrackingScope(this.scope))).parseNode(esTreeNode.consequent);
|
|
15483
|
-
if (esTreeNode.alternate) {
|
|
15484
|
-
this.alternate = new (this.scope.context.getNodeConstructor(esTreeNode.alternate.type))(this, (this.alternateScope = new TrackingScope(this.scope))).parseNode(esTreeNode.alternate);
|
|
15485
|
-
}
|
|
15486
|
-
return super.parseNode(esTreeNode);
|
|
15487
|
-
}
|
|
15488
15327
|
render(code, options) {
|
|
15489
15328
|
const { snippets: { getPropertyAccess } } = options;
|
|
15490
15329
|
// Note that unknown test values are always included
|
|
@@ -15586,10 +15425,10 @@ class IfStatement extends NodeBase {
|
|
|
15586
15425
|
shouldKeepAlternateBranch() {
|
|
15587
15426
|
let currentParent = this.parent;
|
|
15588
15427
|
do {
|
|
15589
|
-
if (currentParent
|
|
15428
|
+
if (currentParent.type === parseAst_js.IfStatement && currentParent.alternate) {
|
|
15590
15429
|
return true;
|
|
15591
15430
|
}
|
|
15592
|
-
if (currentParent
|
|
15431
|
+
if (currentParent.type === parseAst_js.BlockStatement) {
|
|
15593
15432
|
return false;
|
|
15594
15433
|
}
|
|
15595
15434
|
currentParent = currentParent.parent;
|
|
@@ -15694,11 +15533,11 @@ class ImportExpression extends NodeBase {
|
|
|
15694
15533
|
// * import('foo'); // as statement
|
|
15695
15534
|
// * await import('foo') // use as awaited expression in any way
|
|
15696
15535
|
// * import('foo').then(n => {...}) // only if .then is called directly on the import()
|
|
15697
|
-
if (
|
|
15536
|
+
if (parent.type === parseAst_js.ExpressionStatement || parent.type === parseAst_js.AwaitExpression) {
|
|
15698
15537
|
this.localResolution = { resolution, tracked: true };
|
|
15699
15538
|
return;
|
|
15700
15539
|
}
|
|
15701
|
-
if (
|
|
15540
|
+
if (parent.type !== parseAst_js.MemberExpression) {
|
|
15702
15541
|
this.localResolution = { resolution, tracked: false };
|
|
15703
15542
|
return;
|
|
15704
15543
|
}
|
|
@@ -15708,8 +15547,8 @@ class ImportExpression extends NodeBase {
|
|
|
15708
15547
|
while (true) {
|
|
15709
15548
|
if (currentParent.computed ||
|
|
15710
15549
|
currentParent.object !== callExpression ||
|
|
15711
|
-
|
|
15712
|
-
|
|
15550
|
+
currentParent.property.type !== parseAst_js.Identifier ||
|
|
15551
|
+
currentParent.parent.type !== parseAst_js.CallExpression) {
|
|
15713
15552
|
break;
|
|
15714
15553
|
}
|
|
15715
15554
|
const propertyName = currentParent.property.name;
|
|
@@ -15717,20 +15556,20 @@ class ImportExpression extends NodeBase {
|
|
|
15717
15556
|
if (propertyName === 'then') {
|
|
15718
15557
|
const firstArgument = callExpression.arguments[0];
|
|
15719
15558
|
if (firstArgument === undefined ||
|
|
15720
|
-
|
|
15721
|
-
|
|
15559
|
+
firstArgument.type === parseAst_js.FunctionExpression ||
|
|
15560
|
+
firstArgument.type === parseAst_js.ArrowFunctionExpression) {
|
|
15722
15561
|
currentParent.promiseHandler = new ObjectPromiseHandler(getDynamicNamespaceVariable(resolution.namespace));
|
|
15723
15562
|
this.localResolution = { resolution, tracked: true };
|
|
15724
15563
|
return;
|
|
15725
15564
|
}
|
|
15726
15565
|
}
|
|
15727
15566
|
else if (propertyName === 'catch' || propertyName === 'finally') {
|
|
15728
|
-
if (
|
|
15567
|
+
if (callExpression.parent.type === parseAst_js.MemberExpression) {
|
|
15729
15568
|
currentParent.promiseHandler = new EmptyPromiseHandler();
|
|
15730
15569
|
currentParent = callExpression.parent;
|
|
15731
15570
|
continue;
|
|
15732
15571
|
}
|
|
15733
|
-
if (
|
|
15572
|
+
if (callExpression.parent.type === parseAst_js.ExpressionStatement) {
|
|
15734
15573
|
currentParent.promiseHandler = new EmptyPromiseHandler();
|
|
15735
15574
|
this.localResolution = { resolution, tracked: true };
|
|
15736
15575
|
return;
|
|
@@ -15783,10 +15622,6 @@ class ImportExpression extends NodeBase {
|
|
|
15783
15622
|
super.initialise();
|
|
15784
15623
|
this.scope.context.addDynamicImport(this);
|
|
15785
15624
|
}
|
|
15786
|
-
parseNode(esTreeNode) {
|
|
15787
|
-
this.sourceAstNode = esTreeNode.source;
|
|
15788
|
-
return super.parseNode(esTreeNode);
|
|
15789
|
-
}
|
|
15790
15625
|
render(code, options) {
|
|
15791
15626
|
const { snippets: { _, getDirectReturnFunction, getObject, getPropertyAccess }, importAttributesKey } = options;
|
|
15792
15627
|
if (this.inlineNamespace) {
|
|
@@ -15878,10 +15713,13 @@ class ImportExpression extends NodeBase {
|
|
|
15878
15713
|
}
|
|
15879
15714
|
return chunkInfos;
|
|
15880
15715
|
},
|
|
15716
|
+
moduleAttributes: scope.context.module.info.attributes,
|
|
15881
15717
|
moduleId: scope.context.module.id,
|
|
15718
|
+
moduleRawId: scope.context.module.rawId,
|
|
15882
15719
|
targetChunk: targetChunk ? getChunkInfoWithPath(targetChunk) : null,
|
|
15883
15720
|
targetModuleAttributes: resolution && typeof resolution !== 'string' ? resolution.info.attributes : {},
|
|
15884
|
-
targetModuleId: resolution && typeof resolution !== 'string' ? resolution.id : null
|
|
15721
|
+
targetModuleId: resolution && typeof resolution !== 'string' ? resolution.id : null,
|
|
15722
|
+
targetModuleRawId: resolution && typeof resolution !== 'string' ? resolution.info.rawId : null
|
|
15885
15723
|
}
|
|
15886
15724
|
]);
|
|
15887
15725
|
if (mechanism) {
|
|
@@ -16050,16 +15888,14 @@ class JSXIdentifier extends IdentifierBase {
|
|
|
16050
15888
|
: 1 /* IdentifierType.NativeElementName */;
|
|
16051
15889
|
}
|
|
16052
15890
|
case 'JSXMemberExpression': {
|
|
16053
|
-
return this.parent.object === this
|
|
16054
|
-
? 0 /* IdentifierType.Reference */
|
|
16055
|
-
: 2 /* IdentifierType.Other */;
|
|
15891
|
+
return this.parent.object === this ? 0 /* IdentifierType.Reference */ : 2 /* IdentifierType.Other */;
|
|
16056
15892
|
}
|
|
16057
15893
|
case 'JSXAttribute':
|
|
16058
15894
|
case 'JSXNamespacedName': {
|
|
16059
15895
|
return 2 /* IdentifierType.Other */;
|
|
16060
15896
|
}
|
|
16061
15897
|
default: {
|
|
16062
|
-
/* istanbul ignore next */
|
|
15898
|
+
/* istanbul ignore next */ // @ts-expect-error There should be no valid parent type
|
|
16063
15899
|
throw new Error(`Unexpected parent node type for JSXIdentifier: ${this.parent.type}`);
|
|
16064
15900
|
}
|
|
16065
15901
|
}
|
|
@@ -17069,7 +16905,7 @@ class Program extends NodeBase {
|
|
|
17069
16905
|
Program.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
17070
16906
|
Program.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
17071
16907
|
|
|
17072
|
-
class Property extends
|
|
16908
|
+
class Property extends PropertyBase {
|
|
17073
16909
|
//declare method: boolean;
|
|
17074
16910
|
get method() {
|
|
17075
16911
|
return isFlagSet(this.flags, 262144 /* Flag.method */);
|
|
@@ -17098,8 +16934,7 @@ class Property extends MethodBase {
|
|
|
17098
16934
|
}
|
|
17099
16935
|
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
17100
16936
|
const path = this.getPathInProperty(destructuredInitPath);
|
|
17101
|
-
let included = this.value.includeDestructuredIfNecessary(context, path, init) ||
|
|
17102
|
-
this.included;
|
|
16937
|
+
let included = this.value.includeDestructuredIfNecessary(context, path, init) || this.included;
|
|
17103
16938
|
if ((included ||= this.key.hasEffects(createHasEffectsContext()))) {
|
|
17104
16939
|
this.key.include(context, false);
|
|
17105
16940
|
if (!this.value.included) {
|
|
@@ -17150,6 +16985,66 @@ class Property extends MethodBase {
|
|
|
17150
16985
|
Property.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
17151
16986
|
Property.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
17152
16987
|
|
|
16988
|
+
class RestElement extends NodeBase {
|
|
16989
|
+
constructor() {
|
|
16990
|
+
super(...arguments);
|
|
16991
|
+
this.declarationInit = null;
|
|
16992
|
+
}
|
|
16993
|
+
addExportedVariables(variables, exportNamesByVariable) {
|
|
16994
|
+
this.argument.addExportedVariables(variables, exportNamesByVariable);
|
|
16995
|
+
}
|
|
16996
|
+
declare(kind, destructuredInitPath, init) {
|
|
16997
|
+
this.declarationInit = init;
|
|
16998
|
+
return this.argument.declare(kind, getIncludedPatternPath(destructuredInitPath), init);
|
|
16999
|
+
}
|
|
17000
|
+
deoptimizeAssignment(destructuredInitPath, init) {
|
|
17001
|
+
this.argument.deoptimizeAssignment(getIncludedPatternPath(destructuredInitPath), init);
|
|
17002
|
+
}
|
|
17003
|
+
deoptimizePath(path) {
|
|
17004
|
+
if (path.length === 0) {
|
|
17005
|
+
this.argument.deoptimizePath(EMPTY_PATH);
|
|
17006
|
+
}
|
|
17007
|
+
}
|
|
17008
|
+
hasEffectsOnInteractionAtPath(path, interaction, context) {
|
|
17009
|
+
return (path.length > 0 ||
|
|
17010
|
+
this.argument.hasEffectsOnInteractionAtPath(EMPTY_PATH, interaction, context));
|
|
17011
|
+
}
|
|
17012
|
+
hasEffectsWhenDestructuring(context, destructuredInitPath, init) {
|
|
17013
|
+
return this.argument.hasEffectsWhenDestructuring(context, getIncludedPatternPath(destructuredInitPath), init);
|
|
17014
|
+
}
|
|
17015
|
+
includeDestructuredIfNecessary(context, destructuredInitPath, init) {
|
|
17016
|
+
const included = this.argument.includeDestructuredIfNecessary(context, getIncludedPatternPath(destructuredInitPath), init);
|
|
17017
|
+
if (!this.included && included) {
|
|
17018
|
+
this.includeNode(context);
|
|
17019
|
+
}
|
|
17020
|
+
return this.included;
|
|
17021
|
+
}
|
|
17022
|
+
include(context, includeChildrenRecursively) {
|
|
17023
|
+
if (!this.included)
|
|
17024
|
+
this.includeNode(context);
|
|
17025
|
+
// This should just include the identifier, its properties should be
|
|
17026
|
+
// included where the variable is used.
|
|
17027
|
+
this.argument.include(context, includeChildrenRecursively);
|
|
17028
|
+
}
|
|
17029
|
+
markDeclarationReached() {
|
|
17030
|
+
this.argument.markDeclarationReached();
|
|
17031
|
+
}
|
|
17032
|
+
setAssignedValue(value) {
|
|
17033
|
+
this.argument.setAssignedValue(value);
|
|
17034
|
+
}
|
|
17035
|
+
applyDeoptimizations() {
|
|
17036
|
+
this.deoptimized = true;
|
|
17037
|
+
if (this.declarationInit !== null) {
|
|
17038
|
+
this.declarationInit.deoptimizePath([UnknownKey, UnknownKey]);
|
|
17039
|
+
this.scope.context.requestTreeshakingPass();
|
|
17040
|
+
}
|
|
17041
|
+
}
|
|
17042
|
+
}
|
|
17043
|
+
RestElement.prototype.includeNode = onlyIncludeSelf;
|
|
17044
|
+
const getIncludedPatternPath = (destructuredInitPath) => destructuredInitPath.at(-1) === UnknownKey
|
|
17045
|
+
? destructuredInitPath
|
|
17046
|
+
: [...destructuredInitPath, UnknownKey];
|
|
17047
|
+
|
|
17153
17048
|
class ReturnStatement extends NodeBase {
|
|
17154
17049
|
hasEffects(context) {
|
|
17155
17050
|
if (!context.ignore.returnYield || this.argument?.hasEffects(context))
|
|
@@ -17246,13 +17141,44 @@ class SequenceExpression extends NodeBase {
|
|
|
17246
17141
|
node.render(code, options);
|
|
17247
17142
|
}
|
|
17248
17143
|
}
|
|
17249
|
-
if (lastSeparatorPos) {
|
|
17250
|
-
code.remove(lastSeparatorPos, this.end);
|
|
17144
|
+
if (lastSeparatorPos) {
|
|
17145
|
+
code.remove(lastSeparatorPos, this.end);
|
|
17146
|
+
}
|
|
17147
|
+
}
|
|
17148
|
+
}
|
|
17149
|
+
SequenceExpression.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
17150
|
+
SequenceExpression.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
17151
|
+
|
|
17152
|
+
class StaticBlock extends NodeBase {
|
|
17153
|
+
createScope(parentScope) {
|
|
17154
|
+
this.scope = new BlockScope(parentScope);
|
|
17155
|
+
}
|
|
17156
|
+
hasEffects(context) {
|
|
17157
|
+
for (const node of this.body) {
|
|
17158
|
+
if (node.hasEffects(context))
|
|
17159
|
+
return true;
|
|
17160
|
+
}
|
|
17161
|
+
return false;
|
|
17162
|
+
}
|
|
17163
|
+
include(context, includeChildrenRecursively) {
|
|
17164
|
+
this.included = true;
|
|
17165
|
+
for (const node of this.body) {
|
|
17166
|
+
if (includeChildrenRecursively || node.shouldBeIncluded(context))
|
|
17167
|
+
node.include(context, includeChildrenRecursively);
|
|
17168
|
+
}
|
|
17169
|
+
}
|
|
17170
|
+
render(code, options) {
|
|
17171
|
+
if (this.body.length > 0) {
|
|
17172
|
+
const bodyStartPos = findFirstOccurrenceOutsideComment(code.original.slice(this.start, this.end), '{') + 1;
|
|
17173
|
+
renderStatementList(this.body, code, this.start + bodyStartPos, this.end - 1, options);
|
|
17174
|
+
}
|
|
17175
|
+
else {
|
|
17176
|
+
super.render(code, options);
|
|
17251
17177
|
}
|
|
17252
17178
|
}
|
|
17253
17179
|
}
|
|
17254
|
-
|
|
17255
|
-
|
|
17180
|
+
StaticBlock.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
|
|
17181
|
+
StaticBlock.prototype.applyDeoptimizations = doNotDeoptimize;
|
|
17256
17182
|
|
|
17257
17183
|
class Super extends NodeBase {
|
|
17258
17184
|
bind() {
|
|
@@ -17386,10 +17312,6 @@ class SwitchStatement extends NodeBase {
|
|
|
17386
17312
|
}
|
|
17387
17313
|
this.defaultCase = null;
|
|
17388
17314
|
}
|
|
17389
|
-
parseNode(esTreeNode) {
|
|
17390
|
-
this.discriminant = new (this.scope.context.getNodeConstructor(esTreeNode.discriminant.type))(this, this.parentScope).parseNode(esTreeNode.discriminant);
|
|
17391
|
-
return super.parseNode(esTreeNode);
|
|
17392
|
-
}
|
|
17393
17315
|
render(code, options) {
|
|
17394
17316
|
this.discriminant.render(code, options);
|
|
17395
17317
|
if (this.cases.length > 0) {
|
|
@@ -17446,7 +17368,7 @@ class TaggedTemplateExpression extends CallExpressionBase {
|
|
|
17446
17368
|
this.quasi.render(code, options);
|
|
17447
17369
|
if (!this.hasCheckedForWarnings && this.tag.type === parseAst_js.Identifier) {
|
|
17448
17370
|
this.hasCheckedForWarnings = true;
|
|
17449
|
-
const name = this.tag
|
|
17371
|
+
const { name } = this.tag;
|
|
17450
17372
|
const variable = this.scope.findVariable(name);
|
|
17451
17373
|
if (variable.isNamespace) {
|
|
17452
17374
|
this.scope.context.log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logCannotCallNamespace(name), this.start);
|
|
@@ -17480,10 +17402,6 @@ class TemplateElement extends NodeBase {
|
|
|
17480
17402
|
hasEffects() {
|
|
17481
17403
|
return false;
|
|
17482
17404
|
}
|
|
17483
|
-
parseNode(esTreeNode) {
|
|
17484
|
-
this.value = esTreeNode.value;
|
|
17485
|
-
return super.parseNode(esTreeNode);
|
|
17486
|
-
}
|
|
17487
17405
|
render() { }
|
|
17488
17406
|
}
|
|
17489
17407
|
TemplateElement.prototype.includeNode = onlyIncludeSelf;
|
|
@@ -18162,109 +18080,23 @@ class YieldExpression extends NodeBase {
|
|
|
18162
18080
|
}
|
|
18163
18081
|
}
|
|
18164
18082
|
|
|
18165
|
-
|
|
18083
|
+
class TrackingScope extends BlockScope {
|
|
18084
|
+
constructor() {
|
|
18085
|
+
super(...arguments);
|
|
18086
|
+
this.hoistedDeclarations = [];
|
|
18087
|
+
}
|
|
18088
|
+
addDeclaration(identifier, context, init, destructuredInitPath, kind) {
|
|
18089
|
+
this.hoistedDeclarations.push(identifier);
|
|
18090
|
+
return super.addDeclaration(identifier, context, init, destructuredInitPath, kind);
|
|
18091
|
+
}
|
|
18092
|
+
}
|
|
18093
|
+
|
|
18094
|
+
// This file is generated by scripts/generate-buffer-parsers.ts.
|
|
18166
18095
|
// Do not edit this file directly.
|
|
18167
18096
|
function convertProgram(buffer, parent, parentScope) {
|
|
18168
18097
|
return convertNode(parent, parentScope, 0, parseAst_js.getAstBuffer(buffer));
|
|
18169
18098
|
}
|
|
18170
|
-
const
|
|
18171
|
-
'PanicError',
|
|
18172
|
-
'ParseError',
|
|
18173
|
-
'ArrayExpression',
|
|
18174
|
-
'ArrayPattern',
|
|
18175
|
-
'ArrowFunctionExpression',
|
|
18176
|
-
'AssignmentExpression',
|
|
18177
|
-
'AssignmentPattern',
|
|
18178
|
-
'AwaitExpression',
|
|
18179
|
-
'BinaryExpression',
|
|
18180
|
-
'BlockStatement',
|
|
18181
|
-
'BreakStatement',
|
|
18182
|
-
'CallExpression',
|
|
18183
|
-
'CatchClause',
|
|
18184
|
-
'ChainExpression',
|
|
18185
|
-
'ClassBody',
|
|
18186
|
-
'ClassDeclaration',
|
|
18187
|
-
'ClassExpression',
|
|
18188
|
-
'ConditionalExpression',
|
|
18189
|
-
'ContinueStatement',
|
|
18190
|
-
'DebuggerStatement',
|
|
18191
|
-
'Decorator',
|
|
18192
|
-
'ExpressionStatement',
|
|
18193
|
-
'DoWhileStatement',
|
|
18194
|
-
'EmptyStatement',
|
|
18195
|
-
'ExportAllDeclaration',
|
|
18196
|
-
'ExportDefaultDeclaration',
|
|
18197
|
-
'ExportNamedDeclaration',
|
|
18198
|
-
'ExportSpecifier',
|
|
18199
|
-
'ExpressionStatement',
|
|
18200
|
-
'ForInStatement',
|
|
18201
|
-
'ForOfStatement',
|
|
18202
|
-
'ForStatement',
|
|
18203
|
-
'FunctionDeclaration',
|
|
18204
|
-
'FunctionExpression',
|
|
18205
|
-
'Identifier',
|
|
18206
|
-
'IfStatement',
|
|
18207
|
-
'ImportAttribute',
|
|
18208
|
-
'ImportDeclaration',
|
|
18209
|
-
'ImportDefaultSpecifier',
|
|
18210
|
-
'ImportExpression',
|
|
18211
|
-
'ImportNamespaceSpecifier',
|
|
18212
|
-
'ImportSpecifier',
|
|
18213
|
-
'JSXAttribute',
|
|
18214
|
-
'JSXClosingElement',
|
|
18215
|
-
'JSXClosingFragment',
|
|
18216
|
-
'JSXElement',
|
|
18217
|
-
'JSXEmptyExpression',
|
|
18218
|
-
'JSXExpressionContainer',
|
|
18219
|
-
'JSXFragment',
|
|
18220
|
-
'JSXIdentifier',
|
|
18221
|
-
'JSXMemberExpression',
|
|
18222
|
-
'JSXNamespacedName',
|
|
18223
|
-
'JSXOpeningElement',
|
|
18224
|
-
'JSXOpeningFragment',
|
|
18225
|
-
'JSXSpreadAttribute',
|
|
18226
|
-
'JSXSpreadChild',
|
|
18227
|
-
'JSXText',
|
|
18228
|
-
'LabeledStatement',
|
|
18229
|
-
'Literal',
|
|
18230
|
-
'Literal',
|
|
18231
|
-
'Literal',
|
|
18232
|
-
'Literal',
|
|
18233
|
-
'Literal',
|
|
18234
|
-
'Literal',
|
|
18235
|
-
'LogicalExpression',
|
|
18236
|
-
'MemberExpression',
|
|
18237
|
-
'MetaProperty',
|
|
18238
|
-
'MethodDefinition',
|
|
18239
|
-
'NewExpression',
|
|
18240
|
-
'ObjectExpression',
|
|
18241
|
-
'ObjectPattern',
|
|
18242
|
-
'PrivateIdentifier',
|
|
18243
|
-
'Program',
|
|
18244
|
-
'Property',
|
|
18245
|
-
'PropertyDefinition',
|
|
18246
|
-
'RestElement',
|
|
18247
|
-
'ReturnStatement',
|
|
18248
|
-
'SequenceExpression',
|
|
18249
|
-
'SpreadElement',
|
|
18250
|
-
'StaticBlock',
|
|
18251
|
-
'Super',
|
|
18252
|
-
'SwitchCase',
|
|
18253
|
-
'SwitchStatement',
|
|
18254
|
-
'TaggedTemplateExpression',
|
|
18255
|
-
'TemplateElement',
|
|
18256
|
-
'TemplateLiteral',
|
|
18257
|
-
'ThisExpression',
|
|
18258
|
-
'ThrowStatement',
|
|
18259
|
-
'TryStatement',
|
|
18260
|
-
'UnaryExpression',
|
|
18261
|
-
'UpdateExpression',
|
|
18262
|
-
'VariableDeclaration',
|
|
18263
|
-
'VariableDeclarator',
|
|
18264
|
-
'WhileStatement',
|
|
18265
|
-
'YieldExpression'
|
|
18266
|
-
];
|
|
18267
|
-
const nodeConstructors$1 = [
|
|
18099
|
+
const nodeConstructors = [
|
|
18268
18100
|
PanicError,
|
|
18269
18101
|
ParseError,
|
|
18270
18102
|
ArrayExpression,
|
|
@@ -18611,8 +18443,11 @@ const bufferParsers = [
|
|
|
18611
18443
|
node.specifiers = convertNodeList(node, scope, buffer[position], buffer);
|
|
18612
18444
|
node.source = convertNode(node, scope, buffer[position + 1], buffer);
|
|
18613
18445
|
node.attributes = convertNodeList(node, scope, buffer[position + 2], buffer);
|
|
18614
|
-
const
|
|
18615
|
-
node.phase =
|
|
18446
|
+
const phasePosition = buffer[position + 3];
|
|
18447
|
+
node.phase =
|
|
18448
|
+
phasePosition === 0
|
|
18449
|
+
? undefined
|
|
18450
|
+
: parseAst_js.FIXED_STRINGS[buffer[position + 3]];
|
|
18616
18451
|
},
|
|
18617
18452
|
function importDefaultSpecifier(node, position, buffer) {
|
|
18618
18453
|
const { scope } = node;
|
|
@@ -18624,8 +18459,11 @@ const bufferParsers = [
|
|
|
18624
18459
|
node.sourceAstNode = parseAst_js.convertNode(buffer[position], buffer);
|
|
18625
18460
|
const optionsPosition = buffer[position + 1];
|
|
18626
18461
|
node.options = optionsPosition === 0 ? null : convertNode(node, scope, optionsPosition, buffer);
|
|
18627
|
-
const
|
|
18628
|
-
node.phase =
|
|
18462
|
+
const phasePosition = buffer[position + 2];
|
|
18463
|
+
node.phase =
|
|
18464
|
+
phasePosition === 0
|
|
18465
|
+
? undefined
|
|
18466
|
+
: parseAst_js.FIXED_STRINGS[buffer[position + 2]];
|
|
18629
18467
|
},
|
|
18630
18468
|
function importNamespaceSpecifier(node, position, buffer) {
|
|
18631
18469
|
const { scope } = node;
|
|
@@ -18727,7 +18565,7 @@ const bufferParsers = [
|
|
|
18727
18565
|
function literalNumber(node, position, buffer) {
|
|
18728
18566
|
const rawPosition = buffer[position];
|
|
18729
18567
|
node.raw = rawPosition === 0 ? undefined : buffer.convertString(rawPosition);
|
|
18730
|
-
node.value =
|
|
18568
|
+
node.value = buffer.convertFloat64(position + 1);
|
|
18731
18569
|
},
|
|
18732
18570
|
function literalRegExp(node, position, buffer) {
|
|
18733
18571
|
const flags = buffer.convertString(buffer[position]);
|
|
@@ -18856,7 +18694,7 @@ const bufferParsers = [
|
|
|
18856
18694
|
const flags = buffer[position];
|
|
18857
18695
|
node.tail = (flags & 1) === 1;
|
|
18858
18696
|
const cookedPosition = buffer[position + 1];
|
|
18859
|
-
const cooked = cookedPosition === 0 ?
|
|
18697
|
+
const cooked = cookedPosition === 0 ? undefined : buffer.convertString(cookedPosition);
|
|
18860
18698
|
const raw = buffer.convertString(buffer[position + 2]);
|
|
18861
18699
|
node.value = { cooked, raw };
|
|
18862
18700
|
},
|
|
@@ -18918,14 +18756,14 @@ const bufferParsers = [
|
|
|
18918
18756
|
];
|
|
18919
18757
|
function convertNode(parent, parentScope, position, buffer) {
|
|
18920
18758
|
const nodeType = buffer[position];
|
|
18921
|
-
const NodeConstructor = nodeConstructors
|
|
18759
|
+
const NodeConstructor = nodeConstructors[nodeType];
|
|
18922
18760
|
/* istanbul ignore if: This should never be executed but is a safeguard against faulty buffers */
|
|
18923
18761
|
if (!NodeConstructor) {
|
|
18924
18762
|
console.trace();
|
|
18925
18763
|
throw new Error(`Unknown node type: ${nodeType}`);
|
|
18926
18764
|
}
|
|
18927
18765
|
const node = new NodeConstructor(parent, parentScope);
|
|
18928
|
-
node.type = nodeTypeStrings[nodeType];
|
|
18766
|
+
node.type = parseAst_js.nodeTypeStrings[nodeType];
|
|
18929
18767
|
node.start = buffer[position + 1];
|
|
18930
18768
|
node.end = buffer[position + 2];
|
|
18931
18769
|
bufferParsers[nodeType](node, position + 3, buffer);
|
|
@@ -18944,110 +18782,6 @@ function convertNodeList(parent, parentScope, position, buffer) {
|
|
|
18944
18782
|
return list;
|
|
18945
18783
|
}
|
|
18946
18784
|
|
|
18947
|
-
class UnknownNode extends NodeBase {
|
|
18948
|
-
hasEffects() {
|
|
18949
|
-
return true;
|
|
18950
|
-
}
|
|
18951
|
-
include(context) {
|
|
18952
|
-
super.include(context, true);
|
|
18953
|
-
}
|
|
18954
|
-
}
|
|
18955
|
-
|
|
18956
|
-
// This file is generated by scripts/generate-node-index.js.
|
|
18957
|
-
// Do not edit this file directly.
|
|
18958
|
-
const nodeConstructors = {
|
|
18959
|
-
ArrayExpression,
|
|
18960
|
-
ArrayPattern,
|
|
18961
|
-
ArrowFunctionExpression,
|
|
18962
|
-
AssignmentExpression,
|
|
18963
|
-
AssignmentPattern,
|
|
18964
|
-
AwaitExpression,
|
|
18965
|
-
BinaryExpression,
|
|
18966
|
-
BlockStatement,
|
|
18967
|
-
BreakStatement,
|
|
18968
|
-
CallExpression,
|
|
18969
|
-
CatchClause,
|
|
18970
|
-
ChainExpression,
|
|
18971
|
-
ClassBody,
|
|
18972
|
-
ClassDeclaration,
|
|
18973
|
-
ClassExpression,
|
|
18974
|
-
ConditionalExpression,
|
|
18975
|
-
ContinueStatement,
|
|
18976
|
-
DebuggerStatement,
|
|
18977
|
-
Decorator,
|
|
18978
|
-
DoWhileStatement,
|
|
18979
|
-
EmptyStatement,
|
|
18980
|
-
ExportAllDeclaration,
|
|
18981
|
-
ExportDefaultDeclaration,
|
|
18982
|
-
ExportNamedDeclaration,
|
|
18983
|
-
ExportSpecifier,
|
|
18984
|
-
ExpressionStatement,
|
|
18985
|
-
ForInStatement,
|
|
18986
|
-
ForOfStatement,
|
|
18987
|
-
ForStatement,
|
|
18988
|
-
FunctionDeclaration,
|
|
18989
|
-
FunctionExpression,
|
|
18990
|
-
Identifier,
|
|
18991
|
-
IfStatement,
|
|
18992
|
-
ImportAttribute,
|
|
18993
|
-
ImportDeclaration,
|
|
18994
|
-
ImportDefaultSpecifier,
|
|
18995
|
-
ImportExpression,
|
|
18996
|
-
ImportNamespaceSpecifier,
|
|
18997
|
-
ImportSpecifier,
|
|
18998
|
-
JSXAttribute,
|
|
18999
|
-
JSXClosingElement,
|
|
19000
|
-
JSXClosingFragment,
|
|
19001
|
-
JSXElement,
|
|
19002
|
-
JSXEmptyExpression,
|
|
19003
|
-
JSXExpressionContainer,
|
|
19004
|
-
JSXFragment,
|
|
19005
|
-
JSXIdentifier,
|
|
19006
|
-
JSXMemberExpression,
|
|
19007
|
-
JSXNamespacedName,
|
|
19008
|
-
JSXOpeningElement,
|
|
19009
|
-
JSXOpeningFragment,
|
|
19010
|
-
JSXSpreadAttribute,
|
|
19011
|
-
JSXSpreadChild,
|
|
19012
|
-
JSXText,
|
|
19013
|
-
LabeledStatement,
|
|
19014
|
-
Literal,
|
|
19015
|
-
LogicalExpression,
|
|
19016
|
-
MemberExpression,
|
|
19017
|
-
MetaProperty,
|
|
19018
|
-
MethodDefinition,
|
|
19019
|
-
NewExpression,
|
|
19020
|
-
ObjectExpression,
|
|
19021
|
-
ObjectPattern,
|
|
19022
|
-
PanicError,
|
|
19023
|
-
ParseError,
|
|
19024
|
-
PrivateIdentifier,
|
|
19025
|
-
Program,
|
|
19026
|
-
Property,
|
|
19027
|
-
PropertyDefinition,
|
|
19028
|
-
RestElement,
|
|
19029
|
-
ReturnStatement,
|
|
19030
|
-
SequenceExpression,
|
|
19031
|
-
SpreadElement,
|
|
19032
|
-
StaticBlock,
|
|
19033
|
-
Super,
|
|
19034
|
-
SwitchCase,
|
|
19035
|
-
SwitchStatement,
|
|
19036
|
-
TaggedTemplateExpression,
|
|
19037
|
-
TemplateElement,
|
|
19038
|
-
TemplateLiteral,
|
|
19039
|
-
ThisExpression,
|
|
19040
|
-
ThrowStatement,
|
|
19041
|
-
TryStatement,
|
|
19042
|
-
UnaryExpression,
|
|
19043
|
-
UnknownNode,
|
|
19044
|
-
UpdateExpression,
|
|
19045
|
-
VariableDeclaration,
|
|
19046
|
-
VariableDeclarator,
|
|
19047
|
-
WhileStatement,
|
|
19048
|
-
YieldExpression
|
|
19049
|
-
};
|
|
19050
|
-
|
|
19051
18785
|
class ExportShimVariable extends Variable {
|
|
19052
18786
|
constructor(module) {
|
|
19053
18787
|
super(MISSING_EXPORT_SHIM_VARIABLE);
|
|
@@ -19379,10 +19113,12 @@ function getAndExtendSideEffectModules(variable, module) {
|
|
|
19379
19113
|
return sideEffectModules;
|
|
19380
19114
|
}
|
|
19381
19115
|
class Module {
|
|
19382
|
-
constructor(graph, id, options, isEntry, moduleSideEffects, syntheticNamedExports, meta, attributes) {
|
|
19116
|
+
constructor(graph, id, rawId, options, isEntry, moduleSideEffects, syntheticNamedExports, meta, attributes) {
|
|
19383
19117
|
this.graph = graph;
|
|
19384
19118
|
this.id = id;
|
|
19119
|
+
this.rawId = rawId;
|
|
19385
19120
|
this.options = options;
|
|
19121
|
+
this.attributes = attributes;
|
|
19386
19122
|
this.alternativeReexportModules = new Map();
|
|
19387
19123
|
this.chunkFileNames = new Set();
|
|
19388
19124
|
this.chunkNames = [];
|
|
@@ -19407,11 +19143,11 @@ class Module {
|
|
|
19407
19143
|
this.needsExportShim = false;
|
|
19408
19144
|
this.sideEffectDependenciesByVariable = new Map();
|
|
19409
19145
|
this.sourcePhaseSources = new Set();
|
|
19410
|
-
this.
|
|
19146
|
+
this.sourcesWithAttributesList = new Map();
|
|
19411
19147
|
this.allExportsIncluded = false;
|
|
19412
19148
|
this.ast = null;
|
|
19413
19149
|
this.exportAllModules = [];
|
|
19414
|
-
this.
|
|
19150
|
+
this.exportAllSourcesWithAttributesList = new Map();
|
|
19415
19151
|
this.exportDescriptions = new Map();
|
|
19416
19152
|
this.exportedVariablesByName = null;
|
|
19417
19153
|
this.exportNamesByVariable = null;
|
|
@@ -19428,7 +19164,7 @@ class Module {
|
|
|
19428
19164
|
this.preserveSignature = this.options.preserveEntrySignatures;
|
|
19429
19165
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
19430
19166
|
const module = this;
|
|
19431
|
-
const { dynamicImports, dynamicImporters,
|
|
19167
|
+
const { dynamicImports, dynamicImporters, exportAllSourcesWithAttributesList, exportDescriptions, implicitlyLoadedAfter, implicitlyLoadedBefore, importers, reexportDescriptions, sourcesWithAttributesList } = this;
|
|
19432
19168
|
this.info = {
|
|
19433
19169
|
ast: null,
|
|
19434
19170
|
attributes,
|
|
@@ -19448,11 +19184,13 @@ class Module {
|
|
|
19448
19184
|
},
|
|
19449
19185
|
get exportedBindings() {
|
|
19450
19186
|
const exportBindings = { '.': [...exportDescriptions.keys()] };
|
|
19451
|
-
for (const [name, { source }] of reexportDescriptions) {
|
|
19452
|
-
(exportBindings[source] ??= []).push(name);
|
|
19187
|
+
for (const [name, { source, attributes }] of reexportDescriptions) {
|
|
19188
|
+
(exportBindings[generateIdByRawIdAndAttributes(source, attributes)] ??= []).push(name);
|
|
19453
19189
|
}
|
|
19454
|
-
for (const source of
|
|
19455
|
-
(
|
|
19190
|
+
for (const [source, attributesList] of exportAllSourcesWithAttributesList) {
|
|
19191
|
+
for (const attributes of attributesList) {
|
|
19192
|
+
(exportBindings[generateIdByRawIdAndAttributes(source, attributes)] ??= []).push('*');
|
|
19193
|
+
}
|
|
19456
19194
|
}
|
|
19457
19195
|
return exportBindings;
|
|
19458
19196
|
},
|
|
@@ -19460,7 +19198,7 @@ class Module {
|
|
|
19460
19198
|
return [
|
|
19461
19199
|
...exportDescriptions.keys(),
|
|
19462
19200
|
...reexportDescriptions.keys(),
|
|
19463
|
-
...[...
|
|
19201
|
+
...[...exportAllSourcesWithAttributesList].map(() => '*')
|
|
19464
19202
|
];
|
|
19465
19203
|
},
|
|
19466
19204
|
get hasDefaultExport() {
|
|
@@ -19478,12 +19216,16 @@ class Module {
|
|
|
19478
19216
|
return Array.from(implicitlyLoadedBefore, getId).sort();
|
|
19479
19217
|
},
|
|
19480
19218
|
get importedIdResolutions() {
|
|
19481
|
-
return Array.from(
|
|
19219
|
+
return Array.from(sourcesWithAttributesList.entries(), ([source, attributesList]) => attributesList.map(attributes => module.resolvedIds[generateIdByRawIdAndAttributes(source, attributes)]))
|
|
19220
|
+
.flat()
|
|
19221
|
+
.filter(Boolean);
|
|
19482
19222
|
},
|
|
19483
19223
|
get importedIds() {
|
|
19484
19224
|
// We cannot use this.dependencies because this is needed before
|
|
19485
19225
|
// dependencies are populated
|
|
19486
|
-
return Array.from(
|
|
19226
|
+
return Array.from(sourcesWithAttributesList.entries(), ([source, attributesList]) => attributesList.map(attributes => module.resolvedIds[generateIdByRawIdAndAttributes(source, attributes)]?.id))
|
|
19227
|
+
.flat()
|
|
19228
|
+
.filter(Boolean);
|
|
19487
19229
|
},
|
|
19488
19230
|
get importers() {
|
|
19489
19231
|
return importers.sort();
|
|
@@ -19498,13 +19240,14 @@ class Module {
|
|
|
19498
19240
|
},
|
|
19499
19241
|
meta: { ...meta },
|
|
19500
19242
|
moduleSideEffects,
|
|
19243
|
+
rawId,
|
|
19501
19244
|
safeVariableNames: null,
|
|
19502
19245
|
syntheticNamedExports
|
|
19503
19246
|
};
|
|
19504
19247
|
}
|
|
19505
19248
|
basename() {
|
|
19506
|
-
const base =
|
|
19507
|
-
const extension =
|
|
19249
|
+
const base = sp.basename(this.id);
|
|
19250
|
+
const extension = sp.extname(this.id);
|
|
19508
19251
|
return makeLegal(extension ? base.slice(0, -extension.length) : base);
|
|
19509
19252
|
}
|
|
19510
19253
|
bindReferences() {
|
|
@@ -19806,17 +19549,25 @@ class Module {
|
|
|
19806
19549
|
this.importedFromNotTreeshaken ||
|
|
19807
19550
|
this.exportShimVariable.included));
|
|
19808
19551
|
}
|
|
19552
|
+
isEmitted() {
|
|
19553
|
+
return (this.isIncluded() ||
|
|
19554
|
+
this.info.isEntry ||
|
|
19555
|
+
this.includedDynamicImporters.length > 0 ||
|
|
19556
|
+
this.implicitlyLoadedAfter.size > 0);
|
|
19557
|
+
}
|
|
19809
19558
|
linkImports() {
|
|
19810
19559
|
this.addModulesToImportDescriptions(this.importDescriptions);
|
|
19811
19560
|
this.addModulesToImportDescriptions(this.reexportDescriptions);
|
|
19812
19561
|
const externalExportAllModules = [];
|
|
19813
|
-
for (const source of this.
|
|
19814
|
-
const
|
|
19815
|
-
|
|
19816
|
-
|
|
19817
|
-
|
|
19562
|
+
for (const [source, attributesList] of this.exportAllSourcesWithAttributesList) {
|
|
19563
|
+
for (const attributes of attributesList) {
|
|
19564
|
+
const module = this.graph.modulesById.get(this.resolvedIds[generateIdByRawIdAndAttributes(source, attributes)].id);
|
|
19565
|
+
if (module instanceof ExternalModule) {
|
|
19566
|
+
externalExportAllModules.push(module);
|
|
19567
|
+
continue;
|
|
19568
|
+
}
|
|
19569
|
+
this.exportAllModules.push(module);
|
|
19818
19570
|
}
|
|
19819
|
-
this.exportAllModules.push(module);
|
|
19820
19571
|
}
|
|
19821
19572
|
this.exportAllModules.push(...externalExportAllModules);
|
|
19822
19573
|
}
|
|
@@ -19835,7 +19586,7 @@ class Module {
|
|
|
19835
19586
|
}
|
|
19836
19587
|
return { indentExclusionRanges: this.indentExclusionRanges, source, usesTopLevelAwait };
|
|
19837
19588
|
}
|
|
19838
|
-
|
|
19589
|
+
setSource({ astBuffer, code, customTransformCache, originalCode, originalSourcemap, resolvedIds, sourcemapChain, transformDependencies, transformFiles, safeVariableNames, ...moduleOptions }) {
|
|
19839
19590
|
timeStart('generate ast', 3);
|
|
19840
19591
|
if (code.startsWith('#!')) {
|
|
19841
19592
|
const shebangEndPosition = code.indexOf('\n');
|
|
@@ -19878,7 +19629,6 @@ class Module {
|
|
|
19878
19629
|
getImportedJsxFactoryVariable: this.getImportedJsxFactoryVariable.bind(this),
|
|
19879
19630
|
getModuleExecIndex: () => this.execIndex,
|
|
19880
19631
|
getModuleName: this.basename.bind(this),
|
|
19881
|
-
getNodeConstructor: (name) => nodeConstructors[name] || nodeConstructors.UnknownNode,
|
|
19882
19632
|
importDescriptions: this.importDescriptions,
|
|
19883
19633
|
includeDynamicImport: this.includeDynamicImport.bind(this),
|
|
19884
19634
|
includeVariableInModule: this.includeVariableInModule.bind(this),
|
|
@@ -19896,46 +19646,21 @@ class Module {
|
|
|
19896
19646
|
};
|
|
19897
19647
|
this.scope = new ModuleScope(this.graph.scope, this.astContext, this.importDescriptions);
|
|
19898
19648
|
this.namespace = new NamespaceVariable(this.astContext);
|
|
19899
|
-
|
|
19900
|
-
|
|
19901
|
-
|
|
19902
|
-
|
|
19903
|
-
|
|
19904
|
-
|
|
19905
|
-
|
|
19906
|
-
|
|
19907
|
-
|
|
19908
|
-
|
|
19909
|
-
this.ast = convertProgram(astBuffer, programParent, this.scope);
|
|
19910
|
-
// Make lazy and apply LRU cache to not hog the memory
|
|
19911
|
-
Object.defineProperty(this.info, 'ast', {
|
|
19912
|
-
get: () => {
|
|
19913
|
-
if (this.graph.astLru.has(fileName)) {
|
|
19914
|
-
return this.graph.astLru.get(fileName);
|
|
19915
|
-
}
|
|
19916
|
-
else {
|
|
19917
|
-
const parsedAst = this.tryParse();
|
|
19918
|
-
// If the cache is not disabled, we need to keep the AST in memory
|
|
19919
|
-
// until the end when the cache is generated
|
|
19920
|
-
if (this.options.cache !== false) {
|
|
19921
|
-
Object.defineProperty(this.info, 'ast', {
|
|
19922
|
-
value: parsedAst
|
|
19923
|
-
});
|
|
19924
|
-
return parsedAst;
|
|
19925
|
-
}
|
|
19926
|
-
// Otherwise, we keep it in a small LRU cache to not hog too much
|
|
19927
|
-
// memory but allow the same AST to be requested several times.
|
|
19928
|
-
this.graph.astLru.set(fileName, parsedAst);
|
|
19929
|
-
return parsedAst;
|
|
19930
|
-
}
|
|
19931
|
-
}
|
|
19932
|
-
});
|
|
19933
|
-
}
|
|
19649
|
+
this.astBuffer = astBuffer;
|
|
19650
|
+
// When the AST is walked, this data structure will grow as getters are
|
|
19651
|
+
// replaced with fixed properties. By making this a getter, we avoid keeping
|
|
19652
|
+
// a reference to the full AST to conserve memory at the potential cost of
|
|
19653
|
+
// creating AST nodes repeatedly.
|
|
19654
|
+
Object.defineProperty(this.info, 'ast', {
|
|
19655
|
+
enumerable: true,
|
|
19656
|
+
get: () => this.tryParseLazy(this.astBuffer)
|
|
19657
|
+
});
|
|
19658
|
+
this.ast = convertProgram(this.astBuffer, null, this.scope);
|
|
19934
19659
|
timeEnd('generate ast', 3);
|
|
19935
19660
|
}
|
|
19936
19661
|
toJSON() {
|
|
19937
19662
|
return {
|
|
19938
|
-
|
|
19663
|
+
astBuffer: this.astBuffer,
|
|
19939
19664
|
attributes: this.info.attributes,
|
|
19940
19665
|
code: this.info.code,
|
|
19941
19666
|
customTransformCache: this.customTransformCache,
|
|
@@ -19945,6 +19670,7 @@ class Module {
|
|
|
19945
19670
|
moduleSideEffects: this.info.moduleSideEffects,
|
|
19946
19671
|
originalCode: this.originalCode,
|
|
19947
19672
|
originalSourcemap: this.originalSourcemap,
|
|
19673
|
+
rawId: this.rawId,
|
|
19948
19674
|
resolvedIds: this.resolvedIds,
|
|
19949
19675
|
safeVariableNames: this.info.safeVariableNames,
|
|
19950
19676
|
sourcemapChain: this.sourcemapChain,
|
|
@@ -19991,13 +19717,11 @@ class Module {
|
|
|
19991
19717
|
addDynamicImport(node) {
|
|
19992
19718
|
let argument = node.sourceAstNode;
|
|
19993
19719
|
if (argument.type === parseAst_js.TemplateLiteral) {
|
|
19994
|
-
if (argument.quasis.length === 1 &&
|
|
19995
|
-
typeof argument.quasis[0].value.cooked === 'string') {
|
|
19720
|
+
if (argument.quasis.length === 1 && typeof argument.quasis[0].value.cooked === 'string') {
|
|
19996
19721
|
argument = argument.quasis[0].value.cooked;
|
|
19997
19722
|
}
|
|
19998
19723
|
}
|
|
19999
|
-
else if (argument.type === parseAst_js.Literal &&
|
|
20000
|
-
typeof argument.value === 'string') {
|
|
19724
|
+
else if (argument.type === parseAst_js.Literal && typeof argument.value === 'string') {
|
|
20001
19725
|
argument = argument.value;
|
|
20002
19726
|
}
|
|
20003
19727
|
this.dynamicImports.push({ argument, id: null, node });
|
|
@@ -20024,6 +19748,7 @@ class Module {
|
|
|
20024
19748
|
const name = node.exported instanceof Literal ? node.exported.value : node.exported.name;
|
|
20025
19749
|
this.assertUniqueExportName(name, node.exported.start);
|
|
20026
19750
|
this.reexportDescriptions.set(name, {
|
|
19751
|
+
attributes: getAttributesFromImportExportDeclaration(node.attributes),
|
|
20027
19752
|
localName: '*',
|
|
20028
19753
|
module: null, // filled in later,
|
|
20029
19754
|
source,
|
|
@@ -20032,7 +19757,16 @@ class Module {
|
|
|
20032
19757
|
}
|
|
20033
19758
|
else {
|
|
20034
19759
|
// export * from './other'
|
|
20035
|
-
this.
|
|
19760
|
+
const existingAttributesList = this.exportAllSourcesWithAttributesList.get(source);
|
|
19761
|
+
const parsedAttributes = getAttributesFromImportExportDeclaration(node.attributes);
|
|
19762
|
+
if (existingAttributesList) {
|
|
19763
|
+
if (!existingAttributesList.find(attributes => !doAttributesDiffer(attributes, parsedAttributes))) {
|
|
19764
|
+
existingAttributesList.push(parsedAttributes);
|
|
19765
|
+
}
|
|
19766
|
+
}
|
|
19767
|
+
else {
|
|
19768
|
+
this.exportAllSourcesWithAttributesList.set(source, [parsedAttributes]);
|
|
19769
|
+
}
|
|
20036
19770
|
}
|
|
20037
19771
|
}
|
|
20038
19772
|
else if (node.source instanceof Literal) {
|
|
@@ -20043,6 +19777,7 @@ class Module {
|
|
|
20043
19777
|
const name = exported instanceof Literal ? exported.value : exported.name;
|
|
20044
19778
|
this.assertUniqueExportName(name, start);
|
|
20045
19779
|
this.reexportDescriptions.set(name, {
|
|
19780
|
+
attributes: getAttributesFromImportExportDeclaration(node.attributes),
|
|
20046
19781
|
localName: local instanceof Literal ? local.value : local.name,
|
|
20047
19782
|
module: null, // filled in later,
|
|
20048
19783
|
source,
|
|
@@ -20098,6 +19833,7 @@ class Module {
|
|
|
20098
19833
|
? specifier.imported.name
|
|
20099
19834
|
: specifier.imported.value;
|
|
20100
19835
|
this.importDescriptions.set(localName, {
|
|
19836
|
+
attributes: getAttributesFromImportExportDeclaration(node.attributes),
|
|
20101
19837
|
module: null, // filled in later
|
|
20102
19838
|
name,
|
|
20103
19839
|
phase: node.phase === 'source' ? 'source' : 'instance',
|
|
@@ -20107,8 +19843,8 @@ class Module {
|
|
|
20107
19843
|
}
|
|
20108
19844
|
}
|
|
20109
19845
|
addImportSource(importSource) {
|
|
20110
|
-
if (importSource && !this.
|
|
20111
|
-
this.
|
|
19846
|
+
if (importSource && !this.sourcesWithAttributesList.has(importSource)) {
|
|
19847
|
+
this.sourcesWithAttributesList.set(importSource, [parseAst_js.EMPTY_OBJECT]);
|
|
20112
19848
|
}
|
|
20113
19849
|
}
|
|
20114
19850
|
addImportMeta(node) {
|
|
@@ -20133,7 +19869,7 @@ class Module {
|
|
|
20133
19869
|
}
|
|
20134
19870
|
addModulesToImportDescriptions(importDescription) {
|
|
20135
19871
|
for (const specifier of importDescription.values()) {
|
|
20136
|
-
const { id } = this.resolvedIds[specifier.source];
|
|
19872
|
+
const { id } = this.resolvedIds[generateIdByRawIdAndAttributes(specifier.source, specifier.attributes)];
|
|
20137
19873
|
specifier.module = this.graph.modulesById.get(id);
|
|
20138
19874
|
}
|
|
20139
19875
|
}
|
|
@@ -20164,14 +19900,14 @@ class Module {
|
|
|
20164
19900
|
}
|
|
20165
19901
|
addSource(source, declaration) {
|
|
20166
19902
|
const parsedAttributes = getAttributesFromImportExportDeclaration(declaration.attributes);
|
|
20167
|
-
const
|
|
20168
|
-
if (
|
|
20169
|
-
if (doAttributesDiffer(
|
|
20170
|
-
|
|
19903
|
+
const existingAttributesList = this.sourcesWithAttributesList.get(source);
|
|
19904
|
+
if (existingAttributesList) {
|
|
19905
|
+
if (!existingAttributesList.some(attributes => !doAttributesDiffer(attributes, parsedAttributes))) {
|
|
19906
|
+
existingAttributesList.push(parsedAttributes);
|
|
20171
19907
|
}
|
|
20172
19908
|
}
|
|
20173
19909
|
else {
|
|
20174
|
-
this.
|
|
19910
|
+
this.sourcesWithAttributesList.set(source, [parsedAttributes]);
|
|
20175
19911
|
}
|
|
20176
19912
|
if (declaration.phase === 'source') {
|
|
20177
19913
|
this.sourcePhaseSources.add(source);
|
|
@@ -20305,9 +20041,9 @@ class Module {
|
|
|
20305
20041
|
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logShimmedExport(this.id, name));
|
|
20306
20042
|
this.exportDescriptions.set(name, MISSING_EXPORT_SHIM_DESCRIPTION);
|
|
20307
20043
|
}
|
|
20308
|
-
|
|
20044
|
+
tryParseLazy(astBuffer) {
|
|
20309
20045
|
try {
|
|
20310
|
-
return parseAst_js.
|
|
20046
|
+
return parseAst_js.deserializeLazyAst(astBuffer);
|
|
20311
20047
|
}
|
|
20312
20048
|
catch (error_) {
|
|
20313
20049
|
return this.error(parseAst_js.logModuleParseError(error_, this.id), error_.pos);
|
|
@@ -20638,9 +20374,13 @@ const NON_ASSET_EXTENSIONS = new Set([
|
|
|
20638
20374
|
'.cjs',
|
|
20639
20375
|
'.cts'
|
|
20640
20376
|
]);
|
|
20641
|
-
function getGlobalName(chunk, globals, hasExports, log) {
|
|
20642
|
-
const
|
|
20377
|
+
function getGlobalName(chunk, globals, hasExports, boundVariantsByRawId, log) {
|
|
20378
|
+
const { attributes, rawId } = chunk.moduleInfo;
|
|
20379
|
+
const globalName = typeof globals === 'function' ? globals(rawId, { attributes }) : globals[rawId];
|
|
20643
20380
|
if (globalName) {
|
|
20381
|
+
if (hasExports && typeof globals === 'object') {
|
|
20382
|
+
warnIfAmbiguousGlobalName(rawId, globalName, boundVariantsByRawId, log);
|
|
20383
|
+
}
|
|
20644
20384
|
return globalName;
|
|
20645
20385
|
}
|
|
20646
20386
|
if (hasExports) {
|
|
@@ -20648,6 +20388,13 @@ function getGlobalName(chunk, globals, hasExports, log) {
|
|
|
20648
20388
|
return chunk.variableName;
|
|
20649
20389
|
}
|
|
20650
20390
|
}
|
|
20391
|
+
function warnIfAmbiguousGlobalName(rawId, globalName, boundVariantsByRawId, log) {
|
|
20392
|
+
const boundVariants = boundVariantsByRawId.get(rawId) ?? 0;
|
|
20393
|
+
if (boundVariants === 1) {
|
|
20394
|
+
log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logAmbiguousGlobalName(rawId, globalName));
|
|
20395
|
+
}
|
|
20396
|
+
boundVariantsByRawId.set(rawId, boundVariants + 1);
|
|
20397
|
+
}
|
|
20651
20398
|
class Chunk {
|
|
20652
20399
|
constructor(orderedModules, inputOptions, outputOptions, unsetOptions, pluginDriver, modulesById, chunkByModule, externalChunkByModule, facadeChunkByModule, includedNamespaces, manualChunkAlias, getPlaceholder, bundle, inputBase, snippets) {
|
|
20653
20400
|
this.orderedModules = orderedModules;
|
|
@@ -20939,7 +20686,7 @@ class Chunk {
|
|
|
20939
20686
|
let hashPlaceholder = null;
|
|
20940
20687
|
const { chunkFileNames, entryFileNames, file, format, preserveModules } = this.outputOptions;
|
|
20941
20688
|
if (file) {
|
|
20942
|
-
fileName =
|
|
20689
|
+
fileName = sp.basename(file);
|
|
20943
20690
|
}
|
|
20944
20691
|
else if (this.fileName === null) {
|
|
20945
20692
|
const [pattern, patternName] = preserveModules || this.facadeModule?.isUserDefinedEntryPoint
|
|
@@ -21402,7 +21149,9 @@ class Chunk {
|
|
|
21402
21149
|
const { dynamicEntryModules, facadeModule, implicitEntryModules, orderedModules } = this;
|
|
21403
21150
|
return (this.preRenderedChunkInfo = {
|
|
21404
21151
|
exports: this.getExportNames(),
|
|
21152
|
+
facadeModuleAttributes: facadeModule ? facadeModule.info.attributes : {},
|
|
21405
21153
|
facadeModuleId: facadeModule && facadeModule.id,
|
|
21154
|
+
facadeModuleRawId: facadeModule ? facadeModule.info.rawId : null,
|
|
21406
21155
|
isDynamicEntry: dynamicEntryModules.length > 0,
|
|
21407
21156
|
isEntry: !!facadeModule?.info.isEntry,
|
|
21408
21157
|
isImplicitEntry: implicitEntryModules.length > 0,
|
|
@@ -21421,12 +21170,12 @@ class Chunk {
|
|
|
21421
21170
|
// comparing paths; otherwise ids containing sanitized characters escape the
|
|
21422
21171
|
// base via "../" and trip the placeholder validation (#5446).
|
|
21423
21172
|
const sanitizedBase = sanitizeFileName(this.inputBase);
|
|
21424
|
-
const extensionName =
|
|
21173
|
+
const extensionName = sp.extname(sanitizedId);
|
|
21425
21174
|
const idWithoutExtension = NON_ASSET_EXTENSIONS.has(extensionName)
|
|
21426
21175
|
? sanitizedId.slice(0, -extensionName.length)
|
|
21427
21176
|
: sanitizedId;
|
|
21428
21177
|
if (parseAst_js.isAbsolute(idWithoutExtension)) {
|
|
21429
|
-
if (preserveModulesRoot &&
|
|
21178
|
+
if (preserveModulesRoot && sp.resolve(idWithoutExtension).startsWith(preserveModulesRoot)) {
|
|
21430
21179
|
return idWithoutExtension.slice(preserveModulesRoot.length).replace(/^[/\\]/, '');
|
|
21431
21180
|
}
|
|
21432
21181
|
else {
|
|
@@ -21438,7 +21187,7 @@ class Chunk {
|
|
|
21438
21187
|
}
|
|
21439
21188
|
}
|
|
21440
21189
|
else {
|
|
21441
|
-
return (this.outputOptions.virtualDirname.replace(/\/$/, '') + '/' +
|
|
21190
|
+
return (this.outputOptions.virtualDirname.replace(/\/$/, '') + '/' + sp.basename(idWithoutExtension));
|
|
21442
21191
|
}
|
|
21443
21192
|
}
|
|
21444
21193
|
getReexportSpecifiers() {
|
|
@@ -21508,6 +21257,9 @@ class Chunk {
|
|
|
21508
21257
|
const reexportSpecifiers = this.getReexportSpecifiers();
|
|
21509
21258
|
const renderedDependencies = new Map();
|
|
21510
21259
|
const fileName = this.getFileName();
|
|
21260
|
+
const boundVariantsByRawId = this.outputOptions.format === 'iife' || this.outputOptions.format === 'umd'
|
|
21261
|
+
? new Map()
|
|
21262
|
+
: undefined;
|
|
21511
21263
|
for (const dependency of this.dependencies) {
|
|
21512
21264
|
const imports = importSpecifiers.get(dependency) || null;
|
|
21513
21265
|
const reexports = reexportSpecifiers.get(dependency) || null;
|
|
@@ -21523,31 +21275,32 @@ class Chunk {
|
|
|
21523
21275
|
// side effect import, see https://github.com/rollup/rollup/issues/6111
|
|
21524
21276
|
continue;
|
|
21525
21277
|
}
|
|
21526
|
-
|
|
21527
|
-
const importPath = dependency.getImportPath(fileName);
|
|
21528
|
-
// Separate source-phase imports from regular imports
|
|
21529
|
-
const sourcePhaseImport = imports?.find(index => index.phase === 'source');
|
|
21530
|
-
const instanceImports = imports?.filter(index => index.phase !== 'source') ?? null;
|
|
21531
|
-
renderedDependencies.set(dependency, {
|
|
21532
|
-
attributes: dependency instanceof ExternalChunk
|
|
21533
|
-
? dependency.getImportAttributes(this.snippets)
|
|
21534
|
-
: null,
|
|
21535
|
-
defaultVariableName: dependency.defaultVariableName,
|
|
21536
|
-
globalName: dependency instanceof ExternalChunk &&
|
|
21537
|
-
(this.outputOptions.format === 'umd' || this.outputOptions.format === 'iife') &&
|
|
21538
|
-
getGlobalName(dependency, this.outputOptions.globals, (imports || reexports) !== null, this.inputOptions.onLog),
|
|
21539
|
-
importPath,
|
|
21540
|
-
imports: instanceImports && instanceImports.length > 0 ? instanceImports : null,
|
|
21541
|
-
isChunk: dependency instanceof Chunk,
|
|
21542
|
-
name: dependency.variableName,
|
|
21543
|
-
namedExportsMode,
|
|
21544
|
-
namespaceVariableName: dependency.namespaceVariableName,
|
|
21545
|
-
reexports,
|
|
21546
|
-
sourcePhaseImport: sourcePhaseImport?.local
|
|
21547
|
-
});
|
|
21278
|
+
renderedDependencies.set(dependency, this.getRenderedDependency(dependency, imports, reexports, fileName, boundVariantsByRawId));
|
|
21548
21279
|
}
|
|
21549
21280
|
return (this.renderedDependencies = renderedDependencies);
|
|
21550
21281
|
}
|
|
21282
|
+
getRenderedDependency(dependency, imports, reexports, fileName, boundVariantsByRawId) {
|
|
21283
|
+
const namedExportsMode = dependency instanceof ExternalChunk || dependency.exportMode !== 'default';
|
|
21284
|
+
const importPath = dependency.getImportPath(fileName);
|
|
21285
|
+
// Separate source-phase imports from regular imports
|
|
21286
|
+
const sourcePhaseImport = imports?.find(index => index.phase === 'source');
|
|
21287
|
+
const instanceImports = imports?.filter(index => index.phase !== 'source') ?? null;
|
|
21288
|
+
return {
|
|
21289
|
+
attributes: dependency instanceof ExternalChunk ? dependency.getImportAttributes(this.snippets) : null,
|
|
21290
|
+
defaultVariableName: dependency.defaultVariableName,
|
|
21291
|
+
globalName: boundVariantsByRawId &&
|
|
21292
|
+
dependency instanceof ExternalChunk &&
|
|
21293
|
+
getGlobalName(dependency, this.outputOptions.globals, (imports || reexports) !== null, boundVariantsByRawId, this.inputOptions.onLog),
|
|
21294
|
+
importPath,
|
|
21295
|
+
imports: instanceImports && instanceImports.length > 0 ? instanceImports : null,
|
|
21296
|
+
isChunk: dependency instanceof Chunk,
|
|
21297
|
+
name: dependency.variableName,
|
|
21298
|
+
namedExportsMode,
|
|
21299
|
+
namespaceVariableName: dependency.namespaceVariableName,
|
|
21300
|
+
reexports,
|
|
21301
|
+
sourcePhaseImport: sourcePhaseImport?.local
|
|
21302
|
+
};
|
|
21303
|
+
}
|
|
21551
21304
|
inlineChunkDependencies(chunk) {
|
|
21552
21305
|
for (const dependency of chunk.dependencies) {
|
|
21553
21306
|
if (this.dependencies.has(dependency))
|
|
@@ -21623,10 +21376,12 @@ class Chunk {
|
|
|
21623
21376
|
}
|
|
21624
21377
|
const { renderedExports, removedExports } = module.getRenderedExports();
|
|
21625
21378
|
renderedModules[module.id] = {
|
|
21379
|
+
attributes: module.info.attributes,
|
|
21626
21380
|
get code() {
|
|
21627
21381
|
return source?.toString() ?? null;
|
|
21628
21382
|
},
|
|
21629
21383
|
originalLength: module.originalCode.length,
|
|
21384
|
+
rawId: module.info.rawId,
|
|
21630
21385
|
removedExports,
|
|
21631
21386
|
renderedExports,
|
|
21632
21387
|
renderedLength
|
|
@@ -21810,6 +21565,14 @@ function* concatLazy(iterables) {
|
|
|
21810
21565
|
* Then we group all modules with the same dependent entry points into chunks
|
|
21811
21566
|
* as those modules will always be loaded together.
|
|
21812
21567
|
*
|
|
21568
|
+
* Manual chunks act as additional entry points whose entry modules are the
|
|
21569
|
+
* set of their member modules. When analyzing the module graph, reaching one
|
|
21570
|
+
* member means reaching all members of that manual chunk, so all members
|
|
21571
|
+
* share the same dependent entries and each manual chunk forms exactly one
|
|
21572
|
+
* chunk. In entry mode (`onlyExplicitManualChunks: false`), that
|
|
21573
|
+
* chunk also takes over modules whose dependent entries match its own, while
|
|
21574
|
+
* in explicit mode nothing joins it.
|
|
21575
|
+
*
|
|
21813
21576
|
* One non-trivial optimization we can apply is that dynamic entries are
|
|
21814
21577
|
* different from static entries in so far as when a dynamic import occurs,
|
|
21815
21578
|
* some modules are already in memory. If some of these modules are also
|
|
@@ -21912,83 +21675,123 @@ function* concatLazy(iterables) {
|
|
|
21912
21675
|
* those chunks that are already loaded for that dynamic entry and create
|
|
21913
21676
|
* another round of chunks.
|
|
21914
21677
|
*/
|
|
21915
|
-
function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log,
|
|
21916
|
-
const {
|
|
21917
|
-
const
|
|
21678
|
+
function getChunkAssignments(entries, manualChunkAliasByEntry, minChunkSize, log, onlyExplicitManualChunks) {
|
|
21679
|
+
const { manualChunkByModule, manualChunks } = getManualChunkMemberships(manualChunkAliasByEntry, log);
|
|
21680
|
+
const manualChunkIndexByChunk = new Map();
|
|
21681
|
+
manualChunks.forEach((manualChunk, index) => {
|
|
21682
|
+
manualChunkIndexByChunk.set(manualChunk, entries.length + index);
|
|
21683
|
+
});
|
|
21684
|
+
const { entriesAndManualChunksCount, dependentEntriesByModule, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry } = analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualChunkIndexByChunk);
|
|
21685
|
+
const { modulesWithDependentEntries, topLevelAwaitingCycleSingletons } = getModulesWithDependentEntries(dependentEntriesByModule, manualChunkByModule);
|
|
21918
21686
|
// Each chunk is identified by its position in this array
|
|
21919
|
-
const chunkAtoms =
|
|
21687
|
+
const chunkAtoms = getChunkAtoms(modulesWithDependentEntries, onlyExplicitManualChunks);
|
|
21920
21688
|
const staticDependencyAtomsByEntry = getStaticDependencyAtomsByEntry(entriesAndManualChunksCount, chunkAtoms);
|
|
21921
21689
|
// Warning: This will consume dynamicallyDependentEntriesByDynamicEntry.
|
|
21922
21690
|
// If we no longer want this, we should make a copy here.
|
|
21923
21691
|
const alreadyLoadedAtomsByEntry = getAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByDynamicEntry, dynamicImportsByEntry, entriesAndManualChunksCount);
|
|
21924
21692
|
// Warning: This will consume dynamicallyDependentEntriesByAwaitedDynamicEntry.
|
|
21925
21693
|
const awaitedAlreadyLoadedAtomsByEntry = getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynamicallyDependentEntriesByAwaitedDynamicEntry, awaitedDynamicImportsByEntry, entriesAndManualChunksCount);
|
|
21694
|
+
// A manual chunk only behaves like a dynamic entry if its whole member atom
|
|
21695
|
+
// is not already loaded whenever any entry dynamically loads it. Otherwise
|
|
21696
|
+
// there is nothing to gain (and cycles could be created) and the manual
|
|
21697
|
+
// chunk keeps behaving like a static pseudo-entry.
|
|
21698
|
+
keepAlreadyLoadedManualChunksStatic(manualChunkIndexByChunk, chunkAtoms, alreadyLoadedAtomsByEntry);
|
|
21926
21699
|
// This mutates the dependentEntries in chunkAtoms
|
|
21927
21700
|
removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry, awaitedAlreadyLoadedAtomsByEntry);
|
|
21928
|
-
const { chunks, sideEffectAtoms, sizeByAtom } =
|
|
21929
|
-
|
|
21930
|
-
|
|
21931
|
-
modules
|
|
21932
|
-
|
|
21933
|
-
|
|
21934
|
-
}
|
|
21935
|
-
|
|
21936
|
-
|
|
21937
|
-
|
|
21701
|
+
const { chunks, sideEffectAtoms, sizeByAtom } = getChunksFromAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize, onlyExplicitManualChunks);
|
|
21702
|
+
return [
|
|
21703
|
+
...topLevelAwaitingCycleSingletons,
|
|
21704
|
+
...getOptimizedChunks(chunks, minChunkSize, sideEffectAtoms, sizeByAtom, log).map(({ alias, modules }) => ({
|
|
21705
|
+
alias,
|
|
21706
|
+
modules
|
|
21707
|
+
}))
|
|
21708
|
+
];
|
|
21709
|
+
}
|
|
21710
|
+
function getManualChunkMemberships(manualChunkAliasByEntry, log) {
|
|
21711
|
+
const modulesByAlias = Object.create(null);
|
|
21938
21712
|
const sortedEntriesWithAlias = [...manualChunkAliasByEntry].sort(([entryA], [entryB]) => entryA.execIndex - entryB.execIndex);
|
|
21939
21713
|
for (const [entry, alias] of sortedEntriesWithAlias) {
|
|
21940
|
-
|
|
21941
|
-
|
|
21942
|
-
|
|
21943
|
-
|
|
21944
|
-
|
|
21945
|
-
|
|
21714
|
+
(modulesByAlias[alias] ||= []).push(entry);
|
|
21715
|
+
}
|
|
21716
|
+
const manualChunks = [];
|
|
21717
|
+
const manualChunkByModule = new Map();
|
|
21718
|
+
for (const [alias, modules] of Object.entries(modulesByAlias)) {
|
|
21719
|
+
const includedModules = modules.filter(module => module.isEmitted());
|
|
21720
|
+
if (includedModules.length === 0) {
|
|
21721
|
+
log(parseAst_js.LOGLEVEL_WARN, parseAst_js.logEmptyManualChunk(alias));
|
|
21722
|
+
continue;
|
|
21946
21723
|
}
|
|
21947
|
-
|
|
21948
|
-
|
|
21949
|
-
|
|
21950
|
-
|
|
21951
|
-
const manualChunkModulesByModule = new Map();
|
|
21952
|
-
let index = 0;
|
|
21953
|
-
for (const [alias, modules] of manualChunks) {
|
|
21954
|
-
chunkDefinitions[index] = { alias, modules };
|
|
21955
|
-
manualChunkModules[index] = modules;
|
|
21956
|
-
for (const module of modules) {
|
|
21957
|
-
manualChunkModulesByModule.set(module, modules);
|
|
21724
|
+
const manualChunk = { alias, modules: includedModules };
|
|
21725
|
+
manualChunks.push(manualChunk);
|
|
21726
|
+
for (const module of includedModules) {
|
|
21727
|
+
manualChunkByModule.set(module, manualChunk);
|
|
21958
21728
|
}
|
|
21959
|
-
index++;
|
|
21960
21729
|
}
|
|
21961
|
-
return {
|
|
21730
|
+
return { manualChunkByModule, manualChunks };
|
|
21962
21731
|
}
|
|
21963
|
-
|
|
21964
|
-
|
|
21965
|
-
|
|
21966
|
-
|
|
21967
|
-
|
|
21968
|
-
|
|
21969
|
-
|
|
21970
|
-
|
|
21971
|
-
|
|
21732
|
+
/**
|
|
21733
|
+
* The keys are shared by both grouping stages. Non-members join a manual
|
|
21734
|
+
* chunk only in entry mode and only if exactly one manual chunk has their
|
|
21735
|
+
* signature.
|
|
21736
|
+
*/
|
|
21737
|
+
function getChunkKeys(aliasesWithDependentEntries, onlyExplicitManualChunks) {
|
|
21738
|
+
const signatureKeys = new Array(aliasesWithDependentEntries.length);
|
|
21739
|
+
// A value of null means that several manual chunks share this signature, so
|
|
21740
|
+
// no unambiguous alias can be assigned
|
|
21741
|
+
const uniqueAliasBySignatureKey = onlyExplicitManualChunks
|
|
21742
|
+
? null
|
|
21743
|
+
: new Map();
|
|
21744
|
+
for (const [index, { dependentEntries, alias }] of aliasesWithDependentEntries.entries()) {
|
|
21745
|
+
let signature = 0n;
|
|
21746
|
+
for (const entryIndex of dependentEntries) {
|
|
21747
|
+
signature |= 1n << BigInt(entryIndex);
|
|
21748
|
+
}
|
|
21749
|
+
const signatureKey = String(signature);
|
|
21750
|
+
signatureKeys[index] = signatureKey;
|
|
21751
|
+
if (uniqueAliasBySignatureKey && alias !== null) {
|
|
21752
|
+
const existingAlias = uniqueAliasBySignatureKey.get(signatureKey);
|
|
21753
|
+
uniqueAliasBySignatureKey.set(signatureKey, existingAlias === undefined || existingAlias === alias ? alias : null);
|
|
21972
21754
|
}
|
|
21973
21755
|
}
|
|
21756
|
+
// As there is exactly one manual chunk group per alias, manual chunk members
|
|
21757
|
+
// are identified by their alias alone
|
|
21758
|
+
return aliasesWithDependentEntries.map(({ alias }, index) => {
|
|
21759
|
+
const chunkAlias = alias ?? uniqueAliasBySignatureKey?.get(signatureKeys[index]) ?? null;
|
|
21760
|
+
return {
|
|
21761
|
+
alias: chunkAlias,
|
|
21762
|
+
key: chunkAlias === null ? signatureKeys[index] : `manual:${chunkAlias}`
|
|
21763
|
+
};
|
|
21764
|
+
});
|
|
21974
21765
|
}
|
|
21975
|
-
function analyzeModuleGraph(entries,
|
|
21766
|
+
function analyzeModuleGraph(entries, manualChunks, manualChunkByModule, manualChunkIndexByChunk) {
|
|
21976
21767
|
const dynamicEntryModules = new Set();
|
|
21977
21768
|
const awaitedDynamicEntryModules = new Set();
|
|
21978
21769
|
const dependentEntriesByModule = new Map();
|
|
21770
|
+
const manualChunkModules = manualChunks.map(chunk => chunk.modules);
|
|
21979
21771
|
const allEntriesSet = new Set(entries);
|
|
21772
|
+
for (const modules of manualChunkModules) {
|
|
21773
|
+
for (const module of modules) {
|
|
21774
|
+
allEntriesSet.add(module);
|
|
21775
|
+
}
|
|
21776
|
+
}
|
|
21980
21777
|
// Each entry is defined by its position in this array
|
|
21981
21778
|
const allEntriesAndManualChunks = entries.map(module => [module]).concat(manualChunkModules);
|
|
21982
21779
|
const dynamicImportModulesByEntry = new Array(allEntriesAndManualChunks.length);
|
|
21983
21780
|
const awaitedDynamicImportModulesByEntry = new Array(allEntriesAndManualChunks.length);
|
|
21781
|
+
const dynamicallyLoadedManualChunksByEntry = new Array(allEntriesAndManualChunks.length);
|
|
21782
|
+
const awaitedLoadedManualChunksByEntry = new Array(allEntriesAndManualChunks.length);
|
|
21984
21783
|
let entryOrManualChunkIndex = 0;
|
|
21985
21784
|
for (const currentEntryModules of allEntriesAndManualChunks) {
|
|
21986
21785
|
const dynamicImportsForCurrentEntry = new Set();
|
|
21987
21786
|
const awaitedDynamicImportsForCurrentEntry = new Set();
|
|
21988
|
-
const
|
|
21787
|
+
const dynamicManualChunksForCurrentEntry = new Set();
|
|
21788
|
+
const awaitedManualChunksForCurrentEntry = new Set();
|
|
21989
21789
|
dynamicImportModulesByEntry[entryOrManualChunkIndex] = dynamicImportsForCurrentEntry;
|
|
21990
21790
|
awaitedDynamicImportModulesByEntry[entryOrManualChunkIndex] =
|
|
21991
21791
|
awaitedDynamicImportsForCurrentEntry;
|
|
21792
|
+
dynamicallyLoadedManualChunksByEntry[entryOrManualChunkIndex] =
|
|
21793
|
+
dynamicManualChunksForCurrentEntry;
|
|
21794
|
+
awaitedLoadedManualChunksByEntry[entryOrManualChunkIndex] = awaitedManualChunksForCurrentEntry;
|
|
21992
21795
|
const staticDependencies = new Set(currentEntryModules);
|
|
21993
21796
|
let hasTopLevelAwait = false;
|
|
21994
21797
|
// If we have a very large manual chunk, tracking if it is already added to the dependencies will improve performance
|
|
@@ -21996,10 +21799,10 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
|
|
|
21996
21799
|
for (const module of staticDependencies) {
|
|
21997
21800
|
hasTopLevelAwait ||= module.hasTopLevelAwait();
|
|
21998
21801
|
getOrCreate(dependentEntriesByModule, module, (getNewSet)).add(entryOrManualChunkIndex);
|
|
21999
|
-
const
|
|
22000
|
-
if (
|
|
22001
|
-
addedManualChunks.add(
|
|
22002
|
-
for (const manualChunkMember of
|
|
21802
|
+
const manualChunk = manualChunkByModule.get(module);
|
|
21803
|
+
if (manualChunk && !addedManualChunks.has(manualChunk)) {
|
|
21804
|
+
addedManualChunks.add(manualChunk);
|
|
21805
|
+
for (const manualChunkMember of manualChunk.modules) {
|
|
22003
21806
|
staticDependencies.add(manualChunkMember);
|
|
22004
21807
|
}
|
|
22005
21808
|
}
|
|
@@ -22009,16 +21812,20 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
|
|
|
22009
21812
|
}
|
|
22010
21813
|
}
|
|
22011
21814
|
for (const { node: { resolution } } of module.dynamicImports) {
|
|
22012
|
-
if (resolution instanceof Module &&
|
|
22013
|
-
resolution.includedDynamicImporters.length > 0 &&
|
|
22014
|
-
(dynamicEntryModules.has(resolution) || !allEntriesSet.has(resolution))) {
|
|
22015
|
-
dynamicEntriesForCurrentEntry.add(resolution);
|
|
21815
|
+
if (resolution instanceof Module && resolution.includedDynamicImporters.length > 0) {
|
|
22016
21816
|
if (!allEntriesSet.has(resolution)) {
|
|
22017
21817
|
dynamicEntryModules.add(resolution);
|
|
22018
21818
|
allEntriesSet.add(resolution);
|
|
22019
21819
|
allEntriesAndManualChunks.push([resolution]);
|
|
22020
|
-
dynamicImportsForCurrentEntry.add(resolution);
|
|
22021
21820
|
}
|
|
21821
|
+
else if (!dynamicEntryModules.has(resolution)) {
|
|
21822
|
+
const manuallyLoadedChunk = manualChunkByModule.get(resolution);
|
|
21823
|
+
if (!manuallyLoadedChunk) {
|
|
21824
|
+
continue;
|
|
21825
|
+
}
|
|
21826
|
+
dynamicManualChunksForCurrentEntry.add(manuallyLoadedChunk);
|
|
21827
|
+
}
|
|
21828
|
+
dynamicImportsForCurrentEntry.add(resolution);
|
|
22022
21829
|
}
|
|
22023
21830
|
}
|
|
22024
21831
|
for (const dependency of module.implicitlyLoadedBefore) {
|
|
@@ -22027,18 +21834,35 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
|
|
|
22027
21834
|
allEntriesSet.add(dependency);
|
|
22028
21835
|
allEntriesAndManualChunks.push([dependency]);
|
|
22029
21836
|
}
|
|
21837
|
+
else {
|
|
21838
|
+
const manuallyLoadedChunk = manualChunkByModule.get(dependency);
|
|
21839
|
+
if (manuallyLoadedChunk) {
|
|
21840
|
+
dynamicManualChunksForCurrentEntry.add(manuallyLoadedChunk);
|
|
21841
|
+
dynamicImportsForCurrentEntry.add(dependency);
|
|
21842
|
+
}
|
|
21843
|
+
}
|
|
22030
21844
|
}
|
|
22031
21845
|
}
|
|
22032
|
-
// A dynamic import can be awaited indirectly through a static dependency
|
|
21846
|
+
// A dynamic import can be awaited indirectly through a static dependency:
|
|
21847
|
+
// if any module of this entry uses a top-level await, the entry may
|
|
21848
|
+
// still be evaluating when any of its dynamic imports runs, so all of
|
|
21849
|
+
// them are awaited. This includes manual chunks that are loaded
|
|
21850
|
+
// dynamically or implicitly, which behave like dynamic entries here.
|
|
22033
21851
|
if (hasTopLevelAwait) {
|
|
22034
|
-
for (const
|
|
22035
|
-
|
|
22036
|
-
|
|
21852
|
+
for (const dynamicImportTarget of dynamicImportsForCurrentEntry) {
|
|
21853
|
+
const manualChunk = manualChunkByModule.get(dynamicImportTarget);
|
|
21854
|
+
if (manualChunk) {
|
|
21855
|
+
awaitedManualChunksForCurrentEntry.add(manualChunk);
|
|
21856
|
+
}
|
|
21857
|
+
else {
|
|
21858
|
+
awaitedDynamicEntryModules.add(dynamicImportTarget);
|
|
21859
|
+
}
|
|
21860
|
+
awaitedDynamicImportsForCurrentEntry.add(dynamicImportTarget);
|
|
22037
21861
|
}
|
|
22038
21862
|
}
|
|
22039
21863
|
entryOrManualChunkIndex++;
|
|
22040
21864
|
}
|
|
22041
|
-
const { awaitedDynamicEntries, awaitedDynamicImportsByEntry, dynamicEntries, dynamicImportsByEntry } = getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry);
|
|
21865
|
+
const { awaitedDynamicEntries, awaitedDynamicImportsByEntry, dynamicEntries, dynamicImportsByEntry } = getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry, dynamicallyLoadedManualChunksByEntry, awaitedLoadedManualChunksByEntry, manualChunkIndexByChunk);
|
|
22042
21866
|
return {
|
|
22043
21867
|
awaitedDynamicImportsByEntry,
|
|
22044
21868
|
dependentEntriesByModule,
|
|
@@ -22048,12 +21872,14 @@ function analyzeModuleGraph(entries, manualChunkModules, manualChunkModulesByMod
|
|
|
22048
21872
|
entriesAndManualChunksCount: allEntriesAndManualChunks.length
|
|
22049
21873
|
};
|
|
22050
21874
|
}
|
|
22051
|
-
function getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry) {
|
|
21875
|
+
function getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynamicImportModulesByEntry, awaitedDynamicEntryModules, awaitedDynamicImportModulesByEntry, dynamicallyLoadedManualChunksByEntry, awaitedLoadedManualChunksByEntry, manualChunkIndexByChunk) {
|
|
22052
21876
|
const entryIndexByModule = new Map();
|
|
22053
21877
|
const dynamicEntries = new Set();
|
|
22054
21878
|
const awaitedDynamicEntries = new Set();
|
|
22055
21879
|
for (const [entryIndex, entryModules] of allEntriesAndManualChunks.entries()) {
|
|
22056
21880
|
for (const entryModule of entryModules) {
|
|
21881
|
+
// Manual chunk members and in particular members that are also static
|
|
21882
|
+
// entries map to their manual chunk for dynamic-edge bookkeeping
|
|
22057
21883
|
entryIndexByModule.set(entryModule, entryIndex);
|
|
22058
21884
|
if (dynamicEntryModules.has(entryModule)) {
|
|
22059
21885
|
dynamicEntries.add(entryIndex);
|
|
@@ -22063,6 +21889,16 @@ function getDynamicEntries(allEntriesAndManualChunks, dynamicEntryModules, dynam
|
|
|
22063
21889
|
}
|
|
22064
21890
|
}
|
|
22065
21891
|
}
|
|
21892
|
+
for (const dynamicallyLoadedManualChunks of dynamicallyLoadedManualChunksByEntry) {
|
|
21893
|
+
for (const manuallyLoadedChunk of dynamicallyLoadedManualChunks) {
|
|
21894
|
+
dynamicEntries.add(manualChunkIndexByChunk.get(manuallyLoadedChunk));
|
|
21895
|
+
}
|
|
21896
|
+
}
|
|
21897
|
+
for (const awaitedLoadedManualChunks of awaitedLoadedManualChunksByEntry) {
|
|
21898
|
+
for (const awaitedLoadedChunk of awaitedLoadedManualChunks) {
|
|
21899
|
+
awaitedDynamicEntries.add(manualChunkIndexByChunk.get(awaitedLoadedChunk));
|
|
21900
|
+
}
|
|
21901
|
+
}
|
|
22066
21902
|
const dynamicImportsByEntry = getDynamicImportsByEntry(dynamicImportModulesByEntry, entryIndexByModule);
|
|
22067
21903
|
const awaitedDynamicImportsByEntry = getDynamicImportsByEntry(awaitedDynamicImportModulesByEntry, entryIndexByModule);
|
|
22068
21904
|
return {
|
|
@@ -22118,33 +21954,34 @@ function getDynamicallyDependentEntriesByDynamicEntry(dependentEntriesByModule,
|
|
|
22118
21954
|
}
|
|
22119
21955
|
return dynamicallyDependentEntriesByDynamicEntry;
|
|
22120
21956
|
}
|
|
22121
|
-
function
|
|
21957
|
+
function getChunkAtoms(modulesWithDependentEntries, onlyExplicitManualChunks) {
|
|
21958
|
+
const chunkKeys = getChunkKeys(modulesWithDependentEntries, onlyExplicitManualChunks);
|
|
22122
21959
|
const chunkModules = Object.create(null);
|
|
22123
|
-
for (const { dependentEntries, module } of
|
|
22124
|
-
|
|
22125
|
-
|
|
22126
|
-
|
|
22127
|
-
}
|
|
22128
|
-
(chunkModules[String(chunkSignature)] ||= {
|
|
21960
|
+
for (const [index, { dependentEntries, module }] of modulesWithDependentEntries.entries()) {
|
|
21961
|
+
const { alias, key } = chunkKeys[index];
|
|
21962
|
+
(chunkModules[key] ||= {
|
|
21963
|
+
alias,
|
|
22129
21964
|
dependentEntries: new Set(dependentEntries),
|
|
22130
21965
|
modules: []
|
|
22131
21966
|
}).modules.push(module);
|
|
22132
21967
|
}
|
|
22133
21968
|
return Object.values(chunkModules);
|
|
22134
21969
|
}
|
|
22135
|
-
function
|
|
21970
|
+
function getModulesWithDependentEntries(dependentEntriesByModule, manualChunkByModule) {
|
|
21971
|
+
const modulesWithDependentEntries = [];
|
|
21972
|
+
const topLevelAwaitingCycleSingletons = [];
|
|
22136
21973
|
for (const [module, dependentEntries] of dependentEntriesByModule) {
|
|
22137
|
-
|
|
22138
|
-
|
|
22139
|
-
|
|
22140
|
-
|
|
22141
|
-
|
|
22142
|
-
|
|
22143
|
-
|
|
22144
|
-
}
|
|
22145
|
-
yield { dependentEntries, module };
|
|
21974
|
+
const alias = manualChunkByModule.get(module)?.alias ?? null;
|
|
21975
|
+
if (alias === null &&
|
|
21976
|
+
module.cycles.size > 0 &&
|
|
21977
|
+
module.includedTopLevelAwaitingDynamicImporters.size > 0) {
|
|
21978
|
+
topLevelAwaitingCycleSingletons.push({ alias: null, modules: [module] });
|
|
21979
|
+
}
|
|
21980
|
+
else {
|
|
21981
|
+
modulesWithDependentEntries.push({ alias, dependentEntries, module });
|
|
22146
21982
|
}
|
|
22147
21983
|
}
|
|
21984
|
+
return { modulesWithDependentEntries, topLevelAwaitingCycleSingletons };
|
|
22148
21985
|
}
|
|
22149
21986
|
function getStaticDependencyAtomsByEntry(entriesAndManualChunksCount, chunkAtoms) {
|
|
22150
21987
|
// The indices correspond to the indices in allEntries. The atoms correspond
|
|
@@ -22218,6 +22055,28 @@ function getAwaitedAlreadyLoadedAtomsByEntry(staticDependencyAtomsByEntry, dynam
|
|
|
22218
22055
|
}
|
|
22219
22056
|
return awaitedAlreadyLoadedAtomsByEntry;
|
|
22220
22057
|
}
|
|
22058
|
+
/**
|
|
22059
|
+
* Manual chunks whose member atom is already loaded in every context that
|
|
22060
|
+
* dynamically loads them must not be treated like dynamic entries as that
|
|
22061
|
+
* would only cause unnecessary chunk cycles. The all-or-nothing rule resets
|
|
22062
|
+
* their already loaded atoms so that pruning behaves exactly as if they were
|
|
22063
|
+
* static pseudo-entries.
|
|
22064
|
+
*/
|
|
22065
|
+
function keepAlreadyLoadedManualChunksStatic(manualChunkIndexByChunk, chunkAtoms, alreadyLoadedAtomsByEntry) {
|
|
22066
|
+
const memberAtomMaskByAlias = new Map();
|
|
22067
|
+
for (const [index, { alias }] of chunkAtoms.entries()) {
|
|
22068
|
+
if (alias !== null) {
|
|
22069
|
+
memberAtomMaskByAlias.set(alias, 1n << BigInt(index));
|
|
22070
|
+
}
|
|
22071
|
+
}
|
|
22072
|
+
for (const [manualChunk, manualChunkIndex] of manualChunkIndexByChunk) {
|
|
22073
|
+
const memberAtomMask = memberAtomMaskByAlias.get(manualChunk.alias);
|
|
22074
|
+
const alreadyLoadedAtoms = alreadyLoadedAtomsByEntry[manualChunkIndex];
|
|
22075
|
+
if (memberAtomMask !== undefined && (alreadyLoadedAtoms & memberAtomMask) === memberAtomMask) {
|
|
22076
|
+
alreadyLoadedAtomsByEntry[manualChunkIndex] = 0n;
|
|
22077
|
+
}
|
|
22078
|
+
}
|
|
22079
|
+
}
|
|
22221
22080
|
/**
|
|
22222
22081
|
* This removes all unnecessary dynamic entries from the dependentEntries in its
|
|
22223
22082
|
* first argument if a chunk is already loaded without that entry.
|
|
@@ -22237,25 +22096,25 @@ function removeUnnecessaryDependentEntries(chunkAtoms, alreadyLoadedAtomsByEntry
|
|
|
22237
22096
|
chunkMask <<= 1n;
|
|
22238
22097
|
}
|
|
22239
22098
|
}
|
|
22240
|
-
function
|
|
22241
|
-
const
|
|
22099
|
+
function getChunksFromAtoms(chunkAtoms, staticDependencyAtomsByEntry, alreadyLoadedAtomsByEntry, minChunkSize, onlyExplicitManualChunks) {
|
|
22100
|
+
const chunkKeys = getChunkKeys(chunkAtoms, onlyExplicitManualChunks);
|
|
22101
|
+
const chunksByKey = Object.create(null);
|
|
22242
22102
|
const chunkByModule = new Map();
|
|
22243
22103
|
const sizeByAtom = new Array(chunkAtoms.length);
|
|
22244
22104
|
let sideEffectAtoms = 0n;
|
|
22245
22105
|
let atomMask = 1n;
|
|
22246
|
-
|
|
22247
|
-
for (const { dependentEntries, modules } of chunkAtoms) {
|
|
22248
|
-
let chunkSignature = 0n;
|
|
22106
|
+
for (const [atomIndex, { dependentEntries, modules }] of chunkAtoms.entries()) {
|
|
22249
22107
|
let correlatedAtoms = -1n;
|
|
22250
22108
|
for (const entryIndex of dependentEntries) {
|
|
22251
|
-
chunkSignature |= 1n << BigInt(entryIndex);
|
|
22252
22109
|
// Correlated atoms are the atoms that are guaranteed to be loaded as
|
|
22253
22110
|
// well when a given atom is loaded. It is the intersection of the already
|
|
22254
22111
|
// loaded modules of each chunk merged with its static dependencies.
|
|
22255
22112
|
correlatedAtoms &=
|
|
22256
22113
|
staticDependencyAtomsByEntry[entryIndex] | alreadyLoadedAtomsByEntry[entryIndex];
|
|
22257
22114
|
}
|
|
22258
|
-
const
|
|
22115
|
+
const { alias, key } = chunkKeys[atomIndex];
|
|
22116
|
+
const chunk = (chunksByKey[key] ||= {
|
|
22117
|
+
alias,
|
|
22259
22118
|
containedAtoms: 0n,
|
|
22260
22119
|
correlatedAtoms,
|
|
22261
22120
|
dependencies: new Set(),
|
|
@@ -22281,14 +22140,14 @@ function getChunksWithSameDependentEntriesAndCorrelatedAtoms(chunkAtoms, staticD
|
|
|
22281
22140
|
if (!pure) {
|
|
22282
22141
|
sideEffectAtoms |= atomMask;
|
|
22283
22142
|
}
|
|
22284
|
-
sizeByAtom[
|
|
22143
|
+
sizeByAtom[atomIndex] = atomSize;
|
|
22285
22144
|
chunk.containedAtoms |= atomMask;
|
|
22286
22145
|
chunk.modules.push(...modules);
|
|
22287
22146
|
chunk.pure &&= pure;
|
|
22288
22147
|
chunk.size += atomSize;
|
|
22289
22148
|
atomMask <<= 1n;
|
|
22290
22149
|
}
|
|
22291
|
-
const chunks = Object.values(
|
|
22150
|
+
const chunks = Object.values(chunksByKey);
|
|
22292
22151
|
sideEffectAtoms |= addChunkDependenciesAndGetExternalSideEffectAtoms(chunks, chunkByModule, atomMask);
|
|
22293
22152
|
return { chunks, sideEffectAtoms, sizeByAtom };
|
|
22294
22153
|
}
|
|
@@ -22411,16 +22270,22 @@ function getOptimizedChunks(chunks, minChunkSize, sideEffectAtoms, sizeByAtom, l
|
|
|
22411
22270
|
}
|
|
22412
22271
|
mergeChunks(chunkPartition, minChunkSize, sideEffectAtoms, sizeByAtom);
|
|
22413
22272
|
if (minChunkSize > 1) {
|
|
22414
|
-
log('info', parseAst_js.logOptimizeChunkStatus(chunkPartition.small.size + chunkPartition.big.size, chunkPartition.small.size, 'After merging chunks'));
|
|
22273
|
+
log('info', parseAst_js.logOptimizeChunkStatus(chunkPartition.small.size + chunkPartition.big.size + chunkPartition.fixed.size, chunkPartition.small.size, 'After merging chunks'));
|
|
22415
22274
|
}
|
|
22416
22275
|
timeEnd('optimize chunks', 3);
|
|
22417
|
-
return [...chunkPartition.small, ...chunkPartition.big];
|
|
22276
|
+
return [...chunkPartition.small, ...chunkPartition.big, ...chunkPartition.fixed];
|
|
22418
22277
|
}
|
|
22419
22278
|
function getPartitionedChunks(chunks, minChunkSize) {
|
|
22420
22279
|
const smallChunks = [];
|
|
22421
22280
|
const bigChunks = [];
|
|
22281
|
+
const fixedChunks = [];
|
|
22422
22282
|
for (const chunk of chunks) {
|
|
22423
|
-
(chunk.
|
|
22283
|
+
if (chunk.alias !== null) {
|
|
22284
|
+
fixedChunks.push(chunk);
|
|
22285
|
+
}
|
|
22286
|
+
else {
|
|
22287
|
+
(chunk.size < minChunkSize ? smallChunks : bigChunks).push(chunk);
|
|
22288
|
+
}
|
|
22424
22289
|
}
|
|
22425
22290
|
if (smallChunks.length === 0) {
|
|
22426
22291
|
return null;
|
|
@@ -22429,6 +22294,7 @@ function getPartitionedChunks(chunks, minChunkSize) {
|
|
|
22429
22294
|
bigChunks.sort(compareChunkSize);
|
|
22430
22295
|
return {
|
|
22431
22296
|
big: new Set(bigChunks),
|
|
22297
|
+
fixed: new Set(fixedChunks),
|
|
22432
22298
|
small: new Set(smallChunks)
|
|
22433
22299
|
};
|
|
22434
22300
|
}
|
|
@@ -22552,7 +22418,7 @@ function commondir(files) {
|
|
|
22552
22418
|
if (files.length === 0)
|
|
22553
22419
|
return '/';
|
|
22554
22420
|
if (files.length === 1)
|
|
22555
|
-
return
|
|
22421
|
+
return sp.dirname(files[0]);
|
|
22556
22422
|
const commonSegments = files.slice(1).reduce((commonSegments, file) => {
|
|
22557
22423
|
const pathSegments = file.split(/\/+|\\+/);
|
|
22558
22424
|
let index;
|
|
@@ -22824,9 +22690,9 @@ function getCollapsedSourcemap(id, originalCode, originalSourcemap, sourcemapCha
|
|
|
22824
22690
|
if (originalSourcemap) {
|
|
22825
22691
|
const sources = originalSourcemap.sources;
|
|
22826
22692
|
const sourcesContent = originalSourcemap.sourcesContent || [];
|
|
22827
|
-
const directory =
|
|
22693
|
+
const directory = sp.dirname(id) || '.';
|
|
22828
22694
|
const sourceRoot = originalSourcemap.sourceRoot || '.';
|
|
22829
|
-
const baseSources = sources.map((source, index) => new Source(
|
|
22695
|
+
const baseSources = sources.map((source, index) => new Source(sp.resolve(directory, sourceRoot, source), sourcesContent[index]));
|
|
22830
22696
|
source = new Link(originalSourcemap, baseSources);
|
|
22831
22697
|
}
|
|
22832
22698
|
else {
|
|
@@ -22843,9 +22709,9 @@ function collapseSourcemaps(file, map, modules, bundleSourcemapChain, excludeCon
|
|
|
22843
22709
|
const source = bundleSourcemapChain.reduce(linkMap, link);
|
|
22844
22710
|
let { sources, sourcesContent, names, mappings } = source.traceMappings();
|
|
22845
22711
|
if (file) {
|
|
22846
|
-
const directory =
|
|
22847
|
-
sources = sources.map((source) =>
|
|
22848
|
-
file =
|
|
22712
|
+
const directory = sp.dirname(file);
|
|
22713
|
+
sources = sources.map((source) => sp.relative(directory, source));
|
|
22714
|
+
file = sp.basename(file);
|
|
22849
22715
|
}
|
|
22850
22716
|
for (const module of modules) {
|
|
22851
22717
|
resetSourcemapCache(module.originalSourcemap, module.sourcemapChain);
|
|
@@ -22924,11 +22790,11 @@ async function transformChunk(magicString, fileName, usedModules, chunkGraph, op
|
|
|
22924
22790
|
timeStart('sourcemaps', 3);
|
|
22925
22791
|
let resultingFile;
|
|
22926
22792
|
if (file)
|
|
22927
|
-
resultingFile =
|
|
22793
|
+
resultingFile = sp.resolve(sourcemapFile || file);
|
|
22928
22794
|
else if (dir)
|
|
22929
|
-
resultingFile =
|
|
22795
|
+
resultingFile = sp.resolve(dir, fileName);
|
|
22930
22796
|
else
|
|
22931
|
-
resultingFile =
|
|
22797
|
+
resultingFile = sp.resolve(fileName);
|
|
22932
22798
|
const decodedMap = magicString.generateDecodedMap({});
|
|
22933
22799
|
map = collapseSourcemaps(resultingFile, decodedMap, usedModules, sourcemapChain, sourcemapExcludeSources, log);
|
|
22934
22800
|
for (let sourcesIndex = 0; sourcesIndex < map.sources.length; ++sourcesIndex) {
|
|
@@ -23124,8 +22990,8 @@ function getSourceMapComment(fileName, map, sourcemap, sourcemapBaseUrl) {
|
|
|
23124
22990
|
const url = sourcemap === 'inline'
|
|
23125
22991
|
? map.toUrl()
|
|
23126
22992
|
: sourcemapBaseUrl
|
|
23127
|
-
? new URL(
|
|
23128
|
-
:
|
|
22993
|
+
? new URL(sp.basename(fileName), sourcemapBaseUrl).toString()
|
|
22994
|
+
: sp.basename(fileName);
|
|
23129
22995
|
return sourcemap === 'hidden' ? '' : `//# ${SOURCEMAPPING_URL}=${url}\n`;
|
|
23130
22996
|
}
|
|
23131
22997
|
function calculateDebugIdAndGetComment(code, map) {
|
|
@@ -23248,7 +23114,7 @@ class Bundle {
|
|
|
23248
23114
|
? [{ alias: null, modules: includedModules }]
|
|
23249
23115
|
: preserveModules
|
|
23250
23116
|
? includedModules.map(module => ({ alias: null, modules: [module] }))
|
|
23251
|
-
: getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize, this.inputOptions.onLog,
|
|
23117
|
+
: getChunkAssignments(this.graph.entryModules, manualChunkAliasByEntry, experimentalMinChunkSize, this.inputOptions.onLog, onlyExplicitManualChunks);
|
|
23252
23118
|
const chunks = new Array(executableModule.length);
|
|
23253
23119
|
const chunkByModule = new Map();
|
|
23254
23120
|
let index = 0;
|
|
@@ -23261,7 +23127,7 @@ class Bundle {
|
|
|
23261
23127
|
chunk.link();
|
|
23262
23128
|
}
|
|
23263
23129
|
if (!inlineDynamicImports && !preserveModules) {
|
|
23264
|
-
this.checkCircularChunks(chunks);
|
|
23130
|
+
this.checkCircularChunks(chunks, onlyExplicitManualChunks);
|
|
23265
23131
|
}
|
|
23266
23132
|
const facades = [];
|
|
23267
23133
|
for (const chunk of chunks) {
|
|
@@ -23269,23 +23135,29 @@ class Bundle {
|
|
|
23269
23135
|
}
|
|
23270
23136
|
return [...chunks, ...facades];
|
|
23271
23137
|
}
|
|
23272
|
-
checkCircularChunks(chunks) {
|
|
23138
|
+
checkCircularChunks(chunks, onlyExplicitManualChunks) {
|
|
23273
23139
|
const visited = new Set();
|
|
23274
23140
|
const parents = new Map();
|
|
23275
23141
|
const handleDependency = (chunk, parent) => {
|
|
23276
23142
|
if (parents.has(chunk)) {
|
|
23277
23143
|
if (!visited.has(chunk)) {
|
|
23278
23144
|
const path = [chunk.getChunkName()];
|
|
23279
|
-
|
|
23145
|
+
const cycleChunks = [chunk];
|
|
23280
23146
|
let nextChunk = parent;
|
|
23281
23147
|
while (nextChunk !== chunk && nextChunk) {
|
|
23282
23148
|
path.push(nextChunk.getChunkName());
|
|
23283
|
-
|
|
23149
|
+
cycleChunks.push(nextChunk);
|
|
23284
23150
|
nextChunk = parents.get(nextChunk);
|
|
23285
23151
|
}
|
|
23152
|
+
const manualChunkNames = cycleChunks
|
|
23153
|
+
.filter(cycleChunk => cycleChunk.isManualChunk)
|
|
23154
|
+
.map(cycleChunk => cycleChunk.getChunkName());
|
|
23155
|
+
const nonManualChunkName = cycleChunks
|
|
23156
|
+
.find(cycleChunk => !cycleChunk.isManualChunk)
|
|
23157
|
+
?.getChunkName();
|
|
23286
23158
|
path.push(path[0]);
|
|
23287
23159
|
path.reverse();
|
|
23288
|
-
this.inputOptions.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logCircularChunk(path,
|
|
23160
|
+
this.inputOptions.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logCircularChunk(path, manualChunkNames, nonManualChunkName, onlyExplicitManualChunks));
|
|
23289
23161
|
}
|
|
23290
23162
|
return;
|
|
23291
23163
|
}
|
|
@@ -23320,8 +23192,7 @@ function validateOptionsForMultiChunkOutput(outputOptions, log) {
|
|
|
23320
23192
|
function getIncludedModules(modulesById) {
|
|
23321
23193
|
const includedModules = [];
|
|
23322
23194
|
for (const module of modulesById.values()) {
|
|
23323
|
-
if (module instanceof Module &&
|
|
23324
|
-
(module.isIncluded() || module.info.isEntry || module.includedDynamicImporters.length > 0)) {
|
|
23195
|
+
if (module instanceof Module && module.isEmitted()) {
|
|
23325
23196
|
includedModules.push(module);
|
|
23326
23197
|
}
|
|
23327
23198
|
}
|
|
@@ -23355,7 +23226,7 @@ function addModuleToManualChunk(alias, module, manualChunkAliasByEntry) {
|
|
|
23355
23226
|
function isFileNameOutsideOutputDirectory(fileName) {
|
|
23356
23227
|
// Use join() to normalize ".." segments, then replace backslashes so the
|
|
23357
23228
|
// string checks below work identically on Windows and POSIX.
|
|
23358
|
-
const normalized =
|
|
23229
|
+
const normalized = sp.join(fileName).replaceAll('\\', '/');
|
|
23359
23230
|
return (normalized === '..' ||
|
|
23360
23231
|
normalized.startsWith('../') ||
|
|
23361
23232
|
normalized === '.' ||
|
|
@@ -23375,50 +23246,6 @@ function validateOutputBundleFileNames(bundle) {
|
|
|
23375
23246
|
}
|
|
23376
23247
|
}
|
|
23377
23248
|
|
|
23378
|
-
function flru (max) {
|
|
23379
|
-
var num, curr, prev;
|
|
23380
|
-
var limit = max;
|
|
23381
|
-
|
|
23382
|
-
function keep(key, value) {
|
|
23383
|
-
if (++num > limit) {
|
|
23384
|
-
prev = curr;
|
|
23385
|
-
reset(1);
|
|
23386
|
-
++num;
|
|
23387
|
-
}
|
|
23388
|
-
curr[key] = value;
|
|
23389
|
-
}
|
|
23390
|
-
|
|
23391
|
-
function reset(isPartial) {
|
|
23392
|
-
num = 0;
|
|
23393
|
-
curr = Object.create(null);
|
|
23394
|
-
isPartial || (prev=Object.create(null));
|
|
23395
|
-
}
|
|
23396
|
-
|
|
23397
|
-
reset();
|
|
23398
|
-
|
|
23399
|
-
return {
|
|
23400
|
-
clear: reset,
|
|
23401
|
-
has: function (key) {
|
|
23402
|
-
return curr[key] !== void 0 || prev[key] !== void 0;
|
|
23403
|
-
},
|
|
23404
|
-
get: function (key) {
|
|
23405
|
-
var val = curr[key];
|
|
23406
|
-
if (val !== void 0) return val;
|
|
23407
|
-
if ((val=prev[key]) !== void 0) {
|
|
23408
|
-
keep(key, val);
|
|
23409
|
-
return val;
|
|
23410
|
-
}
|
|
23411
|
-
},
|
|
23412
|
-
set: function (key, value) {
|
|
23413
|
-
if (curr[key] !== void 0) {
|
|
23414
|
-
curr[key] = value;
|
|
23415
|
-
} else {
|
|
23416
|
-
keep(key, value);
|
|
23417
|
-
}
|
|
23418
|
-
}
|
|
23419
|
-
};
|
|
23420
|
-
}
|
|
23421
|
-
|
|
23422
23249
|
class GlobalScope extends Scope {
|
|
23423
23250
|
constructor() {
|
|
23424
23251
|
super();
|
|
@@ -23435,7 +23262,7 @@ class GlobalScope extends Scope {
|
|
|
23435
23262
|
}
|
|
23436
23263
|
}
|
|
23437
23264
|
|
|
23438
|
-
function resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes) {
|
|
23265
|
+
function resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes, importerRawId, inputOptions) {
|
|
23439
23266
|
let skipped = null;
|
|
23440
23267
|
let replaceContext = null;
|
|
23441
23268
|
if (skip) {
|
|
@@ -23447,39 +23274,52 @@ function resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolve
|
|
|
23447
23274
|
}
|
|
23448
23275
|
replaceContext = (pluginContext, plugin) => ({
|
|
23449
23276
|
...pluginContext,
|
|
23450
|
-
resolve: (source, importer, { attributes, custom, isEntry, skipSelf
|
|
23277
|
+
resolve: (source, importer, { attributes, custom, importerAttributes: deprecatedImporterAttributes, isEntry, skipSelf } = parseAst_js.BLANK) => {
|
|
23451
23278
|
skipSelf ??= true;
|
|
23279
|
+
const { id: importerId, attributes: importerAttributes, rawId: importerRawId } = importer
|
|
23280
|
+
? getNormalizedImporter(importer, deprecatedImporterAttributes, plugin.name, inputOptions)
|
|
23281
|
+
: parseAst_js.BLANK;
|
|
23452
23282
|
if (skipSelf &&
|
|
23453
23283
|
skip.findIndex(skippedCall => {
|
|
23454
23284
|
return (skippedCall.plugin === plugin &&
|
|
23455
23285
|
skippedCall.source === source &&
|
|
23456
|
-
skippedCall.importer ===
|
|
23286
|
+
skippedCall.importer === importerId);
|
|
23457
23287
|
}) !== -1) {
|
|
23458
23288
|
// This means that the plugin recursively called itself
|
|
23459
23289
|
// Thus returning Promise.resolve(null) in purpose of fallback to default behavior of `resolveId` plugin hook.
|
|
23460
23290
|
return Promise.resolve(null);
|
|
23461
23291
|
}
|
|
23462
|
-
return moduleLoaderResolveId(source,
|
|
23292
|
+
return moduleLoaderResolveId(source, importerId, custom, isEntry, attributes || parseAst_js.EMPTY_OBJECT, importerAttributes || parseAst_js.EMPTY_OBJECT, importerRawId, skipSelf ? [...skip, { importer: importerId, plugin, source }] : skip);
|
|
23463
23293
|
}
|
|
23464
23294
|
});
|
|
23465
23295
|
}
|
|
23466
|
-
return pluginDriver.hookFirstAndGetPlugin('resolveId', [
|
|
23296
|
+
return pluginDriver.hookFirstAndGetPlugin('resolveId', [
|
|
23297
|
+
source,
|
|
23298
|
+
importer,
|
|
23299
|
+
{
|
|
23300
|
+
attributes,
|
|
23301
|
+
custom: customOptions,
|
|
23302
|
+
importerAttributes: importerAttributes || parseAst_js.EMPTY_OBJECT,
|
|
23303
|
+
importerRawId,
|
|
23304
|
+
isEntry
|
|
23305
|
+
}
|
|
23306
|
+
], replaceContext, skipped);
|
|
23467
23307
|
}
|
|
23468
23308
|
|
|
23469
|
-
async function resolveId(source, importer,
|
|
23470
|
-
const pluginResult = await resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes);
|
|
23309
|
+
async function resolveId(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes, importerRawId, inputOptions) {
|
|
23310
|
+
const pluginResult = await resolveIdViaPlugins(source, importer, pluginDriver, moduleLoaderResolveId, skip, customOptions, isEntry, attributes, importerAttributes, importerRawId, inputOptions);
|
|
23471
23311
|
if (pluginResult != null) {
|
|
23472
23312
|
const [resolveIdResult, plugin] = pluginResult;
|
|
23473
|
-
if (typeof resolveIdResult === '
|
|
23313
|
+
if (typeof resolveIdResult === 'string') {
|
|
23474
23314
|
return {
|
|
23475
|
-
|
|
23315
|
+
id: resolveIdResult,
|
|
23476
23316
|
resolvedBy: plugin.name
|
|
23477
23317
|
};
|
|
23478
23318
|
}
|
|
23479
|
-
if (typeof resolveIdResult === '
|
|
23319
|
+
if (typeof resolveIdResult === 'object') {
|
|
23480
23320
|
return {
|
|
23481
|
-
|
|
23482
|
-
resolvedBy: plugin.name
|
|
23321
|
+
...resolveIdResult,
|
|
23322
|
+
resolvedBy: resolveIdResult.resolvedBy || plugin.name
|
|
23483
23323
|
};
|
|
23484
23324
|
}
|
|
23485
23325
|
return resolveIdResult;
|
|
@@ -23492,7 +23332,7 @@ async function resolveId(source, importer, preserveSymlinks, pluginDriver, modul
|
|
|
23492
23332
|
// absolute path is created. Absolute importees therefore shortcircuit the
|
|
23493
23333
|
// resolve call and require no special handing on our part.
|
|
23494
23334
|
// See https://nodejs.org/api/path.html#path_path_resolve_paths
|
|
23495
|
-
return addJsExtensionIfNecessary(importer ?
|
|
23335
|
+
return addJsExtensionIfNecessary(importer ? sp.resolve(sp.dirname(importer), source) : sp.resolve(source), inputOptions.preserveSymlinks, inputOptions.fs);
|
|
23496
23336
|
}
|
|
23497
23337
|
async function addJsExtensionIfNecessary(file, preserveSymlinks, fs) {
|
|
23498
23338
|
return ((await findFile(file, preserveSymlinks, fs)) ??
|
|
@@ -23506,8 +23346,8 @@ async function findFile(file, preserveSymlinks, fs) {
|
|
|
23506
23346
|
return await findFile(await fs.realpath(file), preserveSymlinks, fs);
|
|
23507
23347
|
if ((preserveSymlinks && stats.isSymbolicLink()) || stats.isFile()) {
|
|
23508
23348
|
// check case
|
|
23509
|
-
const name =
|
|
23510
|
-
const files = await fs.readdir(
|
|
23349
|
+
const name = sp.basename(file);
|
|
23350
|
+
const files = await fs.readdir(sp.dirname(file));
|
|
23511
23351
|
if (files.includes(name))
|
|
23512
23352
|
return file;
|
|
23513
23353
|
}
|
|
@@ -23551,7 +23391,7 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
23551
23391
|
return previousCode;
|
|
23552
23392
|
}
|
|
23553
23393
|
if (result.attributes) {
|
|
23554
|
-
parseAst_js.warnDeprecation('Returning attributes from the "transform" hook is
|
|
23394
|
+
parseAst_js.warnDeprecation('Returning attributes from the "transform" hook is deprecated.', parseAst_js.URL_TRANSFORM, true, options);
|
|
23555
23395
|
}
|
|
23556
23396
|
({ code, map, ast } = result);
|
|
23557
23397
|
}
|
|
@@ -23583,7 +23423,8 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
23583
23423
|
currentSource,
|
|
23584
23424
|
id,
|
|
23585
23425
|
{
|
|
23586
|
-
attributes: module.info.attributes
|
|
23426
|
+
attributes: module.info.attributes,
|
|
23427
|
+
rawId: module.info.rawId
|
|
23587
23428
|
}
|
|
23588
23429
|
], transformReducer, (pluginContext, plugin) => {
|
|
23589
23430
|
pluginName = plugin.name;
|
|
@@ -23637,10 +23478,12 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
23637
23478
|
return parseAst_js.error(parseAst_js.logPluginError(error_, pluginName, { hook: 'transform', id }));
|
|
23638
23479
|
}
|
|
23639
23480
|
if (!customTransformCache && // files emitted by a transform hook need to be emitted again if the hook is skipped
|
|
23640
|
-
emittedFiles.length > 0)
|
|
23481
|
+
emittedFiles.length > 0) {
|
|
23641
23482
|
module.transformFiles = emittedFiles;
|
|
23483
|
+
}
|
|
23484
|
+
const astBuffer = ast ? parseAst_js.serializeAst(ast) : await native_js.parseAsync(code, false, options.jsx !== false);
|
|
23642
23485
|
return {
|
|
23643
|
-
|
|
23486
|
+
astBuffer,
|
|
23644
23487
|
code,
|
|
23645
23488
|
customTransformCache,
|
|
23646
23489
|
originalCode,
|
|
@@ -23664,20 +23507,24 @@ class ModuleLoader {
|
|
|
23664
23507
|
this.latestLoadModulesPromise = Promise.resolve();
|
|
23665
23508
|
this.moduleLoadPromises = new Map();
|
|
23666
23509
|
this.modulesWithLoadedDependencies = new Set();
|
|
23667
|
-
this.resolveId = async (source, importer, customOptions, isEntry, attributes, importerAttributes, skip = null) => this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(this.options.external(source, importer, false
|
|
23510
|
+
this.resolveId = async (source, importer, customOptions, isEntry, attributes, importerAttributes, importerRawId, skip = null) => this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(this.options.external(source, importer, false, {
|
|
23511
|
+
attributes,
|
|
23512
|
+
importerAttributes,
|
|
23513
|
+
importerRawId
|
|
23514
|
+
})
|
|
23668
23515
|
? false
|
|
23669
|
-
: await resolveId(source, importer, this.
|
|
23516
|
+
: await resolveId(source, importer, this.pluginDriver, this.resolveId, skip, customOptions, typeof isEntry === 'boolean' ? isEntry : !importer, attributes, importerAttributes, importerRawId, this.options), importer, source, attributes, importerAttributes, importerRawId), attributes);
|
|
23670
23517
|
this.hasModuleSideEffects = options.treeshake
|
|
23671
23518
|
? options.treeshake.moduleSideEffects
|
|
23672
23519
|
: () => true;
|
|
23673
23520
|
}
|
|
23674
23521
|
async addAdditionalModules(unresolvedModules, isAddForManualChunks) {
|
|
23675
|
-
const result = this.extendLoadModulesPromise(Promise.all(unresolvedModules.map(id => this.loadEntryModule(id, false, undefined, null, isAddForManualChunks
|
|
23522
|
+
const result = this.extendLoadModulesPromise(Promise.all(unresolvedModules.map(id => this.loadEntryModule(id, false, undefined, null, isAddForManualChunks))));
|
|
23676
23523
|
await this.awaitLoadModulesPromise();
|
|
23677
23524
|
return result;
|
|
23678
23525
|
}
|
|
23679
23526
|
async addEntryModules(unresolvedEntryModules, isUserDefined) {
|
|
23680
|
-
const newEntryModules = await this.extendLoadModulesPromise(Promise.all(unresolvedEntryModules.map(({ id, importer }) => this.loadEntryModule(id, true, importer, null, undefined,
|
|
23527
|
+
const newEntryModules = await this.extendLoadModulesPromise(Promise.all(unresolvedEntryModules.map(({ id, importer, attributes }) => this.loadEntryModule(id, true, importer, null, undefined, attributes))).then(entryModules => {
|
|
23681
23528
|
let shouldReorder = false;
|
|
23682
23529
|
for (const [index, entryModule] of entryModules.entries()) {
|
|
23683
23530
|
entryModule.isUserDefinedEntryPoint =
|
|
@@ -23701,11 +23548,12 @@ class ModuleLoader {
|
|
|
23701
23548
|
newEntryModules
|
|
23702
23549
|
};
|
|
23703
23550
|
}
|
|
23704
|
-
async emitChunk({ fileName, id, importer, name, implicitlyLoadedAfterOneOf, preserveSignature }) {
|
|
23551
|
+
async emitChunk({ fileName, id, importer, name, implicitlyLoadedAfterOneOf, preserveSignature, attributes }) {
|
|
23705
23552
|
const unresolvedModule = {
|
|
23553
|
+
attributes,
|
|
23706
23554
|
fileName: fileName || null,
|
|
23707
23555
|
id,
|
|
23708
|
-
importer,
|
|
23556
|
+
importer: importer && normalizeModuleId(importer),
|
|
23709
23557
|
name: name || null
|
|
23710
23558
|
};
|
|
23711
23559
|
const module = implicitlyLoadedAfterOneOf
|
|
@@ -23717,14 +23565,20 @@ class ModuleLoader {
|
|
|
23717
23565
|
return module;
|
|
23718
23566
|
}
|
|
23719
23567
|
async preloadModule(resolvedId) {
|
|
23720
|
-
const module = await this.fetchModule(
|
|
23568
|
+
const module = await this.fetchModule({
|
|
23569
|
+
...this.getResolvedIdWithDefaults(resolvedId, parseAst_js.EMPTY_OBJECT),
|
|
23570
|
+
rawId: resolvedId.rawId
|
|
23571
|
+
}, undefined, false, resolvedId.resolveDependencies ? RESOLVE_DEPENDENCIES : true);
|
|
23721
23572
|
return module.info;
|
|
23722
23573
|
}
|
|
23723
23574
|
addEntryWithImplicitDependants(unresolvedModule, implicitlyLoadedAfter) {
|
|
23724
|
-
return this.extendLoadModulesPromise(this.loadEntryModule(unresolvedModule.id, false, unresolvedModule.importer, null
|
|
23575
|
+
return this.extendLoadModulesPromise(this.loadEntryModule(unresolvedModule.id, false, unresolvedModule.importer, null).then(async (entryModule) => {
|
|
23725
23576
|
addChunkNamesToModule(entryModule, unresolvedModule, false);
|
|
23726
23577
|
if (!entryModule.info.isEntry) {
|
|
23727
|
-
const implicitlyLoadedAfterModules = await Promise.all(implicitlyLoadedAfter.map(id =>
|
|
23578
|
+
const implicitlyLoadedAfterModules = await Promise.all(implicitlyLoadedAfter.map(id => {
|
|
23579
|
+
const normalizedId = normalizeModuleIdToObject(id);
|
|
23580
|
+
return this.loadEntryModule(normalizedId.id, false, unresolvedModule.importer, entryModule.id, undefined, normalizedId.attributes);
|
|
23581
|
+
}));
|
|
23728
23582
|
// We need to check again if this is still an entry module as these
|
|
23729
23583
|
// changes need to be performed atomically to avoid race conditions
|
|
23730
23584
|
// if the same module is re-emitted as an entry module.
|
|
@@ -23748,16 +23602,16 @@ class ModuleLoader {
|
|
|
23748
23602
|
source = await this.graph.fileOperationQueue.run(async () => {
|
|
23749
23603
|
const content = await this.pluginDriver.hookFirst('load', [
|
|
23750
23604
|
id,
|
|
23751
|
-
{ attributes: module.info.attributes }
|
|
23605
|
+
{ attributes: module.info.attributes, rawId: module.info.rawId }
|
|
23752
23606
|
]);
|
|
23753
23607
|
if (content !== null) {
|
|
23754
23608
|
if (typeof content === 'object' && content.attributes) {
|
|
23755
|
-
parseAst_js.warnDeprecation('Returning attributes from the "load" hook is
|
|
23609
|
+
parseAst_js.warnDeprecation('Returning attributes from the "load" hook is deprecated.', parseAst_js.URL_LOAD, true, this.options);
|
|
23756
23610
|
}
|
|
23757
23611
|
return content;
|
|
23758
23612
|
}
|
|
23759
|
-
this.graph.watchFiles[
|
|
23760
|
-
return (await this.options.fs.readFile(
|
|
23613
|
+
this.graph.watchFiles[module.info.rawId] = true;
|
|
23614
|
+
return (await this.options.fs.readFile(module.info.rawId, { encoding: 'utf8' }));
|
|
23761
23615
|
});
|
|
23762
23616
|
}
|
|
23763
23617
|
catch (error_) {
|
|
@@ -23786,12 +23640,13 @@ class ModuleLoader {
|
|
|
23786
23640
|
module.updateOptions(cachedModule);
|
|
23787
23641
|
if (await this.pluginDriver.hookFirst('shouldTransformCachedModule', [
|
|
23788
23642
|
{
|
|
23789
|
-
ast: cachedModule.
|
|
23643
|
+
ast: parseAst_js.deserializeLazyAst(cachedModule.astBuffer),
|
|
23790
23644
|
attributes: cachedModule.attributes,
|
|
23791
23645
|
code: cachedModule.code,
|
|
23792
23646
|
id: cachedModule.id,
|
|
23793
23647
|
meta: cachedModule.meta,
|
|
23794
23648
|
moduleSideEffects: cachedModule.moduleSideEffects,
|
|
23649
|
+
rawId: cachedModule.rawId,
|
|
23795
23650
|
resolvedSources: cachedModule.resolvedIds,
|
|
23796
23651
|
syntheticNamedExports: cachedModule.syntheticNamedExports
|
|
23797
23652
|
}
|
|
@@ -23852,19 +23707,16 @@ class ModuleLoader {
|
|
|
23852
23707
|
// Otherwise, if the module does not exist, it waits for the module and all
|
|
23853
23708
|
// its dependencies to be loaded.
|
|
23854
23709
|
// Otherwise, it returns immediately.
|
|
23855
|
-
async fetchModule({ attributes, id, meta, moduleSideEffects, syntheticNamedExports }, importer, isEntry, isPreload) {
|
|
23710
|
+
async fetchModule({ attributes, id, rawId, meta, moduleSideEffects, syntheticNamedExports }, importer, isEntry, isPreload) {
|
|
23856
23711
|
const existingModule = this.modulesById.get(id);
|
|
23857
23712
|
if (existingModule instanceof Module) {
|
|
23858
|
-
if (importer && doAttributesDiffer(attributes, existingModule.info.attributes)) {
|
|
23859
|
-
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logInconsistentImportAttributes(existingModule.info.attributes, attributes, id, importer));
|
|
23860
|
-
}
|
|
23861
23713
|
await this.handleExistingModule(existingModule, isEntry, isPreload);
|
|
23862
23714
|
return existingModule;
|
|
23863
23715
|
}
|
|
23864
23716
|
if (existingModule instanceof ExternalModule) {
|
|
23865
23717
|
return parseAst_js.error(parseAst_js.logExternalModulesCannotBeTransformedToModules(existingModule.id));
|
|
23866
23718
|
}
|
|
23867
|
-
const module = new Module(this.graph, id, this.options, isEntry, moduleSideEffects, syntheticNamedExports, meta, attributes);
|
|
23719
|
+
const module = new Module(this.graph, id, rawId, this.options, isEntry, moduleSideEffects, syntheticNamedExports, meta, attributes);
|
|
23868
23720
|
this.modulesById.set(id, module);
|
|
23869
23721
|
const loadPromise = this.addModuleSource(id, importer, module).then(() => [
|
|
23870
23722
|
this.getResolveStaticDependencyPromises(module),
|
|
@@ -23900,18 +23752,15 @@ class ModuleLoader {
|
|
|
23900
23752
|
}
|
|
23901
23753
|
fetchResolvedDependency(source, importer, resolvedId) {
|
|
23902
23754
|
if (resolvedId.external) {
|
|
23903
|
-
const { attributes, external, id, moduleSideEffects, meta } = resolvedId;
|
|
23755
|
+
const { attributes, external, id, rawId, moduleSideEffects, meta } = resolvedId;
|
|
23904
23756
|
let externalModule = this.modulesById.get(id);
|
|
23905
23757
|
if (!externalModule) {
|
|
23906
|
-
externalModule = new ExternalModule(this.options, id, moduleSideEffects, meta, external !== 'absolute' && parseAst_js.isAbsolute(id), attributes);
|
|
23758
|
+
externalModule = new ExternalModule(this.options, id, rawId, moduleSideEffects, meta, external !== 'absolute' && parseAst_js.isAbsolute(id), attributes);
|
|
23907
23759
|
this.modulesById.set(id, externalModule);
|
|
23908
23760
|
}
|
|
23909
23761
|
else if (!(externalModule instanceof ExternalModule)) {
|
|
23910
23762
|
return parseAst_js.error(parseAst_js.logInternalIdCannotBeExternal(source, importer));
|
|
23911
23763
|
}
|
|
23912
|
-
else if (doAttributesDiffer(externalModule.info.attributes, attributes)) {
|
|
23913
|
-
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logInconsistentImportAttributes(externalModule.info.attributes, attributes, source, importer));
|
|
23914
|
-
}
|
|
23915
23764
|
return Promise.resolve(externalModule);
|
|
23916
23765
|
}
|
|
23917
23766
|
return this.fetchModule(resolvedId, importer, false, false);
|
|
@@ -23934,11 +23783,16 @@ class ModuleLoader {
|
|
|
23934
23783
|
}
|
|
23935
23784
|
}
|
|
23936
23785
|
}
|
|
23937
|
-
getNormalizedResolvedIdWithoutDefaults(resolveIdResult, importer, source) {
|
|
23786
|
+
getNormalizedResolvedIdWithoutDefaults(resolveIdResult, importer, source, attributes, importerAttributes, importerRawId) {
|
|
23938
23787
|
const { makeAbsoluteExternalsRelative } = this.options;
|
|
23939
23788
|
if (resolveIdResult) {
|
|
23940
23789
|
if (typeof resolveIdResult === 'object') {
|
|
23941
|
-
const external = resolveIdResult.external ||
|
|
23790
|
+
const external = resolveIdResult.external ||
|
|
23791
|
+
this.options.external(resolveIdResult.id, importer, true, {
|
|
23792
|
+
attributes: resolveIdResult.attributes || attributes,
|
|
23793
|
+
importerAttributes,
|
|
23794
|
+
importerRawId
|
|
23795
|
+
});
|
|
23942
23796
|
return {
|
|
23943
23797
|
...resolveIdResult,
|
|
23944
23798
|
external: external &&
|
|
@@ -23949,7 +23803,11 @@ class ModuleLoader {
|
|
|
23949
23803
|
'absolute')
|
|
23950
23804
|
};
|
|
23951
23805
|
}
|
|
23952
|
-
const external = this.options.external(resolveIdResult, importer, true
|
|
23806
|
+
const external = this.options.external(resolveIdResult, importer, true, {
|
|
23807
|
+
attributes,
|
|
23808
|
+
importerAttributes,
|
|
23809
|
+
importerRawId
|
|
23810
|
+
});
|
|
23953
23811
|
return {
|
|
23954
23812
|
external: external &&
|
|
23955
23813
|
(isNotAbsoluteExternal(resolveIdResult, source, makeAbsoluteExternalsRelative) ||
|
|
@@ -23962,7 +23820,12 @@ class ModuleLoader {
|
|
|
23962
23820
|
const id = makeAbsoluteExternalsRelative
|
|
23963
23821
|
? normalizeRelativeExternalId(source, importer)
|
|
23964
23822
|
: source;
|
|
23965
|
-
if (resolveIdResult !== false &&
|
|
23823
|
+
if (resolveIdResult !== false &&
|
|
23824
|
+
!this.options.external(id, importer, true, {
|
|
23825
|
+
attributes,
|
|
23826
|
+
importerAttributes,
|
|
23827
|
+
importerRawId
|
|
23828
|
+
})) {
|
|
23966
23829
|
return null;
|
|
23967
23830
|
}
|
|
23968
23831
|
return {
|
|
@@ -23975,6 +23838,7 @@ class ModuleLoader {
|
|
|
23975
23838
|
const resolvedId = await this.resolveDynamicImport(module, dynamicImport.argument, module.id, getAttributesFromImportExpression(dynamicImport.node));
|
|
23976
23839
|
if (!resolvedId || typeof resolvedId === 'string') {
|
|
23977
23840
|
dynamicImport.node.shouldIncludeDynamicAttributes = true;
|
|
23841
|
+
return [dynamicImport, resolvedId];
|
|
23978
23842
|
}
|
|
23979
23843
|
else {
|
|
23980
23844
|
dynamicImport.node.shouldIncludeDynamicAttributes = !!resolvedId.external;
|
|
@@ -23984,12 +23848,19 @@ class ModuleLoader {
|
|
|
23984
23848
|
});
|
|
23985
23849
|
}
|
|
23986
23850
|
getResolveStaticDependencyPromises(module) {
|
|
23987
|
-
return Array.from(module.
|
|
23988
|
-
source,
|
|
23989
|
-
(
|
|
23990
|
-
|
|
23991
|
-
|
|
23992
|
-
|
|
23851
|
+
return Array.from(module.sourcesWithAttributesList)
|
|
23852
|
+
.map(([source, attributesList]) => attributesList.map(attributes => [source, attributes]))
|
|
23853
|
+
.flat()
|
|
23854
|
+
.map(async ([source, attributes]) => {
|
|
23855
|
+
const id = generateIdByRawIdAndAttributes(source, attributes);
|
|
23856
|
+
const existingResolution = module.resolvedIds[id];
|
|
23857
|
+
if (existingResolution) {
|
|
23858
|
+
return [source, existingResolution];
|
|
23859
|
+
}
|
|
23860
|
+
const resolution = this.toModuleResolvedId(this.handleInvalidResolvedId(await this.resolveId(source, module.id, parseAst_js.EMPTY_OBJECT, false, attributes, module.info.attributes, module.info.rawId), source, module.id, attributes));
|
|
23861
|
+
module.resolvedIds[id] = resolution;
|
|
23862
|
+
return [source, resolution];
|
|
23863
|
+
});
|
|
23993
23864
|
}
|
|
23994
23865
|
getResolvedIdWithDefaults(resolvedId, attributes) {
|
|
23995
23866
|
if (!resolvedId) {
|
|
@@ -24046,30 +23917,42 @@ class ModuleLoader {
|
|
|
24046
23917
|
}
|
|
24047
23918
|
return resolvedId;
|
|
24048
23919
|
}
|
|
24049
|
-
async loadEntryModule(unresolvedId, isEntry, importer, implicitlyLoadedBefore, isLoadForManualChunks = false,
|
|
24050
|
-
const
|
|
23920
|
+
async loadEntryModule(unresolvedId, isEntry, importer, implicitlyLoadedBefore, isLoadForManualChunks = false, attributes = parseAst_js.EMPTY_OBJECT) {
|
|
23921
|
+
const implicitlyLoadedBeforeId = implicitlyLoadedBefore
|
|
23922
|
+
? normalizeModuleId(implicitlyLoadedBefore)
|
|
23923
|
+
: null;
|
|
23924
|
+
const { attributes: importerAttributes, rawId: importerRawId, id: importerId } = importer ? normalizeModuleIdToObject(importer) : parseAst_js.BLANK;
|
|
23925
|
+
const resolveIdResult = await resolveId(unresolvedId, importerId, this.pluginDriver, this.resolveId, null, parseAst_js.EMPTY_OBJECT, true, attributes, importerAttributes, importerRawId, this.options);
|
|
24051
23926
|
if (resolveIdResult == null) {
|
|
24052
|
-
return parseAst_js.error(
|
|
23927
|
+
return parseAst_js.error(implicitlyLoadedBeforeId === null
|
|
24053
23928
|
? parseAst_js.logUnresolvedEntry(unresolvedId)
|
|
24054
|
-
: parseAst_js.logUnresolvedImplicitDependant(unresolvedId,
|
|
23929
|
+
: parseAst_js.logUnresolvedImplicitDependant(unresolvedId, implicitlyLoadedBeforeId));
|
|
24055
23930
|
}
|
|
24056
23931
|
const isExternalModules = typeof resolveIdResult === 'object' && resolveIdResult.external;
|
|
24057
23932
|
if (resolveIdResult === false || isExternalModules) {
|
|
24058
|
-
return parseAst_js.error(
|
|
23933
|
+
return parseAst_js.error(implicitlyLoadedBeforeId === null
|
|
24059
23934
|
? isExternalModules && isLoadForManualChunks
|
|
24060
23935
|
? parseAst_js.logExternalModulesCannotBeIncludedInManualChunks(unresolvedId)
|
|
24061
23936
|
: parseAst_js.logEntryCannotBeExternal(unresolvedId)
|
|
24062
|
-
: parseAst_js.logImplicitDependantCannotBeExternal(unresolvedId,
|
|
23937
|
+
: parseAst_js.logImplicitDependantCannotBeExternal(unresolvedId, implicitlyLoadedBeforeId));
|
|
24063
23938
|
}
|
|
24064
|
-
return this.fetchModule(this.getResolvedIdWithDefaults(typeof resolveIdResult === 'object'
|
|
23939
|
+
return this.fetchModule(this.toModuleResolvedId(this.getResolvedIdWithDefaults(typeof resolveIdResult === 'object'
|
|
24065
23940
|
? resolveIdResult
|
|
24066
|
-
: { id: resolveIdResult },
|
|
23941
|
+
: { id: resolveIdResult }, attributes)), undefined, isEntry, false);
|
|
23942
|
+
}
|
|
23943
|
+
toModuleResolvedId(resolveIdResult) {
|
|
23944
|
+
const { id, attributes } = resolveIdResult;
|
|
23945
|
+
return {
|
|
23946
|
+
...resolveIdResult,
|
|
23947
|
+
id: generateIdByRawIdAndAttributes(id, attributes),
|
|
23948
|
+
rawId: id
|
|
23949
|
+
};
|
|
24067
23950
|
}
|
|
24068
23951
|
async resolveDynamicImport(module, specifier, importer, attributes) {
|
|
24069
23952
|
const resolution = await this.pluginDriver.hookFirst('resolveDynamicImport', [
|
|
24070
23953
|
specifier,
|
|
24071
23954
|
importer,
|
|
24072
|
-
{ attributes, importerAttributes: module.info.attributes }
|
|
23955
|
+
{ attributes, importerAttributes: module.info.attributes, importerRawId: module.info.rawId }
|
|
24073
23956
|
]);
|
|
24074
23957
|
if (typeof specifier !== 'string') {
|
|
24075
23958
|
if (typeof resolution === 'string') {
|
|
@@ -24078,26 +23961,26 @@ class ModuleLoader {
|
|
|
24078
23961
|
if (!resolution) {
|
|
24079
23962
|
return null;
|
|
24080
23963
|
}
|
|
24081
|
-
return this.getResolvedIdWithDefaults(resolution, attributes);
|
|
23964
|
+
return this.toModuleResolvedId(this.getResolvedIdWithDefaults(resolution, attributes));
|
|
24082
23965
|
}
|
|
24083
23966
|
if (resolution == null) {
|
|
24084
|
-
const
|
|
23967
|
+
const id = generateIdByRawIdAndAttributes(specifier, attributes);
|
|
23968
|
+
const existingResolution = module.resolvedIds[id];
|
|
24085
23969
|
if (existingResolution) {
|
|
24086
|
-
if (doAttributesDiffer(existingResolution.attributes, attributes)) {
|
|
24087
|
-
this.options.onLog(parseAst_js.LOGLEVEL_WARN, parseAst_js.logInconsistentImportAttributes(existingResolution.attributes, attributes, specifier, importer));
|
|
24088
|
-
}
|
|
24089
23970
|
return existingResolution;
|
|
24090
23971
|
}
|
|
24091
|
-
|
|
23972
|
+
const resolution = this.handleInvalidResolvedId(await this.resolveId(specifier, module.id, parseAst_js.EMPTY_OBJECT, false, attributes, module.info.attributes, module.info.rawId), specifier, module.id, attributes);
|
|
23973
|
+
module.resolvedIds[id] = this.toModuleResolvedId(resolution);
|
|
23974
|
+
return module.resolvedIds[id];
|
|
24092
23975
|
}
|
|
24093
|
-
return this.handleInvalidResolvedId(this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(resolution, importer, specifier), attributes), specifier, importer, attributes);
|
|
23976
|
+
return this.toModuleResolvedId(this.handleInvalidResolvedId(this.getResolvedIdWithDefaults(this.getNormalizedResolvedIdWithoutDefaults(resolution, importer, specifier, attributes, module.info.attributes, module.info.rawId), attributes), specifier, importer, attributes));
|
|
24094
23977
|
}
|
|
24095
23978
|
}
|
|
24096
23979
|
function normalizeRelativeExternalId(source, importer) {
|
|
24097
23980
|
return parseAst_js.isRelative(source)
|
|
24098
23981
|
? importer
|
|
24099
|
-
?
|
|
24100
|
-
:
|
|
23982
|
+
? sp.resolve(importer, '..', source)
|
|
23983
|
+
: sp.resolve(source)
|
|
24101
23984
|
: source;
|
|
24102
23985
|
}
|
|
24103
23986
|
function addChunkNamesToModule(module, { fileName, name }, isUserDefined) {
|
|
@@ -24171,7 +24054,6 @@ function normalizeEntryModules(entryModules) {
|
|
|
24171
24054
|
class Graph {
|
|
24172
24055
|
constructor(options, registerWatchHooks) {
|
|
24173
24056
|
this.options = options;
|
|
24174
|
-
this.astLru = flru(5);
|
|
24175
24057
|
this.cachedModules = new Map();
|
|
24176
24058
|
this.deoptimizationTracker = new EntityPathTracker();
|
|
24177
24059
|
this.entryModules = [];
|
|
@@ -24186,7 +24068,8 @@ class Graph {
|
|
|
24186
24068
|
this.implicitEntryModules = [];
|
|
24187
24069
|
this.modules = [];
|
|
24188
24070
|
this.getModuleInfo = (moduleId) => {
|
|
24189
|
-
const
|
|
24071
|
+
const normalizedModuleId = normalizeModuleId(moduleId);
|
|
24072
|
+
const foundModule = this.modulesById.get(normalizedModuleId);
|
|
24190
24073
|
if (!foundModule)
|
|
24191
24074
|
return null;
|
|
24192
24075
|
return foundModule.info;
|
|
@@ -24521,7 +24404,7 @@ const getModuleContext = (config, context) => {
|
|
|
24521
24404
|
if (configModuleContext) {
|
|
24522
24405
|
const contextByModuleId = Object.create(null);
|
|
24523
24406
|
for (const [key, moduleContext] of Object.entries(configModuleContext)) {
|
|
24524
|
-
contextByModuleId[
|
|
24407
|
+
contextByModuleId[sp.resolve(key)] = moduleContext;
|
|
24525
24408
|
}
|
|
24526
24409
|
return id => contextByModuleId[id] ?? context;
|
|
24527
24410
|
}
|
|
@@ -24612,7 +24495,7 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
|
|
|
24612
24495
|
globals: config.globals || {},
|
|
24613
24496
|
hashCharacters: config.hashCharacters ?? 'base64',
|
|
24614
24497
|
hoistTransitiveImports: config.hoistTransitiveImports ?? true,
|
|
24615
|
-
importAttributesKey: config
|
|
24498
|
+
importAttributesKey: getImportAttributesKey(config, inputOptions),
|
|
24616
24499
|
indent: getIndent(config, compact),
|
|
24617
24500
|
inlineDynamicImports,
|
|
24618
24501
|
interop: getInterop(config),
|
|
@@ -24621,7 +24504,7 @@ async function normalizeOutputOptions(config, inputOptions, unsetInputOptions) {
|
|
|
24621
24504
|
minifyInternalExports: getMinifyInternalExports(config, format, compact),
|
|
24622
24505
|
name: config.name,
|
|
24623
24506
|
noConflict: config.noConflict || false,
|
|
24624
|
-
onlyExplicitManualChunks: config.onlyExplicitManualChunks
|
|
24507
|
+
onlyExplicitManualChunks: config.onlyExplicitManualChunks ?? typeof config.manualChunks === 'function',
|
|
24625
24508
|
outro: getAddon(config, 'outro'),
|
|
24626
24509
|
paths: config.paths || {},
|
|
24627
24510
|
plugins: await normalizePluginOption(config.plugins),
|
|
@@ -24716,7 +24599,7 @@ const getPreserveModulesRoot = (config) => {
|
|
|
24716
24599
|
if (preserveModulesRoot === null || preserveModulesRoot === undefined) {
|
|
24717
24600
|
return undefined;
|
|
24718
24601
|
}
|
|
24719
|
-
return
|
|
24602
|
+
return sp.resolve(preserveModulesRoot);
|
|
24720
24603
|
};
|
|
24721
24604
|
const getAmd = (config) => {
|
|
24722
24605
|
const mergedOption = {
|
|
@@ -24793,6 +24676,12 @@ const getGeneratedCode = (config) => {
|
|
|
24793
24676
|
symbols: configWithPreset.symbols === true
|
|
24794
24677
|
};
|
|
24795
24678
|
};
|
|
24679
|
+
const getImportAttributesKey = (config, inputOptions) => {
|
|
24680
|
+
if (config.importAttributesKey != undefined) {
|
|
24681
|
+
parseAst_js.warnDeprecation(`The "output.importAttributesKey" option is deprecated and will be removed in a future version of Rollup. Only use it if you need to support environments that do not understand the "with" keyword.`, parseAst_js.URL_OUTPUT_IMPORTATTRIBUTESKEY, false, inputOptions);
|
|
24682
|
+
}
|
|
24683
|
+
return config.importAttributesKey ?? 'with';
|
|
24684
|
+
};
|
|
24796
24685
|
const getIndent = (config, compact) => {
|
|
24797
24686
|
if (compact) {
|
|
24798
24687
|
return '';
|
|
@@ -25038,9 +24927,9 @@ function getSortingFileType(file) {
|
|
|
25038
24927
|
return SortingFileType.SECONDARY_CHUNK;
|
|
25039
24928
|
}
|
|
25040
24929
|
async function writeOutputFile(outputFile, outputOptions, { fs: { mkdir, writeFile } }) {
|
|
25041
|
-
const fileName =
|
|
24930
|
+
const fileName = sp.resolve(outputOptions.dir || sp.dirname(outputOptions.file), outputFile.fileName);
|
|
25042
24931
|
// 'recursive: true' does not throw if the folder structure, or parts of it, already exist
|
|
25043
|
-
await mkdir(
|
|
24932
|
+
await mkdir(sp.dirname(fileName), { recursive: true });
|
|
25044
24933
|
return writeFile(fileName, outputFile.type === 'asset' ? outputFile.source : outputFile.code);
|
|
25045
24934
|
}
|
|
25046
24935
|
/**
|
|
@@ -25059,8 +24948,6 @@ exports.createFilter = createFilter;
|
|
|
25059
24948
|
exports.cyan = cyan;
|
|
25060
24949
|
exports.defineConfig = defineConfig;
|
|
25061
24950
|
exports.ensureArray = ensureArray$1;
|
|
25062
|
-
exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
25063
|
-
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
25064
24951
|
exports.getNewArray = getNewArray;
|
|
25065
24952
|
exports.getOrCreate = getOrCreate;
|
|
25066
24953
|
exports.gray = gray;
|