@phenomnomnominal/tsquery
Advanced tools
Comparing version 6.1.2 to 6.1.3
@@ -19,3 +19,3 @@ import { ast } from './ast'; | ||
export { parse } from './parse'; | ||
export { map } from './map'; | ||
export { map, remove } from './map'; | ||
export { replace } from './replace'; | ||
@@ -22,0 +22,0 @@ export { project, files } from './project'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tsquery = exports.files = exports.project = exports.replace = exports.map = exports.parse = exports.query = exports.match = exports.includes = exports.print = exports.ast = exports.SyntaxKind = exports.ScriptKind = void 0; | ||
exports.tsquery = exports.files = exports.project = exports.replace = exports.remove = exports.map = exports.parse = exports.query = exports.match = exports.includes = exports.print = exports.ast = exports.SyntaxKind = exports.ScriptKind = void 0; | ||
const ast_1 = require("./ast"); | ||
@@ -29,2 +29,3 @@ const map_1 = require("./map"); | ||
Object.defineProperty(exports, "map", { enumerable: true, get: function () { return map_2.map; } }); | ||
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return map_2.remove; } }); | ||
var replace_2 = require("./replace"); | ||
@@ -31,0 +32,0 @@ Object.defineProperty(exports, "replace", { enumerable: true, get: function () { return replace_2.replace; } }); |
@@ -11,5 +11,14 @@ /// <reference types="esquery" /> | ||
* @param nodeTransformer - a function to transform any matched `Nodes`. If the original `Node` is returned, there is no change. If a new `Node` is returned, the original `Node` is replaced. If `undefined` is returned, the original `Node` is removed. | ||
* @returns a transformed `Node`. | ||
* @returns a transformed `SourceFile`. | ||
*/ | ||
export declare function map(sourceFile: SourceFile, selector: string | Selector, nodeTransformer: NodeTransformer): SourceFile; | ||
/** | ||
* @public | ||
* Remove AST `Nodes` within a given `Node` matching a `Selector`. | ||
* | ||
* @param sourceFile - the TypeScript [`SourceFile`](https://github.com/microsoft/TypeScript/blob/main/src/services/types.ts#L159) to be searched. | ||
* @param selector - a TSQuery `Selector` (using the [ESQuery selector syntax](https://github.com/estools/esquery)). | ||
* @returns a transformed `SourceFile` with the matching `Nodes` removed. | ||
*/ | ||
export declare function remove(sourceFile: SourceFile, selector: string | Selector): SourceFile; | ||
export declare function createTransformer(nodeTransformer: NodeTransformer): TransformerFactory<Node>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createTransformer = exports.map = void 0; | ||
exports.createTransformer = exports.remove = exports.map = void 0; | ||
const typescript_1 = require("typescript"); | ||
@@ -13,3 +13,3 @@ const index_1 = require("./index"); | ||
* @param nodeTransformer - a function to transform any matched `Nodes`. If the original `Node` is returned, there is no change. If a new `Node` is returned, the original `Node` is replaced. If `undefined` is returned, the original `Node` is removed. | ||
* @returns a transformed `Node`. | ||
* @returns a transformed `SourceFile`. | ||
*/ | ||
@@ -21,2 +21,14 @@ function map(sourceFile, selector, nodeTransformer) { | ||
exports.map = map; | ||
/** | ||
* @public | ||
* Remove AST `Nodes` within a given `Node` matching a `Selector`. | ||
* | ||
* @param sourceFile - the TypeScript [`SourceFile`](https://github.com/microsoft/TypeScript/blob/main/src/services/types.ts#L159) to be searched. | ||
* @param selector - a TSQuery `Selector` (using the [ESQuery selector syntax](https://github.com/estools/esquery)). | ||
* @returns a transformed `SourceFile` with the matching `Nodes` removed. | ||
*/ | ||
function remove(sourceFile, selector) { | ||
return map(sourceFile, selector, () => undefined); | ||
} | ||
exports.remove = remove; | ||
function mapTransform(sourceFile, matches, nodeTransformer) { | ||
@@ -23,0 +35,0 @@ const transformer = createTransformer((node) => { |
@@ -18,2 +18,3 @@ "use strict"; | ||
const file = (0, index_1.ast)(''); | ||
deletePos(source); | ||
return printer.printNode(typescript_1.EmitHint.Unspecified, source, file); | ||
@@ -24,2 +25,6 @@ } | ||
exports.print = print; | ||
function deletePos(node) { | ||
node.pos = -1; | ||
node.forEachChild(deletePos); | ||
} | ||
//# sourceMappingURL=print.js.map |
{ | ||
"name": "@phenomnomnominal/tsquery", | ||
"version": "6.1.2", | ||
"version": "6.1.3", | ||
"description": "Query TypeScript ASTs with the esquery API!", | ||
@@ -24,3 +24,3 @@ "main": "dist/src/index.js", | ||
"test": "jest", | ||
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand", | ||
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --collectCoverage=false", | ||
"prepublishOnly": "npm run build" | ||
@@ -27,0 +27,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86245
1169