8931d6da7e17ca838113b0d3ac627f1613c47e57b9fa3e93d1c3b63a120d9f085b759ce217be3b24286431dda240a676adaf78c4ed2b1e89b46bf6238f8840 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isBindingIdentifier = isBindingIdentifier;
  6. exports.isBlockScoped = isBlockScoped;
  7. exports.isExpression = isExpression;
  8. exports.isFlow = isFlow;
  9. exports.isForAwaitStatement = isForAwaitStatement;
  10. exports.isGenerated = isGenerated;
  11. exports.isPure = isPure;
  12. exports.isReferenced = isReferenced;
  13. exports.isReferencedIdentifier = isReferencedIdentifier;
  14. exports.isReferencedMemberExpression = isReferencedMemberExpression;
  15. exports.isRestProperty = isRestProperty;
  16. exports.isScope = isScope;
  17. exports.isSpreadProperty = isSpreadProperty;
  18. exports.isStatement = isStatement;
  19. exports.isUser = isUser;
  20. exports.isVar = isVar;
  21. var _t = require("@babel/types");
  22. const {
  23. isBinding,
  24. isBlockScoped: nodeIsBlockScoped,
  25. isExportDeclaration,
  26. isExpression: nodeIsExpression,
  27. isFlow: nodeIsFlow,
  28. isForStatement,
  29. isForXStatement,
  30. isIdentifier,
  31. isImportDeclaration,
  32. isImportSpecifier,
  33. isJSXIdentifier,
  34. isJSXMemberExpression,
  35. isMemberExpression,
  36. isRestElement: nodeIsRestElement,
  37. isReferenced: nodeIsReferenced,
  38. isScope: nodeIsScope,
  39. isStatement: nodeIsStatement,
  40. isVar: nodeIsVar,
  41. isVariableDeclaration,
  42. react,
  43. isForOfStatement
  44. } = _t;
  45. const {
  46. isCompatTag
  47. } = react;
  48. function isReferencedIdentifier(opts) {
  49. const {
  50. node,
  51. parent
  52. } = this;
  53. if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
  54. if (isJSXIdentifier(node, opts)) {
  55. if (isCompatTag(node.name)) return false;
  56. } else {
  57. return false;
  58. }
  59. }
  60. return nodeIsReferenced(node, parent, this.parentPath.parent);
  61. }
  62. function isReferencedMemberExpression() {
  63. const {
  64. node,
  65. parent
  66. } = this;
  67. return isMemberExpression(node) && nodeIsReferenced(node, parent);
  68. }
  69. function isBindingIdentifier() {
  70. const {
  71. node,
  72. parent
  73. } = this;
  74. const grandparent = this.parentPath.parent;
  75. return isIdentifier(node) && isBinding(node, parent, grandparent);
  76. }
  77. function isStatement() {
  78. const {
  79. node,
  80. parent
  81. } = this;
  82. if (nodeIsStatement(node)) {
  83. if (isVariableDeclaration(node)) {
  84. if (isForXStatement(parent, {
  85. left: node
  86. })) return false;
  87. if (isForStatement(parent, {
  88. init: node
  89. })) return false;
  90. }
  91. return true;
  92. } else {
  93. return false;
  94. }
  95. }
  96. function isExpression() {
  97. if (this.isIdentifier()) {
  98. return this.isReferencedIdentifier();
  99. } else {
  100. return nodeIsExpression(this.node);
  101. }
  102. }
  103. function isScope() {
  104. return nodeIsScope(this.node, this.parent);
  105. }
  106. function isReferenced() {
  107. return nodeIsReferenced(this.node, this.parent);
  108. }
  109. function isBlockScoped() {
  110. return nodeIsBlockScoped(this.node);
  111. }
  112. function isVar() {
  113. return nodeIsVar(this.node);
  114. }
  115. function isUser() {
  116. return this.node && !!this.node.loc;
  117. }
  118. function isGenerated() {
  119. return !this.isUser();
  120. }
  121. function isPure(constantsOnly) {
  122. return this.scope.isPure(this.node, constantsOnly);
  123. }
  124. function isFlow() {
  125. const {
  126. node
  127. } = this;
  128. if (nodeIsFlow(node)) {
  129. return true;
  130. } else if (isImportDeclaration(node)) {
  131. return node.importKind === "type" || node.importKind === "typeof";
  132. } else if (isExportDeclaration(node)) {
  133. return node.exportKind === "type";
  134. } else if (isImportSpecifier(node)) {
  135. return node.importKind === "type" || node.importKind === "typeof";
  136. } else {
  137. return false;
  138. }
  139. }
  140. function isRestProperty() {
  141. var _this$parentPath;
  142. return nodeIsRestElement(this.node) && ((_this$parentPath = this.parentPath) == null ? void 0 : _this$parentPath.isObjectPattern());
  143. }
  144. function isSpreadProperty() {
  145. var _this$parentPath2;
  146. return nodeIsRestElement(this.node) && ((_this$parentPath2 = this.parentPath) == null ? void 0 : _this$parentPath2.isObjectExpression());
  147. }
  148. function isForAwaitStatement() {
  149. return isForOfStatement(this.node, {
  150. await: true
  151. });
  152. }
  153. {
  154. exports.isExistentialTypeParam = function isExistentialTypeParam() {
  155. throw new Error("`path.isExistentialTypeParam` has been renamed to `path.isExistsTypeAnnotation()` in Babel 7.");
  156. };
  157. exports.isNumericLiteralTypeAnnotation = function isNumericLiteralTypeAnnotation() {
  158. throw new Error("`path.isNumericLiteralTypeAnnotation()` has been renamed to `path.isNumberLiteralTypeAnnotation()` in Babel 7.");
  159. };
  160. }
  161. //# sourceMappingURL=virtual-types-validator.js.map