update modules

This commit is contained in:
Joel Male
2022-11-10 20:43:16 +10:00
parent c9072d53a3
commit 29d4f522f2
5233 changed files with 476623 additions and 533020 deletions
+7
View File
@@ -1,3 +1,10 @@
# 3.21.0
**Features:**
* added `getWellKnownSymbolPropertyOfType` to reliably get symbol named properties due to changes in typescript@4.3
* `getPropertyNameOfWellKnownSymbol` is now deprecated
# 3.20.0
**Features:**
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "tsutils",
"version": "3.20.0",
"version": "3.21.0",
"description": "utilities for working with typescript's AST",
"scripts": {
"precompile": "rimraf \"{,util,typeguard,test{,/rules}/*.{js,d.ts,js.map}\"",
+1
View File
@@ -21,6 +21,7 @@ export declare function isFalsyType(type: ts.Type): boolean;
/** Determines whether the given type is a boolean literal type and matches the given boolean literal (true or false). */
export declare function isBooleanLiteralType(type: ts.Type, literal: boolean): boolean;
export declare function getPropertyOfType(type: ts.Type, name: ts.__String): ts.Symbol | undefined;
export declare function getWellKnownSymbolPropertyOfType(type: ts.Type, wellKnownSymbolName: string, checker: ts.TypeChecker): ts.Symbol | undefined;
/** Determines if writing to a certain property of a given type is allowed. */
export declare function isPropertyReadonlyInType(type: ts.Type, name: ts.__String, checker: ts.TypeChecker): boolean;
export declare function symbolHasReadonlyDeclaration(symbol: ts.Symbol, checker: ts.TypeChecker): boolean;
+34 -2
View File
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
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;
exports.getBaseClassMemberOfClassElement = exports.getIteratorYieldResultFromIteratorResult = exports.getInstanceTypeOfClassLikeDeclaration = exports.getConstructorTypeOfClassLikeDeclaration = exports.getSymbolOfClassLikeDeclaration = exports.getPropertyNameFromType = exports.symbolHasReadonlyDeclaration = exports.isPropertyReadonlyInType = exports.getWellKnownSymbolPropertyOfType = 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");
const type_1 = require("../typeguard/type");
const util_1 = require("./util");
@@ -173,6 +173,26 @@ function getPropertyOfType(type, name) {
return type.getProperties().find((s) => s.escapedName === name);
}
exports.getPropertyOfType = getPropertyOfType;
function getWellKnownSymbolPropertyOfType(type, wellKnownSymbolName, checker) {
const prefix = '__@' + wellKnownSymbolName;
for (const prop of type.getProperties()) {
if (!prop.name.startsWith(prefix))
continue;
const globalSymbol = checker.getApparentType(checker.getTypeAtLocation(prop.valueDeclaration.name.expression)).symbol;
if (prop.escapedName === getPropertyNameOfWellKnownSymbol(checker, globalSymbol, wellKnownSymbolName))
return prop;
}
return;
}
exports.getWellKnownSymbolPropertyOfType = getWellKnownSymbolPropertyOfType;
function getPropertyNameOfWellKnownSymbol(checker, symbolConstructor, symbolName) {
const knownSymbol = symbolConstructor &&
checker.getTypeOfSymbolAtLocation(symbolConstructor, symbolConstructor.valueDeclaration).getProperty(symbolName);
const knownSymbolType = knownSymbol && checker.getTypeOfSymbolAtLocation(knownSymbol, knownSymbol.valueDeclaration);
if (knownSymbolType && type_1.isUniqueESSymbolType(knownSymbolType))
return knownSymbolType.escapedName;
return ('__@' + symbolName);
}
/** Determines if writing to a certain property of a given type is allowed. */
function isPropertyReadonlyInType(type, name, checker) {
let seenProperty = false;
@@ -250,11 +270,23 @@ function getPropertyNameFromType(type) {
}
if (type_1.isUniqueESSymbolType(type))
return {
displayName: `[${type.symbol ? type.symbol.name : type.escapedName.replace(/^__@|@\d+$/g, '')}]`,
displayName: `[${type.symbol
? `${isKnownSymbol(type.symbol) ? 'Symbol.' : ''}${type.symbol.name}`
: type.escapedName.replace(/^__@|@\d+$/g, '')}]`,
symbolName: type.escapedName,
};
}
exports.getPropertyNameFromType = getPropertyNameFromType;
function isKnownSymbol(symbol) {
return util_1.isSymbolFlagSet(symbol, ts.SymbolFlags.Property) &&
symbol.valueDeclaration !== undefined &&
node_1.isInterfaceDeclaration(symbol.valueDeclaration.parent) &&
symbol.valueDeclaration.parent.name.text === 'SymbolConstructor' &&
isGlobalDeclaration(symbol.valueDeclaration.parent);
}
function isGlobalDeclaration(node) {
return util_1.isNodeFlagSet(node.parent, ts.NodeFlags.GlobalAugmentation) || node_1.isSourceFile(node.parent) && !ts.isExternalModule(node.parent);
}
function getSymbolOfClassLikeDeclaration(node, checker) {
var _a;
return checker.getSymbolAtLocation((_a = node.name) !== null && _a !== void 0 ? _a : util_1.getChildOfKind(node, ts.SyntaxKind.ClassKeyword));
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -242,6 +242,7 @@ export interface PropertyName {
displayName: string;
symbolName: ts.__String;
}
/** @deprecated typescript 4.3 removed the concept of literal well known symbols. Use `getPropertyNameFromType` instead. */
export declare function getPropertyNameOfWellKnownSymbol(node: WellKnownSymbolLiteral): PropertyName;
export interface LateBoundPropertyNames {
/** Whether all constituents are literal names. */
+6 -4
View File
@@ -1562,6 +1562,7 @@ function isWellKnownSymbolLiterally(node) {
node.expression.escapedText === 'Symbol';
}
exports.isWellKnownSymbolLiterally = isWellKnownSymbolLiterally;
/** @deprecated typescript 4.3 removed the concept of literal well known symbols. Use `getPropertyNameFromType` instead. */
function getPropertyNameOfWellKnownSymbol(node) {
return {
displayName: `[Symbol.${node.name.text}]`,
@@ -1569,14 +1570,15 @@ function getPropertyNameOfWellKnownSymbol(node) {
};
}
exports.getPropertyNameOfWellKnownSymbol = getPropertyNameOfWellKnownSymbol;
const isTsBefore43 = (([major, minor]) => major < '4' || major === '4' && minor < '3')(ts.versionMajorMinor.split('.'));
function getLateBoundPropertyNames(node, checker) {
const result = {
known: true,
names: [],
};
node = unwrapParentheses(node);
if (isWellKnownSymbolLiterally(node)) {
result.names.push(getPropertyNameOfWellKnownSymbol(node));
if (isTsBefore43 && isWellKnownSymbolLiterally(node)) {
result.names.push(getPropertyNameOfWellKnownSymbol(node)); // wotan-disable-line no-unstable-api-use
}
else {
const type = checker.getTypeAtLocation(node);
@@ -1610,8 +1612,8 @@ function getSingleLateBoundPropertyNameOfPropertyName(node, checker) {
if (node.kind === ts.SyntaxKind.PrivateIdentifier)
return { displayName: node.text, symbolName: checker.getSymbolAtLocation(node).escapedName };
const { expression } = node;
return isWellKnownSymbolLiterally(expression)
? getPropertyNameOfWellKnownSymbol(expression)
return isTsBefore43 && isWellKnownSymbolLiterally(expression)
? getPropertyNameOfWellKnownSymbol(expression) // wotan-disable-line no-unstable-api-use
: type_1.getPropertyNameFromType(checker.getTypeAtLocation(expression));
}
exports.getSingleLateBoundPropertyNameOfPropertyName = getSingleLateBoundPropertyNameOfPropertyName;
+1 -1
View File
File diff suppressed because one or more lines are too long