@atlaspack/transformer-typescript-types 2.14.20 → 2.14.21-typescript-08dcc1c9b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -78,15 +78,20 @@ class TSModuleGraph {
78
78
  }
79
79
  }
80
80
  getExport(m, e) {
81
+ // @ts-expect-error TS2339
81
82
  (0, _assert().default)(e.name != null);
83
+ // @ts-expect-error TS2339
82
84
  let exportName = e.name;
83
85
 
84
86
  // Re-export
87
+ // @ts-expect-error TS2339
85
88
  if (e.specifier && e.imported) {
86
89
  let m = this.getModule(e.specifier);
87
90
  if (!m) {
88
91
  return null;
89
92
  }
93
+
94
+ // @ts-expect-error TS2339
90
95
  let exp = this.resolveExport(m, e.imported);
91
96
  if (!exp) {
92
97
  return null;
@@ -115,6 +120,7 @@ class TSModuleGraph {
115
120
  return {
116
121
  module: m,
117
122
  name: exportName,
123
+ // @ts-expect-error TS2339
118
124
  imported: e.imported != null ? m.getName(e.imported) : exportName
119
125
  };
120
126
  }
@@ -136,6 +142,7 @@ class TSModuleGraph {
136
142
  }
137
143
  resolveExport(module, name) {
138
144
  for (let e of module.exports) {
145
+ // @ts-expect-error TS2339
139
146
  if (e.name === name) {
140
147
  return this.getExport(module, e);
141
148
  } else if (e.specifier) {
@@ -149,6 +156,7 @@ class TSModuleGraph {
149
156
  getAllExports(module = (0, _nullthrows().default)(this.mainModule), excludeDefault = false) {
150
157
  let res = [];
151
158
  for (let e of module.exports) {
159
+ // @ts-expect-error TS2339
152
160
  if (e.name && (!excludeDefault || e.name !== 'default')) {
153
161
  let exp = this.getExport(module, e);
154
162
  if (exp) {
@@ -218,11 +226,14 @@ class TSModuleGraph {
218
226
  // Map of imported specifiers -> map of imported names to local names
219
227
  let imports = new Map();
220
228
  for (let [m, orig] of importedSymbolsToUpdate) {
229
+ // @ts-expect-error TS2339
221
230
  let imp = (0, _nullthrows().default)(m.imports.get(orig));
231
+ // @ts-expect-error TS2345
222
232
  let imported = (0, _nullthrows().default)(this.resolveImport(m, orig));
223
233
 
224
234
  // If the module is bundled, map the local name to the original exported name.
225
235
  if (this.modules.has(imp.specifier)) {
236
+ // @ts-expect-error TS2339
226
237
  m.names.set(orig, imported.imported);
227
238
  continue;
228
239
  }
@@ -244,6 +255,8 @@ class TSModuleGraph {
244
255
  }
245
256
  importedNames.set(imported.imported, name);
246
257
  }
258
+
259
+ // @ts-expect-error TS2339
247
260
  m.names.set(orig, name);
248
261
  }
249
262
  return exportedNames;
@@ -98,14 +98,16 @@ var _default = exports.default = new (_plugin().Transformer)({
98
98
  incremental: false
99
99
  };
100
100
  let host = new (_tsUtils().CompilerHost)(options.inputFS, _typescript().default, logger);
101
- // $FlowFixMe
101
+ // @ts-expect-error TS2345
102
102
  let program = _typescript().default.createProgram([asset.filePath], opts, host);
103
103
  for (let file of program.getSourceFiles()) {
104
104
  if (_path().default.normalize(file.fileName) !== asset.filePath) {
105
105
  asset.invalidateOnFileChange(host.redirectTypes.get(file.fileName) ?? file.fileName);
106
106
  }
107
107
  }
108
- let mainModuleName = (0, _utils().normalizeSeparators)(_path().default.relative(program.getCommonSourceDirectory(), asset.filePath).slice(0, -_path().default.extname(asset.filePath).length));
108
+ let mainModuleName = (0, _utils().normalizeSeparators)(_path().default
109
+ // @ts-expect-error TS2339
110
+ .relative(program.getCommonSourceDirectory(), asset.filePath).slice(0, -_path().default.extname(asset.filePath).length));
109
111
  let moduleGraph = new _TSModuleGraph.TSModuleGraph(mainModuleName);
110
112
  let emitResult = program.emit(undefined, undefined, undefined, true, {
111
113
  afterDeclarations: [
@@ -120,6 +122,7 @@ var _default = exports.default = new (_plugin().Transformer)({
120
122
  });
121
123
  let diagnostics = _typescript().default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
122
124
  let diagnosticIds = new Set();
125
+ // @ts-expect-error TS2304
123
126
  let deduplicatedDiagnostics = [];
124
127
  for (let d of diagnostics) {
125
128
  if (d.start != null && d.length != null && d.messageText != null) {
@@ -144,8 +147,6 @@ var _default = exports.default = new (_plugin().Transformer)({
144
147
  if (file.fileName) {
145
148
  filename = file.fileName;
146
149
  }
147
-
148
- // $FlowFixMe
149
150
  if (source) {
150
151
  let lineChar = file.getLineAndCharacterOfPosition(diagnostic.start);
151
152
  let start = {
@@ -191,6 +192,7 @@ var _default = exports.default = new (_plugin().Transformer)({
191
192
  let code = (0, _nullthrows().default)(host.outputCode);
192
193
  code = code.substring(0, code.lastIndexOf('//# sourceMappingURL'));
193
194
  let map = JSON.parse((0, _nullthrows().default)(host.outputMap));
195
+ // @ts-expect-error TS7006
194
196
  map.sources = map.sources.map(source => _path().default.join(_path().default.dirname(asset.filePath), source));
195
197
  let sourceMap = null;
196
198
  if (map.mappings) {
package/lib/collect.js CHANGED
@@ -33,6 +33,7 @@ function collect(moduleGraph, context, sourceFile) {
33
33
  let _currentModule;
34
34
  let visit = node => {
35
35
  if (_typescript().default.isBundle(node)) {
36
+ // @ts-expect-error TS2345
36
37
  return factory.updateBundle(node, _typescript().default.visitNodes(node.sourceFiles, visit));
37
38
  }
38
39
  if (_typescript().default.isModuleDeclaration(node)) {
@@ -46,28 +47,43 @@ function collect(moduleGraph, context, sourceFile) {
46
47
  let currentModule = (0, _nullthrows().default)(_currentModule);
47
48
  if (_typescript().default.isImportDeclaration(node) && node.importClause) {
48
49
  if (node.importClause.namedBindings) {
50
+ // @ts-expect-error TS2339
49
51
  if (node.importClause.namedBindings.elements) {
52
+ // @ts-expect-error TS2339
50
53
  for (let element of node.importClause.namedBindings.elements) {
51
- currentModule.addImport(element.name.text, node.moduleSpecifier.text, (element.propertyName ?? element.name).text);
54
+ currentModule.addImport(element.name.text,
55
+ // @ts-expect-error TS2339
56
+ node.moduleSpecifier.text, (element.propertyName ?? element.name).text);
52
57
  }
58
+ // @ts-expect-error TS2339
53
59
  } else if (node.importClause.namedBindings.name) {
54
- currentModule.addImport(node.importClause.namedBindings.name.text, node.moduleSpecifier.text, '*');
60
+ currentModule.addImport(
61
+ // @ts-expect-error TS2339
62
+ node.importClause.namedBindings.name.text,
63
+ // @ts-expect-error TS2339
64
+ node.moduleSpecifier.text, '*');
55
65
  }
56
66
  }
57
67
  if (node.importClause.name) {
58
- currentModule.addImport(node.importClause.name.text, node.moduleSpecifier.text, 'default');
68
+ currentModule.addImport(node.importClause.name.text,
69
+ // @ts-expect-error TS2339
70
+ node.moduleSpecifier.text, 'default');
59
71
  }
60
72
  }
61
73
  if (_typescript().default.isExportDeclaration(node)) {
62
74
  if (node.exportClause) {
75
+ // @ts-expect-error TS2339
63
76
  for (let element of node.exportClause.elements) {
64
77
  if (node.moduleSpecifier) {
65
- currentModule.addExport(element.name.text, (element.propertyName ?? element.name).text, node.moduleSpecifier.text);
78
+ currentModule.addExport(element.name.text, (element.propertyName ?? element.name).text,
79
+ // @ts-expect-error TS2339
80
+ node.moduleSpecifier.text);
66
81
  } else {
67
82
  currentModule.addExport(element.name.text, (element.propertyName ?? element.name).text);
68
83
  }
69
84
  }
70
85
  } else {
86
+ // @ts-expect-error TS18048
71
87
  currentModule.addWildcardExport(node.moduleSpecifier.text);
72
88
  }
73
89
  }
@@ -96,8 +112,10 @@ function collect(moduleGraph, context, sourceFile) {
96
112
  if (_typescript().default.isVariableStatement(node) && node.modifiers) {
97
113
  let isExported = node.modifiers.some(m => m.kind === _typescript().default.SyntaxKind.ExportKeyword);
98
114
  for (let v of node.declarationList.declarations) {
115
+ // @ts-expect-error TS2339
99
116
  currentModule.addLocal(v.name.text, v);
100
117
  if (isExported) {
118
+ // @ts-expect-error TS2339
101
119
  currentModule.addExport(v.name.text, v.name.text);
102
120
  }
103
121
  }
@@ -116,13 +134,19 @@ function collect(moduleGraph, context, sourceFile) {
116
134
  // Traverse down an EntityName to the root identifier. Return that to use as the named import specifier,
117
135
  // and collect the remaining parts into a new QualifiedName with the local replacement at the root.
118
136
  // import('react').JSX.Element => import {JSX} from 'react'; JSX.Element
137
+ // @ts-expect-error TS7023
119
138
  function getImportName(qualifier, local, factory) {
120
139
  if (!qualifier) {
140
+ // @ts-expect-error TS2339
121
141
  return ['*', factory.createIdentifier(local)];
122
142
  }
123
143
  if (qualifier.kind === _typescript().default.SyntaxKind.Identifier) {
144
+ // @ts-expect-error TS2339
124
145
  return [qualifier.text, factory.createIdentifier(local)];
125
146
  }
147
+
148
+ // @ts-expect-error TS7022
126
149
  let [name, entity] = getImportName(qualifier.left, local, factory);
150
+ // @ts-expect-error TS2339
127
151
  return [name, factory.createQualifiedName(entity, qualifier.right)];
128
152
  }
package/lib/shake.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.shake = shake;
7
- var _TSModule = require("./TSModule");
8
7
  function _typescript() {
9
8
  const data = _interopRequireDefault(require("typescript"));
10
9
  _typescript = function () {
@@ -43,6 +42,7 @@ function shake(moduleGraph, context, sourceFile) {
43
42
  let _currentModule;
44
43
  let visit = node => {
45
44
  if (_typescript().default.isBundle(node)) {
45
+ // @ts-expect-error TS2345
46
46
  return factory.updateBundle(node, _typescript().default.visitNodes(node.sourceFiles, visit));
47
47
  }
48
48
 
@@ -53,14 +53,19 @@ function shake(moduleGraph, context, sourceFile) {
53
53
  var _node$modifiers$;
54
54
  // Since we are hoisting them to the top-level scope, we need to add a "declare" keyword to make them ambient.
55
55
  // we also want the declare keyword to come after the export keyword to guarantee a valid typings file.
56
+ // @ts-expect-error TS2540
56
57
  node.modifiers ??= [];
57
- const index = ((_node$modifiers$ = node.modifiers[0]) === null || _node$modifiers$ === void 0 ? void 0 : _node$modifiers$.kind) === _typescript().default.SyntaxKind.ExportKeyword ? 1 : 0;
58
+ const index =
59
+ // @ts-expect-error TS18048
60
+ ((_node$modifiers$ = node.modifiers[0]) === null || _node$modifiers$ === void 0 ? void 0 : _node$modifiers$.kind) === _typescript().default.SyntaxKind.ExportKeyword ? 1 : 0;
61
+ // @ts-expect-error TS18048
58
62
  node.modifiers.splice(index, 0, factory.createModifier(_typescript().default.SyntaxKind.DeclareKeyword));
59
63
  return node;
60
64
  }
61
65
  moduleStack.push(_currentModule);
62
66
  let isFirstModule = !_currentModule;
63
67
  _currentModule = moduleGraph.getModule(node.name.text);
68
+ // @ts-expect-error TS2532
64
69
  let statements = _typescript().default.visitEachChild(node, visit, context).body.statements;
65
70
  _currentModule = moduleStack.pop();
66
71
  if (isFirstModule && !addedGeneratedImports) {
@@ -80,10 +85,13 @@ function shake(moduleGraph, context, sourceFile) {
80
85
  let currentModule = (0, _nullthrows().default)(_currentModule);
81
86
  // Remove exports from flattened modules
82
87
  if (_typescript().default.isExportDeclaration(node)) {
83
- if (!node.moduleSpecifier || moduleGraph.getModule(node.moduleSpecifier.text)) {
88
+ if (!node.moduleSpecifier ||
89
+ // @ts-expect-error TS2339
90
+ moduleGraph.getModule(node.moduleSpecifier.text)) {
84
91
  if (!node.moduleSpecifier && node.exportClause) {
85
92
  // Filter exported elements to only external re-exports
86
93
  let exported = [];
94
+ // @ts-expect-error TS2339
87
95
  for (let element of node.exportClause.elements) {
88
96
  let name = (element.propertyName ?? element.name).text;
89
97
  if (exportedNames.get(name) === currentModule && !currentModule.hasBinding(name)) {
@@ -122,7 +130,9 @@ function shake(moduleGraph, context, sourceFile) {
122
130
  }
123
131
 
124
132
  // Remove original export modifiers
125
- node.modifiers = (node.modifiers || []).filter(m => m.kind !== _typescript().default.SyntaxKind.ExportKeyword && m.kind !== _typescript().default.SyntaxKind.DefaultKeyword);
133
+ node.modifiers = (node.modifiers || []).filter(
134
+ // @ts-expect-error TS7006
135
+ m => m.kind !== _typescript().default.SyntaxKind.ExportKeyword && m.kind !== _typescript().default.SyntaxKind.DefaultKeyword);
126
136
 
127
137
  // Rename declarations
128
138
  let newName = currentModule.getName(name);
@@ -137,6 +147,7 @@ function shake(moduleGraph, context, sourceFile) {
137
147
  }
138
148
  node.modifiers.unshift(factory.createModifier(_typescript().default.SyntaxKind.ExportKeyword));
139
149
  } else if (_typescript().default.isFunctionDeclaration(node) || _typescript().default.isClassDeclaration(node)) {
150
+ // @ts-expect-error TS18048
140
151
  node.modifiers.unshift(factory.createModifier(_typescript().default.SyntaxKind.DeclareKeyword));
141
152
  }
142
153
  }
@@ -149,10 +160,14 @@ function shake(moduleGraph, context, sourceFile) {
149
160
  }
150
161
 
151
162
  // Remove original export modifiers
152
- node.modifiers = (node.modifiers || []).filter(m => m.kind !== _typescript().default.SyntaxKind.ExportKeyword && m.kind !== _typescript().default.SyntaxKind.DeclareKeyword);
163
+ node.modifiers = (node.modifiers || []).filter(
164
+ // @ts-expect-error TS7006
165
+ m => m.kind !== _typescript().default.SyntaxKind.ExportKeyword && m.kind !== _typescript().default.SyntaxKind.DeclareKeyword);
153
166
 
154
167
  // Add export modifier if all declarations are exported.
155
- let isExported = node.declarationList.declarations.every(d => exportedNames.get(d.name.text) === currentModule);
168
+ let isExported = node.declarationList.declarations.every(
169
+ // @ts-expect-error TS7006
170
+ d => exportedNames.get(d.name.text) === currentModule);
156
171
  if (isExported) {
157
172
  node.modifiers.unshift(factory.createModifier(_typescript().default.SyntaxKind.ExportKeyword));
158
173
  } else {
@@ -163,6 +178,7 @@ function shake(moduleGraph, context, sourceFile) {
163
178
  }
164
179
  if (_typescript().default.isVariableDeclaration(node)) {
165
180
  // Remove unused variables
181
+ // @ts-expect-error TS2339
166
182
  if (!currentModule.used.has(node.name.text)) {
167
183
  return null;
168
184
  }
@@ -198,10 +214,12 @@ function shake(moduleGraph, context, sourceFile) {
198
214
  return _typescript().default.visitNode(sourceFile, visit);
199
215
  }
200
216
  function generateImports(factory, moduleGraph) {
217
+ // @ts-expect-error TS2304
201
218
  let importStatements = [];
202
219
  for (let [specifier, names] of moduleGraph.getAllImports()) {
203
220
  let defaultSpecifier;
204
221
  let namespaceSpecifier;
222
+ // @ts-expect-error TS2304
205
223
  let namedSpecifiers = [];
206
224
  for (let [name, imported] of names) {
207
225
  if (imported === 'default') {
package/lib/utils.js CHANGED
@@ -17,9 +17,13 @@ function getExportedName(node) {
17
17
  if (!node.modifiers) {
18
18
  return null;
19
19
  }
20
+
21
+ // @ts-expect-error TS7006
20
22
  if (!node.modifiers.some(m => m.kind === _typescript().default.SyntaxKind.ExportKeyword)) {
21
23
  return null;
22
24
  }
25
+
26
+ // @ts-expect-error TS7006
23
27
  if (node.modifiers.some(m => m.kind === _typescript().default.SyntaxKind.DefaultKeyword)) {
24
28
  return 'default';
25
29
  }
package/lib/wrappers.js CHANGED
@@ -20,6 +20,7 @@ function _assert() {
20
20
  }
21
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
22
  /* eslint-disable no-unused-vars */
23
+
23
24
  const [majorVersion, minorVersion] = _typescript().default.versionMajorMinor.split('.').map(num => parseInt(num, 10));
24
25
 
25
26
  // Everything below was generated using https://github.com/mischnic/tsc-version-wrapper
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/transformer-typescript-types",
3
- "version": "2.14.20",
3
+ "version": "2.14.21-typescript-08dcc1c9b.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,16 +10,16 @@
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
12
  "main": "lib/TSTypesTransformer.js",
13
- "source": "src/TSTypesTransformer.js",
13
+ "source": "src/TSTypesTransformer.ts",
14
14
  "engines": {
15
15
  "node": ">= 16.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@atlaspack/diagnostic": "2.14.1",
19
- "@atlaspack/plugin": "2.14.20",
18
+ "@atlaspack/diagnostic": "2.14.2-typescript-08dcc1c9b.0",
19
+ "@atlaspack/plugin": "2.14.21-typescript-08dcc1c9b.0",
20
+ "@atlaspack/ts-utils": "2.14.2-typescript-08dcc1c9b.0",
21
+ "@atlaspack/utils": "2.17.3-typescript-08dcc1c9b.0",
20
22
  "@parcel/source-map": "^2.1.1",
21
- "@atlaspack/ts-utils": "2.14.1",
22
- "@atlaspack/utils": "2.17.2",
23
23
  "nullthrows": "^1.1.1"
24
24
  },
25
25
  "devDependencies": {
@@ -28,5 +28,10 @@
28
28
  "peerDependencies": {
29
29
  "typescript": ">=3.0.0"
30
30
  },
31
- "type": "commonjs"
31
+ "type": "commonjs",
32
+ "scripts": {
33
+ "check-ts": "tsc --noEmit"
34
+ },
35
+ "types": "src/TSTypesTransformer.ts",
36
+ "gitHead": "08dcc1c9bcdc6ab931d55e05ccc0f45669de2f22"
32
37
  }
@@ -1,9 +1,16 @@
1
- // @flow
2
-
3
- export type Import = {|specifier: string, imported: string|};
1
+ export type Import = {
2
+ specifier: string;
3
+ imported: string;
4
+ };
4
5
  export type Export =
5
- | {|name: string, imported: string, specifier?: ?string|}
6
- | {|specifier: string|};
6
+ | {
7
+ name: string;
8
+ imported: string;
9
+ specifier?: string | null | undefined;
10
+ }
11
+ | {
12
+ specifier: string;
13
+ };
7
14
 
8
15
  export class TSModule {
9
16
  imports: Map<string, Import>;
@@ -28,7 +35,7 @@ export class TSModule {
28
35
  }
29
36
 
30
37
  // if not a reexport: imported = local, name = exported
31
- addExport(name: string, imported: string, specifier: ?string) {
38
+ addExport(name: string, imported: string, specifier?: string | null) {
32
39
  this.exports.push({name, specifier, imported});
33
40
  }
34
41
 
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {TSModule, Export} from './TSModule';
3
2
 
4
3
  import nullthrows from 'nullthrows';
@@ -8,7 +7,7 @@ import ts from 'typescript';
8
7
  export class TSModuleGraph {
9
8
  modules: Map<string, TSModule>;
10
9
  mainModuleName: string;
11
- mainModule: ?TSModule;
10
+ mainModule: TSModule | null | undefined;
12
11
  syntheticImportCount: number;
13
12
 
14
13
  constructor(mainModuleName: string) {
@@ -25,7 +24,7 @@ export class TSModuleGraph {
25
24
  }
26
25
  }
27
26
 
28
- getModule(name: string): ?TSModule {
27
+ getModule(name: string): TSModule | null | undefined {
29
28
  return this.modules.get(name);
30
29
  }
31
30
 
@@ -77,17 +76,28 @@ export class TSModuleGraph {
77
76
  getExport(
78
77
  m: TSModule,
79
78
  e: Export,
80
- ): ?{|imported: string, module: TSModule, name: string|} {
79
+ ):
80
+ | {
81
+ imported: string;
82
+ module: TSModule;
83
+ name: string;
84
+ }
85
+ | null
86
+ | undefined {
87
+ // @ts-expect-error TS2339
81
88
  invariant(e.name != null);
89
+ // @ts-expect-error TS2339
82
90
  let exportName = e.name;
83
91
 
84
92
  // Re-export
93
+ // @ts-expect-error TS2339
85
94
  if (e.specifier && e.imported) {
86
95
  let m = this.getModule(e.specifier);
87
96
  if (!m) {
88
97
  return null;
89
98
  }
90
99
 
100
+ // @ts-expect-error TS2339
91
101
  let exp = this.resolveExport(m, e.imported);
92
102
  if (!exp) {
93
103
  return null;
@@ -114,6 +124,7 @@ export class TSModuleGraph {
114
124
  return {
115
125
  module: m,
116
126
  name: exportName,
127
+ // @ts-expect-error TS2339
117
128
  imported: e.imported != null ? m.getName(e.imported) : exportName,
118
129
  };
119
130
  }
@@ -122,7 +133,14 @@ export class TSModuleGraph {
122
133
  module: TSModule,
123
134
  local: string,
124
135
  imported?: string,
125
- ): ?{|imported: string, module: TSModule, name: string|} {
136
+ ):
137
+ | {
138
+ imported: string;
139
+ module: TSModule;
140
+ name: string;
141
+ }
142
+ | null
143
+ | undefined {
126
144
  let i = module.imports.get(local);
127
145
  if (!i) {
128
146
  return null;
@@ -140,8 +158,16 @@ export class TSModuleGraph {
140
158
  resolveExport(
141
159
  module: TSModule,
142
160
  name: string,
143
- ): ?{|imported: string, module: TSModule, name: string|} {
161
+ ):
162
+ | {
163
+ imported: string;
164
+ module: TSModule;
165
+ name: string;
166
+ }
167
+ | null
168
+ | undefined {
144
169
  for (let e of module.exports) {
170
+ // @ts-expect-error TS2339
145
171
  if (e.name === name) {
146
172
  return this.getExport(module, e);
147
173
  } else if (e.specifier) {
@@ -159,9 +185,18 @@ export class TSModuleGraph {
159
185
  getAllExports(
160
186
  module: TSModule = nullthrows(this.mainModule),
161
187
  excludeDefault: boolean = false,
162
- ): Array<{|imported: string, module: TSModule, name: string|}> {
163
- let res = [];
188
+ ): Array<{
189
+ imported: string;
190
+ module: TSModule;
191
+ name: string;
192
+ }> {
193
+ let res: Array<{
194
+ imported: string;
195
+ module: TSModule;
196
+ name: string;
197
+ }> = [];
164
198
  for (let e of module.exports) {
199
+ // @ts-expect-error TS2339
165
200
  if (e.name && (!excludeDefault || e.name !== 'default')) {
166
201
  let exp = this.getExport(module, e);
167
202
  if (exp) {
@@ -209,7 +244,7 @@ export class TSModuleGraph {
209
244
  exportedNames.set(e.name, e.module);
210
245
  }
211
246
 
212
- let importedSymbolsToUpdate = [];
247
+ let importedSymbolsToUpdate: Array<Array<TSModule | string>> = [];
213
248
 
214
249
  // Assign unique names across all modules
215
250
  for (let m of this.modules.values()) {
@@ -240,11 +275,14 @@ export class TSModuleGraph {
240
275
  let imports = new Map();
241
276
 
242
277
  for (let [m, orig] of importedSymbolsToUpdate) {
278
+ // @ts-expect-error TS2339
243
279
  let imp = nullthrows(m.imports.get(orig));
280
+ // @ts-expect-error TS2345
244
281
  let imported = nullthrows(this.resolveImport(m, orig));
245
282
 
246
283
  // If the module is bundled, map the local name to the original exported name.
247
284
  if (this.modules.has(imp.specifier)) {
285
+ // @ts-expect-error TS2339
248
286
  m.names.set(orig, imported.imported);
249
287
  continue;
250
288
  }
@@ -269,6 +307,7 @@ export class TSModuleGraph {
269
307
  importedNames.set(imported.imported, name);
270
308
  }
271
309
 
310
+ // @ts-expect-error TS2339
272
311
  m.names.set(orig, name);
273
312
  }
274
313
 
@@ -1,5 +1,3 @@
1
- // @flow strict-local
2
-
3
1
  import {Transformer} from '@atlaspack/plugin';
4
2
  import path from 'path';
5
3
  import SourceMap from '@parcel/source-map';
@@ -15,7 +13,7 @@ import nullthrows from 'nullthrows';
15
13
  import {collect} from './collect';
16
14
  import {shake} from './shake';
17
15
 
18
- export default (new Transformer({
16
+ export default new Transformer({
19
17
  loadConfig({config, options}) {
20
18
  return loadTSConfig(config, options);
21
19
  },
@@ -41,7 +39,7 @@ export default (new Transformer({
41
39
  };
42
40
 
43
41
  let host = new CompilerHost(options.inputFS, ts, logger);
44
- // $FlowFixMe
42
+ // @ts-expect-error TS2345
45
43
  let program = ts.createProgram([asset.filePath], opts, host);
46
44
 
47
45
  for (let file of program.getSourceFiles()) {
@@ -54,6 +52,7 @@ export default (new Transformer({
54
52
 
55
53
  let mainModuleName = normalizeSeparators(
56
54
  path
55
+ // @ts-expect-error TS2339
57
56
  .relative(program.getCommonSourceDirectory(), asset.filePath)
58
57
  .slice(0, -path.extname(asset.filePath).length),
59
58
  );
@@ -62,11 +61,11 @@ export default (new Transformer({
62
61
  let emitResult = program.emit(undefined, undefined, undefined, true, {
63
62
  afterDeclarations: [
64
63
  // 1. Build module graph
65
- (context) => (sourceFile) => {
64
+ (context: any) => (sourceFile: any) => {
66
65
  return collect(moduleGraph, context, sourceFile);
67
66
  },
68
67
  // 2. Tree shake and rename types
69
- (context) => (sourceFile) => {
68
+ (context: any) => (sourceFile: any) => {
70
69
  return shake(moduleGraph, context, sourceFile);
71
70
  },
72
71
  ],
@@ -77,7 +76,8 @@ export default (new Transformer({
77
76
  .concat(emitResult.diagnostics);
78
77
 
79
78
  let diagnosticIds = new Set();
80
- let deduplicatedDiagnostics = [];
79
+ // @ts-expect-error TS2304
80
+ let deduplicatedDiagnostics: Array<Diagnostic> = [];
81
81
  for (let d of diagnostics) {
82
82
  if (d.start != null && d.length != null && d.messageText != null) {
83
83
  let id = `${d.start}:${d.length}:${ts.flattenDiagnosticMessageText(
@@ -102,14 +102,13 @@ export default (new Transformer({
102
102
  '\n',
103
103
  );
104
104
 
105
- let codeframe: ?DiagnosticCodeFrame;
105
+ let codeframe: DiagnosticCodeFrame | null | undefined;
106
106
  if (file != null && diagnostic.start != null) {
107
107
  let source = file.text || diagnostic.source;
108
108
  if (file.fileName) {
109
109
  filename = file.fileName;
110
110
  }
111
111
 
112
- // $FlowFixMe
113
112
  if (source) {
114
113
  let lineChar = file.getLineAndCharacterOfPosition(diagnostic.start);
115
114
  let start = {
@@ -167,6 +166,7 @@ export default (new Transformer({
167
166
  code = code.substring(0, code.lastIndexOf('//# sourceMappingURL'));
168
167
 
169
168
  let map = JSON.parse(nullthrows(host.outputMap));
169
+ // @ts-expect-error TS7006
170
170
  map.sources = map.sources.map((source) =>
171
171
  path.join(path.dirname(asset.filePath), source),
172
172
  );
@@ -182,4 +182,4 @@ export default (new Transformer({
182
182
  asset.setMap(sourceMap);
183
183
  return [asset];
184
184
  },
185
- }): Transformer<mixed>);
185
+ }) as Transformer<unknown>;
@@ -1,8 +1,7 @@
1
- // @flow
2
1
  import type {TSModuleGraph} from './TSModuleGraph';
3
2
 
4
3
  import nullthrows from 'nullthrows';
5
- import ts, {type EntityName} from 'typescript';
4
+ import ts, {EntityName} from 'typescript';
6
5
  import {TSModule} from './TSModule';
7
6
  import {getExportedName, isDeclaration} from './utils';
8
7
 
@@ -16,10 +15,11 @@ export function collect(
16
15
 
17
16
  // When module definitions are nested inside each other (e.g with module augmentation),
18
17
  // we want to keep track of the hierarchy so we can associated nodes with the right module.
19
- const moduleStack: Array<?TSModule> = [];
20
- let _currentModule: ?TSModule;
18
+ const moduleStack: Array<TSModule | null | undefined> = [];
19
+ let _currentModule: TSModule | null | undefined;
21
20
  let visit = (node: any): any => {
22
21
  if (ts.isBundle(node)) {
22
+ // @ts-expect-error TS2345
23
23
  return factory.updateBundle(node, ts.visitNodes(node.sourceFiles, visit));
24
24
  }
25
25
 
@@ -36,17 +36,23 @@ export function collect(
36
36
  let currentModule = nullthrows(_currentModule);
37
37
  if (ts.isImportDeclaration(node) && node.importClause) {
38
38
  if (node.importClause.namedBindings) {
39
+ // @ts-expect-error TS2339
39
40
  if (node.importClause.namedBindings.elements) {
41
+ // @ts-expect-error TS2339
40
42
  for (let element of node.importClause.namedBindings.elements) {
41
43
  currentModule.addImport(
42
44
  element.name.text,
45
+ // @ts-expect-error TS2339
43
46
  node.moduleSpecifier.text,
44
47
  (element.propertyName ?? element.name).text,
45
48
  );
46
49
  }
50
+ // @ts-expect-error TS2339
47
51
  } else if (node.importClause.namedBindings.name) {
48
52
  currentModule.addImport(
53
+ // @ts-expect-error TS2339
49
54
  node.importClause.namedBindings.name.text,
55
+ // @ts-expect-error TS2339
50
56
  node.moduleSpecifier.text,
51
57
  '*',
52
58
  );
@@ -56,6 +62,7 @@ export function collect(
56
62
  if (node.importClause.name) {
57
63
  currentModule.addImport(
58
64
  node.importClause.name.text,
65
+ // @ts-expect-error TS2339
59
66
  node.moduleSpecifier.text,
60
67
  'default',
61
68
  );
@@ -64,11 +71,13 @@ export function collect(
64
71
 
65
72
  if (ts.isExportDeclaration(node)) {
66
73
  if (node.exportClause) {
74
+ // @ts-expect-error TS2339
67
75
  for (let element of node.exportClause.elements) {
68
76
  if (node.moduleSpecifier) {
69
77
  currentModule.addExport(
70
78
  element.name.text,
71
79
  (element.propertyName ?? element.name).text,
80
+ // @ts-expect-error TS2339
72
81
  node.moduleSpecifier.text,
73
82
  );
74
83
  } else {
@@ -79,6 +88,7 @@ export function collect(
79
88
  }
80
89
  }
81
90
  } else {
91
+ // @ts-expect-error TS18048
82
92
  currentModule.addWildcardExport(node.moduleSpecifier.text);
83
93
  }
84
94
  }
@@ -118,8 +128,10 @@ export function collect(
118
128
  (m) => m.kind === ts.SyntaxKind.ExportKeyword,
119
129
  );
120
130
  for (let v of node.declarationList.declarations) {
131
+ // @ts-expect-error TS2339
121
132
  currentModule.addLocal(v.name.text, v);
122
133
  if (isExported) {
134
+ // @ts-expect-error TS2339
123
135
  currentModule.addExport(v.name.text, v.name.text);
124
136
  }
125
137
  }
@@ -139,19 +151,24 @@ export function collect(
139
151
  // Traverse down an EntityName to the root identifier. Return that to use as the named import specifier,
140
152
  // and collect the remaining parts into a new QualifiedName with the local replacement at the root.
141
153
  // import('react').JSX.Element => import {JSX} from 'react'; JSX.Element
154
+ // @ts-expect-error TS7023
142
155
  function getImportName(
143
- qualifier: ?EntityName,
156
+ qualifier: EntityName | null | undefined,
144
157
  local: string,
145
158
  factory: typeof ts,
146
159
  ) {
147
160
  if (!qualifier) {
161
+ // @ts-expect-error TS2339
148
162
  return ['*', factory.createIdentifier(local)];
149
163
  }
150
164
 
151
165
  if (qualifier.kind === ts.SyntaxKind.Identifier) {
166
+ // @ts-expect-error TS2339
152
167
  return [qualifier.text, factory.createIdentifier(local)];
153
168
  }
154
169
 
170
+ // @ts-expect-error TS7022
155
171
  let [name, entity] = getImportName(qualifier.left, local, factory);
172
+ // @ts-expect-error TS2339
156
173
  return [name, factory.createQualifiedName(entity, qualifier.right)];
157
174
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {TSModule} from './TSModule';
3
2
  import type {TSModuleGraph} from './TSModuleGraph';
4
3
 
@@ -30,13 +29,14 @@ export function shake(
30
29
 
31
30
  // When module definitions are nested inside each other (e.g with module augmentation),
32
31
  // we want to keep track of the hierarchy so we can associated nodes with the right module.
33
- const moduleStack: Array<?TSModule> = [];
32
+ const moduleStack: Array<TSModule | null | undefined> = [];
34
33
 
35
34
  let addedGeneratedImports = false;
36
35
 
37
- let _currentModule: ?TSModule;
36
+ let _currentModule: TSModule | null | undefined;
38
37
  let visit = (node: any): any => {
39
38
  if (ts.isBundle(node)) {
39
+ // @ts-expect-error TS2345
40
40
  return factory.updateBundle(node, ts.visitNodes(node.sourceFiles, visit));
41
41
  }
42
42
 
@@ -46,9 +46,12 @@ export function shake(
46
46
  if (moduleStack.length >= 1) {
47
47
  // Since we are hoisting them to the top-level scope, we need to add a "declare" keyword to make them ambient.
48
48
  // we also want the declare keyword to come after the export keyword to guarantee a valid typings file.
49
+ // @ts-expect-error TS2540
49
50
  node.modifiers ??= [];
50
51
  const index =
52
+ // @ts-expect-error TS18048
51
53
  node.modifiers[0]?.kind === ts.SyntaxKind.ExportKeyword ? 1 : 0;
54
+ // @ts-expect-error TS18048
52
55
  node.modifiers.splice(
53
56
  index,
54
57
  0,
@@ -60,6 +63,7 @@ export function shake(
60
63
  moduleStack.push(_currentModule);
61
64
  let isFirstModule = !_currentModule;
62
65
  _currentModule = moduleGraph.getModule(node.name.text);
66
+ // @ts-expect-error TS2532
63
67
  let statements = ts.visitEachChild(node, visit, context).body.statements;
64
68
  _currentModule = moduleStack.pop();
65
69
 
@@ -85,11 +89,13 @@ export function shake(
85
89
  if (ts.isExportDeclaration(node)) {
86
90
  if (
87
91
  !node.moduleSpecifier ||
92
+ // @ts-expect-error TS2339
88
93
  moduleGraph.getModule(node.moduleSpecifier.text)
89
94
  ) {
90
95
  if (!node.moduleSpecifier && node.exportClause) {
91
96
  // Filter exported elements to only external re-exports
92
- let exported = [];
97
+ let exported: Array<any> = [];
98
+ // @ts-expect-error TS2339
93
99
  for (let element of node.exportClause.elements) {
94
100
  let name = (element.propertyName ?? element.name).text;
95
101
  if (
@@ -135,6 +141,7 @@ export function shake(
135
141
 
136
142
  // Remove original export modifiers
137
143
  node.modifiers = (node.modifiers || []).filter(
144
+ // @ts-expect-error TS7006
138
145
  (m) =>
139
146
  m.kind !== ts.SyntaxKind.ExportKeyword &&
140
147
  m.kind !== ts.SyntaxKind.DefaultKeyword,
@@ -161,6 +168,7 @@ export function shake(
161
168
  ts.isFunctionDeclaration(node) ||
162
169
  ts.isClassDeclaration(node)
163
170
  ) {
171
+ // @ts-expect-error TS18048
164
172
  node.modifiers.unshift(
165
173
  factory.createModifier(ts.SyntaxKind.DeclareKeyword),
166
174
  );
@@ -177,6 +185,7 @@ export function shake(
177
185
 
178
186
  // Remove original export modifiers
179
187
  node.modifiers = (node.modifiers || []).filter(
188
+ // @ts-expect-error TS7006
180
189
  (m) =>
181
190
  m.kind !== ts.SyntaxKind.ExportKeyword &&
182
191
  m.kind !== ts.SyntaxKind.DeclareKeyword,
@@ -184,6 +193,7 @@ export function shake(
184
193
 
185
194
  // Add export modifier if all declarations are exported.
186
195
  let isExported = node.declarationList.declarations.every(
196
+ // @ts-expect-error TS7006
187
197
  (d) => exportedNames.get(d.name.text) === currentModule,
188
198
  );
189
199
  if (isExported) {
@@ -202,6 +212,7 @@ export function shake(
202
212
 
203
213
  if (ts.isVariableDeclaration(node)) {
204
214
  // Remove unused variables
215
+ // @ts-expect-error TS2339
205
216
  if (!currentModule.used.has(node.name.text)) {
206
217
  return null;
207
218
  }
@@ -250,11 +261,13 @@ export function shake(
250
261
  }
251
262
 
252
263
  function generateImports(factory: any, moduleGraph: TSModuleGraph) {
253
- let importStatements = [];
264
+ // @ts-expect-error TS2304
265
+ let importStatements: Array<ImportDeclaration | any> = [];
254
266
  for (let [specifier, names] of moduleGraph.getAllImports()) {
255
267
  let defaultSpecifier;
256
268
  let namespaceSpecifier;
257
- let namedSpecifiers = [];
269
+ // @ts-expect-error TS2304
270
+ let namedSpecifiers: Array<ImportSpecifier | any> = [];
258
271
  for (let [name, imported] of names) {
259
272
  if (imported === 'default') {
260
273
  defaultSpecifier = factory.createIdentifier(name);
@@ -1,15 +1,16 @@
1
- // @flow
2
1
  import ts from 'typescript';
3
2
 
4
- export function getExportedName(node: any): ?string {
3
+ export function getExportedName(node: any): string | null | undefined {
5
4
  if (!node.modifiers) {
6
5
  return null;
7
6
  }
8
7
 
8
+ // @ts-expect-error TS7006
9
9
  if (!node.modifiers.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {
10
10
  return null;
11
11
  }
12
12
 
13
+ // @ts-expect-error TS7006
13
14
  if (node.modifiers.some((m) => m.kind === ts.SyntaxKind.DefaultKeyword)) {
14
15
  return 'default';
15
16
  }
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  /* eslint-disable no-unused-vars */
3
2
  import type {
4
3
  ExportDeclaration,
@@ -26,18 +25,30 @@ const [majorVersion, minorVersion] = ts.versionMajorMinor
26
25
  export const createImportClause: (
27
26
  factory: any,
28
27
  isTypeOnly: boolean,
29
- name: Identifier | void,
30
- namedBindings: NamedImportBindings | void,
28
+ name: Identifier | undefined,
29
+ namedBindings: NamedImportBindings | undefined,
31
30
  ) => ImportClause = (() => {
32
31
  if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 0)) {
33
- return (factory, isTypeOnly, name, namedBindings) =>
34
- factory.createImportClause(isTypeOnly, name, namedBindings);
32
+ return (
33
+ factory: any,
34
+ isTypeOnly: boolean,
35
+ name: undefined | Identifier,
36
+ namedBindings: undefined | NamedImportBindings,
37
+ ) => factory.createImportClause(isTypeOnly, name, namedBindings);
35
38
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 8)) {
36
- return (factory, isTypeOnly, name, namedBindings) =>
37
- factory.createImportClause(name, namedBindings, isTypeOnly);
39
+ return (
40
+ factory: any,
41
+ isTypeOnly: boolean,
42
+ name: undefined | Identifier,
43
+ namedBindings: undefined | NamedImportBindings,
44
+ ) => factory.createImportClause(name, namedBindings, isTypeOnly);
38
45
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 0)) {
39
- return (factory, isTypeOnly, name, namedBindings) =>
40
- factory.createImportClause(name, namedBindings);
46
+ return (
47
+ factory: any,
48
+ isTypeOnly: boolean,
49
+ name: undefined | Identifier,
50
+ namedBindings: undefined | NamedImportBindings,
51
+ ) => factory.createImportClause(name, namedBindings);
41
52
  } else {
42
53
  invariant(false);
43
54
  }
@@ -45,13 +56,19 @@ export const createImportClause: (
45
56
 
46
57
  export const createImportDeclaration: (
47
58
  factory: any,
48
- modifiers: Modifier[] | void,
49
- importClause: ImportClause | void,
59
+ modifiers: Modifier[] | undefined,
60
+ importClause: ImportClause | undefined,
50
61
  moduleSpecifier: Expression,
51
62
  assertClause: AssertClause,
52
63
  ) => ImportDeclaration = (() => {
53
64
  if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 8)) {
54
- return (factory, modifiers, importClause, moduleSpecifier, assertClause) =>
65
+ return (
66
+ factory: any,
67
+ modifiers: undefined | Array<Modifier>,
68
+ importClause: undefined | ImportClause,
69
+ moduleSpecifier: Expression,
70
+ assertClause: AssertClause,
71
+ ) =>
55
72
  factory.createImportDeclaration(
56
73
  modifiers,
57
74
  importClause,
@@ -59,7 +76,13 @@ export const createImportDeclaration: (
59
76
  assertClause,
60
77
  );
61
78
  } else if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 5)) {
62
- return (factory, modifiers, importClause, moduleSpecifier, assertClause) =>
79
+ return (
80
+ factory: any,
81
+ modifiers: undefined | Array<Modifier>,
82
+ importClause: undefined | ImportClause,
83
+ moduleSpecifier: Expression,
84
+ assertClause: AssertClause,
85
+ ) =>
63
86
  factory.createImportDeclaration(
64
87
  undefined /* decorators */,
65
88
  modifiers,
@@ -68,7 +91,13 @@ export const createImportDeclaration: (
68
91
  assertClause,
69
92
  );
70
93
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 0)) {
71
- return (factory, modifiers, importClause, moduleSpecifier, assertClause) =>
94
+ return (
95
+ factory: any,
96
+ modifiers: undefined | Array<Modifier>,
97
+ importClause: undefined | ImportClause,
98
+ moduleSpecifier: Expression,
99
+ assertClause: AssertClause,
100
+ ) =>
72
101
  factory.createImportDeclaration(
73
102
  undefined /* decorators */,
74
103
  modifiers,
@@ -83,15 +112,23 @@ export const createImportDeclaration: (
83
112
  export const createImportSpecifier: (
84
113
  factory: any,
85
114
  isTypeOnly: boolean,
86
- propertyName: Identifier | void,
115
+ propertyName: Identifier | undefined,
87
116
  name: Identifier,
88
117
  ) => ImportSpecifier = (() => {
89
118
  if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 5)) {
90
- return (factory, isTypeOnly, propertyName, name) =>
91
- factory.createImportSpecifier(isTypeOnly, propertyName, name);
119
+ return (
120
+ factory: any,
121
+ isTypeOnly: boolean,
122
+ propertyName: undefined | Identifier,
123
+ name: Identifier,
124
+ ) => factory.createImportSpecifier(isTypeOnly, propertyName, name);
92
125
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 0)) {
93
- return (factory, isTypeOnly, propertyName, name) =>
94
- factory.createImportSpecifier(propertyName, name);
126
+ return (
127
+ factory: any,
128
+ isTypeOnly: boolean,
129
+ propertyName: undefined | Identifier,
130
+ name: Identifier,
131
+ ) => factory.createImportSpecifier(propertyName, name);
95
132
  } else {
96
133
  invariant(false);
97
134
  }
@@ -100,21 +137,21 @@ export const createImportSpecifier: (
100
137
  export const updateExportDeclaration: (
101
138
  factory: any,
102
139
  node: ExportDeclaration,
103
- modifiers: Modifier[] | void,
140
+ modifiers: Modifier[] | undefined,
104
141
  isTypeOnly: boolean,
105
- exportClause: NamedExportBindings | void,
106
- moduleSpecifier: Expression | void,
107
- assertClause: AssertClause | void,
142
+ exportClause: NamedExportBindings | undefined,
143
+ moduleSpecifier: Expression | undefined,
144
+ assertClause: AssertClause | undefined,
108
145
  ) => ExportDeclaration = (() => {
109
146
  if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 8)) {
110
147
  return (
111
- factory,
112
- node,
113
- modifiers,
114
- isTypeOnly,
115
- exportClause,
116
- moduleSpecifier,
117
- assertClause,
148
+ factory: any,
149
+ node: ExportDeclaration,
150
+ modifiers: undefined | Array<Modifier>,
151
+ isTypeOnly: boolean,
152
+ exportClause: undefined | NamedExportBindings,
153
+ moduleSpecifier: undefined | Expression,
154
+ assertClause: undefined | AssertClause,
118
155
  ) =>
119
156
  factory.updateExportDeclaration(
120
157
  node,
@@ -126,13 +163,13 @@ export const updateExportDeclaration: (
126
163
  );
127
164
  } else if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 5)) {
128
165
  return (
129
- factory,
130
- node,
131
- modifiers,
132
- isTypeOnly,
133
- exportClause,
134
- moduleSpecifier,
135
- assertClause,
166
+ factory: any,
167
+ node: ExportDeclaration,
168
+ modifiers: undefined | Array<Modifier>,
169
+ isTypeOnly: boolean,
170
+ exportClause: undefined | NamedExportBindings,
171
+ moduleSpecifier: undefined | Expression,
172
+ assertClause: undefined | AssertClause,
136
173
  ) =>
137
174
  factory.updateExportDeclaration(
138
175
  node,
@@ -145,13 +182,13 @@ export const updateExportDeclaration: (
145
182
  );
146
183
  } else if (majorVersion > 4 || (majorVersion === 4 && minorVersion >= 0)) {
147
184
  return (
148
- factory,
149
- node,
150
- modifiers,
151
- isTypeOnly,
152
- exportClause,
153
- moduleSpecifier,
154
- assertClause,
185
+ factory: any,
186
+ node: ExportDeclaration,
187
+ modifiers: undefined | Array<Modifier>,
188
+ isTypeOnly: boolean,
189
+ exportClause: undefined | NamedExportBindings,
190
+ moduleSpecifier: undefined | Expression,
191
+ assertClause: undefined | AssertClause,
155
192
  ) =>
156
193
  factory.updateExportDeclaration(
157
194
  node,
@@ -163,13 +200,13 @@ export const updateExportDeclaration: (
163
200
  );
164
201
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 8)) {
165
202
  return (
166
- factory,
167
- node,
168
- modifiers,
169
- isTypeOnly,
170
- exportClause,
171
- moduleSpecifier,
172
- assertClause,
203
+ factory: any,
204
+ node: ExportDeclaration,
205
+ modifiers: undefined | Array<Modifier>,
206
+ isTypeOnly: boolean,
207
+ exportClause: undefined | NamedExportBindings,
208
+ moduleSpecifier: undefined | Expression,
209
+ assertClause: undefined | AssertClause,
173
210
  ) =>
174
211
  factory.updateExportDeclaration(
175
212
  node,
@@ -181,13 +218,13 @@ export const updateExportDeclaration: (
181
218
  );
182
219
  } else if (majorVersion > 3 || (majorVersion === 3 && minorVersion >= 0)) {
183
220
  return (
184
- factory,
185
- node,
186
- modifiers,
187
- isTypeOnly,
188
- exportClause,
189
- moduleSpecifier,
190
- assertClause,
221
+ factory: any,
222
+ node: ExportDeclaration,
223
+ modifiers: undefined | Array<Modifier>,
224
+ isTypeOnly: boolean,
225
+ exportClause: undefined | NamedExportBindings,
226
+ moduleSpecifier: undefined | Expression,
227
+ assertClause: undefined | AssertClause,
191
228
  ) =>
192
229
  factory.updateExportDeclaration(
193
230
  node,
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }