arcast/node_modules/@babel/traverse/lib/path/comments.js.map

1 line
3.9 KiB
Plaintext

{"version":3,"names":["_t","require","addComment","_addComment","addComments","_addComments","shareCommentsWithSiblings","key","node","trailing","trailingComments","leading","leadingComments","prev","getSibling","next","hasPrev","Boolean","hasNext","removeIfExisting","list","toRemove","length","set","Set","filter","el","has","type","content","line","comments"],"sources":["../../src/path/comments.ts"],"sourcesContent":["// This file contains methods responsible for dealing with comments.\nimport type * as t from \"@babel/types\";\nimport type NodePath from \"./index.ts\";\nimport {\n addComment as _addComment,\n addComments as _addComments,\n} from \"@babel/types\";\n\n/**\n * Share comments amongst siblings.\n */\n\nexport function shareCommentsWithSiblings(this: NodePath) {\n // NOTE: this assumes numbered keys\n if (typeof this.key === \"string\") return;\n\n const node = this.node;\n if (!node) return;\n\n const trailing = node.trailingComments;\n const leading = node.leadingComments;\n if (!trailing && !leading) return;\n\n const prev = this.getSibling(this.key - 1);\n const next = this.getSibling(this.key + 1);\n const hasPrev = Boolean(prev.node);\n const hasNext = Boolean(next.node);\n\n if (hasPrev) {\n if (leading) {\n prev.addComments(\n \"trailing\",\n removeIfExisting(leading, prev.node.trailingComments),\n );\n }\n if (trailing && !hasNext) prev.addComments(\"trailing\", trailing);\n }\n if (hasNext) {\n if (trailing) {\n next.addComments(\n \"leading\",\n removeIfExisting(trailing, next.node.leadingComments),\n );\n }\n if (leading && !hasPrev) next.addComments(\"leading\", leading);\n }\n}\n\nfunction removeIfExisting<T>(list: T[], toRemove?: T[]): T[] {\n if (!toRemove?.length) return list;\n const set = new Set(toRemove);\n return list.filter(el => {\n return !set.has(el);\n });\n}\n\nexport function addComment(\n this: NodePath,\n type: t.CommentTypeShorthand,\n content: string,\n line?: boolean,\n) {\n _addComment(this.node, type, content, line);\n}\n\n/**\n * Give node `comments` of the specified `type`.\n */\n\nexport function addComments(\n this: NodePath,\n type: t.CommentTypeShorthand,\n comments: t.Comment[],\n) {\n _addComments(this.node, type, comments);\n}\n"],"mappings":";;;;;;;;AA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