From eba500f245708486babdb47e93f346c62e5d4f3f Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Mon, 15 Mar 2021 22:29:23 +0100 Subject: [PATCH 01/18] adds type definitions --- package.json | 170 ++++++++++++++++++++++++----------------------- types/index.d.ts | 26 ++++++++ 2 files changed, 113 insertions(+), 83 deletions(-) create mode 100644 types/index.d.ts diff --git a/package.json b/package.json index adcf96a..aad8eb5 100644 --- a/package.json +++ b/package.json @@ -1,87 +1,91 @@ { - "name": "unist-util-remove", - "version": "2.0.1", - "description": "unist utility to remove nodes from a tree", - "license": "MIT", - "keywords": [ - "unist", - "unist-util", - "util", - "utility", - "ast", - "tree", - "node", - "cascade", - "delete", - "mutable", - "remove", - "squeeze", - "strip" - ], - "repository": "syntax-tree/unist-util-remove", - "bugs": "https://github.com/syntax-tree/unist-util-remove/issues", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - }, - "author": "Eugene Sharygin ", - "contributors": [ - "Eugene Sharygin ", - "Titus Wormer (https://wooorm.com)" - ], - "files": [ - "index.js" - ], - "dependencies": { - "unist-util-is": "^4.0.0" - }, - "devDependencies": { - "nyc": "^15.0.0", - "prettier": "^2.0.0", - "remark-cli": "^9.0.0", - "remark-preset-wooorm": "^8.0.0", - "tape": "^5.0.0", - "unist-builder": "^2.0.0", - "xo": "^0.35.0" - }, - "scripts": { - "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run test-coverage" - }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 - }, - "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, - "bracketSpacing": false, - "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true, - "esnext": false, - "rules": { - "eqeqeq": [ - "error", - "always", - { - "null": "ignore" + "name": "unist-util-remove", + "version": "2.0.1", + "description": "unist utility to remove nodes from a tree", + "license": "MIT", + "keywords": [ + "unist", + "unist-util", + "util", + "utility", + "ast", + "tree", + "node", + "cascade", + "delete", + "mutable", + "remove", + "squeeze", + "strip" + ], + "repository": "syntax-tree/unist-util-remove", + "bugs": "https://github.com/syntax-tree/unist-util-remove/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Eugene Sharygin ", + "contributors": [ + "Eugene Sharygin ", + "Titus Wormer (https://wooorm.com)" + ], + "files": [ + "index.js", + "types/index.d.ts" + ], + "types": "types/index.d.ts", + "dependencies": { + "dtslint": "^4.0.7", + "unist-util-is": "^4.0.0" + }, + "devDependencies": { + "nyc": "^15.0.0", + "prettier": "^2.0.0", + "remark-cli": "^9.0.0", + "remark-preset-wooorm": "^8.0.0", + "tape": "^5.0.0", + "unist-builder": "^2.0.0", + "xo": "^0.35.0" + }, + "scripts": { + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api": "node test", + "test-coverage": "nyc --reporter lcov tape test.js", + "test": "npm run format && npm run test-coverage", + "test-types": "dtslint types" + }, + "nyc": { + "check-coverage": true, + "lines": 100, + "functions": 100, + "branches": 100 + }, + "prettier": { + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "bracketSpacing": false, + "semi": false, + "trailingComma": "none" + }, + "xo": { + "prettier": true, + "esnext": false, + "rules": { + "eqeqeq": [ + "error", + "always", + { + "null": "ignore" + } + ], + "no-eq-null": "off", + "unicorn/explicit-length-check": "off" } - ], - "no-eq-null": "off", - "unicorn/explicit-length-check": "off" + }, + "remarkConfig": { + "plugins": [ + "preset-wooorm" + ] } - }, - "remarkConfig": { - "plugins": [ - "preset-wooorm" - ] - } } diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..7dd5a05 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,26 @@ +// TypeScript Version: 3.5 + +import { Node } from 'unist'; +import { Test } from 'unist-util-is'; + +declare namespace remove { + interface RemoveOptions { + cascade?: boolean; + } +} + +/** + * + * Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. + * + * @param tree Tree to filter + * @param options Whether to drop parent nodes if they had children, but all their children were filtered out + * @param test is-compatible test (such as a type) + */ +declare function remove( + tree: Node, + options: remove.RemoveOptions = {cascade: true}, + test?: Test +): Node; + +export = remove; From 200fc950781686e80ff89f51b61f6924e0900ec7 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Tue, 30 Mar 2021 21:55:49 +0200 Subject: [PATCH 02/18] Update package.json Co-authored-by: Christian Murphy --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aad8eb5..12f0672 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ ], "types": "types/index.d.ts", "dependencies": { - "dtslint": "^4.0.7", + "dtslint": "^4.0.0", "unist-util-is": "^4.0.0" }, "devDependencies": { From 598c89eb4e589089d95521005841dd55d8e3adf7 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Tue, 30 Mar 2021 21:57:10 +0200 Subject: [PATCH 03/18] Update types/index.d.ts Co-authored-by: Christian Murphy --- types/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index 7dd5a05..aa13641 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -17,6 +17,10 @@ declare namespace remove { * @param options Whether to drop parent nodes if they had children, but all their children were filtered out * @param test is-compatible test (such as a type) */ +declare function remove( + tree: Node, + test?: Test +): Node; declare function remove( tree: Node, options: remove.RemoveOptions = {cascade: true}, From 43834f1e1aaa817221739ec7d8fb34798b4b46f8 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Tue, 30 Mar 2021 21:57:27 +0200 Subject: [PATCH 04/18] Update types/index.d.ts Co-authored-by: Christian Murphy --- types/index.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/index.d.ts b/types/index.d.ts index aa13641..8e7b722 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,6 +5,10 @@ import { Test } from 'unist-util-is'; declare namespace remove { interface RemoveOptions { + /** + * Whether to drop parent nodes if they had children, but all their children were filtered out +test + */ cascade?: boolean; } } From 8134e93ba6d4e2800c1caa17dd8e661e91b26ef6 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Tue, 30 Mar 2021 22:12:50 +0200 Subject: [PATCH 05/18] amends based on reviews --- package.json | 11 +++++++---- types/index.d.ts | 8 ++++++++ types/tsconfig.json | 25 +++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 types/tsconfig.json diff --git a/package.json b/package.json index aad8eb5..c340e9a 100644 --- a/package.json +++ b/package.json @@ -34,11 +34,14 @@ "types/index.d.ts" ], "types": "types/index.d.ts", + "ignores": [ + "types" + ], "dependencies": { - "dtslint": "^4.0.7", "unist-util-is": "^4.0.0" }, "devDependencies": { + "dtslint": "^4.0.0", "nyc": "^15.0.0", "prettier": "^2.0.0", "remark-cli": "^9.0.0", @@ -51,8 +54,8 @@ "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run test-coverage", - "test-types": "dtslint types" + "test-types": "dtslint types", + "test": "npm run format && npm run test-coverage && npm run test-types" }, "nyc": { "check-coverage": true, @@ -88,4 +91,4 @@ "preset-wooorm" ] } -} +} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts index 7dd5a05..2516d34 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -5,6 +5,9 @@ import { Test } from 'unist-util-is'; declare namespace remove { interface RemoveOptions { + /** + * Whether to drop parent nodes if they had children, but all their children were filtered out test + */ cascade?: boolean; } } @@ -17,6 +20,11 @@ declare namespace remove { * @param options Whether to drop parent nodes if they had children, but all their children were filtered out * @param test is-compatible test (such as a type) */ +declare function remove( + tree: Node, + test?: Test +): Node; + declare function remove( tree: Node, options: remove.RemoveOptions = {cascade: true}, diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..b036603 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es2017", + "lib": ["es6"], + "module": "commonjs", + "moduleResolution": "node", + "resolveJsonModule": true, + "esModuleInterop": false, + "strict": true, + "strictPropertyInitialization": false, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "sourceMap": true, + "skipLibCheck": true + }, + "include": [ + "./**/*.ts", + "./node_modules/@types" + ], + "exclude": [ + "node_modules", + "coverage" + ] + } + \ No newline at end of file From 43afc881bfe5b42e6426a379999eeda7f4ec3eb2 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Tue, 30 Mar 2021 22:57:23 +0200 Subject: [PATCH 06/18] adds tslint.json --- types/index.d.ts | 15 ++++++--------- types/tslint.json | 9 +++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 types/tslint.json diff --git a/types/index.d.ts b/types/index.d.ts index c41c330..5c85cf9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,14 +1,14 @@ // TypeScript Version: 3.5 -import { Node } from 'unist'; -import { Test } from 'unist-util-is'; +import {Node} from 'unist' +import {Test} from 'unist-util-is' declare namespace remove { interface RemoveOptions { /** * Whether to drop parent nodes if they had children, but all their children were filtered out test */ - cascade?: boolean; + cascade?: boolean } } @@ -20,14 +20,11 @@ declare namespace remove { * @param options Whether to drop parent nodes if they had children, but all their children were filtered out * @param test is-compatible test (such as a type) */ -declare function remove( - tree: Node, - test?: Test -): Node; +declare function remove(tree: Node, test?: Test): Node declare function remove( tree: Node, options: remove.RemoveOptions = {cascade: true}, test?: Test -): Node; +): Node -export = remove; +export = remove diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..9d846e4 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,9 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": true, + "semicolon": false, + "whitespace": false + } +} \ No newline at end of file From c230075fe974cb893d9850d33be7db1dfa030d67 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 00:09:32 +0200 Subject: [PATCH 07/18] fixes formatting --- package.json | 182 ++++++++++++++++++++++---------------------- types/tsconfig.json | 35 +++------ types/tslint.json | 16 ++-- 3 files changed, 111 insertions(+), 122 deletions(-) diff --git a/package.json b/package.json index c340e9a..0bf0a89 100644 --- a/package.json +++ b/package.json @@ -1,94 +1,94 @@ { - "name": "unist-util-remove", - "version": "2.0.1", - "description": "unist utility to remove nodes from a tree", - "license": "MIT", - "keywords": [ - "unist", - "unist-util", - "util", - "utility", - "ast", - "tree", - "node", - "cascade", - "delete", - "mutable", - "remove", - "squeeze", - "strip" - ], - "repository": "syntax-tree/unist-util-remove", - "bugs": "https://github.com/syntax-tree/unist-util-remove/issues", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - }, - "author": "Eugene Sharygin ", - "contributors": [ - "Eugene Sharygin ", - "Titus Wormer (https://wooorm.com)" - ], - "files": [ - "index.js", - "types/index.d.ts" - ], - "types": "types/index.d.ts", - "ignores": [ - "types" - ], - "dependencies": { - "unist-util-is": "^4.0.0" - }, - "devDependencies": { - "dtslint": "^4.0.0", - "nyc": "^15.0.0", - "prettier": "^2.0.0", - "remark-cli": "^9.0.0", - "remark-preset-wooorm": "^8.0.0", - "tape": "^5.0.0", - "unist-builder": "^2.0.0", - "xo": "^0.35.0" - }, - "scripts": { - "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", - "test-api": "node test", - "test-coverage": "nyc --reporter lcov tape test.js", - "test-types": "dtslint types", - "test": "npm run format && npm run test-coverage && npm run test-types" - }, - "nyc": { - "check-coverage": true, - "lines": 100, - "functions": 100, - "branches": 100 - }, - "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, - "bracketSpacing": false, - "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true, - "esnext": false, - "rules": { - "eqeqeq": [ - "error", - "always", - { - "null": "ignore" - } - ], - "no-eq-null": "off", - "unicorn/explicit-length-check": "off" + "name": "unist-util-remove", + "version": "2.0.1", + "description": "unist utility to remove nodes from a tree", + "license": "MIT", + "keywords": [ + "unist", + "unist-util", + "util", + "utility", + "ast", + "tree", + "node", + "cascade", + "delete", + "mutable", + "remove", + "squeeze", + "strip" + ], + "repository": "syntax-tree/unist-util-remove", + "bugs": "https://github.com/syntax-tree/unist-util-remove/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Eugene Sharygin ", + "contributors": [ + "Eugene Sharygin ", + "Titus Wormer (https://wooorm.com)" + ], + "files": [ + "index.js", + "types/index.d.ts" + ], + "types": "types/index.d.ts", + "ignores": [ + "types" + ], + "dependencies": { + "unist-util-is": "^4.0.0" + }, + "devDependencies": { + "dtslint": "^4.0.0", + "nyc": "^15.0.0", + "prettier": "^2.0.0", + "remark-cli": "^9.0.0", + "remark-preset-wooorm": "^8.0.0", + "tape": "^5.0.0", + "unist-builder": "^2.0.0", + "xo": "^0.35.0" + }, + "scripts": { + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api": "node test", + "test-coverage": "nyc --reporter lcov tape test.js", + "test-types": "dtslint types", + "test": "npm run format && npm run test-coverage && npm run test-types" + }, + "nyc": { + "check-coverage": true, + "lines": 100, + "functions": 100, + "branches": 100 + }, + "prettier": { + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "bracketSpacing": false, + "semi": false, + "trailingComma": "none" + }, + "xo": { + "prettier": true, + "esnext": false, + "rules": { + "eqeqeq": [ + "error", + "always", + { + "null": "ignore" } - }, - "remarkConfig": { - "plugins": [ - "preset-wooorm" - ] + ], + "no-eq-null": "off", + "unicorn/explicit-length-check": "off" } -} \ No newline at end of file + }, + "remarkConfig": { + "plugins": [ + "preset-wooorm" + ] + } +} diff --git a/types/tsconfig.json b/types/tsconfig.json index b036603..05a67ff 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -1,25 +1,14 @@ { - "compilerOptions": { - "target": "es2017", - "lib": ["es6"], - "module": "commonjs", - "moduleResolution": "node", - "resolveJsonModule": true, - "esModuleInterop": false, - "strict": true, - "strictPropertyInitialization": false, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "sourceMap": true, - "skipLibCheck": true - }, - "include": [ - "./**/*.ts", - "./node_modules/@types" - ], - "exclude": [ - "node_modules", - "coverage" - ] + "compilerOptions": { + "module": "es2015", + "lib": ["es2015"], + "moduleResolution": "node", + "strict": true, + "noEmit": true, + "baseUrl": ".", + "paths": { + "uninst-util-remove": ["."] + } } - \ No newline at end of file +} + diff --git a/types/tslint.json b/types/tslint.json index 9d846e4..4e872e2 100644 --- a/types/tslint.json +++ b/types/tslint.json @@ -1,9 +1,9 @@ { - "extends": "dtslint/dtslint.json", - "rules": { - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": true, - "semicolon": false, - "whitespace": false - } -} \ No newline at end of file + "extends": "dtslint/dtslint.json", + "rules": { + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": true, + "semicolon": false, + "whitespace": false + } +} From 6baa5dbf2bd549972accf6150e3b8330b40d95f5 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 00:09:48 +0200 Subject: [PATCH 08/18] adds type test --- types/index.d.ts | 17 +++++++++++------ types/test.ts | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 types/test.ts diff --git a/types/index.d.ts b/types/index.d.ts index 5c85cf9..fd60877 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -17,14 +17,19 @@ declare namespace remove { * Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. * * @param tree Tree to filter - * @param options Whether to drop parent nodes if they had children, but all their children were filtered out * @param test is-compatible test (such as a type) */ -declare function remove(tree: Node, test?: Test): Node -declare function remove( +export function remove(tree: Node, test?: Test): Node +/** + * + * Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. + * + * @param tree Tree to filter + * @param options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is {cascade: true} + * @param test is-compatible test (such as a type) + */ +export function remove( tree: Node, - options: remove.RemoveOptions = {cascade: true}, + options?: remove.RemoveOptions, test?: Test ): Node - -export = remove diff --git a/types/test.ts b/types/test.ts new file mode 100644 index 0000000..0c302e9 --- /dev/null +++ b/types/test.ts @@ -0,0 +1,19 @@ +import {remove} from 'uninst-util-remove'; +import * as u from 'unist-builder'; + +let tree = u('root', [ + u('leaf', '1'), + u('node', [ + u('leaf', '2'), + u('node', [u('leaf', '3'), u('other', '4')]), + u('node', [u('leaf', '5')]) + ]), + u('leaf', '6') +]); + +remove() // $ExpectError +remove('leaf') // $ExpectError + +remove(tree) +remove(tree, 'leaf'); +remove(tree, {cascade: false}, 'leaf'); From 027e875c68276c183d266d8125040f80b3c9be53 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Fri, 2 Apr 2021 09:18:46 +0200 Subject: [PATCH 09/18] Update types/test.ts Co-authored-by: Christian Murphy --- types/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/test.ts b/types/test.ts index 0c302e9..6be6845 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,7 +1,7 @@ import {remove} from 'uninst-util-remove'; import * as u from 'unist-builder'; -let tree = u('root', [ +const tree = u('root', [ u('leaf', '1'), u('node', [ u('leaf', '2'), From 7d68fe316afd090e1e0c4f96acc14e450a4a7115 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Fri, 2 Apr 2021 09:18:54 +0200 Subject: [PATCH 10/18] Update types/index.d.ts Co-authored-by: Christian Murphy --- types/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index fd60877..36731a9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -28,8 +28,8 @@ export function remove(tree: Node, test?: Test): Node * @param options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is {cascade: true} * @param test is-compatible test (such as a type) */ -export function remove( - tree: Node, +export function remove( + tree: T, options?: remove.RemoveOptions, test?: Test -): Node +): T | null From 931878b3293bfeda9b09a0adf27879cabacbafb0 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Fri, 2 Apr 2021 09:19:02 +0200 Subject: [PATCH 11/18] Update types/index.d.ts Co-authored-by: Christian Murphy --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 36731a9..389bc90 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -19,7 +19,7 @@ declare namespace remove { * @param tree Tree to filter * @param test is-compatible test (such as a type) */ -export function remove(tree: Node, test?: Test): Node +export function remove(tree: T, test?: Test): T | null /** * * Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. From 3f226b37d14b17851ba3ac7fb5ed41d27d438ffb Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Fri, 2 Apr 2021 09:19:08 +0200 Subject: [PATCH 12/18] Update package.json Co-authored-by: Christian Murphy --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 0bf0a89..8c63a44 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,6 @@ "types/index.d.ts" ], "types": "types/index.d.ts", - "ignores": [ - "types" - ], "dependencies": { "unist-util-is": "^4.0.0" }, From 8ab150dd49ccb7870e0afbc4f7095d9bf04bc6f9 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 09:26:55 +0200 Subject: [PATCH 13/18] adds fixes --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 389bc90..9c6d7f9 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,7 +3,7 @@ import {Node} from 'unist' import {Test} from 'unist-util-is' -declare namespace remove { +export namespace remove { interface RemoveOptions { /** * Whether to drop parent nodes if they had children, but all their children were filtered out test From ab3d07fd19237b663c7f2758e2808ab5ed2289a9 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 09:35:10 +0200 Subject: [PATCH 14/18] fixes multiple export with same name --- types/index.d.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 9c6d7f9..758c15c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,13 +3,11 @@ import {Node} from 'unist' import {Test} from 'unist-util-is' -export namespace remove { - interface RemoveOptions { - /** - * Whether to drop parent nodes if they had children, but all their children were filtered out test - */ - cascade?: boolean - } +export interface RemoveOptions { + /** + * Whether to drop parent nodes if they had children, but all their children were filtered out test + */ + cascade?: boolean } /** @@ -30,6 +28,6 @@ export function remove(tree: T, test?: Test): T | null */ export function remove( tree: T, - options?: remove.RemoveOptions, + options?: RemoveOptions, test?: Test ): T | null From f965220cb3b0bf07024840982abf49abb9de9134 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 11:19:15 +0200 Subject: [PATCH 15/18] changes syntax to matcht unist-builder's one --- types/index.d.ts | 11 ++++++++--- types/test.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 758c15c..ad0ae9f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,7 +3,10 @@ import {Node} from 'unist' import {Test} from 'unist-util-is' -export interface RemoveOptions { +// NOTE: namespace is needed to use `export = remove` +declare namespace remove {} + +declare interface RemoveOptions { /** * Whether to drop parent nodes if they had children, but all their children were filtered out test */ @@ -17,7 +20,7 @@ export interface RemoveOptions { * @param tree Tree to filter * @param test is-compatible test (such as a type) */ -export function remove(tree: T, test?: Test): T | null +declare function remove(tree: T, test?: Test): T | null /** * * Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc. @@ -26,8 +29,10 @@ export function remove(tree: T, test?: Test): T | null * @param options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is {cascade: true} * @param test is-compatible test (such as a type) */ -export function remove( +declare function remove( tree: T, options?: RemoveOptions, test?: Test ): T | null + +export = remove diff --git a/types/test.ts b/types/test.ts index 6be6845..c181ca7 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,4 +1,4 @@ -import {remove} from 'uninst-util-remove'; +import * as remove from 'uninst-util-remove'; import * as u from 'unist-builder'; const tree = u('root', [ From 6a4f5a5f411c82a3d44cbfa8e02aadbd3fd8ac10 Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 11:32:02 +0200 Subject: [PATCH 16/18] fixes superfluous declare --- types/index.d.ts | 2 +- types/test.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index ad0ae9f..3002071 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -6,7 +6,7 @@ import {Test} from 'unist-util-is' // NOTE: namespace is needed to use `export = remove` declare namespace remove {} -declare interface RemoveOptions { +interface RemoveOptions { /** * Whether to drop parent nodes if they had children, but all their children were filtered out test */ diff --git a/types/test.ts b/types/test.ts index c181ca7..8693074 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,5 +1,5 @@ -import * as remove from 'uninst-util-remove'; -import * as u from 'unist-builder'; +import * as remove from 'uninst-util-remove' +import * as u from 'unist-builder' const tree = u('root', [ u('leaf', '1'), @@ -9,11 +9,11 @@ const tree = u('root', [ u('node', [u('leaf', '5')]) ]), u('leaf', '6') -]); +]) -remove() // $ExpectError -remove('leaf') // $ExpectError +remove() // $ExpectError +remove('leaf') // $ExpectError remove(tree) -remove(tree, 'leaf'); -remove(tree, {cascade: false}, 'leaf'); +remove(tree, 'leaf') +remove(tree, {cascade: false}, 'leaf') From 93006d4a98c81c8c8b5f134957c341bb7482a3b4 Mon Sep 17 00:00:00 2001 From: GARCIA Guillaume Date: Fri, 2 Apr 2021 11:34:57 +0200 Subject: [PATCH 17/18] Update types/index.d.ts Co-authored-by: Remco Haszing --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 3002071..14eed51 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -31,7 +31,7 @@ declare function remove(tree: T, test?: Test): T | null */ declare function remove( tree: T, - options?: RemoveOptions, + options?: remove.RemoveOptions, test?: Test ): T | null From b37a296aaa00831f4eaa75809452a5868b40f76f Mon Sep 17 00:00:00 2001 From: Guillaume GARCIA Date: Fri, 2 Apr 2021 11:36:35 +0200 Subject: [PATCH 18/18] adds options within namespace --- types/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 14eed51..ee16410 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -4,13 +4,13 @@ import {Node} from 'unist' import {Test} from 'unist-util-is' // NOTE: namespace is needed to use `export = remove` -declare namespace remove {} - -interface RemoveOptions { - /** - * Whether to drop parent nodes if they had children, but all their children were filtered out test - */ - cascade?: boolean +declare namespace remove { + interface RemoveOptions { + /** + * Whether to drop parent nodes if they had children, but all their children were filtered out test + */ + cascade?: boolean + } } /**