@@ -13,27 +13,44 @@ type UpdateBindingOptions = {
1313} ;
1414
1515/**
16- * Update a specific binding from an import or require statement.
16+ * Update or remove a specific binding from an import or require statement.
1717 *
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.
2122 *
2223 * @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.
2427 * @returns An object containing either an edit operation or a line range to remove, or undefined if no binding found
2528 *
2629 * @example
2730 * ```typescript
2831 * // 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
3040 * // Returns: an edit object that transforms to: const {types} = require("node:util")
3141 * ```
3242 *
3343 * @example
3444 * ```typescript
3545 * // 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
3754 * // Returns: {lineToRemove: Range} to remove the entire line
3855 * ```
3956 *
0 commit comments