@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.
@@ -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,21 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["src"],
4
+ "compilerOptions": {
5
+ "composite": true
6
+ },
7
+ "references": [
8
+ {
9
+ "path": "../../core/diagnostic/tsconfig.json"
10
+ },
11
+ {
12
+ "path": "../../core/plugin/tsconfig.json"
13
+ },
14
+ {
15
+ "path": "../../core/utils/tsconfig.json"
16
+ },
17
+ {
18
+ "path": "../../utils/ts-utils/tsconfig.json"
19
+ }
20
+ ]
21
+ }