source: imaps-frontend/node_modules/@babel/traverse/lib/path/comments.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.addComment = addComment;
7exports.addComments = addComments;
8exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
9var _t = require("@babel/types");
10const {
11 addComment: _addComment,
12 addComments: _addComments
13} = _t;
14function shareCommentsWithSiblings() {
15 if (typeof this.key === "string") return;
16 const node = this.node;
17 if (!node) return;
18 const trailing = node.trailingComments;
19 const leading = node.leadingComments;
20 if (!trailing && !leading) return;
21 const prev = this.getSibling(this.key - 1);
22 const next = this.getSibling(this.key + 1);
23 const hasPrev = Boolean(prev.node);
24 const hasNext = Boolean(next.node);
25 if (hasPrev) {
26 if (leading) {
27 prev.addComments("trailing", removeIfExisting(leading, prev.node.trailingComments));
28 }
29 if (trailing && !hasNext) prev.addComments("trailing", trailing);
30 }
31 if (hasNext) {
32 if (trailing) {
33 next.addComments("leading", removeIfExisting(trailing, next.node.leadingComments));
34 }
35 if (leading && !hasPrev) next.addComments("leading", leading);
36 }
37}
38function removeIfExisting(list, toRemove) {
39 if (!(toRemove != null && toRemove.length)) return list;
40 const set = new Set(toRemove);
41 return list.filter(el => {
42 return !set.has(el);
43 });
44}
45function addComment(type, content, line) {
46 _addComment(this.node, type, content, line);
47}
48function addComments(type, comments) {
49 _addComments(this.node, type, comments);
50}
51
52//# sourceMappingURL=comments.js.map
Note: See TracBrowser for help on using the repository browser.