1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
7 | exports.addComment = addComment;
|
8 | exports.addComments = addComments;
|
9 |
|
10 | var t = _interopRequireWildcard(require("@babel/types"));
|
11 |
|
12 | function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
13 |
|
14 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15 |
|
16 | function shareCommentsWithSiblings() {
|
17 | if (typeof this.key === "string") return;
|
18 | const node = this.node;
|
19 | if (!node) return;
|
20 | const trailing = node.trailingComments;
|
21 | const leading = node.leadingComments;
|
22 | if (!trailing && !leading) return;
|
23 | const prev = this.getSibling(this.key - 1);
|
24 | const next = this.getSibling(this.key + 1);
|
25 | const hasPrev = Boolean(prev.node);
|
26 | const hasNext = Boolean(next.node);
|
27 |
|
28 | if (hasPrev && !hasNext) {
|
29 | prev.addComments("trailing", trailing);
|
30 | } else if (hasNext && !hasPrev) {
|
31 | next.addComments("leading", leading);
|
32 | }
|
33 | }
|
34 |
|
35 | function addComment(type, content, line) {
|
36 | t.addComment(this.node, type, content, line);
|
37 | }
|
38 |
|
39 | function addComments(type, comments) {
|
40 | t.addComments(this.node, type, comments);
|
41 | } |
\ | No newline at end of file |