source: trip-planner-front/node_modules/@babel/types/lib/definitions/typescript.js@ 6a80231

Last change on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 14.7 KB
RevLine 
[6a3a178]1"use strict";
2
3var _utils = require("./utils");
4
5var _core = require("./core");
6
7var _is = require("../validators/is");
8
9const bool = (0, _utils.assertValueType)("boolean");
10const tSFunctionTypeAnnotationCommon = {
11 returnType: {
12 validate: (0, _utils.assertNodeType)("TSTypeAnnotation", "Noop"),
13 optional: true
14 },
15 typeParameters: {
16 validate: (0, _utils.assertNodeType)("TSTypeParameterDeclaration", "Noop"),
17 optional: true
18 }
19};
20(0, _utils.default)("TSParameterProperty", {
21 aliases: ["LVal"],
22 visitor: ["parameter"],
23 fields: {
24 accessibility: {
25 validate: (0, _utils.assertOneOf)("public", "private", "protected"),
26 optional: true
27 },
28 readonly: {
29 validate: (0, _utils.assertValueType)("boolean"),
30 optional: true
31 },
32 parameter: {
33 validate: (0, _utils.assertNodeType)("Identifier", "AssignmentPattern")
34 },
35 override: {
36 validate: (0, _utils.assertValueType)("boolean"),
37 optional: true
38 },
39 decorators: {
40 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("Decorator"))),
41 optional: true
42 }
43 }
44});
45(0, _utils.default)("TSDeclareFunction", {
46 aliases: ["Statement", "Declaration"],
47 visitor: ["id", "typeParameters", "params", "returnType"],
48 fields: Object.assign({}, _core.functionDeclarationCommon, tSFunctionTypeAnnotationCommon)
49});
50(0, _utils.default)("TSDeclareMethod", {
51 visitor: ["decorators", "key", "typeParameters", "params", "returnType"],
52 fields: Object.assign({}, _core.classMethodOrDeclareMethodCommon, tSFunctionTypeAnnotationCommon)
53});
54(0, _utils.default)("TSQualifiedName", {
55 aliases: ["TSEntityName"],
56 visitor: ["left", "right"],
57 fields: {
58 left: (0, _utils.validateType)("TSEntityName"),
59 right: (0, _utils.validateType)("Identifier")
60 }
61});
62const signatureDeclarationCommon = {
63 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),
64 parameters: (0, _utils.validateArrayOfType)(["Identifier", "RestElement"]),
65 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation")
66};
67const callConstructSignatureDeclaration = {
68 aliases: ["TSTypeElement"],
69 visitor: ["typeParameters", "parameters", "typeAnnotation"],
70 fields: signatureDeclarationCommon
71};
72(0, _utils.default)("TSCallSignatureDeclaration", callConstructSignatureDeclaration);
73(0, _utils.default)("TSConstructSignatureDeclaration", callConstructSignatureDeclaration);
74const namedTypeElementCommon = {
75 key: (0, _utils.validateType)("Expression"),
76 computed: (0, _utils.validate)(bool),
77 optional: (0, _utils.validateOptional)(bool)
78};
79(0, _utils.default)("TSPropertySignature", {
80 aliases: ["TSTypeElement"],
81 visitor: ["key", "typeAnnotation", "initializer"],
82 fields: Object.assign({}, namedTypeElementCommon, {
83 readonly: (0, _utils.validateOptional)(bool),
84 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"),
85 initializer: (0, _utils.validateOptionalType)("Expression"),
86 kind: {
87 validate: (0, _utils.assertOneOf)("get", "set")
88 }
89 })
90});
91(0, _utils.default)("TSMethodSignature", {
92 aliases: ["TSTypeElement"],
93 visitor: ["key", "typeParameters", "parameters", "typeAnnotation"],
94 fields: Object.assign({}, signatureDeclarationCommon, namedTypeElementCommon, {
95 kind: {
96 validate: (0, _utils.assertOneOf)("method", "get", "set")
97 }
98 })
99});
100(0, _utils.default)("TSIndexSignature", {
101 aliases: ["TSTypeElement"],
102 visitor: ["parameters", "typeAnnotation"],
103 fields: {
104 readonly: (0, _utils.validateOptional)(bool),
105 static: (0, _utils.validateOptional)(bool),
106 parameters: (0, _utils.validateArrayOfType)("Identifier"),
107 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation")
108 }
109});
110const tsKeywordTypes = ["TSAnyKeyword", "TSBooleanKeyword", "TSBigIntKeyword", "TSIntrinsicKeyword", "TSNeverKeyword", "TSNullKeyword", "TSNumberKeyword", "TSObjectKeyword", "TSStringKeyword", "TSSymbolKeyword", "TSUndefinedKeyword", "TSUnknownKeyword", "TSVoidKeyword"];
111
112for (const type of tsKeywordTypes) {
113 (0, _utils.default)(type, {
114 aliases: ["TSType", "TSBaseType"],
115 visitor: [],
116 fields: {}
117 });
118}
119
120(0, _utils.default)("TSThisType", {
121 aliases: ["TSType", "TSBaseType"],
122 visitor: [],
123 fields: {}
124});
125const fnOrCtrBase = {
126 aliases: ["TSType"],
127 visitor: ["typeParameters", "parameters", "typeAnnotation"]
128};
129(0, _utils.default)("TSFunctionType", Object.assign({}, fnOrCtrBase, {
130 fields: signatureDeclarationCommon
131}));
132(0, _utils.default)("TSConstructorType", Object.assign({}, fnOrCtrBase, {
133 fields: Object.assign({}, signatureDeclarationCommon, {
134 abstract: (0, _utils.validateOptional)(bool)
135 })
136}));
137(0, _utils.default)("TSTypeReference", {
138 aliases: ["TSType"],
139 visitor: ["typeName", "typeParameters"],
140 fields: {
141 typeName: (0, _utils.validateType)("TSEntityName"),
142 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")
143 }
144});
145(0, _utils.default)("TSTypePredicate", {
146 aliases: ["TSType"],
147 visitor: ["parameterName", "typeAnnotation"],
148 builder: ["parameterName", "typeAnnotation", "asserts"],
149 fields: {
150 parameterName: (0, _utils.validateType)(["Identifier", "TSThisType"]),
151 typeAnnotation: (0, _utils.validateOptionalType)("TSTypeAnnotation"),
152 asserts: (0, _utils.validateOptional)(bool)
153 }
154});
155(0, _utils.default)("TSTypeQuery", {
156 aliases: ["TSType"],
157 visitor: ["exprName"],
158 fields: {
159 exprName: (0, _utils.validateType)(["TSEntityName", "TSImportType"])
160 }
161});
162(0, _utils.default)("TSTypeLiteral", {
163 aliases: ["TSType"],
164 visitor: ["members"],
165 fields: {
166 members: (0, _utils.validateArrayOfType)("TSTypeElement")
167 }
168});
169(0, _utils.default)("TSArrayType", {
170 aliases: ["TSType"],
171 visitor: ["elementType"],
172 fields: {
173 elementType: (0, _utils.validateType)("TSType")
174 }
175});
176(0, _utils.default)("TSTupleType", {
177 aliases: ["TSType"],
178 visitor: ["elementTypes"],
179 fields: {
180 elementTypes: (0, _utils.validateArrayOfType)(["TSType", "TSNamedTupleMember"])
181 }
182});
183(0, _utils.default)("TSOptionalType", {
184 aliases: ["TSType"],
185 visitor: ["typeAnnotation"],
186 fields: {
187 typeAnnotation: (0, _utils.validateType)("TSType")
188 }
189});
190(0, _utils.default)("TSRestType", {
191 aliases: ["TSType"],
192 visitor: ["typeAnnotation"],
193 fields: {
194 typeAnnotation: (0, _utils.validateType)("TSType")
195 }
196});
197(0, _utils.default)("TSNamedTupleMember", {
198 visitor: ["label", "elementType"],
199 builder: ["label", "elementType", "optional"],
200 fields: {
201 label: (0, _utils.validateType)("Identifier"),
202 optional: {
203 validate: bool,
204 default: false
205 },
206 elementType: (0, _utils.validateType)("TSType")
207 }
208});
209const unionOrIntersection = {
210 aliases: ["TSType"],
211 visitor: ["types"],
212 fields: {
213 types: (0, _utils.validateArrayOfType)("TSType")
214 }
215};
216(0, _utils.default)("TSUnionType", unionOrIntersection);
217(0, _utils.default)("TSIntersectionType", unionOrIntersection);
218(0, _utils.default)("TSConditionalType", {
219 aliases: ["TSType"],
220 visitor: ["checkType", "extendsType", "trueType", "falseType"],
221 fields: {
222 checkType: (0, _utils.validateType)("TSType"),
223 extendsType: (0, _utils.validateType)("TSType"),
224 trueType: (0, _utils.validateType)("TSType"),
225 falseType: (0, _utils.validateType)("TSType")
226 }
227});
228(0, _utils.default)("TSInferType", {
229 aliases: ["TSType"],
230 visitor: ["typeParameter"],
231 fields: {
232 typeParameter: (0, _utils.validateType)("TSTypeParameter")
233 }
234});
235(0, _utils.default)("TSParenthesizedType", {
236 aliases: ["TSType"],
237 visitor: ["typeAnnotation"],
238 fields: {
239 typeAnnotation: (0, _utils.validateType)("TSType")
240 }
241});
242(0, _utils.default)("TSTypeOperator", {
243 aliases: ["TSType"],
244 visitor: ["typeAnnotation"],
245 fields: {
246 operator: (0, _utils.validate)((0, _utils.assertValueType)("string")),
247 typeAnnotation: (0, _utils.validateType)("TSType")
248 }
249});
250(0, _utils.default)("TSIndexedAccessType", {
251 aliases: ["TSType"],
252 visitor: ["objectType", "indexType"],
253 fields: {
254 objectType: (0, _utils.validateType)("TSType"),
255 indexType: (0, _utils.validateType)("TSType")
256 }
257});
258(0, _utils.default)("TSMappedType", {
259 aliases: ["TSType"],
260 visitor: ["typeParameter", "typeAnnotation", "nameType"],
261 fields: {
262 readonly: (0, _utils.validateOptional)(bool),
263 typeParameter: (0, _utils.validateType)("TSTypeParameter"),
264 optional: (0, _utils.validateOptional)(bool),
265 typeAnnotation: (0, _utils.validateOptionalType)("TSType"),
266 nameType: (0, _utils.validateOptionalType)("TSType")
267 }
268});
269(0, _utils.default)("TSLiteralType", {
270 aliases: ["TSType", "TSBaseType"],
271 visitor: ["literal"],
272 fields: {
273 literal: {
274 validate: function () {
275 const unaryExpression = (0, _utils.assertNodeType)("NumericLiteral", "BigIntLiteral");
276 const unaryOperator = (0, _utils.assertOneOf)("-");
277 const literal = (0, _utils.assertNodeType)("NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral");
278
279 function validator(parent, key, node) {
280 if ((0, _is.default)("UnaryExpression", node)) {
281 unaryOperator(node, "operator", node.operator);
282 unaryExpression(node, "argument", node.argument);
283 } else {
284 literal(parent, key, node);
285 }
286 }
287
288 validator.oneOfNodeTypes = ["NumericLiteral", "StringLiteral", "BooleanLiteral", "BigIntLiteral", "UnaryExpression"];
289 return validator;
290 }()
291 }
292 }
293});
294(0, _utils.default)("TSExpressionWithTypeArguments", {
295 aliases: ["TSType"],
296 visitor: ["expression", "typeParameters"],
297 fields: {
298 expression: (0, _utils.validateType)("TSEntityName"),
299 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")
300 }
301});
302(0, _utils.default)("TSInterfaceDeclaration", {
303 aliases: ["Statement", "Declaration"],
304 visitor: ["id", "typeParameters", "extends", "body"],
305 fields: {
306 declare: (0, _utils.validateOptional)(bool),
307 id: (0, _utils.validateType)("Identifier"),
308 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),
309 extends: (0, _utils.validateOptional)((0, _utils.arrayOfType)("TSExpressionWithTypeArguments")),
310 body: (0, _utils.validateType)("TSInterfaceBody")
311 }
312});
313(0, _utils.default)("TSInterfaceBody", {
314 visitor: ["body"],
315 fields: {
316 body: (0, _utils.validateArrayOfType)("TSTypeElement")
317 }
318});
319(0, _utils.default)("TSTypeAliasDeclaration", {
320 aliases: ["Statement", "Declaration"],
321 visitor: ["id", "typeParameters", "typeAnnotation"],
322 fields: {
323 declare: (0, _utils.validateOptional)(bool),
324 id: (0, _utils.validateType)("Identifier"),
325 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterDeclaration"),
326 typeAnnotation: (0, _utils.validateType)("TSType")
327 }
328});
329(0, _utils.default)("TSAsExpression", {
330 aliases: ["Expression"],
331 visitor: ["expression", "typeAnnotation"],
332 fields: {
333 expression: (0, _utils.validateType)("Expression"),
334 typeAnnotation: (0, _utils.validateType)("TSType")
335 }
336});
337(0, _utils.default)("TSTypeAssertion", {
338 aliases: ["Expression"],
339 visitor: ["typeAnnotation", "expression"],
340 fields: {
341 typeAnnotation: (0, _utils.validateType)("TSType"),
342 expression: (0, _utils.validateType)("Expression")
343 }
344});
345(0, _utils.default)("TSEnumDeclaration", {
346 aliases: ["Statement", "Declaration"],
347 visitor: ["id", "members"],
348 fields: {
349 declare: (0, _utils.validateOptional)(bool),
350 const: (0, _utils.validateOptional)(bool),
351 id: (0, _utils.validateType)("Identifier"),
352 members: (0, _utils.validateArrayOfType)("TSEnumMember"),
353 initializer: (0, _utils.validateOptionalType)("Expression")
354 }
355});
356(0, _utils.default)("TSEnumMember", {
357 visitor: ["id", "initializer"],
358 fields: {
359 id: (0, _utils.validateType)(["Identifier", "StringLiteral"]),
360 initializer: (0, _utils.validateOptionalType)("Expression")
361 }
362});
363(0, _utils.default)("TSModuleDeclaration", {
364 aliases: ["Statement", "Declaration"],
365 visitor: ["id", "body"],
366 fields: {
367 declare: (0, _utils.validateOptional)(bool),
368 global: (0, _utils.validateOptional)(bool),
369 id: (0, _utils.validateType)(["Identifier", "StringLiteral"]),
370 body: (0, _utils.validateType)(["TSModuleBlock", "TSModuleDeclaration"])
371 }
372});
373(0, _utils.default)("TSModuleBlock", {
374 aliases: ["Scopable", "Block", "BlockParent"],
375 visitor: ["body"],
376 fields: {
377 body: (0, _utils.validateArrayOfType)("Statement")
378 }
379});
380(0, _utils.default)("TSImportType", {
381 aliases: ["TSType"],
382 visitor: ["argument", "qualifier", "typeParameters"],
383 fields: {
384 argument: (0, _utils.validateType)("StringLiteral"),
385 qualifier: (0, _utils.validateOptionalType)("TSEntityName"),
386 typeParameters: (0, _utils.validateOptionalType)("TSTypeParameterInstantiation")
387 }
388});
389(0, _utils.default)("TSImportEqualsDeclaration", {
390 aliases: ["Statement"],
391 visitor: ["id", "moduleReference"],
392 fields: {
393 isExport: (0, _utils.validate)(bool),
394 id: (0, _utils.validateType)("Identifier"),
395 moduleReference: (0, _utils.validateType)(["TSEntityName", "TSExternalModuleReference"]),
396 importKind: {
397 validate: (0, _utils.assertOneOf)("type", "value"),
398 optional: true
399 }
400 }
401});
402(0, _utils.default)("TSExternalModuleReference", {
403 visitor: ["expression"],
404 fields: {
405 expression: (0, _utils.validateType)("StringLiteral")
406 }
407});
408(0, _utils.default)("TSNonNullExpression", {
409 aliases: ["Expression"],
410 visitor: ["expression"],
411 fields: {
412 expression: (0, _utils.validateType)("Expression")
413 }
414});
415(0, _utils.default)("TSExportAssignment", {
416 aliases: ["Statement"],
417 visitor: ["expression"],
418 fields: {
419 expression: (0, _utils.validateType)("Expression")
420 }
421});
422(0, _utils.default)("TSNamespaceExportDeclaration", {
423 aliases: ["Statement"],
424 visitor: ["id"],
425 fields: {
426 id: (0, _utils.validateType)("Identifier")
427 }
428});
429(0, _utils.default)("TSTypeAnnotation", {
430 visitor: ["typeAnnotation"],
431 fields: {
432 typeAnnotation: {
433 validate: (0, _utils.assertNodeType)("TSType")
434 }
435 }
436});
437(0, _utils.default)("TSTypeParameterInstantiation", {
438 visitor: ["params"],
439 fields: {
440 params: {
441 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSType")))
442 }
443 }
444});
445(0, _utils.default)("TSTypeParameterDeclaration", {
446 visitor: ["params"],
447 fields: {
448 params: {
449 validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeType)("TSTypeParameter")))
450 }
451 }
452});
453(0, _utils.default)("TSTypeParameter", {
454 builder: ["constraint", "default", "name"],
455 visitor: ["constraint", "default"],
456 fields: {
457 name: {
458 validate: (0, _utils.assertValueType)("string")
459 },
460 constraint: {
461 validate: (0, _utils.assertNodeType)("TSType"),
462 optional: true
463 },
464 default: {
465 validate: (0, _utils.assertNodeType)("TSType"),
466 optional: true
467 }
468 }
469});
Note: See TracBrowser for help on using the repository browser.