7d4a7b1ea53e282e6ef201c0c75e5fe8144d8a717cc89df86fcdf60ded681d98585f322278eecf17055cd96c12501ade85901f5a2bcbcfade2777328e07c9a 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = undefined;
  4. var _babelTypes = require("babel-types");
  5. var t = _interopRequireWildcard(_babelTypes);
  6. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  7. var ReferencedIdentifier = exports.ReferencedIdentifier = {
  8. types: ["Identifier", "JSXIdentifier"],
  9. checkPath: function checkPath(_ref, opts) {
  10. var node = _ref.node,
  11. parent = _ref.parent;
  12. if (!t.isIdentifier(node, opts) && !t.isJSXMemberExpression(parent, opts)) {
  13. if (t.isJSXIdentifier(node, opts)) {
  14. if (_babelTypes.react.isCompatTag(node.name)) return false;
  15. } else {
  16. return false;
  17. }
  18. }
  19. return t.isReferenced(node, parent);
  20. }
  21. };
  22. var ReferencedMemberExpression = exports.ReferencedMemberExpression = {
  23. types: ["MemberExpression"],
  24. checkPath: function checkPath(_ref2) {
  25. var node = _ref2.node,
  26. parent = _ref2.parent;
  27. return t.isMemberExpression(node) && t.isReferenced(node, parent);
  28. }
  29. };
  30. var BindingIdentifier = exports.BindingIdentifier = {
  31. types: ["Identifier"],
  32. checkPath: function checkPath(_ref3) {
  33. var node = _ref3.node,
  34. parent = _ref3.parent;
  35. return t.isIdentifier(node) && t.isBinding(node, parent);
  36. }
  37. };
  38. var Statement = exports.Statement = {
  39. types: ["Statement"],
  40. checkPath: function checkPath(_ref4) {
  41. var node = _ref4.node,
  42. parent = _ref4.parent;
  43. if (t.isStatement(node)) {
  44. if (t.isVariableDeclaration(node)) {
  45. if (t.isForXStatement(parent, { left: node })) return false;
  46. if (t.isForStatement(parent, { init: node })) return false;
  47. }
  48. return true;
  49. } else {
  50. return false;
  51. }
  52. }
  53. };
  54. var Expression = exports.Expression = {
  55. types: ["Expression"],
  56. checkPath: function checkPath(path) {
  57. if (path.isIdentifier()) {
  58. return path.isReferencedIdentifier();
  59. } else {
  60. return t.isExpression(path.node);
  61. }
  62. }
  63. };
  64. var Scope = exports.Scope = {
  65. types: ["Scopable"],
  66. checkPath: function checkPath(path) {
  67. return t.isScope(path.node, path.parent);
  68. }
  69. };
  70. var Referenced = exports.Referenced = {
  71. checkPath: function checkPath(path) {
  72. return t.isReferenced(path.node, path.parent);
  73. }
  74. };
  75. var BlockScoped = exports.BlockScoped = {
  76. checkPath: function checkPath(path) {
  77. return t.isBlockScoped(path.node);
  78. }
  79. };
  80. var Var = exports.Var = {
  81. types: ["VariableDeclaration"],
  82. checkPath: function checkPath(path) {
  83. return t.isVar(path.node);
  84. }
  85. };
  86. var User = exports.User = {
  87. checkPath: function checkPath(path) {
  88. return path.node && !!path.node.loc;
  89. }
  90. };
  91. var Generated = exports.Generated = {
  92. checkPath: function checkPath(path) {
  93. return !path.isUser();
  94. }
  95. };
  96. var Pure = exports.Pure = {
  97. checkPath: function checkPath(path, opts) {
  98. return path.scope.isPure(path.node, opts);
  99. }
  100. };
  101. var Flow = exports.Flow = {
  102. types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
  103. checkPath: function checkPath(_ref5) {
  104. var node = _ref5.node;
  105. if (t.isFlow(node)) {
  106. return true;
  107. } else if (t.isImportDeclaration(node)) {
  108. return node.importKind === "type" || node.importKind === "typeof";
  109. } else if (t.isExportDeclaration(node)) {
  110. return node.exportKind === "type";
  111. } else if (t.isImportSpecifier(node)) {
  112. return node.importKind === "type" || node.importKind === "typeof";
  113. } else {
  114. return false;
  115. }
  116. }
  117. };