meta-resolver.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = createMetaResolver;
  4. var _utils = require("./utils");
  5. const PossibleGlobalObjects = new Set(["global", "globalThis", "self", "window"]);
  6. function createMetaResolver(polyfills) {
  7. const {
  8. static: staticP,
  9. instance: instanceP,
  10. global: globalP
  11. } = polyfills;
  12. return meta => {
  13. if (meta.kind === "global" && globalP && (0, _utils.has)(globalP, meta.name)) {
  14. return {
  15. kind: "global",
  16. desc: globalP[meta.name],
  17. name: meta.name
  18. };
  19. }
  20. if (meta.kind === "property" || meta.kind === "in") {
  21. const {
  22. placement,
  23. object,
  24. key
  25. } = meta;
  26. if (object && placement === "static") {
  27. if (globalP && PossibleGlobalObjects.has(object) && (0, _utils.has)(globalP, key)) {
  28. return {
  29. kind: "global",
  30. desc: globalP[key],
  31. name: key
  32. };
  33. }
  34. if (staticP && (0, _utils.has)(staticP, object) && (0, _utils.has)(staticP[object], key)) {
  35. return {
  36. kind: "static",
  37. desc: staticP[object][key],
  38. name: `${object}$${key}`
  39. };
  40. }
  41. }
  42. if (instanceP && (0, _utils.has)(instanceP, key)) {
  43. return {
  44. kind: "instance",
  45. desc: instanceP[key],
  46. name: `${key}`
  47. };
  48. }
  49. }
  50. };
  51. }