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.

82 lines
2.8 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _default;
  6. var t = _interopRequireWildcard(require("@babel/types"));
  7. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  8. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  9. function getObjRef(node, nodes, scope) {
  10. let ref;
  11. if (t.isIdentifier(node)) {
  12. if (scope.hasBinding(node.name)) {
  13. return node;
  14. } else {
  15. ref = node;
  16. }
  17. } else if (t.isMemberExpression(node)) {
  18. ref = node.object;
  19. if (t.isSuper(ref) || t.isIdentifier(ref) && scope.hasBinding(ref.name)) {
  20. return ref;
  21. }
  22. } else {
  23. throw new Error(`We can't explode this node type ${node["type"]}`);
  24. }
  25. const temp = scope.generateUidIdentifierBasedOnNode(ref);
  26. scope.push({
  27. id: temp
  28. });
  29. nodes.push(t.assignmentExpression("=", t.cloneNode(temp), t.cloneNode(ref)));
  30. return temp;
  31. }
  32. function getPropRef(node, nodes, scope) {
  33. const prop = node.property;
  34. if (t.isPrivateName(prop)) {
  35. throw new Error("We can't generate property ref for private name, please install `@babel/plugin-proposal-class-properties`");
  36. }
  37. const key = t.toComputedKey(node, prop);
  38. if (t.isLiteral(key) && t.isPureish(key)) return key;
  39. const temp = scope.generateUidIdentifierBasedOnNode(prop);
  40. scope.push({
  41. id: temp
  42. });
  43. nodes.push(t.assignmentExpression("=", t.cloneNode(temp), t.cloneNode(prop)));
  44. return temp;
  45. }
  46. function _default(node, nodes, file, scope, allowedSingleIdent) {
  47. let obj;
  48. if (t.isIdentifier(node) && allowedSingleIdent) {
  49. obj = node;
  50. } else {
  51. obj = getObjRef(node, nodes, scope);
  52. }
  53. let ref, uid;
  54. if (t.isIdentifier(node)) {
  55. ref = t.cloneNode(node);
  56. uid = obj;
  57. } else {
  58. const prop = getPropRef(node, nodes, scope);
  59. const computed = node.computed || t.isLiteral(prop);
  60. uid = t.memberExpression(t.cloneNode(obj), t.cloneNode(prop), computed);
  61. ref = t.memberExpression(t.cloneNode(obj), t.cloneNode(prop), computed);
  62. }
  63. return {
  64. uid: uid,
  65. ref: ref
  66. };
  67. }