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.

64 lines
1.8 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  6. exports.default = getValue;
  7. exports.getLiteralValue = getLiteralValue;
  8. var _Literal = require('./Literal');
  9. var _Literal2 = _interopRequireDefault(_Literal);
  10. var _JSXElement = require('./JSXElement');
  11. var _JSXElement2 = _interopRequireDefault(_JSXElement);
  12. var _expressions = require('./expressions');
  13. var _expressions2 = _interopRequireDefault(_expressions);
  14. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  15. // Composition map of types to their extractor functions.
  16. var TYPES = {
  17. Literal: _Literal2.default,
  18. JSXElement: _JSXElement2.default,
  19. JSXExpressionContainer: _expressions2.default
  20. };
  21. // Composition map of types to their extractor functions to handle literals.
  22. var LITERAL_TYPES = _extends({}, TYPES, {
  23. JSXElement: function JSXElement() {
  24. return null;
  25. },
  26. JSXExpressionContainer: _expressions.extractLiteral
  27. });
  28. /**
  29. * This function maps an AST value node
  30. * to its correct extractor function for its
  31. * given type.
  32. *
  33. * This will map correctly for *all* possible types.
  34. *
  35. * @param value - AST Value object on a JSX Attribute.
  36. */
  37. function getValue(value) {
  38. return TYPES[value.type](value);
  39. }
  40. /**
  41. * This function maps an AST value node
  42. * to its correct extractor function for its
  43. * given type.
  44. *
  45. * This will map correctly for *some* possible types that map to literals.
  46. *
  47. * @param value - AST Value object on a JSX Attribute.
  48. */
  49. function getLiteralValue(value) {
  50. return LITERAL_TYPES[value.type](value);
  51. }