| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -879,6 +879,7 @@ namespace ts { | |||
| 879 | 879 | ||
| 880 | 880 | export interface PropertyDeclaration extends ClassElement, JSDocContainer { | |
| 881 | 881 | kind: SyntaxKind.PropertyDeclaration; | |
| 882 | + parent: ClassLikeDeclaration; | ||
| 882 | 883 | name: PropertyName; | |
| 883 | 884 | questionToken?: QuestionToken; // Present for use with reporting a grammar error | |
| 884 | 885 | exclamationToken?: ExclamationToken; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3037,6 +3037,10 @@ namespace ts { | |||
| 3037 | 3037 | return (node as HasType).type || (isInJavaScriptFile(node) ? getJSDocType(node) : undefined); | |
| 3038 | 3038 | } | |
| 3039 | 3039 | ||
| 3040 | + export function getTypeAnnotationNode(node: Node): TypeNode | undefined { | ||
| 3041 | + return (node as HasType).type; | ||
| 3042 | + } | ||
| 3043 | + | ||
| 3040 | 3044 | /** | |
| 3041 | 3045 | * Gets the effective return type annotation of a signature. If the node was parsed in a | |
| 3042 | 3046 | * JavaScript file, gets the return type annotation from JSDoc. | |
@@ -4271,8 +4275,9 @@ namespace ts { | |||
| 4271 | 4275 | } | |
| 4272 | 4276 | } | |
| 4273 | 4277 | ||
| 4274 | - export function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration { | ||
| 4275 | - return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); | ||
| 4278 | + export type ParameterPropertyDeclaration = ParameterDeclaration & { parent: ConstructorDeclaration, name: Identifier }; | ||
| 4279 | + export function isParameterPropertyDeclaration(node: Node): node is ParameterPropertyDeclaration { | ||
| 4280 | + return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && node.parent.kind === SyntaxKind.Constructor; | ||
| 4276 | 4281 | } | |
| 4277 | 4282 | ||
| 4278 | 4283 | export function isEmptyBindingPattern(node: BindingName): node is BindingPattern { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,17 +4,14 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { | |||
| 4 | 4 | const actionDescription = Diagnostics.Generate_get_and_set_accessors.message; | |
| 5 | 5 | registerRefactor(actionName, { getEditsForAction, getAvailableActions }); | |
| 6 | 6 | ||
| 7 | - type AcceptedDeclaration = ParameterDeclaration | PropertyDeclaration | PropertyAssignment; | ||
| 7 | + type AcceptedDeclaration = ParameterPropertyDeclaration | PropertyDeclaration | PropertyAssignment; | ||
| 8 | 8 | type AcceptedNameType = Identifier | StringLiteral; | |
| 9 | 9 | type ContainerDeclaration = ClassLikeDeclaration | ObjectLiteralExpression; | |
| 10 | 10 | ||
| 11 | - interface DeclarationInfo { | ||
| 11 | + interface Info { | ||
| 12 | 12 | container: ContainerDeclaration; | |
| 13 | 13 | isStatic: boolean; | |
| 14 | 14 | type: TypeNode | undefined; | |
| 15 | - } | ||
| 16 | - | ||
| 17 | - interface Info extends DeclarationInfo { | ||
| 18 | 15 | declaration: AcceptedDeclaration; | |
| 19 | 16 | fieldName: AcceptedNameType; | |
| 20 | 17 | accessorName: AcceptedNameType; | |
@@ -92,62 +89,24 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor { | |||
| 92 | 89 | return modifiers && createNodeArray(modifiers); | |
| 93 | 90 | } | |
| 94 | 91 | ||
| 95 | - function getPropertyDeclarationInfo(propertyDeclaration: PropertyDeclaration): DeclarationInfo | undefined { | ||
| 96 | - if (!isClassLike(propertyDeclaration.parent) || !propertyDeclaration.parent.members) return undefined; | ||
| 97 | - | ||
| 98 | - return { | ||
| 99 | - isStatic: hasStaticModifier(propertyDeclaration), | ||
| 100 | - type: propertyDeclaration.type, | ||
| 101 | - container: propertyDeclaration.parent | ||
| 102 | - }; | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - function getParameterPropertyDeclarationInfo(parameterDeclaration: ParameterDeclaration): DeclarationInfo | undefined { | ||
| 106 | - if (!isClassLike(parameterDeclaration.parent.parent) || !parameterDeclaration.parent.parent.members) return undefined; | ||
| 107 | - | ||
| 108 | - return { | ||
| 109 | - isStatic: false, | ||
| 110 | - type: parameterDeclaration.type, | ||
| 111 | - container: parameterDeclaration.parent.parent | ||
| 112 | - }; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - function getPropertyAssignmentDeclarationInfo(propertyAssignment: PropertyAssignment): DeclarationInfo | undefined { | ||
| 116 | - return { | ||
| 117 | - isStatic: false, | ||
| 118 | - type: undefined, | ||
| 119 | - container: propertyAssignment.parent | ||
| 120 | - }; | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - function getDeclarationInfo(declaration: AcceptedDeclaration) { | ||
| 124 | - if (isPropertyDeclaration(declaration)) { | ||
| 125 | - return getPropertyDeclarationInfo(declaration); | ||
| 126 | - } | ||
| 127 | - else if (isPropertyAssignment(declaration)) { | ||
| 128 | - return getPropertyAssignmentDeclarationInfo(declaration); | ||
| 129 | - } | ||
| 130 | - else { | ||
| 131 | - return getParameterPropertyDeclarationInfo(declaration); | ||
| 132 | - } | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | 92 | function getConvertibleFieldAtPosition(file: SourceFile, startPosition: number): Info | undefined { | |
| 136 | 93 | const node = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false); | |
| 137 | 94 | const declaration = findAncestor(node.parent, isAcceptedDeclaration); | |
| 138 | 95 | // make sure propertyDeclaration have AccessibilityModifier or Static Modifier | |
| 139 | 96 | const meaning = ModifierFlags.AccessibilityModifier | ModifierFlags.Static; | |
| 140 | 97 | if (!declaration || !isConvertableName(declaration.name) || (getModifierFlags(declaration) | meaning) !== meaning) return undefined; | |
| 141 | 98 | ||
| 142 | - const info = getDeclarationInfo(declaration); | ||
| 143 | 99 | const fieldName = createPropertyName(getUniqueName(`_${declaration.name.text}`, file.text), declaration.name); | |
| 100 | + const accessorName = createPropertyName(declaration.name.text, declaration.name); | ||
| 144 | 101 | suppressLeadingAndTrailingTrivia(fieldName); | |
| 145 | 102 | suppressLeadingAndTrailingTrivia(declaration); | |
| 146 | 103 | return { | |
| 147 | - ...info, | ||
| 104 | + isStatic: hasStaticModifier(declaration), | ||
| 105 | + type: getTypeAnnotationNode(declaration), | ||
| 106 | + container: declaration.kind === SyntaxKind.Parameter ? declaration.parent.parent : declaration.parent, | ||
| 148 | 107 | declaration, | |
| 149 | 108 | fieldName, | |
| 150 | - accessorName: createPropertyName(declaration.name.text, declaration.name) | ||
| 109 | + accessorName, | ||
| 151 | 110 | }; | |
| 152 | 111 | } | |
| 153 | 112 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -585,6 +585,7 @@ declare namespace ts { | |||
| 585 | 585 | } | |
| 586 | 586 | interface PropertyDeclaration extends ClassElement, JSDocContainer { | |
| 587 | 587 | kind: SyntaxKind.PropertyDeclaration; | |
| 588 | + parent: ClassLikeDeclaration; | ||
| 588 | 589 | name: PropertyName; | |
| 589 | 590 | questionToken?: QuestionToken; | |
| 590 | 591 | exclamationToken?: ExclamationToken; | |
@@ -3010,7 +3011,11 @@ declare namespace ts { | |||
| 3010 | 3011 | */ | |
| 3011 | 3012 | function collapseTextChangeRangesAcrossMultipleVersions(changes: ReadonlyArray<TextChangeRange>): TextChangeRange; | |
| 3012 | 3013 | function getTypeParameterOwner(d: Declaration): Declaration; | |
| 3013 | - function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration; | ||
| 3014 | + type ParameterPropertyDeclaration = ParameterDeclaration & { | ||
| 3015 | + parent: ConstructorDeclaration; | ||
| 3016 | + name: Identifier; | ||
| 3017 | + }; | ||
| 3018 | + function isParameterPropertyDeclaration(node: Node): node is ParameterPropertyDeclaration; | ||
| 3014 | 3019 | function isEmptyBindingPattern(node: BindingName): node is BindingPattern; | |
| 3015 | 3020 | function isEmptyBindingElement(node: BindingElement): boolean; | |
| 3016 | 3021 | function getCombinedModifierFlags(node: Node): ModifierFlags; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -585,6 +585,7 @@ declare namespace ts { | |||
| 585 | 585 | } | |
| 586 | 586 | interface PropertyDeclaration extends ClassElement, JSDocContainer { | |
| 587 | 587 | kind: SyntaxKind.PropertyDeclaration; | |
| 588 | + parent: ClassLikeDeclaration; | ||
| 588 | 589 | name: PropertyName; | |
| 589 | 590 | questionToken?: QuestionToken; | |
| 590 | 591 | exclamationToken?: ExclamationToken; | |
@@ -3010,7 +3011,11 @@ declare namespace ts { | |||
| 3010 | 3011 | */ | |
| 3011 | 3012 | function collapseTextChangeRangesAcrossMultipleVersions(changes: ReadonlyArray<TextChangeRange>): TextChangeRange; | |
| 3012 | 3013 | function getTypeParameterOwner(d: Declaration): Declaration; | |
| 3013 | - function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration; | ||
| 3014 | + type ParameterPropertyDeclaration = ParameterDeclaration & { | ||
| 3015 | + parent: ConstructorDeclaration; | ||
| 3016 | + name: Identifier; | ||
| 3017 | + }; | ||
| 3018 | + function isParameterPropertyDeclaration(node: Node): node is ParameterPropertyDeclaration; | ||
| 3014 | 3019 | function isEmptyBindingPattern(node: BindingName): node is BindingPattern; | |
| 3015 | 3020 | function isEmptyBindingElement(node: BindingElement): boolean; | |
| 3016 | 3021 | function getCombinedModifierFlags(node: Node): ModifierFlags; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments