mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
+15
-6
@@ -5092,20 +5092,25 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getAnnotatedAccessorType(accessor: AccessorDeclaration | undefined): Type | undefined {
|
||||
function getAnnotatedAccessorTypeNode(accessor: AccessorDeclaration | undefined): TypeNode | undefined {
|
||||
if (accessor) {
|
||||
if (accessor.kind === SyntaxKind.GetAccessor) {
|
||||
const getterTypeAnnotation = getEffectiveReturnTypeNode(accessor);
|
||||
return getterTypeAnnotation && getTypeFromTypeNode(getterTypeAnnotation);
|
||||
return getterTypeAnnotation;
|
||||
}
|
||||
else {
|
||||
const setterTypeAnnotation = getEffectiveSetAccessorTypeAnnotationNode(accessor);
|
||||
return setterTypeAnnotation && getTypeFromTypeNode(setterTypeAnnotation);
|
||||
return setterTypeAnnotation;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getAnnotatedAccessorType(accessor: AccessorDeclaration | undefined): Type | undefined {
|
||||
const node = getAnnotatedAccessorTypeNode(accessor);
|
||||
return node && getTypeFromTypeNode(node);
|
||||
}
|
||||
|
||||
function getAnnotatedAccessorThisParameter(accessor: AccessorDeclaration): Symbol | undefined {
|
||||
const parameter = getAccessorThisParameter(accessor);
|
||||
return parameter && parameter.symbol;
|
||||
@@ -23342,9 +23347,13 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
const otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
|
||||
const otherAccessor = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(node as AccessorDeclaration), otherKind);
|
||||
markDecoratorMedataDataTypeNodeAsReferenced(getAnnotatedAccessorTypeNode(node as AccessorDeclaration) || otherAccessor && getAnnotatedAccessorTypeNode(otherAccessor));
|
||||
break;
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
for (const parameter of (<FunctionLikeDeclaration>node).parameters) {
|
||||
markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter));
|
||||
}
|
||||
@@ -27867,8 +27876,8 @@ namespace ts {
|
||||
const otherAccessor = getDeclarationOfKind<AccessorDeclaration>(getSymbolOfNode(accessor), otherKind);
|
||||
const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor;
|
||||
const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor;
|
||||
const setAccessor = accessor.kind === SyntaxKind.SetAccessor ? accessor : otherAccessor;
|
||||
const getAccessor = accessor.kind === SyntaxKind.GetAccessor ? accessor : otherAccessor;
|
||||
const setAccessor = accessor.kind === SyntaxKind.SetAccessor ? accessor : otherAccessor as SetAccessorDeclaration;
|
||||
const getAccessor = accessor.kind === SyntaxKind.GetAccessor ? accessor : otherAccessor as GetAccessorDeclaration;
|
||||
return {
|
||||
firstAccessor,
|
||||
secondAccessor,
|
||||
|
||||
@@ -1750,6 +1750,12 @@ namespace ts {
|
||||
type SerializedEntityNameAsExpression = Identifier | BinaryExpression | PropertyAccessExpression;
|
||||
type SerializedTypeNode = SerializedEntityNameAsExpression | VoidExpression | ConditionalExpression;
|
||||
|
||||
function getAccessorTypeNode(node: AccessorDeclaration) {
|
||||
const accessors = resolver.getAllAccessorDeclarations(node);
|
||||
return accessors.setAccessor && getSetAccessorTypeAnnotationNode(accessors.setAccessor)
|
||||
|| accessors.getAccessor && getEffectiveReturnTypeNode(accessors.getAccessor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the type of a node for use with decorator type metadata.
|
||||
*
|
||||
@@ -1759,10 +1765,10 @@ namespace ts {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.GetAccessor:
|
||||
return serializeTypeNode((<PropertyDeclaration | ParameterDeclaration | GetAccessorDeclaration>node).type);
|
||||
case SyntaxKind.SetAccessor:
|
||||
return serializeTypeNode(getSetAccessorTypeAnnotationNode(<SetAccessorDeclaration>node));
|
||||
case SyntaxKind.GetAccessor:
|
||||
return serializeTypeNode(getAccessorTypeNode(node as AccessorDeclaration));
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
|
||||
@@ -3305,8 +3305,8 @@ namespace ts {
|
||||
export interface AllAccessorDeclarations {
|
||||
firstAccessor: AccessorDeclaration;
|
||||
secondAccessor: AccessorDeclaration | undefined;
|
||||
getAccessor: AccessorDeclaration | undefined;
|
||||
setAccessor: AccessorDeclaration | undefined;
|
||||
getAccessor: GetAccessorDeclaration | undefined;
|
||||
setAccessor: SetAccessorDeclaration | undefined;
|
||||
}
|
||||
|
||||
/** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator metadata */
|
||||
|
||||
@@ -3293,8 +3293,8 @@ namespace ts {
|
||||
// TODO: GH#18217
|
||||
let firstAccessor!: AccessorDeclaration;
|
||||
let secondAccessor!: AccessorDeclaration;
|
||||
let getAccessor!: AccessorDeclaration;
|
||||
let setAccessor!: AccessorDeclaration;
|
||||
let getAccessor!: GetAccessorDeclaration;
|
||||
let setAccessor!: SetAccessorDeclaration;
|
||||
if (hasDynamicName(accessor)) {
|
||||
firstAccessor = accessor;
|
||||
if (accessor.kind === SyntaxKind.GetAccessor) {
|
||||
@@ -3322,11 +3322,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (member.kind === SyntaxKind.GetAccessor && !getAccessor) {
|
||||
getAccessor = <AccessorDeclaration>member;
|
||||
getAccessor = <GetAccessorDeclaration>member;
|
||||
}
|
||||
|
||||
if (member.kind === SyntaxKind.SetAccessor && !setAccessor) {
|
||||
setAccessor = <AccessorDeclaration>member;
|
||||
setAccessor = <SetAccessorDeclaration>member;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user