UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

32 lines (30 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const removeChildren_1 = require("./removeChildren"); function removeCommaSeparatedChild(child, opts) { const { removePrecedingSpaces = undefined } = opts || {}; const childrenToRemove = [child]; const syntaxList = child.getParentSyntaxListOrThrow(); addNextCommaIfAble(); addPreviousCommaIfAble(); removeChildren_1.removeChildren({ children: childrenToRemove, removePrecedingSpaces: removePrecedingSpaces == null ? true : removePrecedingSpaces, removeFollowingSpaces: childrenToRemove[0] === syntaxList.getFirstChild() }); function addNextCommaIfAble() { const commaToken = child.getNextSiblingIfKind(ts.SyntaxKind.CommaToken); if (commaToken != null) childrenToRemove.push(commaToken); } function addPreviousCommaIfAble() { if (syntaxList.getLastChild() !== childrenToRemove[childrenToRemove.length - 1]) return; const precedingComma = child.getPreviousSiblingIfKind(ts.SyntaxKind.CommaToken); if (precedingComma != null) childrenToRemove.splice(0, 0, precedingComma); } } exports.removeCommaSeparatedChild = removeCommaSeparatedChild; //# sourceMappingURL=removeCommaSeparatedChild.js.map