web 3d图形渲染器
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.

152 lines
15 KiB

  1. 'use strict';var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
  2. var _object = require('object.values');var _object2 = _interopRequireDefault(_object);
  3. var _arrayPrototype = require('array.prototype.flat');var _arrayPrototype2 = _interopRequireDefault(_arrayPrototype);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  4. const meta = {
  5. type: 'suggestion',
  6. docs: {
  7. url: (0, _docsUrl2.default)('group-exports') }
  8. /* eslint-disable max-len */ };
  9. const errors = {
  10. ExportNamedDeclaration: 'Multiple named export declarations; consolidate all named exports into a single export declaration',
  11. AssignmentExpression: 'Multiple CommonJS exports; consolidate all exports into a single assignment to `module.exports`'
  12. /* eslint-enable max-len */
  13. /**
  14. * Returns an array with names of the properties in the accessor chain for MemberExpression nodes
  15. *
  16. * Example:
  17. *
  18. * `module.exports = {}` => ['module', 'exports']
  19. * `module.exports.property = true` => ['module', 'exports', 'property']
  20. *
  21. * @param {Node} node AST Node (MemberExpression)
  22. * @return {Array} Array with the property names in the chain
  23. * @private
  24. */ };
  25. function accessorChain(node) {
  26. const chain = [];
  27. do {
  28. chain.unshift(node.property.name);
  29. if (node.object.type === 'Identifier') {
  30. chain.unshift(node.object.name);
  31. break;
  32. }
  33. node = node.object;
  34. } while (node.type === 'MemberExpression');
  35. return chain;
  36. }
  37. function create(context) {
  38. const nodes = {
  39. modules: {
  40. set: new Set(),
  41. sources: {} },
  42. types: {
  43. set: new Set(),
  44. sources: {} },
  45. commonjs: {
  46. set: new Set() } };
  47. return {
  48. ExportNamedDeclaration(node) {
  49. let target = node.exportKind === 'type' ? nodes.types : nodes.modules;
  50. if (!node.source) {
  51. target.set.add(node);
  52. } else if (Array.isArray(target.sources[node.source.value])) {
  53. target.sources[node.source.value].push(node);
  54. } else {
  55. target.sources[node.source.value] = [node];
  56. }
  57. },
  58. AssignmentExpression(node) {
  59. if (node.left.type !== 'MemberExpression') {
  60. return;
  61. }
  62. const chain = accessorChain(node.left);
  63. // Assignments to module.exports
  64. // Deeper assignments are ignored since they just modify what's already being exported
  65. // (ie. module.exports.exported.prop = true is ignored)
  66. if (chain[0] === 'module' && chain[1] === 'exports' && chain.length <= 3) {
  67. nodes.commonjs.set.add(node);
  68. return;
  69. }
  70. // Assignments to exports (exports.* = *)
  71. if (chain[0] === 'exports' && chain.length === 2) {
  72. nodes.commonjs.set.add(node);
  73. return;
  74. }
  75. },
  76. 'Program:exit': function onExit() {
  77. // Report multiple `export` declarations (ES2015 modules)
  78. if (nodes.modules.set.size > 1) {
  79. nodes.modules.set.forEach(node => {
  80. context.report({
  81. node,
  82. message: errors[node.type] });
  83. });
  84. }
  85. // Report multiple `aggregated exports` from the same module (ES2015 modules)
  86. (0, _arrayPrototype2.default)((0, _object2.default)(nodes.modules.sources).
  87. filter(nodesWithSource => Array.isArray(nodesWithSource) && nodesWithSource.length > 1)).
  88. forEach(node => {
  89. context.report({
  90. node,
  91. message: errors[node.type] });
  92. });
  93. // Report multiple `export type` declarations (FLOW ES2015 modules)
  94. if (nodes.types.set.size > 1) {
  95. nodes.types.set.forEach(node => {
  96. context.report({
  97. node,
  98. message: errors[node.type] });
  99. });
  100. }
  101. // Report multiple `aggregated type exports` from the same module (FLOW ES2015 modules)
  102. (0, _arrayPrototype2.default)((0, _object2.default)(nodes.types.sources).
  103. filter(nodesWithSource => Array.isArray(nodesWithSource) && nodesWithSource.length > 1)).
  104. forEach(node => {
  105. context.report({
  106. node,
  107. message: errors[node.type] });
  108. });
  109. // Report multiple `module.exports` assignments (CommonJS)
  110. if (nodes.commonjs.set.size > 1) {
  111. nodes.commonjs.set.forEach(node => {
  112. context.report({
  113. node,
  114. message: errors[node.type] });
  115. });
  116. }
  117. } };
  118. }
  119. module.exports = {
  120. meta,
  121. create };
  122. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb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