tsutils
Advanced tools
Comparing version 3.18.0 to 3.19.0
@@ -0,1 +1,14 @@ | ||
# 3.19.0 | ||
**Features:** | ||
* `getSymbolOfClassLikeDeclaration` to retrieve the symbol of class declarations and expressions regardless whether they have a name or not | ||
* `getBaseOfClassLikeDeclaration` to conventiently get the expression after `extends` | ||
* `getBaseClassMemberOfClassElement` to look up the declaration of a class member in the base class | ||
**Bugfixes:** | ||
* `getConstructorTypeOfClassLikeDeclaration` now really returns the constructor type (the static side of the class), previously it returned the instance type | ||
* `hasExhaustiveCaseClauses` allows additional case clauses with `null`, `undefined` and `never` | ||
# 3.18.0 | ||
@@ -2,0 +15,0 @@ |
{ | ||
"name": "tsutils", | ||
"version": "3.18.0", | ||
"version": "3.19.0", | ||
"description": "utilities for working with typescript's AST", | ||
@@ -17,3 +17,3 @@ "scripts": { | ||
"github-release": "node ./scripts/github-release.js", | ||
"postpublish": "git push origin master --tags; run-s github-release" | ||
"postpublish": "git push origin master --tags && run-s github-release" | ||
}, | ||
@@ -20,0 +20,0 @@ "repository": { |
@@ -29,4 +29,7 @@ import * as ts from 'typescript'; | ||
export declare function getPropertyNameFromType(type: ts.Type): PropertyName | undefined; | ||
export declare function getSymbolOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Symbol; | ||
export declare function getConstructorTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Type; | ||
export declare function getInstanceTypeOfClassLikeDeclaration(node: ts.ClassLikeDeclaration, checker: ts.TypeChecker): ts.Type; | ||
export declare function getIteratorYieldResultFromIteratorResult(type: ts.Type, node: ts.Node, checker: ts.TypeChecker): ts.Type; | ||
/** Lookup the declaration of a class member in the super class. */ | ||
export declare function getBaseClassMemberOfClassElement(node: ts.PropertyDeclaration | ts.MethodDeclaration | ts.AccessorDeclaration, checker: ts.TypeChecker): ts.Symbol | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getIteratorYieldResultFromIteratorResult = exports.getInstanceTypeOfClassLikeDeclaration = exports.getConstructorTypeOfClassLikeDeclaration = exports.getPropertyNameFromType = exports.symbolHasReadonlyDeclaration = exports.isPropertyReadonlyInType = exports.getPropertyOfType = exports.isBooleanLiteralType = exports.isFalsyType = exports.isThenableType = exports.someTypePart = exports.intersectionTypeParts = exports.unionTypeParts = exports.getCallSignaturesOfType = exports.isTypeAssignableToString = exports.isTypeAssignableToNumber = exports.isOptionalChainingUndefinedMarkerType = exports.removeOptionalChainingUndefinedMarkerType = exports.removeOptionalityFromType = exports.isEmptyObjectType = void 0; | ||
exports.getBaseClassMemberOfClassElement = exports.getIteratorYieldResultFromIteratorResult = exports.getInstanceTypeOfClassLikeDeclaration = exports.getConstructorTypeOfClassLikeDeclaration = exports.getSymbolOfClassLikeDeclaration = exports.getPropertyNameFromType = exports.symbolHasReadonlyDeclaration = exports.isPropertyReadonlyInType = exports.getPropertyOfType = exports.isBooleanLiteralType = exports.isFalsyType = exports.isThenableType = exports.someTypePart = exports.intersectionTypeParts = exports.unionTypeParts = exports.getCallSignaturesOfType = exports.isTypeAssignableToString = exports.isTypeAssignableToNumber = exports.isOptionalChainingUndefinedMarkerType = exports.removeOptionalChainingUndefinedMarkerType = exports.removeOptionalityFromType = exports.isEmptyObjectType = void 0; | ||
const ts = require("typescript"); | ||
@@ -258,4 +258,10 @@ const type_1 = require("../typeguard/type"); | ||
exports.getPropertyNameFromType = getPropertyNameFromType; | ||
function getSymbolOfClassLikeDeclaration(node, checker) { | ||
return node.name !== undefined ? checker.getSymbolAtLocation(node.name) : checker.getTypeAtLocation(node).symbol; | ||
} | ||
exports.getSymbolOfClassLikeDeclaration = getSymbolOfClassLikeDeclaration; | ||
function getConstructorTypeOfClassLikeDeclaration(node, checker) { | ||
return checker.getDeclaredTypeOfSymbol(node.name !== undefined ? checker.getSymbolAtLocation(node.name) : checker.getTypeAtLocation(node).symbol); | ||
return node.kind === ts.SyntaxKind.ClassExpression | ||
? checker.getTypeAtLocation(node) | ||
: checker.getTypeOfSymbolAtLocation(getSymbolOfClassLikeDeclaration(node, checker), node); | ||
} | ||
@@ -266,3 +272,3 @@ exports.getConstructorTypeOfClassLikeDeclaration = getConstructorTypeOfClassLikeDeclaration; | ||
? checker.getTypeAtLocation(node) | ||
: checker.getTypeOfSymbolAtLocation(checker.getTypeAtLocation(node).getProperty('prototype'), node); | ||
: checker.getDeclaredTypeOfSymbol(getSymbolOfClassLikeDeclaration(node, checker)); | ||
} | ||
@@ -278,2 +284,18 @@ exports.getInstanceTypeOfClassLikeDeclaration = getInstanceTypeOfClassLikeDeclaration; | ||
exports.getIteratorYieldResultFromIteratorResult = getIteratorYieldResultFromIteratorResult; | ||
/** Lookup the declaration of a class member in the super class. */ | ||
function getBaseClassMemberOfClassElement(node, checker) { | ||
if (!node_1.isClassLikeDeclaration(node.parent)) | ||
return; | ||
const base = util_1.getBaseOfClassLikeExpression(node.parent); | ||
if (base === undefined) | ||
return; | ||
const name = util_1.getSingleLateBoundPropertyNameOfPropertyName(node.name, checker); | ||
if (name === undefined) | ||
return; | ||
const baseType = checker.getTypeAtLocation(util_1.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword) | ||
? base.expression | ||
: base); | ||
return getPropertyOfType(baseType, name.symbolName); | ||
} | ||
exports.getBaseClassMemberOfClassElement = getBaseClassMemberOfClassElement; | ||
//# sourceMappingURL=type.js.map |
@@ -471,2 +471,5 @@ "use strict"; | ||
} | ||
// TODO class decorators resolve outside of class, element and parameter decorator resolve inside/at the class | ||
// TODO computed property name resolves inside/at the cass | ||
// TODO this and super in all of them are resolved outside of the class | ||
class UsageWalker { | ||
@@ -473,0 +476,0 @@ constructor() { |
@@ -264,1 +264,2 @@ import * as ts from 'typescript'; | ||
export declare function hasExhaustiveCaseClauses(node: ts.SwitchStatement, checker: ts.TypeChecker): boolean; | ||
export declare function getBaseOfClassLikeExpression(node: ts.ClassLikeDeclaration): ts.ExpressionWithTypeArguments | undefined; |
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
373493
4485