@atlaspack/transformer-typescript-types 2.14.5-canary.24 → 2.14.5-canary.241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +239 -0
- package/dist/TSModule.js +40 -0
- package/dist/TSModuleGraph.js +233 -0
- package/dist/TSTypesTransformer.js +185 -0
- package/dist/collect.js +137 -0
- package/dist/shake.js +219 -0
- package/dist/utils.js +29 -0
- package/dist/wrappers.js +71 -0
- package/lib/TSModuleGraph.js +13 -0
- package/lib/TSTypesTransformer.js +6 -4
- package/lib/collect.js +28 -4
- package/lib/shake.js +24 -6
- package/lib/types/TSModule.d.ts +25 -0
- package/lib/types/TSModuleGraph.d.ts +33 -0
- package/lib/types/TSTypesTransformer.d.ts +3 -0
- package/lib/types/collect.d.ts +2 -0
- package/lib/types/shake.d.ts +2 -0
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/wrappers.d.ts +8 -0
- package/lib/utils.js +4 -0
- package/lib/wrappers.js +5 -4
- package/package.json +13 -9
- package/src/{TSModule.js → TSModule.ts} +13 -6
- package/src/{TSModuleGraph.js → TSModuleGraph.ts} +48 -9
- package/src/{TSTypesTransformer.js → TSTypesTransformer.ts} +10 -10
- package/src/{collect.js → collect.ts} +22 -5
- package/src/{shake.js → shake.ts} +19 -6
- package/src/{utils.js → utils.ts} +3 -2
- package/src/{wrappers.js → wrappers.ts} +95 -58
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,244 @@
|
|
|
1
1
|
# @atlaspack/transformer-typescript-types
|
|
2
2
|
|
|
3
|
+
## 2.14.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies []:
|
|
8
|
+
- @atlaspack/utils@3.0.2
|
|
9
|
+
- @atlaspack/plugin@2.14.34
|
|
10
|
+
- @atlaspack/ts-utils@2.14.13
|
|
11
|
+
|
|
12
|
+
## 2.14.33
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`236e546`](https://github.com/atlassian-labs/atlaspack/commit/236e5465863dca6044a7191e05260a5b924c342e)]:
|
|
17
|
+
- @atlaspack/utils@3.0.1
|
|
18
|
+
- @atlaspack/plugin@2.14.33
|
|
19
|
+
- @atlaspack/ts-utils@2.14.12
|
|
20
|
+
|
|
21
|
+
## 2.14.32
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933)]:
|
|
26
|
+
- @atlaspack/utils@3.0.0
|
|
27
|
+
- @atlaspack/plugin@2.14.32
|
|
28
|
+
- @atlaspack/ts-utils@2.14.11
|
|
29
|
+
|
|
30
|
+
## 2.14.31
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
|
|
35
|
+
|
|
36
|
+
- Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
|
|
37
|
+
- @atlaspack/diagnostic@2.14.4
|
|
38
|
+
- @atlaspack/plugin@2.14.31
|
|
39
|
+
- @atlaspack/utils@2.19.3
|
|
40
|
+
- @atlaspack/ts-utils@2.14.10
|
|
41
|
+
|
|
42
|
+
## 2.14.30
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies []:
|
|
47
|
+
- @atlaspack/utils@2.19.2
|
|
48
|
+
- @atlaspack/plugin@2.14.30
|
|
49
|
+
- @atlaspack/ts-utils@2.14.9
|
|
50
|
+
|
|
51
|
+
## 2.14.29
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies []:
|
|
56
|
+
- @atlaspack/utils@2.19.1
|
|
57
|
+
- @atlaspack/plugin@2.14.29
|
|
58
|
+
- @atlaspack/ts-utils@2.14.8
|
|
59
|
+
|
|
60
|
+
## 2.14.28
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
|
|
65
|
+
- @atlaspack/utils@2.19.0
|
|
66
|
+
- @atlaspack/plugin@2.14.28
|
|
67
|
+
- @atlaspack/ts-utils@2.14.7
|
|
68
|
+
|
|
69
|
+
## 2.14.27
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies []:
|
|
74
|
+
- @atlaspack/utils@2.18.4
|
|
75
|
+
- @atlaspack/plugin@2.14.27
|
|
76
|
+
- @atlaspack/ts-utils@2.14.6
|
|
77
|
+
|
|
78
|
+
## 2.14.26
|
|
79
|
+
|
|
80
|
+
### Patch Changes
|
|
81
|
+
|
|
82
|
+
- [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
|
|
83
|
+
|
|
84
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
|
|
85
|
+
- @atlaspack/diagnostic@2.14.3
|
|
86
|
+
- @atlaspack/ts-utils@2.14.5
|
|
87
|
+
- @atlaspack/plugin@2.14.26
|
|
88
|
+
- @atlaspack/utils@2.18.3
|
|
89
|
+
|
|
90
|
+
## 2.14.25
|
|
91
|
+
|
|
92
|
+
### Patch Changes
|
|
93
|
+
|
|
94
|
+
- Updated dependencies []:
|
|
95
|
+
- @atlaspack/utils@2.18.2
|
|
96
|
+
- @atlaspack/plugin@2.14.25
|
|
97
|
+
- @atlaspack/ts-utils@2.14.4
|
|
98
|
+
|
|
99
|
+
## 2.14.24
|
|
100
|
+
|
|
101
|
+
### Patch Changes
|
|
102
|
+
|
|
103
|
+
- Updated dependencies []:
|
|
104
|
+
- @atlaspack/utils@2.18.1
|
|
105
|
+
- @atlaspack/plugin@2.14.24
|
|
106
|
+
- @atlaspack/ts-utils@2.14.3
|
|
107
|
+
|
|
108
|
+
## 2.14.23
|
|
109
|
+
|
|
110
|
+
### Patch Changes
|
|
111
|
+
|
|
112
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
|
113
|
+
- @atlaspack/utils@2.18.0
|
|
114
|
+
- @atlaspack/plugin@2.14.23
|
|
115
|
+
|
|
116
|
+
## 2.14.22
|
|
117
|
+
|
|
118
|
+
### Patch Changes
|
|
119
|
+
|
|
120
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
121
|
+
|
|
122
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
|
|
123
|
+
- @atlaspack/diagnostic@2.14.2
|
|
124
|
+
- @atlaspack/ts-utils@2.14.2
|
|
125
|
+
- @atlaspack/plugin@2.14.22
|
|
126
|
+
- @atlaspack/utils@2.17.4
|
|
127
|
+
|
|
128
|
+
## 2.14.21
|
|
129
|
+
|
|
130
|
+
### Patch Changes
|
|
131
|
+
|
|
132
|
+
- Updated dependencies []:
|
|
133
|
+
- @atlaspack/utils@2.17.3
|
|
134
|
+
- @atlaspack/plugin@2.14.21
|
|
135
|
+
|
|
136
|
+
## 2.14.20
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
|
|
141
|
+
|
|
142
|
+
- Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
|
|
143
|
+
- @atlaspack/plugin@2.14.20
|
|
144
|
+
- @atlaspack/utils@2.17.2
|
|
145
|
+
|
|
146
|
+
## 2.14.19
|
|
147
|
+
|
|
148
|
+
### Patch Changes
|
|
149
|
+
|
|
150
|
+
- Updated dependencies []:
|
|
151
|
+
- @atlaspack/utils@2.17.1
|
|
152
|
+
- @atlaspack/plugin@2.14.19
|
|
153
|
+
|
|
154
|
+
## 2.14.18
|
|
155
|
+
|
|
156
|
+
### Patch Changes
|
|
157
|
+
|
|
158
|
+
- Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
|
|
159
|
+
- @atlaspack/utils@2.17.0
|
|
160
|
+
- @atlaspack/plugin@2.14.18
|
|
161
|
+
|
|
162
|
+
## 2.14.17
|
|
163
|
+
|
|
164
|
+
### Patch Changes
|
|
165
|
+
|
|
166
|
+
- Updated dependencies []:
|
|
167
|
+
- @atlaspack/utils@2.16.1
|
|
168
|
+
- @atlaspack/plugin@2.14.17
|
|
169
|
+
|
|
170
|
+
## 2.14.16
|
|
171
|
+
|
|
172
|
+
### Patch Changes
|
|
173
|
+
|
|
174
|
+
- Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
|
|
175
|
+
- @atlaspack/utils@2.16.0
|
|
176
|
+
- @atlaspack/plugin@2.14.16
|
|
177
|
+
|
|
178
|
+
## 2.14.15
|
|
179
|
+
|
|
180
|
+
### Patch Changes
|
|
181
|
+
|
|
182
|
+
- Updated dependencies []:
|
|
183
|
+
- @atlaspack/utils@2.15.3
|
|
184
|
+
- @atlaspack/plugin@2.14.15
|
|
185
|
+
|
|
186
|
+
## 2.14.14
|
|
187
|
+
|
|
188
|
+
### Patch Changes
|
|
189
|
+
|
|
190
|
+
- Updated dependencies []:
|
|
191
|
+
- @atlaspack/utils@2.15.2
|
|
192
|
+
- @atlaspack/plugin@2.14.14
|
|
193
|
+
|
|
194
|
+
## 2.14.13
|
|
195
|
+
|
|
196
|
+
### Patch Changes
|
|
197
|
+
|
|
198
|
+
- Updated dependencies []:
|
|
199
|
+
- @atlaspack/utils@2.15.1
|
|
200
|
+
- @atlaspack/plugin@2.14.13
|
|
201
|
+
|
|
202
|
+
## 2.14.12
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
|
|
207
|
+
- @atlaspack/utils@2.15.0
|
|
208
|
+
- @atlaspack/plugin@2.14.12
|
|
209
|
+
|
|
210
|
+
## 2.14.11
|
|
211
|
+
|
|
212
|
+
### Patch Changes
|
|
213
|
+
|
|
214
|
+
- Updated dependencies []:
|
|
215
|
+
- @atlaspack/utils@2.14.11
|
|
216
|
+
- @atlaspack/plugin@2.14.11
|
|
217
|
+
|
|
218
|
+
## 2.14.10
|
|
219
|
+
|
|
220
|
+
### Patch Changes
|
|
221
|
+
|
|
222
|
+
- Updated dependencies []:
|
|
223
|
+
- @atlaspack/plugin@2.14.10
|
|
224
|
+
- @atlaspack/utils@2.14.10
|
|
225
|
+
|
|
226
|
+
## 2.14.9
|
|
227
|
+
|
|
228
|
+
### Patch Changes
|
|
229
|
+
|
|
230
|
+
- Updated dependencies []:
|
|
231
|
+
- @atlaspack/utils@2.14.9
|
|
232
|
+
- @atlaspack/plugin@2.14.9
|
|
233
|
+
|
|
234
|
+
## 2.14.8
|
|
235
|
+
|
|
236
|
+
### Patch Changes
|
|
237
|
+
|
|
238
|
+
- Updated dependencies []:
|
|
239
|
+
- @atlaspack/utils@2.14.8
|
|
240
|
+
- @atlaspack/plugin@2.14.8
|
|
241
|
+
|
|
3
242
|
## 2.14.7
|
|
4
243
|
|
|
5
244
|
### Patch Changes
|
package/dist/TSModule.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TSModule = void 0;
|
|
4
|
+
class TSModule {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.imports = new Map();
|
|
7
|
+
this.exports = [];
|
|
8
|
+
this.bindings = new Map();
|
|
9
|
+
this.names = new Map();
|
|
10
|
+
this.used = new Set();
|
|
11
|
+
}
|
|
12
|
+
addImport(local, specifier, imported) {
|
|
13
|
+
this.imports.set(local, { specifier, imported });
|
|
14
|
+
if (imported !== '*' && imported !== 'default') {
|
|
15
|
+
this.names.set(local, local);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// if not a reexport: imported = local, name = exported
|
|
19
|
+
addExport(name, imported, specifier) {
|
|
20
|
+
this.exports.push({ name, specifier, imported });
|
|
21
|
+
}
|
|
22
|
+
addWildcardExport(specifier) {
|
|
23
|
+
this.exports.push({ specifier });
|
|
24
|
+
}
|
|
25
|
+
addLocal(name, node) {
|
|
26
|
+
const bindings = this.bindings.get(name) ?? new Set();
|
|
27
|
+
bindings.add(node);
|
|
28
|
+
this.bindings.set(name, bindings);
|
|
29
|
+
if (name !== 'default') {
|
|
30
|
+
this.names.set(name, name);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getName(name) {
|
|
34
|
+
return this.names.get(name) || name;
|
|
35
|
+
}
|
|
36
|
+
hasBinding(name) {
|
|
37
|
+
return this.bindings.has(name);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.TSModule = TSModule;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TSModuleGraph = void 0;
|
|
7
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
10
|
+
class TSModuleGraph {
|
|
11
|
+
constructor(mainModuleName) {
|
|
12
|
+
this.modules = new Map();
|
|
13
|
+
this.mainModuleName = mainModuleName;
|
|
14
|
+
this.mainModule = null;
|
|
15
|
+
this.syntheticImportCount = 0;
|
|
16
|
+
}
|
|
17
|
+
addModule(name, module) {
|
|
18
|
+
this.modules.set(name, module);
|
|
19
|
+
if (name === this.mainModuleName) {
|
|
20
|
+
this.mainModule = module;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getModule(name) {
|
|
24
|
+
return this.modules.get(name);
|
|
25
|
+
}
|
|
26
|
+
markUsed(module, name, context) {
|
|
27
|
+
// If name is imported, mark used in the original module
|
|
28
|
+
if (module.imports.has(name)) {
|
|
29
|
+
module.used.add(name);
|
|
30
|
+
let resolved = this.resolveImport(module, name);
|
|
31
|
+
// Missing or external
|
|
32
|
+
if (!resolved || resolved.module === module) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return this.markUsed(resolved.module, resolved.imported, context);
|
|
36
|
+
}
|
|
37
|
+
if (module.used.has(name)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
module.used.add(name);
|
|
41
|
+
// Visit all child nodes of the original binding and mark any referenced types as used.
|
|
42
|
+
let visit = (node) => {
|
|
43
|
+
if (typescript_1.default.isQualifiedName(node) && typescript_1.default.isIdentifier(node.left)) {
|
|
44
|
+
let resolved = this.resolveImport(module, node.left.text, node.right.text);
|
|
45
|
+
if (resolved) {
|
|
46
|
+
this.markUsed(resolved.module, resolved.imported, context);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (typescript_1.default.isIdentifier(node)) {
|
|
50
|
+
this.markUsed(module, node.text, context);
|
|
51
|
+
}
|
|
52
|
+
return typescript_1.default.visitEachChild(node, visit, context);
|
|
53
|
+
};
|
|
54
|
+
let bindings = module.bindings.get(name);
|
|
55
|
+
if (bindings) {
|
|
56
|
+
for (let node of bindings) {
|
|
57
|
+
typescript_1.default.visitEachChild(node, visit, context);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getExport(m, e) {
|
|
62
|
+
// @ts-expect-error TS2339
|
|
63
|
+
(0, assert_1.default)(e.name != null);
|
|
64
|
+
// @ts-expect-error TS2339
|
|
65
|
+
let exportName = e.name;
|
|
66
|
+
// Re-export
|
|
67
|
+
// @ts-expect-error TS2339
|
|
68
|
+
if (e.specifier && e.imported) {
|
|
69
|
+
let m = this.getModule(e.specifier);
|
|
70
|
+
if (!m) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
// @ts-expect-error TS2339
|
|
74
|
+
let exp = this.resolveExport(m, e.imported);
|
|
75
|
+
if (!exp) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
module: exp.module,
|
|
80
|
+
imported: exp.imported || exp.name,
|
|
81
|
+
name: exportName,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// Import and then export
|
|
85
|
+
if (m.imports.has(exportName)) {
|
|
86
|
+
let imp = this.resolveImport(m, exportName);
|
|
87
|
+
if (!imp) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return { module: imp.module, imported: imp.name, name: exportName };
|
|
91
|
+
}
|
|
92
|
+
// Named export
|
|
93
|
+
return {
|
|
94
|
+
module: m,
|
|
95
|
+
name: exportName,
|
|
96
|
+
// @ts-expect-error TS2339
|
|
97
|
+
imported: e.imported != null ? m.getName(e.imported) : exportName,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
resolveImport(module, local, imported) {
|
|
101
|
+
let i = module.imports.get(local);
|
|
102
|
+
if (!i) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
let m = this.getModule(i.specifier);
|
|
106
|
+
if (!m) {
|
|
107
|
+
// External module. pass through the import.
|
|
108
|
+
return { module, name: local, imported: imported || i.imported };
|
|
109
|
+
}
|
|
110
|
+
return this.resolveExport(m, imported || i.imported);
|
|
111
|
+
}
|
|
112
|
+
resolveExport(module, name) {
|
|
113
|
+
for (let e of module.exports) {
|
|
114
|
+
// @ts-expect-error TS2339
|
|
115
|
+
if (e.name === name) {
|
|
116
|
+
return this.getExport(module, e);
|
|
117
|
+
}
|
|
118
|
+
else if (e.specifier) {
|
|
119
|
+
const m = this.resolveExport((0, nullthrows_1.default)(this.getModule(e.specifier)), name);
|
|
120
|
+
if (m) {
|
|
121
|
+
return m;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
getAllExports(module = (0, nullthrows_1.default)(this.mainModule), excludeDefault = false) {
|
|
127
|
+
let res = [];
|
|
128
|
+
for (let e of module.exports) {
|
|
129
|
+
// @ts-expect-error TS2339
|
|
130
|
+
if (e.name && (!excludeDefault || e.name !== 'default')) {
|
|
131
|
+
let exp = this.getExport(module, e);
|
|
132
|
+
if (exp) {
|
|
133
|
+
res.push(exp);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (e.specifier) {
|
|
137
|
+
let m = this.getModule(e.specifier);
|
|
138
|
+
if (m) {
|
|
139
|
+
res.push(...this.getAllExports(m, true));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return res;
|
|
144
|
+
}
|
|
145
|
+
getAllImports() {
|
|
146
|
+
// Build a map of all imports for external modules
|
|
147
|
+
let importsBySpecifier = new Map();
|
|
148
|
+
for (let module of this.modules.values()) {
|
|
149
|
+
for (let [name, imp] of module.imports) {
|
|
150
|
+
if (module.used.has(name) && !this.modules.has(imp.specifier)) {
|
|
151
|
+
let importMap = importsBySpecifier.get(imp.specifier);
|
|
152
|
+
if (!importMap) {
|
|
153
|
+
importMap = new Map();
|
|
154
|
+
importsBySpecifier.set(imp.specifier, importMap);
|
|
155
|
+
}
|
|
156
|
+
name = module.getName(name);
|
|
157
|
+
importMap.set(name, imp.imported);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return importsBySpecifier;
|
|
162
|
+
}
|
|
163
|
+
propagate(context) {
|
|
164
|
+
// Resolve all exported values, and mark them as used.
|
|
165
|
+
let names = Object.create(null);
|
|
166
|
+
let exportedNames = new Map();
|
|
167
|
+
for (let e of this.getAllExports()) {
|
|
168
|
+
this.markUsed(e.module, e.imported, context);
|
|
169
|
+
e.module.names.set(e.imported, e.name);
|
|
170
|
+
names[e.name] = 1;
|
|
171
|
+
exportedNames.set(e.name, e.module);
|
|
172
|
+
}
|
|
173
|
+
let importedSymbolsToUpdate = [];
|
|
174
|
+
// Assign unique names across all modules
|
|
175
|
+
for (let m of this.modules.values()) {
|
|
176
|
+
for (let [orig, name] of m.names) {
|
|
177
|
+
if (exportedNames.has(name) && exportedNames.get(name) === m) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (!m.used.has(orig)) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (m.imports.has(orig)) {
|
|
184
|
+
// Update imports after all modules's local variables have been renamed
|
|
185
|
+
importedSymbolsToUpdate.push([m, orig]);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (names[name]) {
|
|
189
|
+
m.names.set(name, `_${name}${names[name]++}`);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
names[name] = 1;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Map of imported specifiers -> map of imported names to local names
|
|
197
|
+
let imports = new Map();
|
|
198
|
+
for (let [m, orig] of importedSymbolsToUpdate) {
|
|
199
|
+
// @ts-expect-error TS2339
|
|
200
|
+
let imp = (0, nullthrows_1.default)(m.imports.get(orig));
|
|
201
|
+
// @ts-expect-error TS2345
|
|
202
|
+
let imported = (0, nullthrows_1.default)(this.resolveImport(m, orig));
|
|
203
|
+
// If the module is bundled, map the local name to the original exported name.
|
|
204
|
+
if (this.modules.has(imp.specifier)) {
|
|
205
|
+
// @ts-expect-error TS2339
|
|
206
|
+
m.names.set(orig, imported.imported);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
// If it's external, then we need to dedup duplicate imported names, and ensure
|
|
210
|
+
// that they do not conflict with any exported or local names.
|
|
211
|
+
let importedNames = imports.get(imp.specifier);
|
|
212
|
+
if (!importedNames) {
|
|
213
|
+
importedNames = new Map();
|
|
214
|
+
imports.set(imp.specifier, importedNames);
|
|
215
|
+
}
|
|
216
|
+
let name = importedNames.get(imported.imported);
|
|
217
|
+
if (!name) {
|
|
218
|
+
if (names[imported.imported]) {
|
|
219
|
+
name = `_${imported.imported}${names[imported.imported]++}`;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
name = imported.imported;
|
|
223
|
+
names[imported.imported] = 1;
|
|
224
|
+
}
|
|
225
|
+
importedNames.set(imported.imported, name);
|
|
226
|
+
}
|
|
227
|
+
// @ts-expect-error TS2339
|
|
228
|
+
m.names.set(orig, name);
|
|
229
|
+
}
|
|
230
|
+
return exportedNames;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.TSModuleGraph = TSModuleGraph;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const plugin_1 = require("@atlaspack/plugin");
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const source_map_1 = __importDefault(require("@parcel/source-map"));
|
|
42
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
43
|
+
const ts_utils_1 = require("@atlaspack/ts-utils");
|
|
44
|
+
const utils_1 = require("@atlaspack/utils");
|
|
45
|
+
const diagnostic_1 = __importStar(require("@atlaspack/diagnostic"));
|
|
46
|
+
const TSModuleGraph_1 = require("./TSModuleGraph");
|
|
47
|
+
const nullthrows_1 = __importDefault(require("nullthrows"));
|
|
48
|
+
const collect_1 = require("./collect");
|
|
49
|
+
const shake_1 = require("./shake");
|
|
50
|
+
exports.default = new plugin_1.Transformer({
|
|
51
|
+
loadConfig({ config, options }) {
|
|
52
|
+
return (0, ts_utils_1.loadTSConfig)(config, options);
|
|
53
|
+
},
|
|
54
|
+
transform({ asset, config, options, logger }) {
|
|
55
|
+
let opts = {
|
|
56
|
+
// React is the default. Users can override this by supplying their own tsconfig,
|
|
57
|
+
// which many TypeScript users will already have for typechecking, etc.
|
|
58
|
+
jsx: typescript_1.default.JsxEmit.React,
|
|
59
|
+
moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
|
|
60
|
+
...config,
|
|
61
|
+
// Always emit output
|
|
62
|
+
noEmit: false,
|
|
63
|
+
noEmitOnError: false,
|
|
64
|
+
declaration: true,
|
|
65
|
+
declarationMap: true,
|
|
66
|
+
isolatedModules: false,
|
|
67
|
+
emitDeclarationOnly: true,
|
|
68
|
+
outFile: 'index.d.ts',
|
|
69
|
+
// createProgram doesn't support incremental mode
|
|
70
|
+
composite: false,
|
|
71
|
+
incremental: false,
|
|
72
|
+
};
|
|
73
|
+
let host = new ts_utils_1.CompilerHost(options.inputFS, typescript_1.default, logger);
|
|
74
|
+
// @ts-expect-error TS2345
|
|
75
|
+
let program = typescript_1.default.createProgram([asset.filePath], opts, host);
|
|
76
|
+
for (let file of program.getSourceFiles()) {
|
|
77
|
+
if (path_1.default.normalize(file.fileName) !== asset.filePath) {
|
|
78
|
+
asset.invalidateOnFileChange(host.redirectTypes.get(file.fileName) ?? file.fileName);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let mainModuleName = (0, utils_1.normalizeSeparators)(path_1.default
|
|
82
|
+
// @ts-expect-error TS2339
|
|
83
|
+
.relative(program.getCommonSourceDirectory(), asset.filePath)
|
|
84
|
+
.slice(0, -path_1.default.extname(asset.filePath).length));
|
|
85
|
+
let moduleGraph = new TSModuleGraph_1.TSModuleGraph(mainModuleName);
|
|
86
|
+
let emitResult = program.emit(undefined, undefined, undefined, true, {
|
|
87
|
+
afterDeclarations: [
|
|
88
|
+
// 1. Build module graph
|
|
89
|
+
(context) => (sourceFile) => {
|
|
90
|
+
return (0, collect_1.collect)(moduleGraph, context, sourceFile);
|
|
91
|
+
},
|
|
92
|
+
// 2. Tree shake and rename types
|
|
93
|
+
(context) => (sourceFile) => {
|
|
94
|
+
return (0, shake_1.shake)(moduleGraph, context, sourceFile);
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
let diagnostics = typescript_1.default
|
|
99
|
+
.getPreEmitDiagnostics(program)
|
|
100
|
+
.concat(emitResult.diagnostics);
|
|
101
|
+
let diagnosticIds = new Set();
|
|
102
|
+
// @ts-expect-error TS2304
|
|
103
|
+
let deduplicatedDiagnostics = [];
|
|
104
|
+
for (let d of diagnostics) {
|
|
105
|
+
if (d.start != null && d.length != null && d.messageText != null) {
|
|
106
|
+
let id = `${d.start}:${d.length}:${typescript_1.default.flattenDiagnosticMessageText(d.messageText, '\n')}`;
|
|
107
|
+
if (!diagnosticIds.has(id)) {
|
|
108
|
+
deduplicatedDiagnostics.push(d);
|
|
109
|
+
}
|
|
110
|
+
diagnosticIds.add(id);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
deduplicatedDiagnostics.push(d);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let parcelDiagnostics = deduplicatedDiagnostics.map((diagnostic) => {
|
|
117
|
+
let filename = asset.filePath;
|
|
118
|
+
let { file } = diagnostic;
|
|
119
|
+
let diagnosticMessage = typescript_1.default.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
|
|
120
|
+
let codeframe;
|
|
121
|
+
if (file != null && diagnostic.start != null) {
|
|
122
|
+
let source = file.text || diagnostic.source;
|
|
123
|
+
if (file.fileName) {
|
|
124
|
+
filename = file.fileName;
|
|
125
|
+
}
|
|
126
|
+
if (source) {
|
|
127
|
+
let lineChar = file.getLineAndCharacterOfPosition(diagnostic.start);
|
|
128
|
+
let start = {
|
|
129
|
+
line: lineChar.line + 1,
|
|
130
|
+
column: lineChar.character + 1,
|
|
131
|
+
};
|
|
132
|
+
let end = {
|
|
133
|
+
line: start.line,
|
|
134
|
+
column: start.column + 1,
|
|
135
|
+
};
|
|
136
|
+
if (typeof diagnostic.start === 'number' &&
|
|
137
|
+
typeof diagnostic.length === 'number') {
|
|
138
|
+
let endCharPosition = file.getLineAndCharacterOfPosition(diagnostic.start + diagnostic.length);
|
|
139
|
+
end = {
|
|
140
|
+
line: endCharPosition.line + 1,
|
|
141
|
+
column: endCharPosition.character,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
codeframe = {
|
|
145
|
+
filePath: filename,
|
|
146
|
+
code: source,
|
|
147
|
+
codeHighlights: [
|
|
148
|
+
{
|
|
149
|
+
start,
|
|
150
|
+
end,
|
|
151
|
+
message: (0, diagnostic_1.escapeMarkdown)(diagnosticMessage),
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
message: (0, diagnostic_1.escapeMarkdown)(diagnosticMessage),
|
|
159
|
+
codeFrames: codeframe ? [codeframe] : undefined,
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
if (host.outputCode == null) {
|
|
163
|
+
throw new diagnostic_1.default({ diagnostic: parcelDiagnostics });
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
for (let d of parcelDiagnostics) {
|
|
167
|
+
logger.warn(d);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let code = (0, nullthrows_1.default)(host.outputCode);
|
|
171
|
+
code = code.substring(0, code.lastIndexOf('//# sourceMappingURL'));
|
|
172
|
+
let map = JSON.parse((0, nullthrows_1.default)(host.outputMap));
|
|
173
|
+
// @ts-expect-error TS7006
|
|
174
|
+
map.sources = map.sources.map((source) => path_1.default.join(path_1.default.dirname(asset.filePath), source));
|
|
175
|
+
let sourceMap = null;
|
|
176
|
+
if (map.mappings) {
|
|
177
|
+
sourceMap = new source_map_1.default(options.projectRoot);
|
|
178
|
+
sourceMap.addVLQMap(map);
|
|
179
|
+
}
|
|
180
|
+
asset.type = 'ts';
|
|
181
|
+
asset.setCode(code);
|
|
182
|
+
asset.setMap(sourceMap);
|
|
183
|
+
return [asset];
|
|
184
|
+
},
|
|
185
|
+
});
|