* Serializes a type node for use with decorator type metadata. * * Types are serialized in the following fashion: * - Void types point to "undefined" (e.g. "void 0") * - Function and Constructor types point to the global "Function" constructor. * - Interf
(node)
| 92815 | * @param node The type node to serialize. |
| 92816 | */ |
| 92817 | function serializeTypeNode(node) { |
| 92818 | if (node === undefined) { |
| 92819 | return factory.createIdentifier("Object"); |
| 92820 | } |
| 92821 | switch (node.kind) { |
| 92822 | case 114 /* SyntaxKind.VoidKeyword */: |
| 92823 | case 153 /* SyntaxKind.UndefinedKeyword */: |
| 92824 | case 143 /* SyntaxKind.NeverKeyword */: |
| 92825 | return factory.createVoidZero(); |
| 92826 | case 191 /* SyntaxKind.ParenthesizedType */: |
| 92827 | return serializeTypeNode(node.type); |
| 92828 | case 179 /* SyntaxKind.FunctionType */: |
| 92829 | case 180 /* SyntaxKind.ConstructorType */: |
| 92830 | return factory.createIdentifier("Function"); |
| 92831 | case 183 /* SyntaxKind.ArrayType */: |
| 92832 | case 184 /* SyntaxKind.TupleType */: |
| 92833 | return factory.createIdentifier("Array"); |
| 92834 | case 177 /* SyntaxKind.TypePredicate */: |
| 92835 | case 133 /* SyntaxKind.BooleanKeyword */: |
| 92836 | return factory.createIdentifier("Boolean"); |
| 92837 | case 198 /* SyntaxKind.TemplateLiteralType */: |
| 92838 | case 150 /* SyntaxKind.StringKeyword */: |
| 92839 | return factory.createIdentifier("String"); |
| 92840 | case 148 /* SyntaxKind.ObjectKeyword */: |
| 92841 | return factory.createIdentifier("Object"); |
| 92842 | case 196 /* SyntaxKind.LiteralType */: |
| 92843 | switch (node.literal.kind) { |
| 92844 | case 10 /* SyntaxKind.StringLiteral */: |
| 92845 | case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */: |
| 92846 | return factory.createIdentifier("String"); |
| 92847 | case 219 /* SyntaxKind.PrefixUnaryExpression */: |
| 92848 | case 8 /* SyntaxKind.NumericLiteral */: |
| 92849 | return factory.createIdentifier("Number"); |
| 92850 | case 9 /* SyntaxKind.BigIntLiteral */: |
| 92851 | return getGlobalBigIntNameWithFallback(); |
| 92852 | case 110 /* SyntaxKind.TrueKeyword */: |
| 92853 | case 95 /* SyntaxKind.FalseKeyword */: |
| 92854 | return factory.createIdentifier("Boolean"); |
| 92855 | case 104 /* SyntaxKind.NullKeyword */: |
| 92856 | return factory.createVoidZero(); |
| 92857 | default: |
| 92858 | return ts.Debug.failBadSyntaxKind(node.literal); |
| 92859 | } |
| 92860 | case 147 /* SyntaxKind.NumberKeyword */: |
| 92861 | return factory.createIdentifier("Number"); |
| 92862 | case 158 /* SyntaxKind.BigIntKeyword */: |
| 92863 | return getGlobalBigIntNameWithFallback(); |
| 92864 | case 151 /* SyntaxKind.SymbolKeyword */: |
| 92865 | return languageVersion < 2 /* ScriptTarget.ES2015 */ |
| 92866 | ? getGlobalSymbolNameWithFallback() |
| 92867 | : factory.createIdentifier("Symbol"); |
| 92868 | case 178 /* SyntaxKind.TypeReference */: |
| 92869 | return serializeTypeReferenceNode(node); |
| 92870 | case 188 /* SyntaxKind.IntersectionType */: |
| 92871 | case 187 /* SyntaxKind.UnionType */: |
| 92872 | return serializeTypeList(node.types); |
| 92873 | case 189 /* SyntaxKind.ConditionalType */: |
| 92874 | return serializeTypeList([node.trueType, node.falseType]); |
no test coverage detected