@@ -8646,39 +8646,36 @@ namespace ts {
8646
8646
*/
8647
8647
function getEffectiveDecoratorFirstArgumentType(node: Node): Type {
8648
8648
// The first argument to a decorator is its `target`.
8649
- switch (node.kind) {
8650
- case SyntaxKind.ClassDeclaration:
8651
- case SyntaxKind.ClassExpression:
8652
- // For a class decorator, the `target` is the type of the class (e.g. the
8653
- // "static" or "constructor" side of the class)
8649
+ if (node.kind === SyntaxKind.ClassDeclaration) {
8650
+ // For a class decorator, the `target` is the type of the class (e.g. the
8651
+ // "static" or "constructor" side of the class)
8652
+ let classSymbol = getSymbolOfNode(node);
8653
+ return getTypeOfSymbol(classSymbol);
8654
+ }
8655
+
8656
+ if (node.kind === SyntaxKind.Parameter) {
8657
+ // For a parameter decorator, the `target` is the parent type of the
8658
+ // parameter's containing method.
8659
+ node = node.parent;
8660
+ if (node.kind === SyntaxKind.Constructor) {
8654
8661
let classSymbol = getSymbolOfNode(node);
8655
8662
return getTypeOfSymbol(classSymbol);
8663
+ }
8664
+ }
8656
8665
8657
- case SyntaxKind.Parameter:
8658
- // For a parameter decorator, the `target` is the parent type of the
8659
- // parameter's containing method.
8660
- node = node.parent;
8661
- if (node.kind === SyntaxKind.Constructor) {
8662
- let classSymbol = getSymbolOfNode(node);
8663
- return getTypeOfSymbol(classSymbol);
8664
- }
8665
-
8666
- // fall-through
8667
-
8668
- case SyntaxKind.PropertyDeclaration:
8669
- case SyntaxKind.MethodDeclaration:
8670
- case SyntaxKind.GetAccessor:
8671
- case SyntaxKind.SetAccessor:
8672
- // For a property or method decorator, the `target` is the
8673
- // "static"-side type of the parent of the member if the member is
8674
- // declared "static"; otherwise, it is the "instance"-side type of the
8675
- // parent of the member.
8676
- return getParentTypeOfClassElement(<ClassElement>node);
8677
-
8678
- default:
8679
- Debug.fail("Unsupported decorator target.");
8680
- return unknownType;
8666
+ if (node.kind === SyntaxKind.PropertyDeclaration ||
8667
+ node.kind === SyntaxKind.MethodDeclaration ||
8668
+ node.kind === SyntaxKind.GetAccessor ||
8669
+ node.kind === SyntaxKind.SetAccessor) {
8670
+ // For a property or method decorator, the `target` is the
8671
+ // "static"-side type of the parent of the member if the member is
8672
+ // declared "static"; otherwise, it is the "instance"-side type of the
8673
+ // parent of the member.
8674
+ return getParentTypeOfClassElement(<ClassElement>node);
8681
8675
}
8676
+
8677
+ Debug.fail("Unsupported decorator target.");
8678
+ return unknownType;
8682
8679
}
8683
8680
8684
8681
/**
@@ -8698,57 +8695,54 @@ namespace ts {
8698
8695
*/
8699
8696
function getEffectiveDecoratorSecondArgumentType(node: Node) {
8700
8697
// The second argument to a decorator is its `propertyKey`
8701
- switch (node.kind) {
8702
- case SyntaxKind.ClassDeclaration:
8703
- Debug.fail("Class decorators should not have a second synthetic argument.") ;
8704
- return unknownType;
8698
+ if (node.kind === SyntaxKind.ClassDeclaration ) {
8699
+ Debug.fail("Class decorators should not have a second synthetic argument.");
8700
+ return unknownType ;
8701
+ }
8705
8702
8706
- case SyntaxKind.Parameter:
8707
- node = node.parent;
8708
- if (node.kind === SyntaxKind.Constructor) {
8709
- // For a constructor parameter decorator, the `propertyKey` will be `undefined`.
8710
- return anyType;
8711
- }
8703
+ if (node.kind === SyntaxKind.Parameter) {
8704
+ node = node.parent;
8705
+ if (node.kind === SyntaxKind.Constructor) {
8706
+ // For a constructor parameter decorator, the `propertyKey` will be `undefined`.
8707
+ return anyType;
8708
+ }
8712
8709
8713
8710
// For a non-constructor parameter decorator, the `propertyKey` will be either
8714
8711
// a string or a symbol, based on the name of the parameter's containing method.
8712
+ }
8715
8713
8716
- // fall-through
8717
-
8718
- case SyntaxKind.PropertyDeclaration:
8719
- case SyntaxKind.MethodDeclaration:
8720
- case SyntaxKind.GetAccessor:
8721
- case SyntaxKind.SetAccessor:
8722
- // The `propertyKey` for a property or method decorator will be a
8723
- // string literal type if the member name is an identifier, number, or string;
8724
- // otherwise, if the member name is a computed property name it will
8725
- // be either string or symbol.
8726
- let element = <ClassElement>node;
8727
- switch (element.name.kind) {
8728
- case SyntaxKind.Identifier:
8729
- case SyntaxKind.NumericLiteral:
8730
- case SyntaxKind.StringLiteral:
8731
- return getStringLiteralType(<StringLiteral>element.name);
8732
-
8733
- case SyntaxKind.ComputedPropertyName:
8734
- let nameType = checkComputedPropertyName(<ComputedPropertyName>element.name);
8735
- if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) {
8736
- return nameType;
8737
- }
8738
- else {
8739
- return stringType;
8740
- }
8741
-
8742
- default:
8743
- Debug.fail("Unsupported property name.");
8744
- return unknownType;
8745
- }
8714
+ if (node.kind === SyntaxKind.PropertyDeclaration ||
8715
+ node.kind === SyntaxKind.MethodDeclaration ||
8716
+ node.kind === SyntaxKind.GetAccessor ||
8717
+ node.kind === SyntaxKind.SetAccessor) {
8718
+ // The `propertyKey` for a property or method decorator will be a
8719
+ // string literal type if the member name is an identifier, number, or string;
8720
+ // otherwise, if the member name is a computed property name it will
8721
+ // be either string or symbol.
8722
+ let element = <ClassElement>node;
8723
+ switch (element.name.kind) {
8724
+ case SyntaxKind.Identifier:
8725
+ case SyntaxKind.NumericLiteral:
8726
+ case SyntaxKind.StringLiteral:
8727
+ return getStringLiteralType(<StringLiteral>element.name);
8746
8728
8729
+ case SyntaxKind.ComputedPropertyName:
8730
+ let nameType = checkComputedPropertyName(<ComputedPropertyName>element.name);
8731
+ if (allConstituentTypesHaveKind(nameType, TypeFlags.ESSymbol)) {
8732
+ return nameType;
8733
+ }
8734
+ else {
8735
+ return stringType;
8736
+ }
8747
8737
8748
- default:
8749
- Debug.fail("Unsupported decorator target.");
8750
- return unknownType;
8738
+ default:
8739
+ Debug.fail("Unsupported property name.");
8740
+ return unknownType;
8741
+ }
8751
8742
}
8743
+
8744
+ Debug.fail("Unsupported decorator target.");
8745
+ return unknownType;
8752
8746
}
8753
8747
8754
8748
/**
@@ -8761,31 +8755,32 @@ namespace ts {
8761
8755
function getEffectiveDecoratorThirdArgumentType(node: Node) {
8762
8756
// The third argument to a decorator is either its `descriptor` for a method decorator
8763
8757
// or its `parameterIndex` for a paramter decorator
8764
- switch (node.kind) {
8765
- case SyntaxKind.ClassDeclaration:
8766
- Debug.fail("Class decorators should not have a third synthetic argument.");
8767
- return unknownType;
8768
-
8769
- case SyntaxKind.Parameter:
8770
- // The `parameterIndex` for a parameter decorator is always a number
8771
- return numberType;
8758
+ if (node.kind === SyntaxKind.ClassDeclaration) {
8759
+ Debug.fail("Class decorators should not have a third synthetic argument.");
8760
+ return unknownType;
8761
+ }
8772
8762
8773
- case SyntaxKind.PropertyDeclaration:
8774
- Debug.fail("Property decorators should not have a third synthetic argument.");
8775
- return unknownType;
8763
+ if (node.kind === SyntaxKind.Parameter) {
8764
+ // The `parameterIndex` for a parameter decorator is always a number
8765
+ return numberType;
8766
+ }
8776
8767
8777
- case SyntaxKind.MethodDeclaration:
8778
- case SyntaxKind.GetAccessor:
8779
- case SyntaxKind.SetAccessor:
8780
- // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor<T>`
8781
- // for the type of the member.
8782
- let propertyType = getTypeOfNode(node);
8783
- return createTypedPropertyDescriptorType(propertyType);
8768
+ if (node.kind === SyntaxKind.PropertyDeclaration) {
8769
+ Debug.fail("Property decorators should not have a third synthetic argument.");
8770
+ return unknownType;
8771
+ }
8784
8772
8785
- default:
8786
- Debug.fail("Unsupported decorator target.");
8787
- return unknownType;
8773
+ if (node.kind === SyntaxKind.MethodDeclaration ||
8774
+ node.kind === SyntaxKind.GetAccessor ||
8775
+ node.kind === SyntaxKind.SetAccessor) {
8776
+ // The `descriptor` for a method decorator will be a `TypedPropertyDescriptor<T>`
8777
+ // for the type of the member.
8778
+ let propertyType = getTypeOfNode(node);
8779
+ return createTypedPropertyDescriptorType(propertyType);
8788
8780
}
8781
+
8782
+ Debug.fail("Unsupported decorator target.");
8783
+ return unknownType;
8789
8784
}
8790
8785
8791
8786
/**
0 commit comments