UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

31 lines (29 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ts = require("typescript"); const removeChildren_1 = require("./removeChildren"); function removeCommaSeparatedChild(child) { const childrenToRemove = [child]; const syntaxList = child.getParentSyntaxListOrThrow(); addNextCommaIfAble(); addPreviousCommaIfAble(); removeChildren_1.removeChildren({ children: childrenToRemove, removePrecedingSpaces: true, 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