Documentation
¶
Overview ¶
pseudochecker is a limited "checker" that returns pseudo-"types" of expressions - mostly those which trivially have type nodes
Index ¶
- Variables
- func IsInConstContext(node *ast.Node) bool
- type PseudoChecker
- func (ch *PseudoChecker) GetReturnTypeOfSignature(signatureNode *ast.Node) *PseudoType
- func (ch *PseudoChecker) GetTypeOfAccessor(accessor *ast.Node) *PseudoType
- func (ch *PseudoChecker) GetTypeOfDeclaration(node *ast.Node) *PseudoType
- func (ch *PseudoChecker) GetTypeOfExpression(node *ast.Node) *PseudoType
- type PseudoGetAccessor
- type PseudoObjectElement
- func NewPseudoGetAccessor(signature *ast.Node, name *ast.Node, optional bool, t *PseudoType) *PseudoObjectElement
- func NewPseudoObjectMethod(signature *ast.Node, name *ast.Node, optional bool, ...) *PseudoObjectElement
- func NewPseudoPropertyAssignment(readonly bool, name *ast.Node, optional bool, t *PseudoType) *PseudoObjectElement
- func NewPseudoSetAccessor(signature *ast.Node, name *ast.Node, optional bool, p *PseudoParameter) *PseudoObjectElement
- func (e *PseudoObjectElement) AsPseudoGetAccessor() *PseudoGetAccessor
- func (e *PseudoObjectElement) AsPseudoObjectElement() *PseudoObjectElement
- func (e *PseudoObjectElement) AsPseudoObjectMethod() *PseudoObjectMethod
- func (e *PseudoObjectElement) AsPseudoPropertyAssignment() *PseudoPropertyAssignment
- func (e *PseudoObjectElement) AsPseudoSetAccessor() *PseudoSetAccessor
- func (e *PseudoObjectElement) Signature() *ast.Node
- type PseudoObjectElementKind
- type PseudoObjectMethod
- type PseudoParameter
- type PseudoPropertyAssignment
- type PseudoSetAccessor
- type PseudoType
- func NewPseudoTypeBigIntLiteral(node *ast.Node) *PseudoType
- func NewPseudoTypeDirect(typeNode *ast.Node) *PseudoType
- func NewPseudoTypeInferred(expr *ast.Node) *PseudoType
- func NewPseudoTypeInferredWithErrors(expr *ast.Node, errorNodes []*ast.Node) *PseudoType
- func NewPseudoTypeMaybeConstLocation(loc *ast.Node, ct *PseudoType, reg *PseudoType) *PseudoType
- func NewPseudoTypeNoResult(decl *ast.Node) *PseudoType
- func NewPseudoTypeNumericLiteral(node *ast.Node) *PseudoType
- func NewPseudoTypeObjectLiteral(elements []*PseudoObjectElement) *PseudoType
- func NewPseudoTypeSingleCallSignature(signature *ast.Node, parameters []*PseudoParameter, ...) *PseudoType
- func NewPseudoTypeStringLiteral(node *ast.Node) *PseudoType
- func NewPseudoTypeTuple(elements []*PseudoType) *PseudoType
- func NewPseudoTypeUnion(types []*PseudoType) *PseudoType
- func (t *PseudoType) AsPseudoTypeDirect() *PseudoTypeDirect
- func (t *PseudoType) AsPseudoTypeInferred() *PseudoTypeInferred
- func (t *PseudoType) AsPseudoTypeLiteral() *PseudoTypeLiteral
- func (t *PseudoType) AsPseudoTypeMaybeConstLocation() *PseudoTypeMaybeConstLocation
- func (t *PseudoType) AsPseudoTypeNoResult() *PseudoTypeNoResult
- func (t *PseudoType) AsPseudoTypeObjectLiteral() *PseudoTypeObjectLiteral
- func (t *PseudoType) AsPseudoTypeSingleCallSignature() *PseudoTypeSingleCallSignature
- func (t *PseudoType) AsPseudoTypeTuple() *PseudoTypeTuple
- func (t *PseudoType) AsPseudoTypeUnion() *PseudoTypeUnion
- type PseudoTypeBase
- type PseudoTypeDefault
- type PseudoTypeDirect
- type PseudoTypeInferred
- type PseudoTypeKind
- type PseudoTypeLiteral
- type PseudoTypeMaybeConstLocation
- type PseudoTypeNoResult
- type PseudoTypeObjectLiteral
- type PseudoTypeSingleCallSignature
- type PseudoTypeTuple
- type PseudoTypeUnion
Constants ¶
This section is empty.
Variables ¶
var ( PseudoTypeUndefined = newPseudoType(PseudoTypeKindUndefined, &PseudoTypeBase{}) PseudoTypeNull = newPseudoType(PseudoTypeKindNull, &PseudoTypeBase{}) PseudoTypeAny = newPseudoType(PseudoTypeKindAny, &PseudoTypeBase{}) PseudoTypeString = newPseudoType(PseudoTypeKindString, &PseudoTypeBase{}) PseudoTypeNumber = newPseudoType(PseudoTypeKindNumber, &PseudoTypeBase{}) PseudoTypeBigInt = newPseudoType(PseudoTypeKindBigInt, &PseudoTypeBase{}) PseudoTypeBoolean = newPseudoType(PseudoTypeKindBoolean, &PseudoTypeBase{}) PseudoTypeFalse = newPseudoType(PseudoTypeKindFalse, &PseudoTypeBase{}) PseudoTypeTrue = newPseudoType(PseudoTypeKindTrue, &PseudoTypeBase{}) )
Functions ¶
func IsInConstContext ¶
IsInConstContext traverses up the parent chain to determine if the node is within a const context without needing any persistent traversal scope tracking (which could be unreliable in the presence of `typeof` queries anyway!)
Types ¶
type PseudoChecker ¶
type PseudoChecker struct {
// contains filtered or unexported fields
}
func NewPseudoChecker ¶
func NewPseudoChecker(strictNullChecks bool, exactOptionalPropertyTypes bool) *PseudoChecker
func (*PseudoChecker) GetReturnTypeOfSignature ¶
func (ch *PseudoChecker) GetReturnTypeOfSignature(signatureNode *ast.Node) *PseudoType
func (*PseudoChecker) GetTypeOfAccessor ¶
func (ch *PseudoChecker) GetTypeOfAccessor(accessor *ast.Node) *PseudoType
func (*PseudoChecker) GetTypeOfDeclaration ¶
func (ch *PseudoChecker) GetTypeOfDeclaration(node *ast.Node) *PseudoType
func (*PseudoChecker) GetTypeOfExpression ¶
func (ch *PseudoChecker) GetTypeOfExpression(node *ast.Node) *PseudoType
type PseudoGetAccessor ¶
type PseudoGetAccessor struct {
PseudoObjectElement
Signature *ast.Node
Type *PseudoType
}
type PseudoObjectElement ¶
type PseudoObjectElement struct {
Name *ast.Node
Optional bool
Kind PseudoObjectElementKind
// contains filtered or unexported fields
}
func NewPseudoGetAccessor ¶
func NewPseudoGetAccessor(signature *ast.Node, name *ast.Node, optional bool, t *PseudoType) *PseudoObjectElement
func NewPseudoObjectMethod ¶
func NewPseudoObjectMethod(signature *ast.Node, name *ast.Node, optional bool, typeParameters []*ast.TypeParameterDeclaration, parameters []*PseudoParameter, returnType *PseudoType) *PseudoObjectElement
func NewPseudoPropertyAssignment ¶
func NewPseudoPropertyAssignment(readonly bool, name *ast.Node, optional bool, t *PseudoType) *PseudoObjectElement
func NewPseudoSetAccessor ¶
func NewPseudoSetAccessor(signature *ast.Node, name *ast.Node, optional bool, p *PseudoParameter) *PseudoObjectElement
func (*PseudoObjectElement) AsPseudoGetAccessor ¶
func (e *PseudoObjectElement) AsPseudoGetAccessor() *PseudoGetAccessor
func (*PseudoObjectElement) AsPseudoObjectElement ¶
func (e *PseudoObjectElement) AsPseudoObjectElement() *PseudoObjectElement
func (*PseudoObjectElement) AsPseudoObjectMethod ¶
func (e *PseudoObjectElement) AsPseudoObjectMethod() *PseudoObjectMethod
func (*PseudoObjectElement) AsPseudoPropertyAssignment ¶
func (e *PseudoObjectElement) AsPseudoPropertyAssignment() *PseudoPropertyAssignment
func (*PseudoObjectElement) AsPseudoSetAccessor ¶
func (e *PseudoObjectElement) AsPseudoSetAccessor() *PseudoSetAccessor
func (*PseudoObjectElement) Signature ¶
func (e *PseudoObjectElement) Signature() *ast.Node
type PseudoObjectElementKind ¶
type PseudoObjectElementKind int8
const ( PseudoObjectElementKindMethod PseudoObjectElementKind = iota PseudoObjectElementKindPropertyAssignment PseudoObjectElementKindSetAccessor PseudoObjectElementKindGetAccessor )
type PseudoObjectMethod ¶
type PseudoObjectMethod struct {
PseudoObjectElement
Signature *ast.Node
TypeParameters []*ast.TypeParameterDeclaration
Parameters []*PseudoParameter
ReturnType *PseudoType
}
type PseudoParameter ¶
type PseudoParameter struct {
Rest bool
Name *ast.Node
Optional bool
Type *PseudoType
}
func NewPseudoParameter ¶
func NewPseudoParameter(isRest bool, name *ast.Node, isOptional bool, t *PseudoType) *PseudoParameter
type PseudoPropertyAssignment ¶
type PseudoPropertyAssignment struct {
PseudoObjectElement
Readonly bool
Type *PseudoType
}
type PseudoSetAccessor ¶
type PseudoSetAccessor struct {
PseudoObjectElement
Signature *ast.Node
Parameter *PseudoParameter
}
type PseudoType ¶
type PseudoType struct {
Kind PseudoTypeKind
// contains filtered or unexported fields
}
func NewPseudoTypeBigIntLiteral ¶
func NewPseudoTypeBigIntLiteral(node *ast.Node) *PseudoType
func NewPseudoTypeDirect ¶
func NewPseudoTypeDirect(typeNode *ast.Node) *PseudoType
func NewPseudoTypeInferred ¶
func NewPseudoTypeInferred(expr *ast.Node) *PseudoType
func NewPseudoTypeInferredWithErrors ¶ added in v0.0.2
func NewPseudoTypeInferredWithErrors(expr *ast.Node, errorNodes []*ast.Node) *PseudoType
func NewPseudoTypeMaybeConstLocation ¶
func NewPseudoTypeMaybeConstLocation(loc *ast.Node, ct *PseudoType, reg *PseudoType) *PseudoType
func NewPseudoTypeNoResult ¶
func NewPseudoTypeNoResult(decl *ast.Node) *PseudoType
func NewPseudoTypeNumericLiteral ¶
func NewPseudoTypeNumericLiteral(node *ast.Node) *PseudoType
func NewPseudoTypeObjectLiteral ¶
func NewPseudoTypeObjectLiteral(elements []*PseudoObjectElement) *PseudoType
func NewPseudoTypeSingleCallSignature ¶
func NewPseudoTypeSingleCallSignature(signature *ast.Node, parameters []*PseudoParameter, typeParameters []*ast.TypeParameterDeclaration, returnType *PseudoType) *PseudoType
func NewPseudoTypeStringLiteral ¶
func NewPseudoTypeStringLiteral(node *ast.Node) *PseudoType
func NewPseudoTypeTuple ¶
func NewPseudoTypeTuple(elements []*PseudoType) *PseudoType
func NewPseudoTypeUnion ¶
func NewPseudoTypeUnion(types []*PseudoType) *PseudoType
func (*PseudoType) AsPseudoTypeDirect ¶
func (t *PseudoType) AsPseudoTypeDirect() *PseudoTypeDirect
func (*PseudoType) AsPseudoTypeInferred ¶
func (t *PseudoType) AsPseudoTypeInferred() *PseudoTypeInferred
func (*PseudoType) AsPseudoTypeLiteral ¶
func (t *PseudoType) AsPseudoTypeLiteral() *PseudoTypeLiteral
func (*PseudoType) AsPseudoTypeMaybeConstLocation ¶
func (t *PseudoType) AsPseudoTypeMaybeConstLocation() *PseudoTypeMaybeConstLocation
func (*PseudoType) AsPseudoTypeNoResult ¶
func (t *PseudoType) AsPseudoTypeNoResult() *PseudoTypeNoResult
func (*PseudoType) AsPseudoTypeObjectLiteral ¶
func (t *PseudoType) AsPseudoTypeObjectLiteral() *PseudoTypeObjectLiteral
func (*PseudoType) AsPseudoTypeSingleCallSignature ¶
func (t *PseudoType) AsPseudoTypeSingleCallSignature() *PseudoTypeSingleCallSignature
func (*PseudoType) AsPseudoTypeTuple ¶
func (t *PseudoType) AsPseudoTypeTuple() *PseudoTypeTuple
func (*PseudoType) AsPseudoTypeUnion ¶
func (t *PseudoType) AsPseudoTypeUnion() *PseudoTypeUnion
type PseudoTypeBase ¶
type PseudoTypeBase struct {
PseudoTypeDefault
}
type PseudoTypeDefault ¶
type PseudoTypeDefault struct {
PseudoType
}
func (*PseudoTypeDefault) AsPseudoType ¶
func (b *PseudoTypeDefault) AsPseudoType() *PseudoType
type PseudoTypeDirect ¶
type PseudoTypeDirect struct {
PseudoTypeBase
TypeNode *ast.Node
}
PseudoTypeDirect directly encodes the type referred to by a given TypeNode
type PseudoTypeInferred ¶
type PseudoTypeInferred struct {
PseudoTypeBase
Expression *ast.Node
ErrorNodes []*ast.Node
}
PseudoTypeInferred directly encodes the type referred to by a given Expression These represent cases where the expression was too complex for the pseudochecker. Most of the time, these locations will produce an error under ID. Specific error nodes (shorthand properties, spread assignments, etc.) are stored on the ErrorNodes field, collected during pseudochecker construction.
type PseudoTypeKind ¶
type PseudoTypeKind int16
const ( PseudoTypeKindDirect PseudoTypeKind = iota PseudoTypeKindInferred PseudoTypeKindNoResult PseudoTypeKindMaybeConstLocation PseudoTypeKindUnion PseudoTypeKindUndefined PseudoTypeKindNull PseudoTypeKindAny PseudoTypeKindString PseudoTypeKindNumber PseudoTypeKindBigInt PseudoTypeKindBoolean PseudoTypeKindFalse PseudoTypeKindTrue PseudoTypeKindSingleCallSignature PseudoTypeKindTuple PseudoTypeKindObjectLiteral PseudoTypeKindStringLiteral PseudoTypeKindNumericLiteral PseudoTypeKindBigIntLiteral )
type PseudoTypeLiteral ¶
type PseudoTypeLiteral struct {
PseudoTypeBase
Node *ast.Node
}
PseudoTypeLiteral represents a literal type
type PseudoTypeMaybeConstLocation ¶
type PseudoTypeMaybeConstLocation struct {
PseudoTypeBase
Node *ast.Node
ConstType *PseudoType
RegularType *PseudoType
}
PseudoTypeMaybeConstLocation encodes the const/regular types of a location so the builder can later select the appropriate pseudotype based on the location's context. This is used to ensure accuracy in nested expressions without exposing type-based functionality to the pseudochecker. A nodebuilder that doesn't do contextual typing would need to, as policy, reject these types if they are in a contextually typed position! (Otherwise they could pick one, but either type could be wrong, depending on context!) At the top-level, which is generally what ID is concerned with, nothing is contextually typed, so these cases don't generally cause problems. Once you get into reused nodes in nested expressions, however, this becomes important. In strada, checker `isConstContext` functionality exposed to the pseudochecker + type comparison sanity checking on nested results masks the need for this abstraction, but with it present it clearly highlights a shortcoming of the ID infernce model and how "standalone" it can(n't) truly be without substantial restrictions on expression inference.
type PseudoTypeNoResult ¶
type PseudoTypeNoResult struct {
PseudoTypeBase
Declaration *ast.Node
}
PseudoTypeNoResult is analogous to PseudoTypeInferred in that it references a case where the type was too complex for the pseudochecker. Rather than an expression, however, it is referring to the return type of a signature or declaration.
type PseudoTypeObjectLiteral ¶
type PseudoTypeObjectLiteral struct {
PseudoTypeBase
Elements []*PseudoObjectElement
}
PseudoTypeObjectLiteral represents an object type originaing from an object literal
type PseudoTypeSingleCallSignature ¶
type PseudoTypeSingleCallSignature struct {
PseudoTypeBase
Signature *ast.Node
Parameters []*PseudoParameter
TypeParameters []*ast.TypeParameterDeclaration
ReturnType *PseudoType
}
PseudoTypeSingleCallSignature represents an object type with a single call signature, like an arrow or function expression
type PseudoTypeTuple ¶
type PseudoTypeTuple struct {
PseudoTypeBase
Elements []*PseudoType
}
PseudoTypeTuple represents a tuple originaing from an `as const` array literal
type PseudoTypeUnion ¶
type PseudoTypeUnion struct {
PseudoTypeBase
Types []*PseudoType
}
PseudoTypeUnion is a collection of psudotypes joined into a union