1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 | const MODULE_REFERENCE_REGEXP = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
|
11 |
|
12 | const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
|
13 | const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | class ConcatenationScope {
|
41 | |
42 |
|
43 |
|
44 |
|
45 | constructor(modulesMap, currentModule) {
|
46 | this._currentModule = currentModule;
|
47 | if (Array.isArray(modulesMap)) {
|
48 | const map = new Map();
|
49 | for (const info of modulesMap) {
|
50 | map.set(info.module, info);
|
51 | }
|
52 | modulesMap = map;
|
53 | }
|
54 | this._modulesMap = modulesMap;
|
55 | }
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 | isModuleInScope(module) {
|
62 | return this._modulesMap.has(module);
|
63 | }
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 | registerExport(exportName, symbol) {
|
71 | if (!this._currentModule.exportMap) {
|
72 | this._currentModule.exportMap = new Map();
|
73 | }
|
74 | if (!this._currentModule.exportMap.has(exportName)) {
|
75 | this._currentModule.exportMap.set(exportName, symbol);
|
76 | }
|
77 | }
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 | registerRawExport(exportName, expression) {
|
85 | if (!this._currentModule.rawExportMap) {
|
86 | this._currentModule.rawExportMap = new Map();
|
87 | }
|
88 | if (!this._currentModule.rawExportMap.has(exportName)) {
|
89 | this._currentModule.rawExportMap.set(exportName, expression);
|
90 | }
|
91 | }
|
92 |
|
93 | |
94 |
|
95 |
|
96 | registerNamespaceExport(symbol) {
|
97 | this._currentModule.namespaceExportSymbol = symbol;
|
98 | }
|
99 |
|
100 | |
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | createModuleReference(
|
107 | module,
|
108 | { ids = undefined, call = false, directImport = false, asiSafe = false }
|
109 | ) {
|
110 | const info = this._modulesMap.get(module);
|
111 | const callFlag = call ? "_call" : "";
|
112 | const directImportFlag = directImport ? "_directImport" : "";
|
113 | const asiSafeFlag = asiSafe
|
114 | ? "_asiSafe1"
|
115 | : asiSafe === false
|
116 | ? "_asiSafe0"
|
117 | : "";
|
118 | const exportData = ids
|
119 | ? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
|
120 | : "ns";
|
121 |
|
122 | return `__WEBPACK_MODULE_REFERENCE__${info.index}_${exportData}${callFlag}${directImportFlag}${asiSafeFlag}__._`;
|
123 | }
|
124 |
|
125 | |
126 |
|
127 |
|
128 |
|
129 | static isModuleReference(name) {
|
130 | return MODULE_REFERENCE_REGEXP.test(name);
|
131 | }
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 | static matchModuleReference(name) {
|
138 | const match = MODULE_REFERENCE_REGEXP.exec(name);
|
139 | if (!match) return null;
|
140 | const index = +match[1];
|
141 | const asiSafe = match[5];
|
142 | return {
|
143 | index,
|
144 | ids:
|
145 | match[2] === "ns"
|
146 | ? []
|
147 | : JSON.parse(Buffer.from(match[2], "hex").toString("utf-8")),
|
148 | call: !!match[3],
|
149 | directImport: !!match[4],
|
150 | asiSafe: asiSafe ? asiSafe === "1" : undefined
|
151 | };
|
152 | }
|
153 | }
|
154 |
|
155 | ConcatenationScope.DEFAULT_EXPORT = DEFAULT_EXPORT;
|
156 | ConcatenationScope.NAMESPACE_OBJECT_EXPORT = NAMESPACE_OBJECT_EXPORT;
|
157 |
|
158 | module.exports = ConcatenationScope;
|