Comparing version 3.19.1 to 3.20.0
@@ -0,1 +1,11 @@ | ||
# 3.20.0 | ||
**Features:** | ||
* `findImports` and `findImportLikeNodes` take an additional parameter `ignoreFileName`. The default value for this paramter is `true` to remain backwards compatible. When set to `false`, it matches the behavior of TypeScript, i.e. only looks for `require` in JavaScript files. | ||
**Bugfixes:** | ||
* `getJsDoc` for `EndOfFileToken` now returns `JSDoc` comments whose contents are usable with the type checker | ||
# 3.19.1 | ||
@@ -2,0 +12,0 @@ |
{ | ||
"name": "tsutils", | ||
"version": "3.19.1", | ||
"version": "3.20.0", | ||
"description": "utilities for working with typescript's AST", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -26,3 +26,3 @@ import * as ts from 'typescript'; | ||
wrapped: WrappedAst; | ||
/** depth-first array of all nodes */ | ||
/** depth-first array of all nodes excluding SourceFile */ | ||
flat: ReadonlyArray<ts.Node>; | ||
@@ -29,0 +29,0 @@ } |
@@ -21,9 +21,6 @@ "use strict"; | ||
let current = wrapped; | ||
let previous = current; | ||
ts.forEachChild(sourceFile, function wrap(node) { | ||
flat.push(node); | ||
const parent = current; | ||
previous.next = current = { | ||
function collectChildren(node) { | ||
current.children.push({ | ||
node, | ||
parent, | ||
parent: current, | ||
kind: node.kind, | ||
@@ -33,11 +30,46 @@ children: [], | ||
skip: undefined, | ||
}; | ||
if (previous !== parent) | ||
setSkip(previous, current); | ||
previous = current; | ||
parent.children.push(current); | ||
if (util_1.isNodeKind(node.kind)) | ||
ts.forEachChild(node, wrap); | ||
current = parent; | ||
}); | ||
}); | ||
} | ||
const stack = []; | ||
while (true) { | ||
if (current.children.length === 0) { | ||
ts.forEachChild(current.node, collectChildren); | ||
if (current.children.length === 0) { | ||
current = current.parent; // nothing to do here, go back to parent | ||
} | ||
else { | ||
// recurse into first child | ||
const firstChild = current.children[0]; | ||
current.next = firstChild; | ||
flat.push(firstChild.node); | ||
if (util_1.isNodeKind(firstChild.kind)) | ||
current = firstChild; | ||
stack.push(1); // set index in stack so we know where to continue processing children | ||
} | ||
} | ||
else { | ||
const index = stack[stack.length - 1]; | ||
if (index < current.children.length) { // handles 2nd child to the last | ||
const currentChild = current.children[index]; | ||
flat.push(currentChild.node); | ||
let previous = current.children[index - 1]; | ||
while (previous.children.length !== 0) { | ||
previous.skip = currentChild; | ||
previous = previous.children[previous.children.length - 1]; | ||
} | ||
previous.skip = previous.next = currentChild; | ||
++stack[stack.length - 1]; | ||
if (util_1.isNodeKind(currentChild.kind)) | ||
current = currentChild; // recurse into child | ||
} | ||
else { | ||
// done on this node | ||
if (stack.length === 1) | ||
break; | ||
// remove index from stack and go back to parent | ||
stack.pop(); | ||
current = current.parent; | ||
} | ||
} | ||
} | ||
return { | ||
@@ -49,8 +81,2 @@ wrapped, | ||
exports.convertAst = convertAst; | ||
function setSkip(node, skip) { | ||
do { | ||
node.skip = skip; | ||
node = node.parent; | ||
} while (node !== skip.parent); | ||
} | ||
//# sourceMappingURL=convert-ast.js.map |
@@ -82,3 +82,3 @@ "use strict"; | ||
if (declaration.constraint === undefined) | ||
return true; | ||
return true; // TODO really? | ||
return check(checker.getTypeFromTypeNode(declaration.constraint)); | ||
@@ -85,0 +85,0 @@ } |
@@ -158,3 +158,3 @@ import * as ts from 'typescript'; | ||
export declare function canHaveJsDoc(node: ts.Node): node is ts.HasJSDoc; | ||
/** Gets the JSDoc of any node. For performance reasons this function should only be called when `canHaveJsDoc` returns true. */ | ||
/** Gets the JSDoc of a node. For performance reasons this function should only be called when `canHaveJsDoc` returns true. */ | ||
export declare function getJsDoc(node: ts.Node, sourceFile?: ts.SourceFile): ts.JSDoc[]; | ||
@@ -181,3 +181,3 @@ /** | ||
} | ||
export declare function findImports(sourceFile: ts.SourceFile, kinds: ImportKind): (ts.StringLiteral | ts.NoSubstitutionTemplateLiteral)[]; | ||
export declare function findImports(sourceFile: ts.SourceFile, kinds: ImportKind, ignoreFileName?: boolean): (ts.StringLiteral | ts.NoSubstitutionTemplateLiteral)[]; | ||
export declare type ImportLike = ts.ImportDeclaration | ts.ImportEqualsDeclaration & { | ||
@@ -193,3 +193,3 @@ moduleReference: ts.ExternalModuleReference; | ||
} | ts.ImportTypeNode; | ||
export declare function findImportLikeNodes(sourceFile: ts.SourceFile, kinds: ImportKind): ImportLike[]; | ||
export declare function findImportLikeNodes(sourceFile: ts.SourceFile, kinds: ImportKind, ignoreFileName?: boolean): ImportLike[]; | ||
/** | ||
@@ -196,0 +196,0 @@ * Ambient context means the statement itself has the `declare` keyword |
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 too big to display
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
377950
4547