Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

typescript.js 14KB

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