@@ -13,27 +13,44 @@ type UpdateBindingOptions = {
13
13
} ;
14
14
15
15
/**
16
- * Update a specific binding from an import or require statement.
16
+ * Update or remove a specific binding from an import or require statement.
17
17
*
18
- * Analyzes the provided AST node to find and remove a specific binding from destructured imports.
19
- * If the binding is the only one in the statement, the entire import line is marked for removal.
20
- * If there are multiple bindings, only the specified binding is removed from the destructuring pattern.
18
+ * Analyzes the provided AST node to find and update a specific binding from destructured imports.
19
+ * If `newBinding` is provided in options, the binding will be replaced with the new name.
20
+ * If `newBinding` is not provided, the binding will be removed.
21
+ * If the binding is the only one in the statement and no replacement is provided, the entire import line is marked for removal.
21
22
*
22
23
* @param node - The AST node representing the import or require statement
23
- * @param binding - The name of the binding to remove (e.g., "isNativeError")
24
+ * @param binding - The name of the binding to update or remove (e.g., "isNativeError")
25
+ * @param options - Optional configuration object
26
+ * @param options.newBinding - The new binding name to replace the old one. If not provided, the binding is removed.
24
27
* @returns An object containing either an edit operation or a line range to remove, or undefined if no binding found
25
28
*
26
29
* @example
27
30
* ```typescript
28
31
* // Given an import: const {types, isNativeError} = require("node:util")
29
- * // And binding: "isNativeError"
32
+ * // And binding: "isNativeError", options: {newBinding: "isError"}
33
+ * // Returns: an edit object that transforms to: const {types, isError} = require("node:util")
34
+ * ```
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Given an import: const {types, isNativeError} = require("node:util")
39
+ * // And binding: "isNativeError", options: undefined
30
40
* // Returns: an edit object that transforms to: const {types} = require("node:util")
31
41
* ```
32
42
*
33
43
* @example
34
44
* ```typescript
35
45
* // Given an import: const {isNativeError} = require("node:util")
36
- * // And binding: "isNativeError"
46
+ * // And binding: "isNativeError", options: {newBinding: "isError"}
47
+ * // Returns: an edit object that transforms to: const {isError} = require("node:util")
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Given an import: const {isNativeError} = require("node:util")
53
+ * // And binding: "isNativeError", options: undefined
37
54
* // Returns: {lineToRemove: Range} to remove the entire line
38
55
* ```
39
56
*
0 commit comments