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.

142 lines
15 KiB

  1. 'use strict';var _declaredScope = require('eslint-module-utils/declaredScope');var _declaredScope2 = _interopRequireDefault(_declaredScope);
  2. var _ExportMap = require('../ExportMap');var _ExportMap2 = _interopRequireDefault(_ExportMap);
  3. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  4. function message(deprecation) {
  5. return 'Deprecated' + (deprecation.description ? ': ' + deprecation.description : '.');
  6. }
  7. function getDeprecation(metadata) {
  8. if (!metadata || !metadata.doc) return;
  9. let deprecation;
  10. if (metadata.doc.tags.some(t => t.title === 'deprecated' && (deprecation = t))) {
  11. return deprecation;
  12. }
  13. }
  14. module.exports = {
  15. meta: {
  16. type: 'suggestion',
  17. docs: {
  18. url: (0, _docsUrl2.default)('no-deprecated') },
  19. schema: [] },
  20. create: function (context) {
  21. const deprecated = new Map(),
  22. namespaces = new Map();
  23. function checkSpecifiers(node) {
  24. if (node.type !== 'ImportDeclaration') return;
  25. if (node.source == null) return; // local export, ignore
  26. const imports = _ExportMap2.default.get(node.source.value, context);
  27. if (imports == null) return;
  28. let moduleDeprecation;
  29. if (imports.doc &&
  30. imports.doc.tags.some(t => t.title === 'deprecated' && (moduleDeprecation = t))) {
  31. context.report({ node, message: message(moduleDeprecation) });
  32. }
  33. if (imports.errors.length) {
  34. imports.reportErrors(context, node);
  35. return;
  36. }
  37. node.specifiers.forEach(function (im) {
  38. let imported, local;
  39. switch (im.type) {
  40. case 'ImportNamespaceSpecifier':{
  41. if (!imports.size) return;
  42. namespaces.set(im.local.name, imports);
  43. return;
  44. }
  45. case 'ImportDefaultSpecifier':
  46. imported = 'default';
  47. local = im.local.name;
  48. break;
  49. case 'ImportSpecifier':
  50. imported = im.imported.name;
  51. local = im.local.name;
  52. break;
  53. default:return; // can't handle this one
  54. }
  55. // unknown thing can't be deprecated
  56. const exported = imports.get(imported);
  57. if (exported == null) return;
  58. // capture import of deep namespace
  59. if (exported.namespace) namespaces.set(local, exported.namespace);
  60. const deprecation = getDeprecation(imports.get(imported));
  61. if (!deprecation) return;
  62. context.report({ node: im, message: message(deprecation) });
  63. deprecated.set(local, deprecation);
  64. });
  65. }
  66. return {
  67. 'Program': (_ref) => {let body = _ref.body;return body.forEach(checkSpecifiers);},
  68. 'Identifier': function (node) {
  69. if (node.parent.type === 'MemberExpression' && node.parent.property === node) {
  70. return; // handled by MemberExpression
  71. }
  72. // ignore specifier identifiers
  73. if (node.parent.type.slice(0, 6) === 'Import') return;
  74. if (!deprecated.has(node.name)) return;
  75. if ((0, _declaredScope2.default)(context, node.name) !== 'module') return;
  76. context.report({
  77. node,
  78. message: message(deprecated.get(node.name)) });
  79. },
  80. 'MemberExpression': function (dereference) {
  81. if (dereference.object.type !== 'Identifier') return;
  82. if (!namespaces.has(dereference.object.name)) return;
  83. if ((0, _declaredScope2.default)(context, dereference.object.name) !== 'module') return;
  84. // go deep
  85. var namespace = namespaces.get(dereference.object.name);
  86. var namepath = [dereference.object.name];
  87. // while property is namespace and parent is member expression, keep validating
  88. while (namespace instanceof _ExportMap2.default &&
  89. dereference.type === 'MemberExpression') {
  90. // ignore computed parts for now
  91. if (dereference.computed) return;
  92. const metadata = namespace.get(dereference.property.name);
  93. if (!metadata) break;
  94. const deprecation = getDeprecation(metadata);
  95. if (deprecation) {
  96. context.report({ node: dereference.property, message: message(deprecation) });
  97. }
  98. // stash and pop
  99. namepath.push(dereference.property.name);
  100. namespace = metadata.namespace;
  101. dereference = dereference.parent;
  102. }
  103. } };
  104. } };
  105. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1kZXByZWNhdGVkLmpzIl0sIm5hbWVzIjpbIm1lc3NhZ2UiLCJkZXByZWNhdGlvbiIsImRlc2NyaXB0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