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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.TSTypeAnnotation = TSTypeAnnotation;
  6. exports.TSTypeParameterDeclaration = exports.TSTypeParameterInstantiation = TSTypeParameterInstantiation;
  7. exports.TSTypeParameter = TSTypeParameter;
  8. exports.TSParameterProperty = TSParameterProperty;
  9. exports.TSDeclareFunction = TSDeclareFunction;
  10. exports.TSDeclareMethod = TSDeclareMethod;
  11. exports.TSQualifiedName = TSQualifiedName;
  12. exports.TSCallSignatureDeclaration = TSCallSignatureDeclaration;
  13. exports.TSConstructSignatureDeclaration = TSConstructSignatureDeclaration;
  14. exports.TSPropertySignature = TSPropertySignature;
  15. exports.tsPrintPropertyOrMethodName = tsPrintPropertyOrMethodName;
  16. exports.TSMethodSignature = TSMethodSignature;
  17. exports.TSIndexSignature = TSIndexSignature;
  18. exports.TSAnyKeyword = TSAnyKeyword;
  19. exports.TSBigIntKeyword = TSBigIntKeyword;
  20. exports.TSUnknownKeyword = TSUnknownKeyword;
  21. exports.TSNumberKeyword = TSNumberKeyword;
  22. exports.TSObjectKeyword = TSObjectKeyword;
  23. exports.TSBooleanKeyword = TSBooleanKeyword;
  24. exports.TSStringKeyword = TSStringKeyword;
  25. exports.TSSymbolKeyword = TSSymbolKeyword;
  26. exports.TSVoidKeyword = TSVoidKeyword;
  27. exports.TSUndefinedKeyword = TSUndefinedKeyword;
  28. exports.TSNullKeyword = TSNullKeyword;
  29. exports.TSNeverKeyword = TSNeverKeyword;
  30. exports.TSIntrinsicKeyword = TSIntrinsicKeyword;
  31. exports.TSThisType = TSThisType;
  32. exports.TSFunctionType = TSFunctionType;
  33. exports.TSConstructorType = TSConstructorType;
  34. exports.tsPrintFunctionOrConstructorType = tsPrintFunctionOrConstructorType;
  35. exports.TSTypeReference = TSTypeReference;
  36. exports.TSTypePredicate = TSTypePredicate;
  37. exports.TSTypeQuery = TSTypeQuery;
  38. exports.TSTypeLiteral = TSTypeLiteral;
  39. exports.tsPrintTypeLiteralOrInterfaceBody = tsPrintTypeLiteralOrInterfaceBody;
  40. exports.tsPrintBraced = tsPrintBraced;
  41. exports.TSArrayType = TSArrayType;
  42. exports.TSTupleType = TSTupleType;
  43. exports.TSOptionalType = TSOptionalType;
  44. exports.TSRestType = TSRestType;
  45. exports.TSNamedTupleMember = TSNamedTupleMember;
  46. exports.TSUnionType = TSUnionType;
  47. exports.TSIntersectionType = TSIntersectionType;
  48. exports.tsPrintUnionOrIntersectionType = tsPrintUnionOrIntersectionType;
  49. exports.TSConditionalType = TSConditionalType;
  50. exports.TSInferType = TSInferType;
  51. exports.TSParenthesizedType = TSParenthesizedType;
  52. exports.TSTypeOperator = TSTypeOperator;
  53. exports.TSIndexedAccessType = TSIndexedAccessType;
  54. exports.TSMappedType = TSMappedType;
  55. exports.TSLiteralType = TSLiteralType;
  56. exports.TSExpressionWithTypeArguments = TSExpressionWithTypeArguments;
  57. exports.TSInterfaceDeclaration = TSInterfaceDeclaration;
  58. exports.TSInterfaceBody = TSInterfaceBody;
  59. exports.TSTypeAliasDeclaration = TSTypeAliasDeclaration;
  60. exports.TSAsExpression = TSAsExpression;
  61. exports.TSTypeAssertion = TSTypeAssertion;
  62. exports.TSEnumDeclaration = TSEnumDeclaration;
  63. exports.TSEnumMember = TSEnumMember;
  64. exports.TSModuleDeclaration = TSModuleDeclaration;
  65. exports.TSModuleBlock = TSModuleBlock;
  66. exports.TSImportType = TSImportType;
  67. exports.TSImportEqualsDeclaration = TSImportEqualsDeclaration;
  68. exports.TSExternalModuleReference = TSExternalModuleReference;
  69. exports.TSNonNullExpression = TSNonNullExpression;
  70. exports.TSExportAssignment = TSExportAssignment;
  71. exports.TSNamespaceExportDeclaration = TSNamespaceExportDeclaration;
  72. exports.tsPrintSignatureDeclarationBase = tsPrintSignatureDeclarationBase;
  73. exports.tsPrintClassMemberModifiers = tsPrintClassMemberModifiers;
  74. var t = require("@babel/types");
  75. function TSTypeAnnotation(node) {
  76. this.token(":");
  77. this.space();
  78. if (node.optional) this.token("?");
  79. this.print(node.typeAnnotation, node);
  80. }
  81. function TSTypeParameterInstantiation(node) {
  82. this.token("<");
  83. this.printList(node.params, node, {});
  84. this.token(">");
  85. }
  86. function TSTypeParameter(node) {
  87. this.word(node.name);
  88. if (node.constraint) {
  89. this.space();
  90. this.word("extends");
  91. this.space();
  92. this.print(node.constraint, node);
  93. }
  94. if (node.default) {
  95. this.space();
  96. this.token("=");
  97. this.space();
  98. this.print(node.default, node);
  99. }
  100. }
  101. function TSParameterProperty(node) {
  102. if (node.accessibility) {
  103. this.word(node.accessibility);
  104. this.space();
  105. }
  106. if (node.readonly) {
  107. this.word("readonly");
  108. this.space();
  109. }
  110. this._param(node.parameter);
  111. }
  112. function TSDeclareFunction(node) {
  113. if (node.declare) {
  114. this.word("declare");
  115. this.space();
  116. }
  117. this._functionHead(node);
  118. this.token(";");
  119. }
  120. function TSDeclareMethod(node) {
  121. this._classMethodHead(node);
  122. this.token(";");
  123. }
  124. function TSQualifiedName(node) {
  125. this.print(node.left, node);
  126. this.token(".");
  127. this.print(node.right, node);
  128. }
  129. function TSCallSignatureDeclaration(node) {
  130. this.tsPrintSignatureDeclarationBase(node);
  131. this.token(";");
  132. }
  133. function TSConstructSignatureDeclaration(node) {
  134. this.word("new");
  135. this.space();
  136. this.tsPrintSignatureDeclarationBase(node);
  137. this.token(";");
  138. }
  139. function TSPropertySignature(node) {
  140. const {
  141. readonly,
  142. initializer
  143. } = node;
  144. if (readonly) {
  145. this.word("readonly");
  146. this.space();
  147. }
  148. this.tsPrintPropertyOrMethodName(node);
  149. this.print(node.typeAnnotation, node);
  150. if (initializer) {
  151. this.space();
  152. this.token("=");
  153. this.space();
  154. this.print(initializer, node);
  155. }
  156. this.token(";");
  157. }
  158. function tsPrintPropertyOrMethodName(node) {
  159. if (node.computed) {
  160. this.token("[");
  161. }
  162. this.print(node.key, node);
  163. if (node.computed) {
  164. this.token("]");
  165. }
  166. if (node.optional) {
  167. this.token("?");
  168. }
  169. }
  170. function TSMethodSignature(node) {
  171. const {
  172. kind
  173. } = node;
  174. if (kind === "set" || kind === "get") {
  175. this.word(kind);
  176. this.space();
  177. }
  178. this.tsPrintPropertyOrMethodName(node);
  179. this.tsPrintSignatureDeclarationBase(node);
  180. this.token(";");
  181. }
  182. function TSIndexSignature(node) {
  183. const {
  184. readonly,
  185. static: isStatic
  186. } = node;
  187. if (isStatic) {
  188. this.word("static");
  189. this.space();
  190. }
  191. if (readonly) {
  192. this.word("readonly");
  193. this.space();
  194. }
  195. this.token("[");
  196. this._parameters(node.parameters, node);
  197. this.token("]");
  198. this.print(node.typeAnnotation, node);
  199. this.token(";");
  200. }
  201. function TSAnyKeyword() {
  202. this.word("any");
  203. }
  204. function TSBigIntKeyword() {
  205. this.word("bigint");
  206. }
  207. function TSUnknownKeyword() {
  208. this.word("unknown");
  209. }
  210. function TSNumberKeyword() {
  211. this.word("number");
  212. }
  213. function TSObjectKeyword() {
  214. this.word("object");
  215. }
  216. function TSBooleanKeyword() {
  217. this.word("boolean");
  218. }
  219. function TSStringKeyword() {
  220. this.word("string");
  221. }
  222. function TSSymbolKeyword() {
  223. this.word("symbol");
  224. }
  225. function TSVoidKeyword() {
  226. this.word("void");
  227. }
  228. function TSUndefinedKeyword() {
  229. this.word("undefined");
  230. }
  231. function TSNullKeyword() {
  232. this.word("null");
  233. }
  234. function TSNeverKeyword() {
  235. this.word("never");
  236. }
  237. function TSIntrinsicKeyword() {
  238. this.word("intrinsic");
  239. }
  240. function TSThisType() {
  241. this.word("this");
  242. }
  243. function TSFunctionType(node) {
  244. this.tsPrintFunctionOrConstructorType(node);
  245. }
  246. function TSConstructorType(node) {
  247. if (node.abstract) {
  248. this.word("abstract");
  249. this.space();
  250. }
  251. this.word("new");
  252. this.space();
  253. this.tsPrintFunctionOrConstructorType(node);
  254. }
  255. function tsPrintFunctionOrConstructorType(node) {
  256. const {
  257. typeParameters,
  258. parameters
  259. } = node;
  260. this.print(typeParameters, node);
  261. this.token("(");
  262. this._parameters(parameters, node);
  263. this.token(")");
  264. this.space();
  265. this.token("=>");
  266. this.space();
  267. this.print(node.typeAnnotation.typeAnnotation, node);
  268. }
  269. function TSTypeReference(node) {
  270. this.print(node.typeName, node);
  271. this.print(node.typeParameters, node);
  272. }
  273. function TSTypePredicate(node) {
  274. if (node.asserts) {
  275. this.word("asserts");
  276. this.space();
  277. }
  278. this.print(node.parameterName);
  279. if (node.typeAnnotation) {
  280. this.space();
  281. this.word("is");
  282. this.space();
  283. this.print(node.typeAnnotation.typeAnnotation);
  284. }
  285. }
  286. function TSTypeQuery(node) {
  287. this.word("typeof");
  288. this.space();
  289. this.print(node.exprName);
  290. }
  291. function TSTypeLiteral(node) {
  292. this.tsPrintTypeLiteralOrInterfaceBody(node.members, node);
  293. }
  294. function tsPrintTypeLiteralOrInterfaceBody(members, node) {
  295. this.tsPrintBraced(members, node);
  296. }
  297. function tsPrintBraced(members, node) {
  298. this.token("{");
  299. if (members.length) {
  300. this.indent();
  301. this.newline();
  302. for (const member of members) {
  303. this.print(member, node);
  304. this.newline();
  305. }
  306. this.dedent();
  307. this.rightBrace();
  308. } else {
  309. this.token("}");
  310. }
  311. }
  312. function TSArrayType(node) {
  313. this.print(node.elementType, node);
  314. this.token("[]");
  315. }
  316. function TSTupleType(node) {
  317. this.token("[");
  318. this.printList(node.elementTypes, node);
  319. this.token("]");
  320. }
  321. function TSOptionalType(node) {
  322. this.print(node.typeAnnotation, node);
  323. this.token("?");
  324. }
  325. function TSRestType(node) {
  326. this.token("...");
  327. this.print(node.typeAnnotation, node);
  328. }
  329. function TSNamedTupleMember(node) {
  330. this.print(node.label, node);
  331. if (node.optional) this.token("?");
  332. this.token(":");
  333. this.space();
  334. this.print(node.elementType, node);
  335. }
  336. function TSUnionType(node) {
  337. this.tsPrintUnionOrIntersectionType(node, "|");
  338. }
  339. function TSIntersectionType(node) {
  340. this.tsPrintUnionOrIntersectionType(node, "&");
  341. }
  342. function tsPrintUnionOrIntersectionType(node, sep) {
  343. this.printJoin(node.types, node, {
  344. separator() {
  345. this.space();
  346. this.token(sep);
  347. this.space();
  348. }
  349. });
  350. }
  351. function TSConditionalType(node) {
  352. this.print(node.checkType);
  353. this.space();
  354. this.word("extends");
  355. this.space();
  356. this.print(node.extendsType);
  357. this.space();
  358. this.token("?");
  359. this.space();
  360. this.print(node.trueType);
  361. this.space();
  362. this.token(":");
  363. this.space();
  364. this.print(node.falseType);
  365. }
  366. function TSInferType(node) {
  367. this.token("infer");
  368. this.space();
  369. this.print(node.typeParameter);
  370. }
  371. function TSParenthesizedType(node) {
  372. this.token("(");
  373. this.print(node.typeAnnotation, node);
  374. this.token(")");
  375. }
  376. function TSTypeOperator(node) {
  377. this.word(node.operator);
  378. this.space();
  379. this.print(node.typeAnnotation, node);
  380. }
  381. function TSIndexedAccessType(node) {
  382. this.print(node.objectType, node);
  383. this.token("[");
  384. this.print(node.indexType, node);
  385. this.token("]");
  386. }
  387. function TSMappedType(node) {
  388. const {
  389. nameType,
  390. optional,
  391. readonly,
  392. typeParameter
  393. } = node;
  394. this.token("{");
  395. this.space();
  396. if (readonly) {
  397. tokenIfPlusMinus(this, readonly);
  398. this.word("readonly");
  399. this.space();
  400. }
  401. this.token("[");
  402. this.word(typeParameter.name);
  403. this.space();
  404. this.word("in");
  405. this.space();
  406. this.print(typeParameter.constraint, typeParameter);
  407. if (nameType) {
  408. this.space();
  409. this.word("as");
  410. this.space();
  411. this.print(nameType, node);
  412. }
  413. this.token("]");
  414. if (optional) {
  415. tokenIfPlusMinus(this, optional);
  416. this.token("?");
  417. }
  418. this.token(":");
  419. this.space();
  420. this.print(node.typeAnnotation, node);
  421. this.space();
  422. this.token("}");
  423. }
  424. function tokenIfPlusMinus(self, tok) {
  425. if (tok !== true) {
  426. self.token(tok);
  427. }
  428. }
  429. function TSLiteralType(node) {
  430. this.print(node.literal, node);
  431. }
  432. function TSExpressionWithTypeArguments(node) {
  433. this.print(node.expression, node);
  434. this.print(node.typeParameters, node);
  435. }
  436. function TSInterfaceDeclaration(node) {
  437. const {
  438. declare,
  439. id,
  440. typeParameters,
  441. extends: extendz,
  442. body
  443. } = node;
  444. if (declare) {
  445. this.word("declare");
  446. this.space();
  447. }
  448. this.word("interface");
  449. this.space();
  450. this.print(id, node);
  451. this.print(typeParameters, node);
  452. if (extendz != null && extendz.length) {
  453. this.space();
  454. this.word("extends");
  455. this.space();
  456. this.printList(extendz, node);
  457. }
  458. this.space();
  459. this.print(body, node);
  460. }
  461. function TSInterfaceBody(node) {
  462. this.tsPrintTypeLiteralOrInterfaceBody(node.body, node);
  463. }
  464. function TSTypeAliasDeclaration(node) {
  465. const {
  466. declare,
  467. id,
  468. typeParameters,
  469. typeAnnotation
  470. } = node;
  471. if (declare) {
  472. this.word("declare");
  473. this.space();
  474. }
  475. this.word("type");
  476. this.space();
  477. this.print(id, node);
  478. this.print(typeParameters, node);
  479. this.space();
  480. this.token("=");
  481. this.space();
  482. this.print(typeAnnotation, node);
  483. this.token(";");
  484. }
  485. function TSAsExpression(node) {
  486. const {
  487. expression,
  488. typeAnnotation
  489. } = node;
  490. this.print(expression, node);
  491. this.space();
  492. this.word("as");
  493. this.space();
  494. this.print(typeAnnotation, node);
  495. }
  496. function TSTypeAssertion(node) {
  497. const {
  498. typeAnnotation,
  499. expression
  500. } = node;
  501. this.token("<");
  502. this.print(typeAnnotation, node);
  503. this.token(">");
  504. this.space();
  505. this.print(expression, node);
  506. }
  507. function TSEnumDeclaration(node) {
  508. const {
  509. declare,
  510. const: isConst,
  511. id,
  512. members
  513. } = node;
  514. if (declare) {
  515. this.word("declare");
  516. this.space();
  517. }
  518. if (isConst) {
  519. this.word("const");
  520. this.space();
  521. }
  522. this.word("enum");
  523. this.space();
  524. this.print(id, node);
  525. this.space();
  526. this.tsPrintBraced(members, node);
  527. }
  528. function TSEnumMember(node) {
  529. const {
  530. id,
  531. initializer
  532. } = node;
  533. this.print(id, node);
  534. if (initializer) {
  535. this.space();
  536. this.token("=");
  537. this.space();
  538. this.print(initializer, node);
  539. }
  540. this.token(",");
  541. }
  542. function TSModuleDeclaration(node) {
  543. const {
  544. declare,
  545. id
  546. } = node;
  547. if (declare) {
  548. this.word("declare");
  549. this.space();
  550. }
  551. if (!node.global) {
  552. this.word(id.type === "Identifier" ? "namespace" : "module");
  553. this.space();
  554. }
  555. this.print(id, node);
  556. if (!node.body) {
  557. this.token(";");
  558. return;
  559. }
  560. let body = node.body;
  561. while (body.type === "TSModuleDeclaration") {
  562. this.token(".");
  563. this.print(body.id, body);
  564. body = body.body;
  565. }
  566. this.space();
  567. this.print(body, node);
  568. }
  569. function TSModuleBlock(node) {
  570. this.tsPrintBraced(node.body, node);
  571. }
  572. function TSImportType(node) {
  573. const {
  574. argument,
  575. qualifier,
  576. typeParameters
  577. } = node;
  578. this.word("import");
  579. this.token("(");
  580. this.print(argument, node);
  581. this.token(")");
  582. if (qualifier) {
  583. this.token(".");
  584. this.print(qualifier, node);
  585. }
  586. if (typeParameters) {
  587. this.print(typeParameters, node);
  588. }
  589. }
  590. function TSImportEqualsDeclaration(node) {
  591. const {
  592. isExport,
  593. id,
  594. moduleReference
  595. } = node;
  596. if (isExport) {
  597. this.word("export");
  598. this.space();
  599. }
  600. this.word("import");
  601. this.space();
  602. this.print(id, node);
  603. this.space();
  604. this.token("=");
  605. this.space();
  606. this.print(moduleReference, node);
  607. this.token(";");
  608. }
  609. function TSExternalModuleReference(node) {
  610. this.token("require(");
  611. this.print(node.expression, node);
  612. this.token(")");
  613. }
  614. function TSNonNullExpression(node) {
  615. this.print(node.expression, node);
  616. this.token("!");
  617. }
  618. function TSExportAssignment(node) {
  619. this.word("export");
  620. this.space();
  621. this.token("=");
  622. this.space();
  623. this.print(node.expression, node);
  624. this.token(";");
  625. }
  626. function TSNamespaceExportDeclaration(node) {
  627. this.word("export");
  628. this.space();
  629. this.word("as");
  630. this.space();
  631. this.word("namespace");
  632. this.space();
  633. this.print(node.id, node);
  634. }
  635. function tsPrintSignatureDeclarationBase(node) {
  636. const {
  637. typeParameters,
  638. parameters
  639. } = node;
  640. this.print(typeParameters, node);
  641. this.token("(");
  642. this._parameters(parameters, node);
  643. this.token(")");
  644. this.print(node.typeAnnotation, node);
  645. }
  646. function tsPrintClassMemberModifiers(node, isField) {
  647. if (isField && node.declare) {
  648. this.word("declare");
  649. this.space();
  650. }
  651. if (node.accessibility) {
  652. this.word(node.accessibility);
  653. this.space();
  654. }
  655. if (node.static) {
  656. this.word("static");
  657. this.space();
  658. }
  659. if (node.override) {
  660. this.word("override");
  661. this.space();
  662. }
  663. if (node.abstract) {
  664. this.word("abstract");
  665. this.space();
  666. }
  667. if (isField && node.readonly) {
  668. this.word("readonly");
  669. this.space();
  670. }
  671. }