Features:
- added
getWellKnownSymbolPropertyOfType
to reliably get symbol named properties due to changes in [email protected] getPropertyNameOfWellKnownSymbol
is now deprecated
Features:
findImports
andfindImportLikeNodes
take an additional parameterignoreFileName
. The default value for this paramter istrue
to remain backwards compatible. When set tofalse
, it matches the behavior of TypeScript, i.e. only looks forrequire
in JavaScript files.
Bugfixes:
getJsDoc
forEndOfFileToken
now returnsJSDoc
comments whose contents are usable with the type checker
Bugfixes:
getSymbolOfClassLikeDeclaration
no longer crashes on anonymous mixin classes
Features:
getSymbolOfClassLikeDeclaration
to retrieve the symbol of class declarations and expressions regardless whether they have a name or notgetBaseOfClassLikeDeclaration
to conventiently get the expression afterextends
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 typehasExhaustiveCaseClauses
allows additional case clauses withnull
,undefined
andnever
Features:
- Source maps for easier debugging
- JSDoc is preserved in declaration files
- Comments are presered in transpiled code
- Everything you need to handle the control flow changes of [email protected]
callExpressionAffectsControlFlow
to determine whether a CallExpression affects control flow by returningnever
orasserts
hasExhaustiveCaseClauses
to determine whether a SwitchStatement's CaseClauses handle every possible valueendsControlFlow
andgetControlFlowEnd
take an optionalchecker
parameter to recognize exhaustive SwitchStatements and control flow effects of CallExpressions
formatPseudoBigInt
converts TypeScript's representation of a BigInt to its literal representation as you would write it in your source codegetAstNodeAtPosition
similar togetTokenAtPosition
, but only operates on AST NodesremoveOptionalChainingUndefinedMarkerType
andisOptionalChainingUndefinedMarkerType
to handle types originating in an optional chainfindImports
andfindImportLikeNodes
: prepare for import assertionsgetTsCheckDirective
as new name forgetCheckJsDirective
getCheckJsDirective
is now deprecated
Bugfixes:
getUsageDomain
: handles NamespaceExport and NamedTupleMembergetPropertyName
: handles parentheses and negative numeric literals, excludes RegExp literals and private identifiersgetSingleLateBoundPropertyNameOfPropertyName
andgetLateBoundPropertyNamesOfPropertyName
: handles private identifiershasAccessModifier
: handles JSDoc access modifierhasSideEffects
: correctly determines side effects of (static) property initializersisExpressionValueUsed
: handle nullish coalescing and conditional assignment operatorscanHaveJsDoc
: aligned with upstream changes in TypeScriptisCompilerOptionEnabled
:noUncheckedIndexedAccess
requiresstrictNullChecks
checkJs
impliesallowJs
emitDeclarationOnly
requiresdeclaration
isInConstContext
: handle template string interpolations- excluded unnecessary files from npm package
Bugfixes:
isValidJsxIdentifier
,isValidPropertyAccess
,isValidPropertyName
: fix unicode character width handling
Features:
isValidJsxIdentifier
added an optional parameter to specify the target ECMAScript version
Bugfixes:
isValidJsxIdentifier
now handles astral plane characters
Features:
- added
getIteratorYieldResultFromIteratorResult
to extract theyield
ed type fromIteratorResult<TYield, TReturn, TNext>
Features:
isValidIdentifier
,isValidPropertyName
,isValidPropertyAccess
,isValidNumericLiteral
added an optional parameter to specify the target ECMAScript version
Bugfixes:
isValidPropertyName
,isValidPropertyAccess
now handle astral plane characters
Bugfixes:
findImports
: fixed crash on nested namespaces
Features:
- added
getInstanceTypeOfClassLikeDeclaration
andgetConstructorTypeOfClassLikeDeclaration
- added
AccessKind.Delete
togetAccessKind
:getAccessKind(node) & AccessKind.Modification
can now be used to restore the old behavior ofisReassignmentTarget(node)
Features:
getAccessKind
determines whether an expression is read from, written to or both- optimized
getPropertyOfType
for unambiguous property names to partially work around microsoft/TypeScript#31565
Bugfixes:
isReassignmentTarget
no longer returnstrue
forDeleteExpression
as it doesn't assign a value to the operand
Features:
getLateBoundPropertyNamesOfPropertyName
returns all statically analyzable names of a property, method, ...getSingleLateBoundPropertyNameOfPropertyName
returns the literal name of a property, method, ... if statically analyzable
Bugfixes:
- fixed circular import
Features:
- typeguards:
isNumericOrStringLikeLiteral
,isTupleTypeReference
intersectionTypeParts
as counterpart tounionTypeParts
someTypePart
to execute a callback for each union or intersection constituent until the callback returns truegetPropertyOfType
looks up a property by its escaped nameisPropertyReadonlyInType
determines whether a property in a given type cannot be written tosymbolHasReadonlyDeclaration
determines if a Symbol has any readonly or constant declarationisNumericPropertyName
determines whether a property name would match an index signatureisBindableObjectDefinePropertyCall
returns true for statically analyzable forms ofObject.defineProperty(o, 'p', {value, writable})
isReadonlyAssignmentDeclaration
determines whether anObject.defineProperty
call is known to result in a readonly propertygetLateBoundPropertyNames
returns all known property names of an expressiongetPropertyNameFromType
extracts the property name of literal typesisWellKnownSymbolLiterally
to recognize expressions in the form ofSymbol.<name>
getPropertyNameOfWellKnownSymbol
returns the escaped name for a well known symbol literalunwrapParentheses
returns the first child expression that is not aParenthesizedExpression
Features:
isCompilerOptionEnabled
:incremental
is implicitly enabled bycomposite
Bugfixes:
collectVariableUsage
/getUsageDomain
: no longer treatas const
as type usage
Bugfixes:
- reverted invalid deprecation of
canHaveJsdoc
- fixed condition in
parseJsdocOfNode
Features:
- added typeguards:
isNullLiteral
andisBooleanLiteral
Features:
- exposes typeguards for [email protected] by default
- added utilities:
isConstAssertion
andisInConstContext
Features:
- added
isBlockScopedDeclarationStatement
- added
isInSingleStatementContext
Features:
- added
getCheckJsDirective
utility to parse// @ts-check
and// @ts-nocheck
pragmas
Bugfixes:
- Published declaration files no longer contain
const enum
. They are now declared as regular enums instead.
Bugfixes:
isThenableType
allowsNode
instead ofExpression
as parameterisBlockScopeBoundary
andisScopeBoundary
considerWithStatement
as scope boundary
Features:
- correctly handle BigInt literals
- added typeguard
isBigIntLiteral
isLiteralType
recognises BigIntgetPropertyName
adds special handling for BigInt
- added typeguard
Features:
- added utility
commentText
to get the actual text content of a comment excluding the characters needed to start and end the comment
Bugfixes:
findImports
: fixed handling of ImportEqualsDeclaration
Features:
isCompilerOptionEnabled
: recognizesstrictBindCallApply
getTokenAtPosition
: optionally includes JSDoc during lookup
Bugfixes:
isCompilerOptionEnabled
: correctly implements logic forallowSyntheticDefaultImports
findImportLikeNodes
: correctly finds imports in namespacesfindImportLikeNodes
/findImports
: finds import types in JSDoc of JS files
Features:
- added utility
findImportLikeNodes
that works similar tofindImports
but returns the import statement or expression instead of the module specifier and doesn't filter non-string module specifiers
Features:
- added utilities:
isKeywordKind
andisValidJsxIdentifier
- exposes typeguards for [email protected] by default
- Dropped support for
typescript@<2.8.0
- Dropped support for Node.js 4
- Removed deprecated APIs:
getIdentifierText
,isJsxFramgment
,ImportOptions
- deprected overloads of
isModifierFlagSet
,findImports
andgetControlFlowEnd
- control flow related symbols can no longer be imported from
'tsutils/util/util'
, import directly from'tsutils/util/control-flow'
or'tsutils/util'
isFunctionScopeBoundary
andisBlockScopeBoundary
now return a enum member ofScopeBoundary
instead of a booleanisFunctionScopeBoundary
no longer returns a truthy value forInterfaceDeclaration
,TypeAliasDeclaration
Features:
- added utility
isTypeScopeBoundary
returningScopeBoundary.Type
orScopeBoundary.ConditionalType
- added enum
ScopeBoundarySelector
whose members can be used to determine if a declaration belongs to a givenScopeBoundary
by using bitwise AND
Bugfixes:
collectVariableUsage
now correctly handlesinfer T
nested inside function signatures or mapped typesisCompilerOptionEnabled
correctly handlesskipDefaultLibCHeck
andsuppressImplicitAnyIndexErrors
Features:
- added utility
isCompilerOptionEnabled
Typeguards are now split into multiple submodules for each version of TypeScript (starting with 2.8.0).
That means you can now import directly from "tsutils/typeguard/2.8"
to get compatible declaraton files for [email protected].
For more information please read the relevant section in README.md.
Features:
- added typeguards:
isTupleType
,isOptionalTypeNode
,isRestTypeNode
,isSyntheticExpression
(currently available from"tsutils/typeguard/3.0"
) - added utility
isStrictCompilerOptionEnabled
Avoid crash caused by removed function in [email protected]
.
Added support for [email protected] nightly builds.
Features:
- added
getIIFE
utility
Bugfixes:
forEachComment
andforEachTokenWithTrivia
no longer duplicate comments around missing nodes
Bugfixes:
- fixed crash in
hasSideEffects
with tagged template literal without substitution:tag`template`
Features:
- added typeguard
isLiteralTypeNode
- added support for type imports (
type T = import('foo')
) tofindImports
viaImportKind.ImportType
Bugfixes:
collectVariableUsage
: fixed name lookup in function signatures to match runtime behavior. Note that this is not completely fixed in TypeScript, yet. See: Microsoft/TypeScript#22825 and Microsoft/TypeScript#22769
Features:
- added utilities:
isStatementInAmbientContext
andisAmbientModuleBlock
Features:
- added typeguards for [email protected]:
isConditionalTypeNode
,isInferTypeNode
,isConditionalType
,isInstantiableType
,isSubstitutionType
Features:
- added typeguard
isForInOrOfStatement
Bugfixes:
- correctly handle comments in generic JSX elements:
<MyComponent<string>/*comment*/></MyComponent>
- fixed a bug with false positive trailing comments at the end of JSX self closing element:
<div><br/>/*no comment*/</div>
Bugfixes:
collectVariableUsage
: handle ConditionalTypes andinfer T
, which will be introduced in [email protected] and are already available in nightly buildsisLiteralType
no longer returns true forts.TypeFlags.BooleanLiteral
as this is not ats.LiteralType
Bugfixes:
endsControlFlow
:- handle loops that might not even run a single iteration
- handle constant boolean conditions in loops and if
Features:
- added
isFalsyType
utility
Bugfixes:
- fixed compile error with
[email protected]
Bugfixes:
isReassignmentTarget
: handle type assertions and non-null assertion
Bugfixes:
forEachDeclaredVariable
uses a more precise type for the callback parameter to make it useable again with [email protected]
Features:
- added
isUniqueESSymbolType
typeguard
Features:
- added
isThenableType
utility - added
unionTypeParts
utility
Bugfixes:
forEachComment
,getCommentAtPosition
andisPositionInComment
: skip shebang (#! something
) to not miss following comments at the start of the file
Features:
- added
WrappedAst
interface that models the type of a wrapped SourceFile more accurate - added
getWrappedNodeAtPosition
utiltiy that takes aNodeWrap
and returns the most deeply nested NodeWrap that contains the given position
Features:
getControlFlowEnd
accepts BlockLike as argument
Bugfixes:
getControlFlowEnd
andendsControlFlow
: correctly handle nested LabeledStatementsendsControlFlow
removed erroneous special case when an IterationStatement is passed as argument whose parent is a LabeledStatement.- if you want labels of an IterationStatement (or SwitchStatement) to be handled, you need to pass the LabeledStatement as argument.
⚠️ this fix may change the returned value if you relied on the buggy behavior
Deprecations:
- deprecated overload of
getControlFlowEnd
that contains thelabel
parameter. This parameter is no longer used and should no longer be passed to the function.
Bugfixes:
getControlFlowEnd
andendsControlFlow
(#22)- ThrowStatements inside
try
are filtered out if there is acatch
clause - TryStatements with
catch
only end control flow iftry
ANDcatch
definitely end control flow
- ThrowStatements inside
Features:
- added
kind
property toNodeWrap
- added
getControlFlowEnd
to public API
Features:
- added
isDecorator
andisCallLikeExpression
typeguards
Features:
- added
convertAst
utility to produce a flattened and wrapped version of the AST
Features:
- added
isDeleteExpression
- added
getLineBreakStyle
Bugfixes:
- fixed name of
isJsxFragment
Features:
- added support for
JsxFragment
introduced in [email protected] - added corresponding typeguard functions
Bugfixes:
endsControlFlow
- added missing logic for labeled statement, iteration statements and try-catch
- added missing logic for
break
andcontinue
with labels - take all jump statements into account, not only the last statement
isValidIdentifier
andisValidNumericLiteral
handle irregular whitespacefindImports
searches in ambient modules inside regular.ts
files (not only.d.ts
)canHaveJsDoc
is now a typeguard
Bugfixes:
forEachTokenWithTrivia
- handles irregular whitespace and no longer visits some tokens twice
- correctly calculates the range of JsxText
API-Changes:
- deprecated
ImportOptions
if favor of the newImportKind
enum
Bugfixes:
parseJsDocOfNode
: set correctpos
,end
andparent
properties. Also affectsgetJsDoc
ofEndOfFileToken
Bugfixes:
collectVariableUsage
: correctly consider catch binding as block scoped declaration inside catch block
Bugfixes:
getJsDoc
now correctly returns JsDoc forEndOfFileToken
Features:
- added utility
parseJsDocOfNode
Features:
- added utility
findImports
to find all kinds of imports in a source file
Features:
- added typeguard
isMappedTypeNode
- added utilities
canHaveJsDoc
andgetJsDoc
Bugfixes:
collectVariableUsage
: handle global augmentation like other module augmentations
Bugfixes:
- Support
[email protected]
with optional catch binding collectVariableUsage
fixed a bug where method decorator had method's parameters in scope
- Compatibility with the latest typescript nightly
- Added
getIdentifierText
to unescape identifiers across typescript versions
Bugfixes:
isReassignmentTarget
don't returntrue
for right side of assignment
Features:
- Added
isReassignmentTarget
utility
Bugfixes:
getDeclarationDomain
now returnsundefined
for Parameter in IndexSignaturecollectVariableUsage
ignores Parameter in IndexSignature
Bugfixes:
collectVariableUsage
:- don't merge imports with global declarations
- treat everything in a declaration file as exported if there is no explicit
export {};
isExpressionValueUsed
: handle destructuring infor...of
Features:
- Added
getModifier
utility - Added
DeclarationDomain.Import
to distinguish imports from other declarations
Bugfixes:
collectVariableUsage
ignore jump labels as inbreak label;
Bugfixes:
isFunctionWithBody
handles constructor overload correctly.
Features:
- Implemented
isExpressionValueUsed
to check whether the result of an expression is actually used. - Implemented
getDeclarationDomain
to determine if a given declaration introduces a new symbol in the value or type domain.
collectVariableUses
is now usable
- no longer ignores signatures and its parameters
- don't merge declarations and uses across domains
- no longer marks exceptions in catch clause or parameter properties as exported
- fixed exports of namespaces
- fixed scoping of ClassExpression name
- correcly handle ambient namespaces and module augmentations
- fixed how
: typeof foo
is handled for parameters and function return type - still WIP:
export {Foo as Bar}
inside ambient namespaces and modules
Bugfixes:
getLineRanges
:contentLength
now contains the correct line length when there are multiple consecutive line break charactersgetTokenAtPosition
: don't match tokens that end at the specified position (because that's already outside of their range)- deprecated the misnamed
isModfierFlagSet
, use the newisModifierFlagSet
instead
Features:
- Added typeguard:
isJsDoc
- Added experimental scope and usage analysis (
getUsageDomain
andcollectVariableUsage
)
Bugfixes:
forEachComment
no longer omits some comments when callback returns a truthy valueisPositionInComment
fixed false positive inside JSXText
Features:
- Added utility:
getCommentAtPosition
Bugfixes:
- Fixed bit value of
SideEffectOptions.JsxElement
to be a power of 2
Features:
- Added utilities:
getTokenAtPosition
andisPositionInComment
Features:
- Added typeguard
isExpression
- Added utilities:
hasSideEffects
,getDeclarationOfBindingElement
Breaking Changes:
- Dropped compatibility with
typescript@<2.1.0
- Removed misnamed
isNumericliteral
, useisNumericLiteral
instead (notice the uppercase L) - Removed
isEnumLiteralType
which will cause compile errors with [email protected] - Refactored directory structure: all imports that referenced subdirectories (e.g.
require('tsutils/src/typeguard')
will be broken
Features:
- New directory structure allows imports of typeguards or utils independently, e.g. (
require('tsutils/typeguard')
)
Bugfixes:
isObjectFlagSet
now uses the correctobjectFlags
property
Bugfixes:
getNextToken
no longer omitsEndOfFileToken
when there is no trivia before EOF. That means the only inputs wheregetNextToken
returnsundefined
areSourceFile
andEndOfFileToken
Features:
- Added typeguards for types
- Added utilities for flag checking:
isNodeFlagSet
,isTypeFlagSet
,isSymbolFlagSet
,isObjectFlagSet
,isModifierFlagSet
Features:
- Support peer dependency of typescript nightlies of 2.4.0
- Added typeguards:
isJsxAttributes
,isIntersectionTypeNode
,isTypeOperatorNode
,isTypePredicateNode
,isTypeQueryNode
,isUnionTypeNode
Bugfixes:
isFunctionScopeBoundary
now handles Interfaces, TypeAliases, FunctionSignatures, etc
Features:
- Added utilities:
isThisParameter
,isSameLine
andisFunctionWithBody
Features:
- Add
isValidPropertyAccess
,isValidNumericLiteral
andisValidPropertyName
Features:
- Add
isValidIdentifier
Features:
- Add
contentLength
property to the result ofgetLineRanges
Bugfixes:
canHaveLeadingTrivia
:- Fix property access on undefined parent reference
- Fixes: palantir/tslint#2330
hasOwnThisReference
: now includes accessors on object literals
Features:
- Typeguards:
- isTypeParameterDeclaration
- isEnitityName
Bugfixes:
hasOwnThisReference
:- exclude overload signatures of function declarations
- add method declarations on object literals
Bugfixes:
- Fix name of
isNumericLiteral
Features:
- Typeguards:
- isEnumMember
- isExpressionWithTypeArguments
- isImportSpecifier
- Utilities:
- isJsDocKind, isTypeNodeKind
- Allow typescript@next in peerDependencies
Bugfixes:
- Fix isBlockScopeBoundary: Remove WithStatement, IfStatment, DoStatement and WhileStatement because they are no scope boundary whitout a block.
Features:
- Added more typeguards:
- isAssertionExpression
- isEmptyStatement
- isJsxAttributeLike
- isJsxOpeningLikeElement
- isNonNullExpression
- isSyntaxList
- Utilities:
- getNextToken, getPreviousToken
- hasOwnThisReference
- getLineRanges
Features:
- Initial implementation of typeguards
- Utilities:
- getChildOfKind
- isNodeKind, isAssignmentKind
- hasModifier, isParameterProperty, hasAccessModifier
- getPreviousStatement, getNextStatement
- getPropertyName
- forEachDestructuringIdentifier, forEachDeclaredVariable
- getVariableDeclarationKind, isBlockScopedVariableDeclarationList, isBlockScopedVariableDeclaration
- isScopeBoundary, isFunctionScopeBoundary, isBlockScopeBoundary
- forEachToken, forEachTokenWithTrivia, forEachComment
- endsControlFlow