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.

60 lines
1.9 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 _pluginSyntaxNullishCoalescingOperator = _interopRequireDefault(require("@babel/plugin-syntax-nullish-coalescing-operator"));
  8. var _core = require("@babel/core");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. var _default = (0, _helperPluginUtils.declare)((api, {
  11. loose = false
  12. }) => {
  13. var _api$assumption;
  14. api.assertVersion(7);
  15. const noDocumentAll = (_api$assumption = api.assumption("noDocumentAll")) != null ? _api$assumption : loose;
  16. return {
  17. name: "proposal-nullish-coalescing-operator",
  18. inherits: _pluginSyntaxNullishCoalescingOperator.default,
  19. visitor: {
  20. LogicalExpression(path) {
  21. const {
  22. node,
  23. scope
  24. } = path;
  25. if (node.operator !== "??") {
  26. return;
  27. }
  28. let ref;
  29. let assignment;
  30. if (scope.isStatic(node.left)) {
  31. ref = node.left;
  32. assignment = _core.types.cloneNode(node.left);
  33. } else if (scope.path.isPattern()) {
  34. path.replaceWith(_core.template.ast`(() => ${path.node})()`);
  35. return;
  36. } else {
  37. ref = scope.generateUidIdentifierBasedOnNode(node.left);
  38. scope.push({
  39. id: _core.types.cloneNode(ref)
  40. });
  41. assignment = _core.types.assignmentExpression("=", ref, node.left);
  42. }
  43. path.replaceWith(_core.types.conditionalExpression(noDocumentAll ? _core.types.binaryExpression("!=", assignment, _core.types.nullLiteral()) : _core.types.logicalExpression("&&", _core.types.binaryExpression("!==", assignment, _core.types.nullLiteral()), _core.types.binaryExpression("!==", _core.types.cloneNode(ref), scope.buildUndefinedNode())), _core.types.cloneNode(ref), node.right));
  44. }
  45. }
  46. };
  47. });
  48. exports.default = _default;