Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1013 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = toKeyAlias;
|
---|
| 7 |
|
---|
| 8 | var _generated = require("../validators/generated");
|
---|
| 9 |
|
---|
| 10 | var _cloneNode = require("../clone/cloneNode");
|
---|
| 11 |
|
---|
| 12 | var _removePropertiesDeep = require("../modifications/removePropertiesDeep");
|
---|
| 13 |
|
---|
| 14 | function toKeyAlias(node, key = node.key) {
|
---|
| 15 | let alias;
|
---|
| 16 |
|
---|
| 17 | if (node.kind === "method") {
|
---|
| 18 | return toKeyAlias.increment() + "";
|
---|
| 19 | } else if ((0, _generated.isIdentifier)(key)) {
|
---|
| 20 | alias = key.name;
|
---|
| 21 | } else if ((0, _generated.isStringLiteral)(key)) {
|
---|
| 22 | alias = JSON.stringify(key.value);
|
---|
| 23 | } else {
|
---|
| 24 | alias = JSON.stringify((0, _removePropertiesDeep.default)((0, _cloneNode.default)(key)));
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | if (node.computed) {
|
---|
| 28 | alias = `[${alias}]`;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | if (node.static) {
|
---|
| 32 | alias = `static:${alias}`;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | return alias;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | toKeyAlias.uid = 0;
|
---|
| 39 |
|
---|
| 40 | toKeyAlias.increment = function () {
|
---|
| 41 | if (toKeyAlias.uid >= Number.MAX_SAFE_INTEGER) {
|
---|
| 42 | return toKeyAlias.uid = 0;
|
---|
| 43 | } else {
|
---|
| 44 | return toKeyAlias.uid++;
|
---|
| 45 | }
|
---|
| 46 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.