expo-type-information 0.0.2 → 0.0.4
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/build/cli.js +3 -1
- package/build/cli.js.map +1 -1
- package/build/commands/commandUtils.js +2 -2
- package/build/commands/commandUtils.js.map +1 -1
- package/build/commands/generateJSXIntrinsicsCommand.js +3 -1
- package/build/commands/generateJSXIntrinsicsCommand.js.map +1 -1
- package/build/commands/generateMocksForFileCommand.js +3 -1
- package/build/commands/generateMocksForFileCommand.js.map +1 -1
- package/build/commands/generateModuleTypesCommand.js +3 -1
- package/build/commands/generateModuleTypesCommand.js.map +1 -1
- package/build/commands/generateViewTypesCommand.js +3 -1
- package/build/commands/generateViewTypesCommand.js.map +1 -1
- package/build/commands/inlineModulesInterfaceCommand.js +5 -2
- package/build/commands/inlineModulesInterfaceCommand.js.map +1 -1
- package/build/commands/moduleInterfaceCommand.js +7 -1
- package/build/commands/moduleInterfaceCommand.js.map +1 -1
- package/build/commands/preprocessFileCommand.d.ts +2 -0
- package/build/commands/preprocessFileCommand.js +31 -0
- package/build/commands/preprocessFileCommand.js.map +1 -0
- package/build/commands/shortModuleInterfaceCommand.js +1 -1
- package/build/commands/shortModuleInterfaceCommand.js.map +1 -1
- package/build/commands/typeInformationCommand.js +3 -1
- package/build/commands/typeInformationCommand.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js.map +1 -1
- package/build/mockgen.d.ts +21 -0
- package/build/mockgen.js +21 -0
- package/build/mockgen.js.map +1 -1
- package/build/typeInformation.d.ts +114 -11
- package/build/typeInformation.js +37 -16
- package/build/typeInformation.js.map +1 -1
- package/build/typescriptGeneration.d.ts +50 -0
- package/build/typescriptGeneration.js +42 -1
- package/build/typescriptGeneration.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +3 -1
- package/src/commands/commandUtils.ts +2 -2
- package/src/commands/generateJSXIntrinsicsCommand.ts +6 -4
- package/src/commands/generateMocksForFileCommand.ts +4 -4
- package/src/commands/generateModuleTypesCommand.ts +4 -4
- package/src/commands/generateViewTypesCommand.ts +4 -4
- package/src/commands/inlineModulesInterfaceCommand.ts +10 -3
- package/src/commands/moduleInterfaceCommand.ts +7 -1
- package/src/commands/preprocessFileCommand.ts +41 -0
- package/src/commands/shortModuleInterfaceCommand.ts +1 -1
- package/src/commands/typeInformationCommand.ts +4 -4
- package/src/index.ts +1 -0
- package/src/mockgen.ts +21 -0
- package/src/typeInformation.ts +141 -22
- package/src/typescriptGeneration.ts +53 -1
- package/tests/__snapshots__/typeInformation.test.ts.snap +25 -25
package/src/typeInformation.ts
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
} from './swift/sourcekittenTypeInformation';
|
|
9
9
|
import { taskAll } from './utils';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Represents the kind of a parsed identifier from a native file.
|
|
13
|
+
*/
|
|
11
14
|
export enum IdentifierKind {
|
|
12
15
|
BASIC,
|
|
13
16
|
ENUM,
|
|
@@ -15,40 +18,85 @@ export enum IdentifierKind {
|
|
|
15
18
|
CLASS,
|
|
16
19
|
}
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Represents a parametrized type, that is a generic type with specified parameters e.g. Map<string, number>.
|
|
23
|
+
*/
|
|
18
24
|
export type ParametrizedType = {
|
|
19
25
|
name: TypeIdentifier;
|
|
20
26
|
types: Type[];
|
|
21
27
|
};
|
|
22
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Represents an argument passed to a function or constructor.
|
|
31
|
+
*/
|
|
23
32
|
export type Argument = { name: string | undefined; type: Type };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents a single field within a record or a struct.
|
|
36
|
+
*/
|
|
24
37
|
export type Field = Argument;
|
|
25
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Represents a struct or dictionary-like record consisting of named fields.
|
|
41
|
+
*/
|
|
26
42
|
export type RecordType = {
|
|
27
43
|
name: string;
|
|
28
44
|
fields: Field[];
|
|
29
45
|
};
|
|
30
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Represents a single case inside an enum declaration.
|
|
49
|
+
*/
|
|
31
50
|
export type EnumCase = string;
|
|
32
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Represents an enum type, containing its name and all associated cases.
|
|
54
|
+
*/
|
|
33
55
|
export type EnumType = {
|
|
34
56
|
name: string;
|
|
35
57
|
cases: EnumCase[];
|
|
36
58
|
};
|
|
37
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Represents a union or a sum type where a value can be one of several different types.
|
|
62
|
+
*/
|
|
38
63
|
export type SumType = {
|
|
39
64
|
types: Type[];
|
|
40
65
|
};
|
|
41
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Represents a dictionary type, defining the explicit types for its keys and values.
|
|
69
|
+
*/
|
|
42
70
|
export type DictionaryType = {
|
|
43
71
|
key: Type;
|
|
44
72
|
value: Type;
|
|
45
73
|
};
|
|
46
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Represents an optional type that can also resolve to null or undefined.
|
|
77
|
+
* > **Note:** The information that this type is optional is implicit and exists only in the type system and on the parent type. There is no field on the `OptionalType` object that explicitly indicates that.
|
|
78
|
+
*/
|
|
47
79
|
export type OptionalType = Type;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Represents a list or array of a specific type.
|
|
83
|
+
* > **Note:** The information that this type is array is implicit and exists only in the type system and on the parent type. There is no field on the `ArrayType` object that explicitly indicates that.
|
|
84
|
+
*/
|
|
48
85
|
export type ArrayType = Type;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Represents a type identifier as a string reference.
|
|
89
|
+
*/
|
|
49
90
|
export type TypeIdentifier = string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Represents an anonymous type, a one that is not named instead written directly in the code, such as inline generics, arrays, or optionals.
|
|
94
|
+
*/
|
|
50
95
|
export type AnonymousType = ParametrizedType | SumType | OptionalType | DictionaryType | ArrayType;
|
|
51
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Categorizes the type node within the abstract syntax tree.
|
|
99
|
+
*/
|
|
52
100
|
export enum TypeKind {
|
|
53
101
|
BASIC,
|
|
54
102
|
IDENTIFIER,
|
|
@@ -59,6 +107,9 @@ export enum TypeKind {
|
|
|
59
107
|
DICTIONARY,
|
|
60
108
|
}
|
|
61
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Represents a basic type that is not user defined.
|
|
112
|
+
*/
|
|
62
113
|
export enum BasicType {
|
|
63
114
|
ANY,
|
|
64
115
|
STRING,
|
|
@@ -66,32 +117,55 @@ export enum BasicType {
|
|
|
66
117
|
BOOLEAN,
|
|
67
118
|
VOID,
|
|
68
119
|
UNDEFINED,
|
|
120
|
+
/** Represents a type that couldn't be resolved */
|
|
69
121
|
UNRESOLVED,
|
|
70
122
|
}
|
|
71
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Represents an abstract type node.
|
|
126
|
+
*/
|
|
72
127
|
export type Type = {
|
|
73
128
|
kind: TypeKind;
|
|
74
129
|
type: BasicType | TypeIdentifier | AnonymousType;
|
|
75
130
|
};
|
|
76
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Represents a DSL property declaration.
|
|
134
|
+
*/
|
|
77
135
|
export type PropertyDeclaration = ConstantDeclaration;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Represents a DSL view declaration.
|
|
139
|
+
*/
|
|
78
140
|
export type ViewDeclaration = ModuleClassDeclaration;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Represents a DSL event declaration.
|
|
144
|
+
*/
|
|
79
145
|
export type EventDeclaration = string;
|
|
80
146
|
|
|
81
147
|
/**
|
|
82
|
-
*
|
|
148
|
+
* Retains information of where the thing was defined in the file.
|
|
83
149
|
* As collecting type information is written in asynchronous way it is non-deterministic.
|
|
84
|
-
* To make it deterministic we just sort the declaration by the definitionOffset,
|
|
150
|
+
* To make it deterministic we just sort the declaration by the definitionOffset, maintaining the same ordering as in original file.
|
|
151
|
+
* @header TypeInfoTypes
|
|
85
152
|
*/
|
|
86
153
|
export type DefinitionOffset = {
|
|
87
154
|
definitionOffset: number;
|
|
88
155
|
};
|
|
89
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Represents a DSL constant declaration.
|
|
159
|
+
*/
|
|
90
160
|
export type ConstantDeclaration = {
|
|
91
161
|
name: string;
|
|
92
162
|
type: Type;
|
|
93
163
|
} & DefinitionOffset;
|
|
94
164
|
|
|
165
|
+
/**
|
|
166
|
+
* Represents a DSL function declaration.
|
|
167
|
+
* @hideType
|
|
168
|
+
*/
|
|
95
169
|
export type FunctionDeclaration = {
|
|
96
170
|
name: string;
|
|
97
171
|
returnType: Type;
|
|
@@ -99,15 +173,24 @@ export type FunctionDeclaration = {
|
|
|
99
173
|
parameters: Type[];
|
|
100
174
|
} & DefinitionOffset;
|
|
101
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Represents a DSL prop declaration.
|
|
178
|
+
*/
|
|
102
179
|
export type PropDeclaration = {
|
|
103
180
|
name: string;
|
|
104
181
|
arguments: Argument[];
|
|
105
182
|
} & DefinitionOffset;
|
|
106
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Represents a DSL class constructor declaration.
|
|
186
|
+
*/
|
|
107
187
|
export type ConstructorDeclaration = {
|
|
108
188
|
arguments: Argument[];
|
|
109
189
|
} & DefinitionOffset;
|
|
110
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Represents a DSL native class declaration.
|
|
193
|
+
*/
|
|
111
194
|
export type ClassDeclaration = {
|
|
112
195
|
name: string;
|
|
113
196
|
constructor: ConstructorDeclaration | null;
|
|
@@ -116,6 +199,9 @@ export type ClassDeclaration = {
|
|
|
116
199
|
properties: PropertyDeclaration[];
|
|
117
200
|
} & DefinitionOffset;
|
|
118
201
|
|
|
202
|
+
/**
|
|
203
|
+
* Represents a DSL module declaration.
|
|
204
|
+
*/
|
|
119
205
|
export type ModuleClassDeclaration = {
|
|
120
206
|
name: string;
|
|
121
207
|
constructor: ConstructorDeclaration | null;
|
|
@@ -129,15 +215,27 @@ export type ModuleClassDeclaration = {
|
|
|
129
215
|
events: EventDeclaration[];
|
|
130
216
|
} & DefinitionOffset;
|
|
131
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Represents a definition of an identifier.
|
|
220
|
+
*/
|
|
132
221
|
export type IdentifierDefinition = {
|
|
133
222
|
kind: IdentifierKind;
|
|
134
223
|
definition: string | RecordType | EnumType | ClassDeclaration;
|
|
135
224
|
};
|
|
136
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Maps type identifier strings to their definition objects.
|
|
228
|
+
*/
|
|
137
229
|
export type TypeIdentifierDefinitionMap = Map<string, IdentifierDefinition>;
|
|
138
230
|
|
|
231
|
+
/**
|
|
232
|
+
* Serialized version of the `TypeIdentifierDefinitionMap`.
|
|
233
|
+
*/
|
|
139
234
|
export type TypeIdentifierDefinitionList = [string, IdentifierDefinition][];
|
|
140
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Serialized version of the `FileTypeInformation`, suitable for JSON storage or testing environments.
|
|
238
|
+
*/
|
|
141
239
|
export type FileTypeInformationSerialized = {
|
|
142
240
|
usedTypeIdentifiersList: string[];
|
|
143
241
|
declaredTypeIdentifiersList: string[];
|
|
@@ -149,9 +247,10 @@ export type FileTypeInformationSerialized = {
|
|
|
149
247
|
};
|
|
150
248
|
|
|
151
249
|
/**
|
|
152
|
-
* FileTypeInformation object abstracts over type related information in a file.
|
|
250
|
+
* `FileTypeInformation` object abstracts over type related information in a file.
|
|
153
251
|
* The abstraction is closely related to Typescript and expo NativeModules (both to be independent of the actual native side
|
|
154
252
|
* and to give accurate information about what and how we can use the given module).
|
|
253
|
+
* @header TypeInfoTypes
|
|
155
254
|
*/
|
|
156
255
|
export type FileTypeInformation = {
|
|
157
256
|
/**
|
|
@@ -190,9 +289,10 @@ export type FileTypeInformation = {
|
|
|
190
289
|
};
|
|
191
290
|
|
|
192
291
|
/**
|
|
193
|
-
* Used for testing purposes, maps Sets and Maps to Arrays and returns FileTypeInformationSerialized object which can be written to a JSON.
|
|
194
|
-
* @param
|
|
195
|
-
* @returns FileTypeInformationSerialized object.
|
|
292
|
+
* Used for testing purposes, maps Sets and Maps to Arrays and returns `FileTypeInformationSerialized` object which can be written to a JSON.
|
|
293
|
+
* @param fileTypeinformation `FileTypeInformation` object to serialize.
|
|
294
|
+
* @returns a `FileTypeInformationSerialized` object.
|
|
295
|
+
* @header TypeInformationAbstraction
|
|
196
296
|
*/
|
|
197
297
|
export function serializeTypeInformation({
|
|
198
298
|
usedTypeIdentifiers,
|
|
@@ -215,9 +315,10 @@ export function serializeTypeInformation({
|
|
|
215
315
|
}
|
|
216
316
|
|
|
217
317
|
/**
|
|
218
|
-
*
|
|
219
|
-
* @param
|
|
220
|
-
* @returns FileTypeInformation object.
|
|
318
|
+
* Used for testing purposes, maps Arrays to Sets and Maps depending on the field and returns `FileTypeInformation` object.
|
|
319
|
+
* @param fileTypeinformationSerialized `FileTypeInformationSerialized` object to deserialize.
|
|
320
|
+
* @returns `FileTypeInformation` object.
|
|
321
|
+
* @header TypeInformationAbstraction
|
|
221
322
|
*/
|
|
222
323
|
export function deserializeTypeInformation({
|
|
223
324
|
usedTypeIdentifiersList,
|
|
@@ -241,7 +342,7 @@ export function deserializeTypeInformation({
|
|
|
241
342
|
|
|
242
343
|
/**
|
|
243
344
|
* Defines the level of type inference to apply when extracting type information.
|
|
244
|
-
* Note
|
|
345
|
+
* > **Note:** In case where type inference is on, it may take more then twice the time to compute the type information.
|
|
245
346
|
*/
|
|
246
347
|
export enum TypeInferenceOption {
|
|
247
348
|
/** No type inference will be performed. */
|
|
@@ -252,12 +353,18 @@ export enum TypeInferenceOption {
|
|
|
252
353
|
PREPROCESS_AND_INFERENCE,
|
|
253
354
|
}
|
|
254
355
|
|
|
356
|
+
/**
|
|
357
|
+
* Defines an input option for extracting type information directly from a raw string of source code.
|
|
358
|
+
*/
|
|
255
359
|
export type StringInputOption = {
|
|
256
360
|
type: 'string';
|
|
257
361
|
fileContent: string;
|
|
258
362
|
language: 'Swift';
|
|
259
363
|
};
|
|
260
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Defines an input option for extracting type information from a set of physical files.
|
|
367
|
+
*/
|
|
261
368
|
export type FileInputOption = {
|
|
262
369
|
type: 'file';
|
|
263
370
|
inputFileAbsolutePaths: string[];
|
|
@@ -292,12 +399,33 @@ async function withTempFile<T>(content: string, fn: (filePath: string) => Promis
|
|
|
292
399
|
}
|
|
293
400
|
}
|
|
294
401
|
|
|
402
|
+
export async function withPreparedSingleFile<T>(
|
|
403
|
+
{ input, typeInference }: GetFileTypeInformationOptions,
|
|
404
|
+
fn: (filePath: string) => Promise<T>
|
|
405
|
+
): Promise<T> {
|
|
406
|
+
const shouldPreprocessFile = typeInference === TypeInferenceOption.PREPROCESS_AND_INFERENCE;
|
|
407
|
+
if (!shouldPreprocessFile && input.type === 'file' && input.inputFileAbsolutePaths.length === 0) {
|
|
408
|
+
return fn(input.inputFileAbsolutePaths[0] as string);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const fileContent =
|
|
412
|
+
input.type === 'file'
|
|
413
|
+
? await mergeFileContents(input.inputFileAbsolutePaths)
|
|
414
|
+
: input.fileContent;
|
|
415
|
+
|
|
416
|
+
if (shouldPreprocessFile) {
|
|
417
|
+
return withTempFile(preprocessSwiftFile(fileContent), fn);
|
|
418
|
+
}
|
|
419
|
+
return withTempFile(fileContent, fn);
|
|
420
|
+
}
|
|
421
|
+
|
|
295
422
|
/**
|
|
296
423
|
* Reads and extracts `FileTypeInformation` from either a provided file path or a raw string of source code.
|
|
297
424
|
* If a raw string is provided, or if the `PREPROCESS_AND_INFERENCE` inference option is selected,
|
|
298
425
|
* the function will create a temporary file with the (optionally preprocessed) content to facilitate parsing.
|
|
299
426
|
* @param options - Configuration object containing the input source (file or string) and the desired level of type inference.
|
|
300
|
-
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it
|
|
427
|
+
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it resolves to `null`.
|
|
428
|
+
* @header TypeInformationAbstraction
|
|
301
429
|
*/
|
|
302
430
|
export async function getFileTypeInformation({
|
|
303
431
|
input,
|
|
@@ -311,16 +439,7 @@ export async function getFileTypeInformation({
|
|
|
311
439
|
});
|
|
312
440
|
}
|
|
313
441
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
? await mergeFileContents(input.inputFileAbsolutePaths)
|
|
317
|
-
: input.fileContent;
|
|
318
|
-
|
|
319
|
-
const preprocessedContent = shouldPreprocessFile ? preprocessSwiftFile(fileContent) : fileContent;
|
|
320
|
-
|
|
321
|
-
return withTempFile(preprocessedContent, async (tempFilePath) => {
|
|
322
|
-
return getSwiftFileTypeInformation(tempFilePath, {
|
|
323
|
-
typeInference: typeInferenceOn,
|
|
324
|
-
});
|
|
442
|
+
return withPreparedSingleFile({ input, typeInference }, async (tempFilePath) => {
|
|
443
|
+
return getSwiftFileTypeInformation(tempFilePath, { typeInference: typeInferenceOn });
|
|
325
444
|
});
|
|
326
445
|
}
|
|
@@ -40,8 +40,17 @@ const voidKeywordType = () => ts.factory.createKeywordTypeNode(ts.SyntaxKind.Voi
|
|
|
40
40
|
|
|
41
41
|
const newlineIdentifier = () => ts.factory.createIdentifier('\n\n');
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* A helper type which contains the generated file content and name.
|
|
45
|
+
*/
|
|
43
46
|
export type OutputFile = {
|
|
47
|
+
/**
|
|
48
|
+
* @field Generated file content.
|
|
49
|
+
*/
|
|
44
50
|
content: string;
|
|
51
|
+
/**
|
|
52
|
+
* @field Generated file base name (e.g. `ExpoSettings.types.ts`).
|
|
53
|
+
*/
|
|
45
54
|
name: string;
|
|
46
55
|
};
|
|
47
56
|
|
|
@@ -717,7 +726,9 @@ export function buildEnumTypeDeclaration(
|
|
|
717
726
|
return ts.factory.createEnumDeclaration(
|
|
718
727
|
constructModifiersArray({ exported, declare: declared }),
|
|
719
728
|
enumType.name,
|
|
720
|
-
enumType.cases.map((enumcase) =>
|
|
729
|
+
enumType.cases.map((enumcase) =>
|
|
730
|
+
ts.factory.createEnumMember(enumcase, ts.factory.createStringLiteral(enumcase))
|
|
731
|
+
)
|
|
721
732
|
);
|
|
722
733
|
}
|
|
723
734
|
|
|
@@ -999,6 +1010,14 @@ async function tsNodesToString(elements: ts.Node[]): Promise<string> {
|
|
|
999
1010
|
return await prettifyCode(printedTs, 'typescript');
|
|
1000
1011
|
}
|
|
1001
1012
|
|
|
1013
|
+
/**
|
|
1014
|
+
* Helper function that takes a file content string and formats it using `prettier` formatter.
|
|
1015
|
+
* @param text Content of a JavaScript/TypeScript file to format.
|
|
1016
|
+
* @param parser An option of which parser to use to format the file.
|
|
1017
|
+
* @default "babel"
|
|
1018
|
+
* @returns A promise which resolves to the `text` string after formatting using `prettier` with the given `parser`.
|
|
1019
|
+
* @header TypescriptGeneration
|
|
1020
|
+
*/
|
|
1002
1021
|
export async function prettifyCode(text: string, parser: 'babel' | 'typescript' = 'babel') {
|
|
1003
1022
|
return await prettier.format(text, {
|
|
1004
1023
|
parser,
|
|
@@ -1009,6 +1028,12 @@ export async function prettifyCode(text: string, parser: 'babel' | 'typescript'
|
|
|
1009
1028
|
});
|
|
1010
1029
|
}
|
|
1011
1030
|
|
|
1031
|
+
/**
|
|
1032
|
+
* Generates the TypeScript string content for a native View's type declaration file.
|
|
1033
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
1034
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
1035
|
+
* @header TypescriptGeneration
|
|
1036
|
+
*/
|
|
1012
1037
|
export async function generateViewTypesFileContent(
|
|
1013
1038
|
fileTypeInformation: FileTypeInformation
|
|
1014
1039
|
): Promise<string | null> {
|
|
@@ -1019,6 +1044,12 @@ export async function generateViewTypesFileContent(
|
|
|
1019
1044
|
return tsNodesToString(buildViewDeclarationNodes(ctx));
|
|
1020
1045
|
}
|
|
1021
1046
|
|
|
1047
|
+
/**
|
|
1048
|
+
* Generates the TypeScript string content for a native View's type declaration file which mounts the View props on the global `JSXIntrinsics`.
|
|
1049
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
1050
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
1051
|
+
* @header TypescriptGeneration
|
|
1052
|
+
*/
|
|
1022
1053
|
export async function generateJSXIntrinsicsFileContent(
|
|
1023
1054
|
fileTypeInformation: FileTypeInformation
|
|
1024
1055
|
): Promise<string | null> {
|
|
@@ -1029,6 +1060,12 @@ export async function generateJSXIntrinsicsFileContent(
|
|
|
1029
1060
|
return tsNodesToString(buildJSXIntrinsicsViewNodes(ctx));
|
|
1030
1061
|
}
|
|
1031
1062
|
|
|
1063
|
+
/**
|
|
1064
|
+
* Generates the TypeScript string content for a native module type declaration file.
|
|
1065
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
1066
|
+
* @returns A promise that resolves to a string containing the TypeScript module declaration file content or `null` if the generation has failed.
|
|
1067
|
+
* @header TypescriptGeneration
|
|
1068
|
+
*/
|
|
1032
1069
|
export async function generateModuleTypesFileContent(
|
|
1033
1070
|
fileTypeInformation: FileTypeInformation
|
|
1034
1071
|
): Promise<string | null> {
|
|
@@ -1039,6 +1076,13 @@ export async function generateModuleTypesFileContent(
|
|
|
1039
1076
|
return tsNodesToString(buildModuleDeclarationNodes(ctx));
|
|
1040
1077
|
}
|
|
1041
1078
|
|
|
1079
|
+
/**
|
|
1080
|
+
* Generates a short TypeScript interface for an Expo module. This creates the content for two files: a volatile generated file containing raw type definitions,
|
|
1081
|
+
* and a stable user-facing file that wraps and exports the native module methods in new functions.
|
|
1082
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
1083
|
+
* @returns A promise that resolves to an object containing the string contents for both the volatile generated file and the stable TypeScript interface file.
|
|
1084
|
+
* @header TypescriptGeneration
|
|
1085
|
+
*/
|
|
1042
1086
|
export async function generateConciseTsInterface(
|
|
1043
1087
|
fileTypeInformation: FileTypeInformation
|
|
1044
1088
|
): Promise<{
|
|
@@ -1062,6 +1106,14 @@ export async function generateConciseTsInterface(
|
|
|
1062
1106
|
};
|
|
1063
1107
|
}
|
|
1064
1108
|
|
|
1109
|
+
/**
|
|
1110
|
+
* Generates a full, multi-file TypeScript interface for an Expo module.
|
|
1111
|
+
* The generated interface is separated into a file with type definitions, a file which wraps the native module, a file for each view defined in a module and an index file which reexports all definitions from the other files.
|
|
1112
|
+
*
|
|
1113
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
1114
|
+
* @returns A promise that resolves to an object containing the string contents for all of the generated files or `null` if the generation has failed.
|
|
1115
|
+
* @header TypescriptGeneration
|
|
1116
|
+
*/
|
|
1065
1117
|
export async function generateFullTsInterface(fileTypeInformation: FileTypeInformation): Promise<{
|
|
1066
1118
|
moduleTypesFile: OutputFile;
|
|
1067
1119
|
moduleViewsFiles: OutputFile[];
|
|
@@ -34,11 +34,11 @@ export type TestRecordClass = {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export enum TestEnum {
|
|
37
|
-
simpleCase,
|
|
38
|
-
multipleCases1,
|
|
39
|
-
multipleCases2,
|
|
40
|
-
caseWithArgs1,
|
|
41
|
-
caseWithArgs2
|
|
37
|
+
simpleCase = 'simpleCase',
|
|
38
|
+
multipleCases1 = 'multipleCases1',
|
|
39
|
+
multipleCases2 = 'multipleCases2',
|
|
40
|
+
caseWithArgs1 = 'caseWithArgs1',
|
|
41
|
+
caseWithArgs2 = 'caseWithArgs2'
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export declare class TestClassWithConstructor {
|
|
@@ -298,11 +298,11 @@ export type TestRecordClass = {
|
|
|
298
298
|
};
|
|
299
299
|
|
|
300
300
|
export enum TestEnum {
|
|
301
|
-
simpleCase,
|
|
302
|
-
multipleCases1,
|
|
303
|
-
multipleCases2,
|
|
304
|
-
caseWithArgs1,
|
|
305
|
-
caseWithArgs2
|
|
301
|
+
simpleCase = 'simpleCase',
|
|
302
|
+
multipleCases1 = 'multipleCases1',
|
|
303
|
+
multipleCases2 = 'multipleCases2',
|
|
304
|
+
caseWithArgs1 = 'caseWithArgs1',
|
|
305
|
+
caseWithArgs2 = 'caseWithArgs2'
|
|
306
306
|
}
|
|
307
307
|
|
|
308
308
|
export declare class TestClassWithConstructor {
|
|
@@ -387,11 +387,11 @@ export type TestRecordClass = {
|
|
|
387
387
|
|
|
388
388
|
|
|
389
389
|
export enum TestEnum {
|
|
390
|
-
simpleCase,
|
|
391
|
-
multipleCases1,
|
|
392
|
-
multipleCases2,
|
|
393
|
-
caseWithArgs1,
|
|
394
|
-
caseWithArgs2
|
|
390
|
+
simpleCase = "simpleCase",
|
|
391
|
+
multipleCases1 = "multipleCases1",
|
|
392
|
+
multipleCases2 = "multipleCases2",
|
|
393
|
+
caseWithArgs1 = "caseWithArgs1",
|
|
394
|
+
caseWithArgs2 = "caseWithArgs2"
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
|
|
@@ -454,11 +454,11 @@ exports[`Same generated mock file JS 1`] = `
|
|
|
454
454
|
* */
|
|
455
455
|
export var TestEnum;
|
|
456
456
|
(function (TestEnum) {
|
|
457
|
-
TestEnum[
|
|
458
|
-
TestEnum[
|
|
459
|
-
TestEnum[
|
|
460
|
-
TestEnum[
|
|
461
|
-
TestEnum[
|
|
457
|
+
TestEnum["simpleCase"] = "simpleCase";
|
|
458
|
+
TestEnum["multipleCases1"] = "multipleCases1";
|
|
459
|
+
TestEnum["multipleCases2"] = "multipleCases2";
|
|
460
|
+
TestEnum["caseWithArgs1"] = "caseWithArgs1";
|
|
461
|
+
TestEnum["caseWithArgs2"] = "caseWithArgs2";
|
|
462
462
|
})(TestEnum || (TestEnum = {}));
|
|
463
463
|
export function SimpleFunction(a, b) { return 0; }
|
|
464
464
|
export function TestUntypedFunction() { return ""; }
|
|
@@ -517,11 +517,11 @@ export type TestRecordClass = {
|
|
|
517
517
|
};
|
|
518
518
|
|
|
519
519
|
export enum TestEnum {
|
|
520
|
-
simpleCase,
|
|
521
|
-
multipleCases1,
|
|
522
|
-
multipleCases2,
|
|
523
|
-
caseWithArgs1,
|
|
524
|
-
caseWithArgs2
|
|
520
|
+
simpleCase = 'simpleCase',
|
|
521
|
+
multipleCases1 = 'multipleCases1',
|
|
522
|
+
multipleCases2 = 'multipleCases2',
|
|
523
|
+
caseWithArgs1 = 'caseWithArgs1',
|
|
524
|
+
caseWithArgs2 = 'caseWithArgs2'
|
|
525
525
|
}
|
|
526
526
|
|
|
527
527
|
export declare class TestClassWithConstructor {
|