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.

88 lines
3.0 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _helperAnnotateAsPure = _interopRequireDefault(require("@babel/helper-annotate-as-pure"));
  8. var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
  9. var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
  10. var _core = require("@babel/core");
  11. var _globals = _interopRequireDefault(require("globals"));
  12. var _transformClass = _interopRequireDefault(require("./transformClass"));
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. const getBuiltinClasses = category => Object.keys(_globals.default[category]).filter(name => /^[A-Z]/.test(name));
  15. const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
  16. var _default = (0, _helperPluginUtils.declare)((api, options) => {
  17. var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
  18. api.assertVersion(7);
  19. const {
  20. loose
  21. } = options;
  22. const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : options.loose;
  23. const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : options.loose;
  24. const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : options.loose;
  25. const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : options.loose;
  26. const VISITED = Symbol();
  27. return {
  28. name: "transform-classes",
  29. visitor: {
  30. ExportDefaultDeclaration(path) {
  31. if (!path.get("declaration").isClassDeclaration()) return;
  32. (0, _helperSplitExportDeclaration.default)(path);
  33. },
  34. ClassDeclaration(path) {
  35. const {
  36. node
  37. } = path;
  38. const ref = node.id || path.scope.generateUidIdentifier("class");
  39. path.replaceWith(_core.types.variableDeclaration("let", [_core.types.variableDeclarator(ref, _core.types.toExpression(node))]));
  40. },
  41. ClassExpression(path, state) {
  42. const {
  43. node
  44. } = path;
  45. if (node[VISITED]) return;
  46. const inferred = (0, _helperFunctionName.default)(path);
  47. if (inferred && inferred !== node) {
  48. path.replaceWith(inferred);
  49. return;
  50. }
  51. node[VISITED] = true;
  52. path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
  53. setClassMethods,
  54. constantSuper,
  55. superIsCallableConstructor,
  56. noClassCalls
  57. }));
  58. if (path.isCallExpression()) {
  59. (0, _helperAnnotateAsPure.default)(path);
  60. if (path.get("callee").isArrowFunctionExpression()) {
  61. path.get("callee").arrowFunctionToExpression();
  62. }
  63. }
  64. }
  65. }
  66. };
  67. });
  68. exports.default = _default;