Skip to content

Commit a23b1a2

Browse files
committed
feature: @putout/operate: remove: do not throw when no node
1 parent a41ca23 commit a23b1a2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/operate/lib/remove.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const {entries} = Object;
44
const isOneDeclaration = ({node}) => node.declarations.length === 1;
55

66
module.exports.remove = (path) => {
7+
if (!path.node)
8+
return;
9+
710
const {scope} = path;
811
const prev = getPrevSibling(path);
912
const next = getNextSibling(path);

packages/operate/lib/remove.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,21 @@ test('@putout/operate: remove: no scope', (t) => {
4242
t.equal(code, expected);
4343
t.end();
4444
});
45+
46+
test('@putout/operate: remove: not found', (t) => {
47+
const source = `x ? a() : b();\n`;
48+
const ast = parse(source);
49+
50+
traverse(ast, {
51+
ConditionalExpression: (path) => {
52+
const nextPath = path.getNextSibling();
53+
54+
remove(nextPath);
55+
},
56+
});
57+
58+
const code = print(ast);
59+
60+
t.equal(code, source);
61+
t.end();
62+
});

0 commit comments

Comments
 (0)