main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | exports.default = void 0;
|
---|
| 7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
| 8 | var _core = require("@babel/core");
|
---|
| 9 | function getName(key) {
|
---|
| 10 | if (_core.types.isIdentifier(key)) {
|
---|
| 11 | return key.name;
|
---|
| 12 | }
|
---|
| 13 | return key.value.toString();
|
---|
| 14 | }
|
---|
| 15 | var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
|
---|
| 16 | api.assertVersion(7);
|
---|
| 17 | return {
|
---|
| 18 | name: "transform-duplicate-keys",
|
---|
| 19 | visitor: {
|
---|
| 20 | ObjectExpression(path) {
|
---|
| 21 | const {
|
---|
| 22 | node
|
---|
| 23 | } = path;
|
---|
| 24 | const plainProps = node.properties.filter(prop => !_core.types.isSpreadElement(prop) && !prop.computed);
|
---|
| 25 | const alreadySeenData = Object.create(null);
|
---|
| 26 | const alreadySeenGetters = Object.create(null);
|
---|
| 27 | const alreadySeenSetters = Object.create(null);
|
---|
| 28 | for (const prop of plainProps) {
|
---|
| 29 | const name = getName(prop.key);
|
---|
| 30 | let isDuplicate = false;
|
---|
| 31 | switch (prop.kind) {
|
---|
| 32 | case "get":
|
---|
| 33 | if (alreadySeenData[name] || alreadySeenGetters[name]) {
|
---|
| 34 | isDuplicate = true;
|
---|
| 35 | }
|
---|
| 36 | alreadySeenGetters[name] = true;
|
---|
| 37 | break;
|
---|
| 38 | case "set":
|
---|
| 39 | if (alreadySeenData[name] || alreadySeenSetters[name]) {
|
---|
| 40 | isDuplicate = true;
|
---|
| 41 | }
|
---|
| 42 | alreadySeenSetters[name] = true;
|
---|
| 43 | break;
|
---|
| 44 | default:
|
---|
| 45 | if (alreadySeenData[name] || alreadySeenGetters[name] || alreadySeenSetters[name]) {
|
---|
| 46 | isDuplicate = true;
|
---|
| 47 | }
|
---|
| 48 | alreadySeenData[name] = true;
|
---|
| 49 | }
|
---|
| 50 | if (isDuplicate) {
|
---|
| 51 | prop.computed = true;
|
---|
| 52 | prop.key = _core.types.stringLiteral(name);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | };
|
---|
| 58 | });
|
---|
| 59 |
|
---|
| 60 | //# sourceMappingURL=index.js.map
|
---|
Note:
See
TracBrowser
for help on using the repository browser.