@@ -128,7 +128,6 @@ import {
128
128
isModuleDeclaration ,
129
129
isOmittedExpression ,
130
130
isPrivateIdentifier ,
131
- isPropertySignature ,
132
131
isSemicolonClassElement ,
133
132
isSetAccessorDeclaration ,
134
133
isSourceFile ,
@@ -722,7 +721,6 @@ export function transformDeclarations(context: TransformationContext) {
722
721
| FunctionDeclaration
723
722
| MethodDeclaration
724
723
| GetAccessorDeclaration
725
- | SetAccessorDeclaration
726
724
| BindingElement
727
725
| ConstructSignatureDeclaration
728
726
| VariableDeclaration
@@ -741,46 +739,43 @@ export function transformDeclarations(context: TransformationContext) {
741
739
// Literal const declarations will have an initializer ensured rather than a type
742
740
return ;
743
741
}
744
- const shouldUseResolverType = node . kind === SyntaxKind . Parameter &&
745
- ( resolver . isRequiredInitializedParameter ( node ) ||
746
- resolver . isOptionalUninitializedParameterProperty ( node ) ) ;
747
- if ( type && ! shouldUseResolverType ) {
742
+ const shouldAddImplicitUndefined = node . kind === SyntaxKind . Parameter && resolver . requiresAddingImplicitUndefined ( node ) ;
743
+ if ( type && ! shouldAddImplicitUndefined ) {
748
744
return visitNode ( type , visitDeclarationSubtree , isTypeNode ) ;
749
745
}
750
- if ( ! getParseTreeNode ( node ) ) {
751
- return type ? visitNode ( type , visitDeclarationSubtree , isTypeNode ) : factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
752
- }
753
- if ( node . kind === SyntaxKind . SetAccessor ) {
754
- // Set accessors with no associated type node (from it's param or get accessor return) are `any` since they are never contextually typed right now
755
- // (The inferred type here will be void, but the old declaration emitter printed `any`, so this replicates that)
756
- return factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
757
- }
746
+
758
747
errorNameNode = node . name ;
759
748
let oldDiag : typeof getSymbolAccessibilityDiagnostic ;
760
749
if ( ! suppressNewDiagnosticContexts ) {
761
750
oldDiag = getSymbolAccessibilityDiagnostic ;
762
751
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode ( node ) ;
763
752
}
764
- if ( node . kind === SyntaxKind . VariableDeclaration || node . kind === SyntaxKind . BindingElement ) {
765
- return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
766
- }
767
- if (
768
- node . kind === SyntaxKind . Parameter
769
- || node . kind === SyntaxKind . PropertyDeclaration
770
- || node . kind === SyntaxKind . PropertySignature
771
- ) {
772
- if ( isPropertySignature ( node ) || ! node . initializer ) return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldUseResolverType ) ) ;
773
- return cleanup ( resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldUseResolverType ) || resolver . createTypeOfExpression ( node . initializer , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
753
+ let typeNode ;
754
+ switch ( node . kind ) {
755
+ case SyntaxKind . Parameter :
756
+ case SyntaxKind . PropertySignature :
757
+ case SyntaxKind . PropertyDeclaration :
758
+ case SyntaxKind . BindingElement :
759
+ case SyntaxKind . VariableDeclaration :
760
+ typeNode = resolver . createTypeOfDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker , shouldAddImplicitUndefined ) ;
761
+ break ;
762
+ case SyntaxKind . FunctionDeclaration :
763
+ case SyntaxKind . ConstructSignature :
764
+ case SyntaxKind . MethodSignature :
765
+ case SyntaxKind . MethodDeclaration :
766
+ case SyntaxKind . GetAccessor :
767
+ case SyntaxKind . CallSignature :
768
+ typeNode = resolver . createReturnTypeOfSignatureDeclaration ( node , node , declarationEmitNodeBuilderFlags , symbolTracker ) ;
769
+ break ;
770
+ default :
771
+ Debug . assertNever ( node ) ;
774
772
}
775
- return cleanup ( resolver . createReturnTypeOfSignatureDeclaration ( node , enclosingDeclaration , declarationEmitNodeBuilderFlags , symbolTracker ) ) ;
776
773
777
- function cleanup ( returnValue : TypeNode | undefined ) {
778
- errorNameNode = undefined ;
779
- if ( ! suppressNewDiagnosticContexts ) {
780
- getSymbolAccessibilityDiagnostic = oldDiag ;
781
- }
782
- return returnValue || factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
774
+ errorNameNode = undefined ;
775
+ if ( ! suppressNewDiagnosticContexts ) {
776
+ getSymbolAccessibilityDiagnostic = oldDiag ! ;
783
777
}
778
+ return typeNode ?? factory . createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
784
779
}
785
780
786
781
function isDeclarationAndNotVisible ( node : NamedDeclaration ) {
0 commit comments