Dashboard sipadu mbip
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getTypeAnnotation = getTypeAnnotation;
  6. exports._getTypeAnnotation = _getTypeAnnotation;
  7. exports.isBaseType = isBaseType;
  8. exports.couldBeBaseType = couldBeBaseType;
  9. exports.baseTypeStrictlyMatches = baseTypeStrictlyMatches;
  10. exports.isGenericType = isGenericType;
  11. var inferers = _interopRequireWildcard(require("./inferers"));
  12. var t = _interopRequireWildcard(require("@babel/types"));
  13. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  14. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  15. function getTypeAnnotation() {
  16. if (this.typeAnnotation) return this.typeAnnotation;
  17. let type = this._getTypeAnnotation() || t.anyTypeAnnotation();
  18. if (t.isTypeAnnotation(type)) type = type.typeAnnotation;
  19. return this.typeAnnotation = type;
  20. }
  21. function _getTypeAnnotation() {
  22. const node = this.node;
  23. if (!node) {
  24. if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
  25. const declar = this.parentPath.parentPath;
  26. const declarParent = declar.parentPath;
  27. if (declar.key === "left" && declarParent.isForInStatement()) {
  28. return t.stringTypeAnnotation();
  29. }
  30. if (declar.key === "left" && declarParent.isForOfStatement()) {
  31. return t.anyTypeAnnotation();
  32. }
  33. return t.voidTypeAnnotation();
  34. } else {
  35. return;
  36. }
  37. }
  38. if (node.typeAnnotation) {
  39. return node.typeAnnotation;
  40. }
  41. let inferer = inferers[node.type];
  42. if (inferer) {
  43. return inferer.call(this, node);
  44. }
  45. inferer = inferers[this.parentPath.type];
  46. if (inferer && inferer.validParent) {
  47. return this.parentPath.getTypeAnnotation();
  48. }
  49. }
  50. function isBaseType(baseName, soft) {
  51. return _isBaseType(baseName, this.getTypeAnnotation(), soft);
  52. }
  53. function _isBaseType(baseName, type, soft) {
  54. if (baseName === "string") {
  55. return t.isStringTypeAnnotation(type);
  56. } else if (baseName === "number") {
  57. return t.isNumberTypeAnnotation(type);
  58. } else if (baseName === "boolean") {
  59. return t.isBooleanTypeAnnotation(type);
  60. } else if (baseName === "any") {
  61. return t.isAnyTypeAnnotation(type);
  62. } else if (baseName === "mixed") {
  63. return t.isMixedTypeAnnotation(type);
  64. } else if (baseName === "empty") {
  65. return t.isEmptyTypeAnnotation(type);
  66. } else if (baseName === "void") {
  67. return t.isVoidTypeAnnotation(type);
  68. } else {
  69. if (soft) {
  70. return false;
  71. } else {
  72. throw new Error(`Unknown base type ${baseName}`);
  73. }
  74. }
  75. }
  76. function couldBeBaseType(name) {
  77. const type = this.getTypeAnnotation();
  78. if (t.isAnyTypeAnnotation(type)) return true;
  79. if (t.isUnionTypeAnnotation(type)) {
  80. for (const type2 of type.types) {
  81. if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
  82. return true;
  83. }
  84. }
  85. return false;
  86. } else {
  87. return _isBaseType(name, type, true);
  88. }
  89. }
  90. function baseTypeStrictlyMatches(right) {
  91. const left = this.getTypeAnnotation();
  92. right = right.getTypeAnnotation();
  93. if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) {
  94. return right.type === left.type;
  95. }
  96. }
  97. function isGenericType(genericName) {
  98. const type = this.getTypeAnnotation();
  99. return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, {
  100. name: genericName
  101. });
  102. }