expo-type-information 0.0.2 → 0.0.3
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 +1 -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/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 +113 -11
- package/build/typeInformation.js +21 -8
- package/build/typeInformation.js.map +1 -1
- package/build/typescriptGeneration.d.ts +50 -0
- package/build/typescriptGeneration.js +41 -0
- package/build/typescriptGeneration.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +1 -2
- 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/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 +119 -11
- package/src/typescriptGeneration.ts +50 -0
|
@@ -1,38 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the kind of a parsed identifier from a native file.
|
|
3
|
+
*/
|
|
1
4
|
export declare enum IdentifierKind {
|
|
2
5
|
BASIC = 0,
|
|
3
6
|
ENUM = 1,
|
|
4
7
|
RECORD = 2,
|
|
5
8
|
CLASS = 3
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Represents a parametrized type, that is a generic type with specified parameters e.g. Map<string, number>.
|
|
12
|
+
*/
|
|
7
13
|
export type ParametrizedType = {
|
|
8
14
|
name: TypeIdentifier;
|
|
9
15
|
types: Type[];
|
|
10
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Represents an argument passed to a function or constructor.
|
|
19
|
+
*/
|
|
11
20
|
export type Argument = {
|
|
12
21
|
name: string | undefined;
|
|
13
22
|
type: Type;
|
|
14
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Represents a single field within a record or a struct.
|
|
26
|
+
*/
|
|
15
27
|
export type Field = Argument;
|
|
28
|
+
/**
|
|
29
|
+
* Represents a struct or dictionary-like record consisting of named fields.
|
|
30
|
+
*/
|
|
16
31
|
export type RecordType = {
|
|
17
32
|
name: string;
|
|
18
33
|
fields: Field[];
|
|
19
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Represents a single case inside an enum declaration.
|
|
37
|
+
*/
|
|
20
38
|
export type EnumCase = string;
|
|
39
|
+
/**
|
|
40
|
+
* Represents an enum type, containing its name and all associated cases.
|
|
41
|
+
*/
|
|
21
42
|
export type EnumType = {
|
|
22
43
|
name: string;
|
|
23
44
|
cases: EnumCase[];
|
|
24
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* Represents a union or a sum type where a value can be one of several different types.
|
|
48
|
+
*/
|
|
25
49
|
export type SumType = {
|
|
26
50
|
types: Type[];
|
|
27
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Represents a dictionary type, defining the explicit types for its keys and values.
|
|
54
|
+
*/
|
|
28
55
|
export type DictionaryType = {
|
|
29
56
|
key: Type;
|
|
30
57
|
value: Type;
|
|
31
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* Represents an optional type that can also resolve to null or undefined.
|
|
61
|
+
* > **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.
|
|
62
|
+
*/
|
|
32
63
|
export type OptionalType = Type;
|
|
64
|
+
/**
|
|
65
|
+
* Represents a list or array of a specific type.
|
|
66
|
+
* > **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.
|
|
67
|
+
*/
|
|
33
68
|
export type ArrayType = Type;
|
|
69
|
+
/**
|
|
70
|
+
* Represents a type identifier as a string reference.
|
|
71
|
+
*/
|
|
34
72
|
export type TypeIdentifier = string;
|
|
73
|
+
/**
|
|
74
|
+
* Represents an anonymous type, a one that is not named instead written directly in the code, such as inline generics, arrays, or optionals.
|
|
75
|
+
*/
|
|
35
76
|
export type AnonymousType = ParametrizedType | SumType | OptionalType | DictionaryType | ArrayType;
|
|
77
|
+
/**
|
|
78
|
+
* Categorizes the type node within the abstract syntax tree.
|
|
79
|
+
*/
|
|
36
80
|
export declare enum TypeKind {
|
|
37
81
|
BASIC = 0,
|
|
38
82
|
IDENTIFIER = 1,
|
|
@@ -42,6 +86,9 @@ export declare enum TypeKind {
|
|
|
42
86
|
ARRAY = 5,
|
|
43
87
|
DICTIONARY = 6
|
|
44
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Represents a basic type that is not user defined.
|
|
91
|
+
*/
|
|
45
92
|
export declare enum BasicType {
|
|
46
93
|
ANY = 0,
|
|
47
94
|
STRING = 1,
|
|
@@ -49,40 +96,70 @@ export declare enum BasicType {
|
|
|
49
96
|
BOOLEAN = 3,
|
|
50
97
|
VOID = 4,
|
|
51
98
|
UNDEFINED = 5,
|
|
99
|
+
/** Represents a type that couldn't be resolved */
|
|
52
100
|
UNRESOLVED = 6
|
|
53
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Represents an abstract type node.
|
|
104
|
+
*/
|
|
54
105
|
export type Type = {
|
|
55
106
|
kind: TypeKind;
|
|
56
107
|
type: BasicType | TypeIdentifier | AnonymousType;
|
|
57
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
* Represents a DSL property declaration.
|
|
111
|
+
*/
|
|
58
112
|
export type PropertyDeclaration = ConstantDeclaration;
|
|
113
|
+
/**
|
|
114
|
+
* Represents a DSL view declaration.
|
|
115
|
+
*/
|
|
59
116
|
export type ViewDeclaration = ModuleClassDeclaration;
|
|
117
|
+
/**
|
|
118
|
+
* Represents a DSL event declaration.
|
|
119
|
+
*/
|
|
60
120
|
export type EventDeclaration = string;
|
|
61
121
|
/**
|
|
62
|
-
*
|
|
122
|
+
* Retains information of where the thing was defined in the file.
|
|
63
123
|
* As collecting type information is written in asynchronous way it is non-deterministic.
|
|
64
|
-
* To make it deterministic we just sort the declaration by the definitionOffset,
|
|
124
|
+
* To make it deterministic we just sort the declaration by the definitionOffset, maintaining the same ordering as in original file.
|
|
125
|
+
* @header TypeInfoTypes
|
|
65
126
|
*/
|
|
66
127
|
export type DefinitionOffset = {
|
|
67
128
|
definitionOffset: number;
|
|
68
129
|
};
|
|
130
|
+
/**
|
|
131
|
+
* Represents a DSL constant declaration.
|
|
132
|
+
*/
|
|
69
133
|
export type ConstantDeclaration = {
|
|
70
134
|
name: string;
|
|
71
135
|
type: Type;
|
|
72
136
|
} & DefinitionOffset;
|
|
137
|
+
/**
|
|
138
|
+
* Represents a DSL function declaration.
|
|
139
|
+
* @hideType
|
|
140
|
+
*/
|
|
73
141
|
export type FunctionDeclaration = {
|
|
74
142
|
name: string;
|
|
75
143
|
returnType: Type;
|
|
76
144
|
arguments: Argument[];
|
|
77
145
|
parameters: Type[];
|
|
78
146
|
} & DefinitionOffset;
|
|
147
|
+
/**
|
|
148
|
+
* Represents a DSL prop declaration.
|
|
149
|
+
*/
|
|
79
150
|
export type PropDeclaration = {
|
|
80
151
|
name: string;
|
|
81
152
|
arguments: Argument[];
|
|
82
153
|
} & DefinitionOffset;
|
|
154
|
+
/**
|
|
155
|
+
* Represents a DSL class constructor declaration.
|
|
156
|
+
*/
|
|
83
157
|
export type ConstructorDeclaration = {
|
|
84
158
|
arguments: Argument[];
|
|
85
159
|
} & DefinitionOffset;
|
|
160
|
+
/**
|
|
161
|
+
* Represents a DSL native class declaration.
|
|
162
|
+
*/
|
|
86
163
|
export type ClassDeclaration = {
|
|
87
164
|
name: string;
|
|
88
165
|
constructor: ConstructorDeclaration | null;
|
|
@@ -90,6 +167,9 @@ export type ClassDeclaration = {
|
|
|
90
167
|
asyncMethods: FunctionDeclaration[];
|
|
91
168
|
properties: PropertyDeclaration[];
|
|
92
169
|
} & DefinitionOffset;
|
|
170
|
+
/**
|
|
171
|
+
* Represents a DSL module declaration.
|
|
172
|
+
*/
|
|
93
173
|
export type ModuleClassDeclaration = {
|
|
94
174
|
name: string;
|
|
95
175
|
constructor: ConstructorDeclaration | null;
|
|
@@ -102,12 +182,24 @@ export type ModuleClassDeclaration = {
|
|
|
102
182
|
views: ViewDeclaration[];
|
|
103
183
|
events: EventDeclaration[];
|
|
104
184
|
} & DefinitionOffset;
|
|
185
|
+
/**
|
|
186
|
+
* Represents a definition of an identifier.
|
|
187
|
+
*/
|
|
105
188
|
export type IdentifierDefinition = {
|
|
106
189
|
kind: IdentifierKind;
|
|
107
190
|
definition: string | RecordType | EnumType | ClassDeclaration;
|
|
108
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* Maps type identifier strings to their definition objects.
|
|
194
|
+
*/
|
|
109
195
|
export type TypeIdentifierDefinitionMap = Map<string, IdentifierDefinition>;
|
|
196
|
+
/**
|
|
197
|
+
* Serialized version of the `TypeIdentifierDefinitionMap`.
|
|
198
|
+
*/
|
|
110
199
|
export type TypeIdentifierDefinitionList = [string, IdentifierDefinition][];
|
|
200
|
+
/**
|
|
201
|
+
* Serialized version of the `FileTypeInformation`, suitable for JSON storage or testing environments.
|
|
202
|
+
*/
|
|
111
203
|
export type FileTypeInformationSerialized = {
|
|
112
204
|
usedTypeIdentifiersList: string[];
|
|
113
205
|
declaredTypeIdentifiersList: string[];
|
|
@@ -118,9 +210,10 @@ export type FileTypeInformationSerialized = {
|
|
|
118
210
|
enums: EnumType[];
|
|
119
211
|
};
|
|
120
212
|
/**
|
|
121
|
-
* FileTypeInformation object abstracts over type related information in a file.
|
|
213
|
+
* `FileTypeInformation` object abstracts over type related information in a file.
|
|
122
214
|
* The abstraction is closely related to Typescript and expo NativeModules (both to be independent of the actual native side
|
|
123
215
|
* and to give accurate information about what and how we can use the given module).
|
|
216
|
+
* @header TypeInfoTypes
|
|
124
217
|
*/
|
|
125
218
|
export type FileTypeInformation = {
|
|
126
219
|
/**
|
|
@@ -158,20 +251,22 @@ export type FileTypeInformation = {
|
|
|
158
251
|
enums: EnumType[];
|
|
159
252
|
};
|
|
160
253
|
/**
|
|
161
|
-
* Used for testing purposes, maps Sets and Maps to Arrays and returns FileTypeInformationSerialized object which can be written to a JSON.
|
|
162
|
-
* @param
|
|
163
|
-
* @returns FileTypeInformationSerialized object.
|
|
254
|
+
* Used for testing purposes, maps Sets and Maps to Arrays and returns `FileTypeInformationSerialized` object which can be written to a JSON.
|
|
255
|
+
* @param fileTypeinformation `FileTypeInformation` object to serialize.
|
|
256
|
+
* @returns a `FileTypeInformationSerialized` object.
|
|
257
|
+
* @header TypeInformationAbstraction
|
|
164
258
|
*/
|
|
165
259
|
export declare function serializeTypeInformation({ usedTypeIdentifiers, declaredTypeIdentifiers, inferredTypeParametersCount, typeIdentifierDefinitionMap, moduleClasses, records, enums, }: FileTypeInformation): FileTypeInformationSerialized;
|
|
166
260
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param
|
|
169
|
-
* @returns FileTypeInformation object.
|
|
261
|
+
* Used for testing purposes, maps Arrays to Sets and Maps depending on the field and returns `FileTypeInformation` object.
|
|
262
|
+
* @param fileTypeinformationSerialized `FileTypeInformationSerialized` object to deserialize.
|
|
263
|
+
* @returns `FileTypeInformation` object.
|
|
264
|
+
* @header TypeInformationAbstraction
|
|
170
265
|
*/
|
|
171
266
|
export declare function deserializeTypeInformation({ usedTypeIdentifiersList, declaredTypeIdentifiersList, inferredTypeParametersCountList, typeIdentifierDefinitionList, moduleClasses, records, enums, }: FileTypeInformationSerialized): FileTypeInformation;
|
|
172
267
|
/**
|
|
173
268
|
* Defines the level of type inference to apply when extracting type information.
|
|
174
|
-
* Note
|
|
269
|
+
* > **Note:** In case where type inference is on, it may take more then twice the time to compute the type information.
|
|
175
270
|
*/
|
|
176
271
|
export declare enum TypeInferenceOption {
|
|
177
272
|
/** No type inference will be performed. */
|
|
@@ -181,11 +276,17 @@ export declare enum TypeInferenceOption {
|
|
|
181
276
|
/** Preprocesses the file by injecting returns to extract more type info from sourcekitten. */
|
|
182
277
|
PREPROCESS_AND_INFERENCE = 2
|
|
183
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Defines an input option for extracting type information directly from a raw string of source code.
|
|
281
|
+
*/
|
|
184
282
|
export type StringInputOption = {
|
|
185
283
|
type: 'string';
|
|
186
284
|
fileContent: string;
|
|
187
285
|
language: 'Swift';
|
|
188
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* Defines an input option for extracting type information from a set of physical files.
|
|
289
|
+
*/
|
|
189
290
|
export type FileInputOption = {
|
|
190
291
|
type: 'file';
|
|
191
292
|
inputFileAbsolutePaths: string[];
|
|
@@ -204,6 +305,7 @@ export type GetFileTypeInformationOptions = {
|
|
|
204
305
|
* If a raw string is provided, or if the `PREPROCESS_AND_INFERENCE` inference option is selected,
|
|
205
306
|
* the function will create a temporary file with the (optionally preprocessed) content to facilitate parsing.
|
|
206
307
|
* @param options - Configuration object containing the input source (file or string) and the desired level of type inference.
|
|
207
|
-
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it
|
|
308
|
+
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it resolves to `null`.
|
|
309
|
+
* @header TypeInformationAbstraction
|
|
208
310
|
*/
|
|
209
311
|
export declare function getFileTypeInformation({ input, typeInference, }: GetFileTypeInformationOptions): Promise<FileTypeInformation | null>;
|
package/build/typeInformation.js
CHANGED
|
@@ -42,6 +42,9 @@ const os = __importStar(require("os"));
|
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const sourcekittenTypeInformation_1 = require("./swift/sourcekittenTypeInformation");
|
|
44
44
|
const utils_1 = require("./utils");
|
|
45
|
+
/**
|
|
46
|
+
* Represents the kind of a parsed identifier from a native file.
|
|
47
|
+
*/
|
|
45
48
|
var IdentifierKind;
|
|
46
49
|
(function (IdentifierKind) {
|
|
47
50
|
IdentifierKind[IdentifierKind["BASIC"] = 0] = "BASIC";
|
|
@@ -49,6 +52,9 @@ var IdentifierKind;
|
|
|
49
52
|
IdentifierKind[IdentifierKind["RECORD"] = 2] = "RECORD";
|
|
50
53
|
IdentifierKind[IdentifierKind["CLASS"] = 3] = "CLASS";
|
|
51
54
|
})(IdentifierKind || (exports.IdentifierKind = IdentifierKind = {}));
|
|
55
|
+
/**
|
|
56
|
+
* Categorizes the type node within the abstract syntax tree.
|
|
57
|
+
*/
|
|
52
58
|
var TypeKind;
|
|
53
59
|
(function (TypeKind) {
|
|
54
60
|
TypeKind[TypeKind["BASIC"] = 0] = "BASIC";
|
|
@@ -59,6 +65,9 @@ var TypeKind;
|
|
|
59
65
|
TypeKind[TypeKind["ARRAY"] = 5] = "ARRAY";
|
|
60
66
|
TypeKind[TypeKind["DICTIONARY"] = 6] = "DICTIONARY";
|
|
61
67
|
})(TypeKind || (exports.TypeKind = TypeKind = {}));
|
|
68
|
+
/**
|
|
69
|
+
* Represents a basic type that is not user defined.
|
|
70
|
+
*/
|
|
62
71
|
var BasicType;
|
|
63
72
|
(function (BasicType) {
|
|
64
73
|
BasicType[BasicType["ANY"] = 0] = "ANY";
|
|
@@ -67,12 +76,14 @@ var BasicType;
|
|
|
67
76
|
BasicType[BasicType["BOOLEAN"] = 3] = "BOOLEAN";
|
|
68
77
|
BasicType[BasicType["VOID"] = 4] = "VOID";
|
|
69
78
|
BasicType[BasicType["UNDEFINED"] = 5] = "UNDEFINED";
|
|
79
|
+
/** Represents a type that couldn't be resolved */
|
|
70
80
|
BasicType[BasicType["UNRESOLVED"] = 6] = "UNRESOLVED";
|
|
71
81
|
})(BasicType || (exports.BasicType = BasicType = {}));
|
|
72
82
|
/**
|
|
73
|
-
* Used for testing purposes, maps Sets and Maps to Arrays and returns FileTypeInformationSerialized object which can be written to a JSON.
|
|
74
|
-
* @param
|
|
75
|
-
* @returns FileTypeInformationSerialized object.
|
|
83
|
+
* Used for testing purposes, maps Sets and Maps to Arrays and returns `FileTypeInformationSerialized` object which can be written to a JSON.
|
|
84
|
+
* @param fileTypeinformation `FileTypeInformation` object to serialize.
|
|
85
|
+
* @returns a `FileTypeInformationSerialized` object.
|
|
86
|
+
* @header TypeInformationAbstraction
|
|
76
87
|
*/
|
|
77
88
|
function serializeTypeInformation({ usedTypeIdentifiers, declaredTypeIdentifiers, inferredTypeParametersCount, typeIdentifierDefinitionMap, moduleClasses, records, enums, }) {
|
|
78
89
|
return {
|
|
@@ -86,9 +97,10 @@ function serializeTypeInformation({ usedTypeIdentifiers, declaredTypeIdentifiers
|
|
|
86
97
|
};
|
|
87
98
|
}
|
|
88
99
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param
|
|
91
|
-
* @returns FileTypeInformation object.
|
|
100
|
+
* Used for testing purposes, maps Arrays to Sets and Maps depending on the field and returns `FileTypeInformation` object.
|
|
101
|
+
* @param fileTypeinformationSerialized `FileTypeInformationSerialized` object to deserialize.
|
|
102
|
+
* @returns `FileTypeInformation` object.
|
|
103
|
+
* @header TypeInformationAbstraction
|
|
92
104
|
*/
|
|
93
105
|
function deserializeTypeInformation({ usedTypeIdentifiersList, declaredTypeIdentifiersList, inferredTypeParametersCountList, typeIdentifierDefinitionList, moduleClasses, records, enums, }) {
|
|
94
106
|
return {
|
|
@@ -103,7 +115,7 @@ function deserializeTypeInformation({ usedTypeIdentifiersList, declaredTypeIdent
|
|
|
103
115
|
}
|
|
104
116
|
/**
|
|
105
117
|
* Defines the level of type inference to apply when extracting type information.
|
|
106
|
-
* Note
|
|
118
|
+
* > **Note:** In case where type inference is on, it may take more then twice the time to compute the type information.
|
|
107
119
|
*/
|
|
108
120
|
var TypeInferenceOption;
|
|
109
121
|
(function (TypeInferenceOption) {
|
|
@@ -134,7 +146,8 @@ async function withTempFile(content, fn) {
|
|
|
134
146
|
* If a raw string is provided, or if the `PREPROCESS_AND_INFERENCE` inference option is selected,
|
|
135
147
|
* the function will create a temporary file with the (optionally preprocessed) content to facilitate parsing.
|
|
136
148
|
* @param options - Configuration object containing the input source (file or string) and the desired level of type inference.
|
|
137
|
-
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it
|
|
149
|
+
* @returns A promise that resolves to a `FileTypeInformation` object if the input was parsed successfully. Otherwise, it resolves to `null`.
|
|
150
|
+
* @header TypeInformationAbstraction
|
|
138
151
|
*/
|
|
139
152
|
async function getFileTypeInformation({ input, typeInference, }) {
|
|
140
153
|
const shouldPreprocessFile = typeInference === TypeInferenceOption.PREPROCESS_AND_INFERENCE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeInformation.js","sourceRoot":"","sources":["../src/typeInformation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"typeInformation.js","sourceRoot":"","sources":["../src/typeInformation.ts"],"names":[],"mappings":";;;;;;;;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,EAAE;YAC/C,aAAa,EAAE,eAAe;SAC/B,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { ClassDeclaration, ConstructorDeclaration, EnumType, FileTypeInformation, FunctionDeclaration, ModuleClassDeclaration, RecordType, Type, ViewDeclaration } from './typeInformation';
|
|
3
|
+
/**
|
|
4
|
+
* A helper type which contains the generated file content and name.
|
|
5
|
+
*/
|
|
3
6
|
export type OutputFile = {
|
|
7
|
+
/**
|
|
8
|
+
* @field Generated file content.
|
|
9
|
+
*/
|
|
4
10
|
content: string;
|
|
11
|
+
/**
|
|
12
|
+
* @field Generated file base name (e.g. `ExpoSettings.types.ts`).
|
|
13
|
+
*/
|
|
5
14
|
name: string;
|
|
6
15
|
};
|
|
7
16
|
export interface GenerationContext {
|
|
@@ -44,14 +53,55 @@ export declare function buildExposedTypesDeclarations(ctx: GenerationContext, op
|
|
|
44
53
|
declare?: boolean;
|
|
45
54
|
}): ts.Node[];
|
|
46
55
|
export declare function getViewPropsTypeName(view: ViewDeclaration): string;
|
|
56
|
+
/**
|
|
57
|
+
* Helper function that takes a file content string and formats it using `prettier` formatter.
|
|
58
|
+
* @param text Content of a JavaScript/TypeScript file to format.
|
|
59
|
+
* @param parser An option of which parser to use to format the file.
|
|
60
|
+
* @default "babel"
|
|
61
|
+
* @returns A promise which resolves to the `text` string after formatting using `prettier` with the given `parser`.
|
|
62
|
+
* @header TypescriptGeneration
|
|
63
|
+
*/
|
|
47
64
|
export declare function prettifyCode(text: string, parser?: 'babel' | 'typescript'): Promise<string>;
|
|
65
|
+
/**
|
|
66
|
+
* Generates the TypeScript string content for a native View's type declaration file.
|
|
67
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
68
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
69
|
+
* @header TypescriptGeneration
|
|
70
|
+
*/
|
|
48
71
|
export declare function generateViewTypesFileContent(fileTypeInformation: FileTypeInformation): Promise<string | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Generates the TypeScript string content for a native View's type declaration file which mounts the View props on the global `JSXIntrinsics`.
|
|
74
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
75
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
76
|
+
* @header TypescriptGeneration
|
|
77
|
+
*/
|
|
49
78
|
export declare function generateJSXIntrinsicsFileContent(fileTypeInformation: FileTypeInformation): Promise<string | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Generates the TypeScript string content for a native module type declaration file.
|
|
81
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
82
|
+
* @returns A promise that resolves to a string containing the TypeScript module declaration file content or `null` if the generation has failed.
|
|
83
|
+
* @header TypescriptGeneration
|
|
84
|
+
*/
|
|
50
85
|
export declare function generateModuleTypesFileContent(fileTypeInformation: FileTypeInformation): Promise<string | null>;
|
|
86
|
+
/**
|
|
87
|
+
* Generates a short TypeScript interface for an Expo module. This creates the content for two files: a volatile generated file containing raw type definitions,
|
|
88
|
+
* and a stable user-facing file that wraps and exports the native module methods in new functions.
|
|
89
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
90
|
+
* @returns A promise that resolves to an object containing the string contents for both the volatile generated file and the stable TypeScript interface file.
|
|
91
|
+
* @header TypescriptGeneration
|
|
92
|
+
*/
|
|
51
93
|
export declare function generateConciseTsInterface(fileTypeInformation: FileTypeInformation): Promise<{
|
|
52
94
|
volatileGeneratedFileContent: string;
|
|
53
95
|
moduleTypescriptInterfaceFileContent: string;
|
|
54
96
|
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Generates a full, multi-file TypeScript interface for an Expo module.
|
|
99
|
+
* 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.
|
|
100
|
+
*
|
|
101
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
102
|
+
* @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.
|
|
103
|
+
* @header TypescriptGeneration
|
|
104
|
+
*/
|
|
55
105
|
export declare function generateFullTsInterface(fileTypeInformation: FileTypeInformation): Promise<{
|
|
56
106
|
moduleTypesFile: OutputFile;
|
|
57
107
|
moduleViewsFiles: OutputFile[];
|
|
@@ -557,6 +557,14 @@ async function tsNodesToString(elements) {
|
|
|
557
557
|
const printedTs = printer.printList(typescript_1.default.ListFormat.MultiLine | typescript_1.default.ListFormat.PreserveLines, viewTypes, resultFile);
|
|
558
558
|
return await prettifyCode(printedTs, 'typescript');
|
|
559
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Helper function that takes a file content string and formats it using `prettier` formatter.
|
|
562
|
+
* @param text Content of a JavaScript/TypeScript file to format.
|
|
563
|
+
* @param parser An option of which parser to use to format the file.
|
|
564
|
+
* @default "babel"
|
|
565
|
+
* @returns A promise which resolves to the `text` string after formatting using `prettier` with the given `parser`.
|
|
566
|
+
* @header TypescriptGeneration
|
|
567
|
+
*/
|
|
560
568
|
async function prettifyCode(text, parser = 'babel') {
|
|
561
569
|
return await prettier_1.default.format(text, {
|
|
562
570
|
parser,
|
|
@@ -566,6 +574,12 @@ async function prettifyCode(text, parser = 'babel') {
|
|
|
566
574
|
singleQuote: true,
|
|
567
575
|
});
|
|
568
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Generates the TypeScript string content for a native View's type declaration file.
|
|
579
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
580
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
581
|
+
* @header TypescriptGeneration
|
|
582
|
+
*/
|
|
569
583
|
async function generateViewTypesFileContent(fileTypeInformation) {
|
|
570
584
|
const ctx = createDefaultGenerationContext(fileTypeInformation);
|
|
571
585
|
if (!ctx) {
|
|
@@ -573,6 +587,12 @@ async function generateViewTypesFileContent(fileTypeInformation) {
|
|
|
573
587
|
}
|
|
574
588
|
return tsNodesToString(buildViewDeclarationNodes(ctx));
|
|
575
589
|
}
|
|
590
|
+
/**
|
|
591
|
+
* Generates the TypeScript string content for a native View's type declaration file which mounts the View props on the global `JSXIntrinsics`.
|
|
592
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
593
|
+
* @returns A promise that resolves to a string containing the TypeScript declaration file content or `null` if the generation has failed.
|
|
594
|
+
* @header TypescriptGeneration
|
|
595
|
+
*/
|
|
576
596
|
async function generateJSXIntrinsicsFileContent(fileTypeInformation) {
|
|
577
597
|
const ctx = createDefaultGenerationContext(fileTypeInformation);
|
|
578
598
|
if (!ctx) {
|
|
@@ -580,6 +600,12 @@ async function generateJSXIntrinsicsFileContent(fileTypeInformation) {
|
|
|
580
600
|
}
|
|
581
601
|
return tsNodesToString(buildJSXIntrinsicsViewNodes(ctx));
|
|
582
602
|
}
|
|
603
|
+
/**
|
|
604
|
+
* Generates the TypeScript string content for a native module type declaration file.
|
|
605
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
606
|
+
* @returns A promise that resolves to a string containing the TypeScript module declaration file content or `null` if the generation has failed.
|
|
607
|
+
* @header TypescriptGeneration
|
|
608
|
+
*/
|
|
583
609
|
async function generateModuleTypesFileContent(fileTypeInformation) {
|
|
584
610
|
const ctx = createDefaultGenerationContext(fileTypeInformation);
|
|
585
611
|
if (!ctx) {
|
|
@@ -587,6 +613,13 @@ async function generateModuleTypesFileContent(fileTypeInformation) {
|
|
|
587
613
|
}
|
|
588
614
|
return tsNodesToString(buildModuleDeclarationNodes(ctx));
|
|
589
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Generates a short TypeScript interface for an Expo module. This creates the content for two files: a volatile generated file containing raw type definitions,
|
|
618
|
+
* and a stable user-facing file that wraps and exports the native module methods in new functions.
|
|
619
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
620
|
+
* @returns A promise that resolves to an object containing the string contents for both the volatile generated file and the stable TypeScript interface file.
|
|
621
|
+
* @header TypescriptGeneration
|
|
622
|
+
*/
|
|
590
623
|
async function generateConciseTsInterface(fileTypeInformation) {
|
|
591
624
|
const ctx = createDefaultGenerationContext(fileTypeInformation);
|
|
592
625
|
if (!ctx) {
|
|
@@ -599,6 +632,14 @@ async function generateConciseTsInterface(fileTypeInformation) {
|
|
|
599
632
|
moduleTypescriptInterfaceFileContent,
|
|
600
633
|
};
|
|
601
634
|
}
|
|
635
|
+
/**
|
|
636
|
+
* Generates a full, multi-file TypeScript interface for an Expo module.
|
|
637
|
+
* 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.
|
|
638
|
+
*
|
|
639
|
+
* @param fileTypeInformation The abstracted type information of an Expo module.
|
|
640
|
+
* @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.
|
|
641
|
+
* @header TypescriptGeneration
|
|
642
|
+
*/
|
|
602
643
|
async function generateFullTsInterface(fileTypeInformation) {
|
|
603
644
|
const ctx = createDefaultGenerationContext(fileTypeInformation);
|
|
604
645
|
if (!ctx) {
|