source: trip-planner-front/node_modules/@babel/plugin-transform-duplicate-keys/lib/index.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _helperPluginUtils = require("@babel/helper-plugin-utils");
9
10var _core = require("@babel/core");
11
12function getName(key) {
13 if (_core.types.isIdentifier(key)) {
14 return key.name;
15 }
16
17 return key.value.toString();
18}
19
20var _default = (0, _helperPluginUtils.declare)(api => {
21 api.assertVersion(7);
22 return {
23 name: "transform-duplicate-keys",
24 visitor: {
25 ObjectExpression(path) {
26 const {
27 node
28 } = path;
29 const plainProps = node.properties.filter(prop => !_core.types.isSpreadElement(prop) && !prop.computed);
30 const alreadySeenData = Object.create(null);
31 const alreadySeenGetters = Object.create(null);
32 const alreadySeenSetters = Object.create(null);
33
34 for (const prop of plainProps) {
35 const name = getName(prop.key);
36 let isDuplicate = false;
37
38 switch (prop.kind) {
39 case "get":
40 if (alreadySeenData[name] || alreadySeenGetters[name]) {
41 isDuplicate = true;
42 }
43
44 alreadySeenGetters[name] = true;
45 break;
46
47 case "set":
48 if (alreadySeenData[name] || alreadySeenSetters[name]) {
49 isDuplicate = true;
50 }
51
52 alreadySeenSetters[name] = true;
53 break;
54
55 default:
56 if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
57 isDuplicate = true;
58 }
59
60 alreadySeenData[name] = true;
61 }
62
63 if (isDuplicate) {
64 prop.computed = true;
65 prop.key = _core.types.stringLiteral(name);
66 }
67 }
68 }
69
70 }
71 };
72});
73
74exports.default = _default;
Note: See TracBrowser for help on using the repository browser.