Skip to content

Commit

Permalink
fix more unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregoor committed Nov 6, 2024
1 parent 02347cf commit 9199c83
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
9 changes: 1 addition & 8 deletions src/actions/unwrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ test.each([
["let n = ≤1≥;", "≤1≥"],
["[1•, 2]", "[≤1≥]"],
["(ab: ≤A≥) => {}", "(≤A≥) => {}"],
[
`fn(23, ≤(o) => {
const { a } = o;
}≥);`,
`≤(o) => {
const { a } = o;
}≥;`,
],
["fn(≤a≥, b)", "fn(≤a≥)"],
])("%s", (sourceWithCursor: string, expected: string) => {
const { source, cursors } = parseCursorSource(sourceWithCursor);
const code = new Code(source, "javascript");
Expand Down
7 changes: 1 addition & 6 deletions src/actions/unwrap.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { SyntaxNode } from "web-tree-sitter";

import { changeCode, Sub } from "~/change";
import { Code } from "~/code";
import { Range } from "~/range";
import { sliceRange } from "~/utils";

const isFieldOnParent = (n: SyntaxNode) =>
n.parent?.childForFieldName(n.type)?.equals(n);

export function unwrap(code: Code, cursor: Range): Sub | null {
const node = code.tree.getNode(cursor);
for (const ancestor of node.iterAncestors()) {
if (cursor.includes(ancestor) || isFieldOnParent(ancestor.inner)) {
if (cursor.includes(ancestor)) {
continue;
}

Expand Down

0 comments on commit 9199c83

Please sign in to comment.