1eb7df72260a4f9bb3f5cd289002de479eddb2cbeed0c26e131595c4b9b5b5ccf1996821f194a2db19e799f8ca0b20c2a7c71fa1ef50e1e46f319eea568bb4 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = toKeyAlias;
  6. var _index = require("../validators/generated/index.js");
  7. var _cloneNode = require("../clone/cloneNode.js");
  8. var _removePropertiesDeep = require("../modifications/removePropertiesDeep.js");
  9. function toKeyAlias(node, key = node.key) {
  10. let alias;
  11. if (node.kind === "method") {
  12. return toKeyAlias.increment() + "";
  13. } else if ((0, _index.isIdentifier)(key)) {
  14. alias = key.name;
  15. } else if ((0, _index.isStringLiteral)(key)) {
  16. alias = JSON.stringify(key.value);
  17. } else {
  18. alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneNode.default)(key)));
  19. }
  20. if (node.computed) {
  21. alias = `[${alias}]`;
  22. }
  23. if (node.static) {
  24. alias = `static:${alias}`;
  25. }
  26. return alias;
  27. }
  28. toKeyAlias.uid = 0;
  29. toKeyAlias.increment = function () {
  30. if (toKeyAlias.uid >= Number.MAX_SAFE_INTEGER) {
  31. return toKeyAlias.uid = 0;
  32. } else {
  33. return toKeyAlias.uid++;
  34. }
  35. };
  36. //# sourceMappingURL=toKeyAlias.js.map