@teambit/typescript 0.0.965 → 0.0.966
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export-identifier.d.ts +5 -4
- package/dist/export-identifier.js +23 -4
- package/dist/export-identifier.js.map +1 -1
- package/dist/identifier-list.d.ts +7 -0
- package/dist/identifier-list.js +21 -0
- package/dist/identifier-list.js.map +1 -0
- package/dist/identifier.d.ts +9 -0
- package/dist/identifier.js +30 -0
- package/dist/identifier.js.map +1 -0
- package/dist/{preview-1674271762484.js → preview-1674531051110.js} +2 -2
- package/dist/schema-extractor-context.d.ts +40 -8
- package/dist/schema-extractor-context.js +243 -101
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/schema-transformer.d.ts +2 -2
- package/dist/schema-transformer.js.map +1 -1
- package/dist/transformers/array-type.d.ts +10 -0
- package/dist/transformers/array-type.js +38 -0
- package/dist/transformers/array-type.js.map +1 -0
- package/dist/transformers/binding-element.d.ts +2 -2
- package/dist/transformers/binding-element.js +7 -7
- package/dist/transformers/binding-element.js.map +1 -1
- package/dist/transformers/class-declaration.d.ts +2 -2
- package/dist/transformers/class-declaration.js +6 -20
- package/dist/transformers/class-declaration.js.map +1 -1
- package/dist/transformers/conditional-type.d.ts +10 -0
- package/dist/transformers/conditional-type.js +39 -0
- package/dist/transformers/conditional-type.js.map +1 -0
- package/dist/transformers/constructor.d.ts +10 -0
- package/dist/transformers/constructor.js +50 -0
- package/dist/transformers/constructor.js.map +1 -0
- package/dist/transformers/enum-declaration.d.ts +2 -2
- package/dist/transformers/enum-declaration.js +4 -4
- package/dist/transformers/enum-declaration.js.map +1 -1
- package/dist/transformers/{export-assignment-declaration.d.ts → export-assignment.d.ts} +7 -2
- package/dist/transformers/export-assignment.js +41 -0
- package/dist/transformers/export-assignment.js.map +1 -0
- package/dist/transformers/export-declaration.d.ts +2 -3
- package/dist/transformers/export-declaration.js +21 -10
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-like.d.ts +11 -0
- package/dist/transformers/function-like.js +82 -0
- package/dist/transformers/function-like.js.map +1 -0
- package/dist/transformers/get-accessor.d.ts +10 -0
- package/dist/transformers/get-accessor.js +48 -0
- package/dist/transformers/get-accessor.js.map +1 -0
- package/dist/transformers/import-declaration.d.ts +10 -0
- package/dist/transformers/import-declaration.js +74 -0
- package/dist/transformers/import-declaration.js.map +1 -0
- package/dist/transformers/index-signature.d.ts +10 -0
- package/dist/transformers/index-signature.js +45 -0
- package/dist/transformers/index-signature.js.map +1 -0
- package/dist/transformers/index.d.ts +28 -3
- package/dist/transformers/index.js +337 -12
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/indexed-access-type.d.ts +10 -0
- package/dist/transformers/indexed-access-type.js +37 -0
- package/dist/transformers/indexed-access-type.js.map +1 -0
- package/dist/transformers/interface-declaration.d.ts +2 -2
- package/dist/transformers/interface-declaration.js +6 -20
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/intersection-type.d.ts +10 -0
- package/dist/transformers/intersection-type.js +48 -0
- package/dist/transformers/intersection-type.js.map +1 -0
- package/dist/transformers/keyword-type.d.ts +13 -0
- package/dist/transformers/keyword-type.js +55 -0
- package/dist/transformers/keyword-type.js.map +1 -0
- package/dist/transformers/literal-type.d.ts +13 -0
- package/dist/transformers/literal-type.js +40 -0
- package/dist/transformers/literal-type.js.map +1 -0
- package/dist/transformers/named-tuple.d.ts +10 -0
- package/dist/transformers/named-tuple.js +38 -0
- package/dist/transformers/named-tuple.js.map +1 -0
- package/dist/transformers/parameter.d.ts +13 -0
- package/dist/transformers/parameter.js +112 -0
- package/dist/transformers/parameter.js.map +1 -0
- package/dist/transformers/parenthesized-type.d.ts +10 -0
- package/dist/transformers/parenthesized-type.js +36 -0
- package/dist/transformers/parenthesized-type.js.map +1 -0
- package/dist/transformers/property-declaration.d.ts +11 -0
- package/dist/transformers/property-declaration.js +57 -0
- package/dist/transformers/property-declaration.js.map +1 -0
- package/dist/transformers/set-accessor.d.ts +10 -0
- package/dist/transformers/set-accessor.js +45 -0
- package/dist/transformers/set-accessor.js.map +1 -0
- package/dist/transformers/source-file-transformer.d.ts +3 -2
- package/dist/transformers/source-file-transformer.js +44 -15
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/template-literal-type-span.d.ts +10 -0
- package/dist/transformers/template-literal-type-span.js +37 -0
- package/dist/transformers/template-literal-type-span.js.map +1 -0
- package/dist/transformers/template-literal-type.d.ts +10 -0
- package/dist/transformers/template-literal-type.js +45 -0
- package/dist/transformers/template-literal-type.js.map +1 -0
- package/dist/transformers/this-type.d.ts +10 -0
- package/dist/transformers/this-type.js +35 -0
- package/dist/transformers/this-type.js.map +1 -0
- package/dist/transformers/tuple-type.d.ts +10 -0
- package/dist/transformers/tuple-type.js +47 -0
- package/dist/transformers/tuple-type.js.map +1 -0
- package/dist/transformers/type-alias.d.ts +2 -2
- package/dist/transformers/type-alias.js +5 -12
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/type-literal.d.ts +14 -0
- package/dist/transformers/type-literal.js +49 -0
- package/dist/transformers/type-literal.js.map +1 -0
- package/dist/transformers/type-operator.d.ts +14 -0
- package/dist/transformers/type-operator.js +52 -0
- package/dist/transformers/type-operator.js.map +1 -0
- package/dist/transformers/type-predicate.d.ts +10 -0
- package/dist/transformers/type-predicate.js +38 -0
- package/dist/transformers/type-predicate.js.map +1 -0
- package/dist/transformers/type-query.d.ts +13 -0
- package/dist/transformers/type-query.js +42 -0
- package/dist/transformers/type-query.js.map +1 -0
- package/dist/transformers/type-reference.d.ts +16 -0
- package/dist/transformers/type-reference.js +56 -0
- package/dist/transformers/type-reference.js.map +1 -0
- package/dist/transformers/union-type.d.ts +10 -0
- package/dist/transformers/union-type.js +48 -0
- package/dist/transformers/union-type.js.map +1 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +2 -10
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.d.ts +2 -2
- package/dist/transformers/variable-declaration.js +11 -11
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/transformers/variable-statement.d.ts +2 -2
- package/dist/transformers/variable-statement.js +5 -5
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.extractor.d.ts +10 -4
- package/dist/typescript.extractor.js +70 -17
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +4 -2
- package/dist/typescript.main.runtime.js +5 -11
- package/dist/typescript.main.runtime.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.966.tgz +0 -0
- package/package.json +17 -17
- package/transformers/array-type.ts +21 -0
- package/transformers/binding-element.ts +2 -2
- package/transformers/class-declaration.ts +4 -6
- package/transformers/conditional-type.ts +23 -0
- package/transformers/constructor.ts +40 -0
- package/transformers/enum-declaration.ts +3 -3
- package/transformers/{export-assignment-declaration.ts → export-assignment.ts} +9 -3
- package/transformers/export-declaration.ts +35 -8
- package/transformers/function-like.ts +65 -0
- package/transformers/get-accessor.ts +24 -0
- package/transformers/import-declaration.ts +56 -0
- package/transformers/index-signature.ts +24 -0
- package/transformers/index.ts +28 -3
- package/transformers/indexed-access-type.ts +21 -0
- package/transformers/interface-declaration.ts +5 -7
- package/transformers/intersection-type.ts +25 -0
- package/transformers/keyword-type.ts +39 -0
- package/transformers/literal-type.ts +23 -0
- package/transformers/named-tuple.ts +22 -0
- package/transformers/parameter.ts +110 -0
- package/transformers/parenthesized-type.ts +20 -0
- package/transformers/property-declaration.ts +33 -0
- package/transformers/set-accessor.ts +25 -0
- package/transformers/source-file-transformer.ts +56 -24
- package/transformers/template-literal-type-span.ts +21 -0
- package/transformers/template-literal-type.ts +24 -0
- package/transformers/this-type.ts +19 -0
- package/transformers/tuple-type.ts +24 -0
- package/transformers/type-alias.ts +3 -4
- package/transformers/type-literal.ts +26 -0
- package/transformers/type-operator.ts +37 -0
- package/transformers/type-predicate.ts +22 -0
- package/transformers/type-query.ts +25 -0
- package/transformers/type-reference.ts +33 -0
- package/transformers/union-type.ts +25 -0
- package/transformers/utils/jsdoc-to-doc-schema.ts +2 -4
- package/transformers/variable-declaration.ts +7 -4
- package/transformers/variable-statement.ts +3 -3
- package/dist/export-list.d.ts +0 -6
- package/dist/export-list.js +0 -17
- package/dist/export-list.js.map +0 -1
- package/dist/transformers/export-assignment-declaration.js +0 -29
- package/dist/transformers/export-assignment-declaration.js.map +0 -1
- package/dist/transformers/function-declaration.d.ts +0 -11
- package/dist/transformers/function-declaration.js +0 -49
- package/dist/transformers/function-declaration.js.map +0 -1
- package/dist/transformers/utils/class-element-to-schema.d.ts +0 -4
- package/dist/transformers/utils/class-element-to-schema.js +0 -95
- package/dist/transformers/utils/class-element-to-schema.js.map +0 -1
- package/dist/transformers/utils/get-params.d.ts +0 -4
- package/dist/transformers/utils/get-params.js +0 -100
- package/dist/transformers/utils/get-params.js.map +0 -1
- package/dist/transformers/utils/to-function-like-schema.d.ts +0 -4
- package/dist/transformers/utils/to-function-like-schema.js +0 -58
- package/dist/transformers/utils/to-function-like-schema.js.map +0 -1
- package/dist/transformers/utils/type-element-to-schema.d.ts +0 -7
- package/dist/transformers/utils/type-element-to-schema.js +0 -106
- package/dist/transformers/utils/type-element-to-schema.js.map +0 -1
- package/dist/transformers/utils/type-node-to-schema.d.ts +0 -4
- package/dist/transformers/utils/type-node-to-schema.js +0 -274
- package/dist/transformers/utils/type-node-to-schema.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.965.tgz +0 -0
- package/transformers/function-declaration.ts +0 -25
- package/transformers/utils/class-element-to-schema.ts +0 -64
- package/transformers/utils/get-params.ts +0 -92
- package/transformers/utils/to-function-like-schema.ts +0 -39
- package/transformers/utils/type-element-to-schema.ts +0 -79
- package/transformers/utils/type-node-to-schema.ts +0 -294
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
require("core-js/modules/es.promise.js");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.typeNodeToSchema = typeNodeToSchema;
|
|
9
|
-
function _typescript() {
|
|
10
|
-
const data = require("typescript");
|
|
11
|
-
_typescript = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
function _semanticsEntities() {
|
|
17
|
-
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
18
|
-
_semanticsEntities = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _pMapSeries() {
|
|
24
|
-
const data = _interopRequireDefault(require("p-map-series"));
|
|
25
|
-
_pMapSeries = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
function _getParams() {
|
|
31
|
-
const data = require("./get-params");
|
|
32
|
-
_getParams = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
function _typeElementToSchema() {
|
|
38
|
-
const data = require("./type-element-to-schema");
|
|
39
|
-
_typeElementToSchema = function () {
|
|
40
|
-
return data;
|
|
41
|
-
};
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
// eslint-disable-next-line complexity
|
|
45
|
-
async function typeNodeToSchema(node, context) {
|
|
46
|
-
const location = context.getLocation(node);
|
|
47
|
-
if (isKeywordType(node)) {
|
|
48
|
-
return new (_semanticsEntities().KeywordTypeSchema)(location, node.getText());
|
|
49
|
-
}
|
|
50
|
-
switch (node.kind) {
|
|
51
|
-
case _typescript().SyntaxKind.IntersectionType:
|
|
52
|
-
return intersectionType(node, context);
|
|
53
|
-
case _typescript().SyntaxKind.UnionType:
|
|
54
|
-
return unionType(node, context);
|
|
55
|
-
case _typescript().SyntaxKind.TypeReference:
|
|
56
|
-
return typeReference(node, context);
|
|
57
|
-
case _typescript().SyntaxKind.TypeLiteral:
|
|
58
|
-
return typeLiteral(node, context);
|
|
59
|
-
case _typescript().SyntaxKind.LiteralType:
|
|
60
|
-
// e.g. string/boolean
|
|
61
|
-
return new (_semanticsEntities().LiteralTypeSchema)(location, node.getText());
|
|
62
|
-
case _typescript().SyntaxKind.FunctionType:
|
|
63
|
-
return functionType(node, context);
|
|
64
|
-
case _typescript().SyntaxKind.TypeQuery:
|
|
65
|
-
return typeQuery(node, context);
|
|
66
|
-
case _typescript().SyntaxKind.ArrayType:
|
|
67
|
-
return arrayType(node, context);
|
|
68
|
-
case _typescript().SyntaxKind.TypeOperator:
|
|
69
|
-
return typeOperator(node, context);
|
|
70
|
-
case _typescript().SyntaxKind.TupleType:
|
|
71
|
-
return tupleType(node, context);
|
|
72
|
-
case _typescript().SyntaxKind.ParenthesizedType:
|
|
73
|
-
return parenthesizedType(node, context);
|
|
74
|
-
case _typescript().SyntaxKind.TypePredicate:
|
|
75
|
-
return typePredicate(node, context);
|
|
76
|
-
case _typescript().SyntaxKind.IndexedAccessType:
|
|
77
|
-
return indexedAccessType(node, context);
|
|
78
|
-
case _typescript().SyntaxKind.TemplateLiteralTypeSpan:
|
|
79
|
-
return templateLiteralTypeSpan(node, context);
|
|
80
|
-
case _typescript().SyntaxKind.TemplateLiteralType:
|
|
81
|
-
return templateLiteralType(node, context);
|
|
82
|
-
case _typescript().SyntaxKind.ThisType:
|
|
83
|
-
return thisType(node, context);
|
|
84
|
-
case _typescript().SyntaxKind.ConditionalType:
|
|
85
|
-
return conditionalType(node, context);
|
|
86
|
-
case _typescript().SyntaxKind.NamedTupleMember:
|
|
87
|
-
return namedTupleType(node, context);
|
|
88
|
-
case _typescript().SyntaxKind.ConstructorType:
|
|
89
|
-
case _typescript().SyntaxKind.OptionalType:
|
|
90
|
-
case _typescript().SyntaxKind.RestType:
|
|
91
|
-
case _typescript().SyntaxKind.InferType:
|
|
92
|
-
case _typescript().SyntaxKind.MappedType:
|
|
93
|
-
case _typescript().SyntaxKind.ImportType:
|
|
94
|
-
case _typescript().SyntaxKind.ExpressionWithTypeArguments:
|
|
95
|
-
case _typescript().SyntaxKind.JSDocTypeExpression:
|
|
96
|
-
case _typescript().SyntaxKind.JSDocAllType:
|
|
97
|
-
case _typescript().SyntaxKind.JSDocUnknownType:
|
|
98
|
-
case _typescript().SyntaxKind.JSDocNonNullableType:
|
|
99
|
-
case _typescript().SyntaxKind.JSDocNullableType:
|
|
100
|
-
case _typescript().SyntaxKind.JSDocOptionalType:
|
|
101
|
-
case _typescript().SyntaxKind.JSDocFunctionType:
|
|
102
|
-
case _typescript().SyntaxKind.JSDocVariadicType:
|
|
103
|
-
case _typescript().SyntaxKind.JSDocNamepathType:
|
|
104
|
-
case _typescript().SyntaxKind.JSDocSignature:
|
|
105
|
-
case _typescript().SyntaxKind.JSDocTypeLiteral:
|
|
106
|
-
return unimplementedSchema(node, context);
|
|
107
|
-
default:
|
|
108
|
-
return unimplementedSchema(node, context);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function unimplementedSchema(node, context) {
|
|
112
|
-
return new (_semanticsEntities().UnImplementedSchema)(context.getLocation(node), node.getText(), _typescript().SyntaxKind[node.kind]);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* whether it's kind of `ts.KeywordTypeSyntaxKind`
|
|
116
|
-
*/
|
|
117
|
-
function isKeywordType(node) {
|
|
118
|
-
switch (node.kind) {
|
|
119
|
-
case _typescript().SyntaxKind.AnyKeyword:
|
|
120
|
-
case _typescript().SyntaxKind.BigIntKeyword:
|
|
121
|
-
case _typescript().SyntaxKind.BooleanKeyword:
|
|
122
|
-
case _typescript().SyntaxKind.IntrinsicKeyword:
|
|
123
|
-
case _typescript().SyntaxKind.NeverKeyword:
|
|
124
|
-
case _typescript().SyntaxKind.NumberKeyword:
|
|
125
|
-
case _typescript().SyntaxKind.ObjectKeyword:
|
|
126
|
-
case _typescript().SyntaxKind.StringKeyword:
|
|
127
|
-
case _typescript().SyntaxKind.SymbolKeyword:
|
|
128
|
-
case _typescript().SyntaxKind.UndefinedKeyword:
|
|
129
|
-
case _typescript().SyntaxKind.UnknownKeyword:
|
|
130
|
-
case _typescript().SyntaxKind.VoidKeyword:
|
|
131
|
-
return true;
|
|
132
|
-
default:
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
async function intersectionType(node, context) {
|
|
137
|
-
const types = await (0, _pMapSeries().default)(node.types, async type => {
|
|
138
|
-
const typeSchema = await typeNodeToSchema(type, context);
|
|
139
|
-
return typeSchema;
|
|
140
|
-
});
|
|
141
|
-
const location = context.getLocation(node);
|
|
142
|
-
return new (_semanticsEntities().TypeIntersectionSchema)(location, types);
|
|
143
|
-
}
|
|
144
|
-
async function unionType(node, context) {
|
|
145
|
-
const types = await (0, _pMapSeries().default)(node.types, async type => {
|
|
146
|
-
const typeSchema = await typeNodeToSchema(type, context);
|
|
147
|
-
return typeSchema;
|
|
148
|
-
});
|
|
149
|
-
const location = context.getLocation(node);
|
|
150
|
-
return new (_semanticsEntities().TypeUnionSchema)(location, types);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* not to be confused with "LiteralType", which is string/boolean/null.
|
|
155
|
-
* this "TypeLiteral" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.
|
|
156
|
-
*/
|
|
157
|
-
async function typeLiteral(node, context) {
|
|
158
|
-
const members = await (0, _pMapSeries().default)(node.members, member => (0, _typeElementToSchema().typeElementToSchema)(member, context));
|
|
159
|
-
const location = context.getLocation(node);
|
|
160
|
-
return new (_semanticsEntities().TypeLiteralSchema)(location, members);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* In the following example, `AriaButtonProps` is a type reference
|
|
165
|
-
* ```ts
|
|
166
|
-
* import type { AriaButtonProps } from '@react-types/button';
|
|
167
|
-
* export type ButtonProps = AriaButtonProps & { a: string };
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
async function typeReference(node, context) {
|
|
171
|
-
const name = node.typeName.getText();
|
|
172
|
-
const type = await context.resolveType(node, name, false);
|
|
173
|
-
if (node.typeArguments && type instanceof _semanticsEntities().TypeRefSchema) {
|
|
174
|
-
const args = await (0, _pMapSeries().default)(node.typeArguments, arg => typeNodeToSchema(arg, context));
|
|
175
|
-
type.typeArgs = args;
|
|
176
|
-
}
|
|
177
|
-
return type;
|
|
178
|
-
}
|
|
179
|
-
async function functionType(node, context) {
|
|
180
|
-
var _node$name, _node$modifiers;
|
|
181
|
-
const name = ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) || '';
|
|
182
|
-
const params = await (0, _getParams().getParams)(node.parameters, context);
|
|
183
|
-
const returnType = await typeNodeToSchema(node.type, context);
|
|
184
|
-
const location = context.getLocation(node);
|
|
185
|
-
const modifiers = ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.map(modifier => modifier.getText())) || [];
|
|
186
|
-
const doc = await context.jsDocToDocSchema(node);
|
|
187
|
-
return new (_semanticsEntities().FunctionLikeSchema)(location, name, params, returnType, '', modifiers, doc);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* e.g. `typeof Foo`
|
|
192
|
-
*/
|
|
193
|
-
async function typeQuery(node, context) {
|
|
194
|
-
const displaySig = await context.getQuickInfoDisplayString(node.exprName);
|
|
195
|
-
const type = await context.resolveType(node.exprName, node.exprName.getText(), false);
|
|
196
|
-
const location = context.getLocation(node);
|
|
197
|
-
return new (_semanticsEntities().TypeQuerySchema)(location, type, displaySig);
|
|
198
|
-
}
|
|
199
|
-
async function arrayType(node, context) {
|
|
200
|
-
const type = await typeNodeToSchema(node.elementType, context);
|
|
201
|
-
const location = context.getLocation(node);
|
|
202
|
-
return new (_semanticsEntities().TypeArraySchema)(location, type);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* e.g. keyof typeof Foo
|
|
207
|
-
*/
|
|
208
|
-
async function typeOperator(node, context) {
|
|
209
|
-
const operatorName = getOperatorName(node.operator);
|
|
210
|
-
const type = await typeNodeToSchema(node.type, context);
|
|
211
|
-
return new (_semanticsEntities().TypeOperatorSchema)(context.getLocation(node), operatorName, type);
|
|
212
|
-
}
|
|
213
|
-
function getOperatorName(operator) {
|
|
214
|
-
switch (operator) {
|
|
215
|
-
case _typescript().SyntaxKind.KeyOfKeyword:
|
|
216
|
-
return 'keyof';
|
|
217
|
-
case _typescript().SyntaxKind.UniqueKeyword:
|
|
218
|
-
return 'unique';
|
|
219
|
-
case _typescript().SyntaxKind.ReadonlyKeyword:
|
|
220
|
-
return 'readonly';
|
|
221
|
-
default:
|
|
222
|
-
throw new Error(`getOperatorName: unable to find operator name for ${operator}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
async function tupleType(node, context) {
|
|
226
|
-
const elements = await (0, _pMapSeries().default)(node.elements, async elem => {
|
|
227
|
-
const typeSchema = await typeNodeToSchema(elem, context);
|
|
228
|
-
return typeSchema;
|
|
229
|
-
});
|
|
230
|
-
return new (_semanticsEntities().TupleTypeSchema)(context.getLocation(node), elements);
|
|
231
|
-
}
|
|
232
|
-
async function parenthesizedType(node, context) {
|
|
233
|
-
const type = await typeNodeToSchema(node.type, context);
|
|
234
|
-
return new (_semanticsEntities().ParenthesizedTypeSchema)(context.getLocation(node), type);
|
|
235
|
-
}
|
|
236
|
-
async function typePredicate(node, context) {
|
|
237
|
-
const parameterName = (0, _typescript().isIdentifier)(node.parameterName) ? node.parameterName.getText() : 'this';
|
|
238
|
-
const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;
|
|
239
|
-
const hasAssertsModifier = Boolean(node.assertsModifier);
|
|
240
|
-
return new (_semanticsEntities().TypePredicateSchema)(context.getLocation(node), parameterName, type, hasAssertsModifier);
|
|
241
|
-
}
|
|
242
|
-
async function indexedAccessType(node, context) {
|
|
243
|
-
const objectType = await typeNodeToSchema(node.objectType, context);
|
|
244
|
-
const indexType = await typeNodeToSchema(node.indexType, context);
|
|
245
|
-
return new (_semanticsEntities().IndexedAccessSchema)(context.getLocation(node), objectType, indexType);
|
|
246
|
-
}
|
|
247
|
-
async function templateLiteralType(node, context) {
|
|
248
|
-
const templateSpans = await (0, _pMapSeries().default)(node.templateSpans, span => templateLiteralTypeSpan(span, context));
|
|
249
|
-
const head = node.head.text;
|
|
250
|
-
return new (_semanticsEntities().TemplateLiteralTypeSchema)(context.getLocation(node), head, templateSpans);
|
|
251
|
-
}
|
|
252
|
-
async function templateLiteralTypeSpan(node, context) {
|
|
253
|
-
const type = await typeNodeToSchema(node.type, context);
|
|
254
|
-
const literal = node.literal.text;
|
|
255
|
-
return new (_semanticsEntities().TemplateLiteralTypeSpanSchema)(context.getLocation(node), literal, type);
|
|
256
|
-
}
|
|
257
|
-
async function thisType(node, context) {
|
|
258
|
-
return new (_semanticsEntities().ThisTypeSchema)(context.getLocation(node));
|
|
259
|
-
}
|
|
260
|
-
async function conditionalType(node, context) {
|
|
261
|
-
const checkType = await typeNodeToSchema(node.checkType, context);
|
|
262
|
-
const extendsType = await typeNodeToSchema(node.extendsType, context);
|
|
263
|
-
const trueType = await typeNodeToSchema(node.trueType, context);
|
|
264
|
-
const falseType = await typeNodeToSchema(node.falseType, context);
|
|
265
|
-
return new (_semanticsEntities().ConditionalTypeSchema)(context.getLocation(node), checkType, extendsType, trueType, falseType);
|
|
266
|
-
}
|
|
267
|
-
async function namedTupleType(node, context) {
|
|
268
|
-
const name = node.name.getText();
|
|
269
|
-
const location = context.getLocation(node);
|
|
270
|
-
const type = await typeNodeToSchema(node.type, context);
|
|
271
|
-
return new (_semanticsEntities().NamedTupleSchema)(location, type, name);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
//# sourceMappingURL=type-node-to-schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["typeNodeToSchema","node","context","location","getLocation","isKeywordType","KeywordTypeSchema","getText","kind","SyntaxKind","IntersectionType","intersectionType","UnionType","unionType","TypeReference","typeReference","TypeLiteral","typeLiteral","LiteralType","LiteralTypeSchema","FunctionType","functionType","TypeQuery","typeQuery","ArrayType","arrayType","TypeOperator","typeOperator","TupleType","tupleType","ParenthesizedType","parenthesizedType","TypePredicate","typePredicate","IndexedAccessType","indexedAccessType","TemplateLiteralTypeSpan","templateLiteralTypeSpan","TemplateLiteralType","templateLiteralType","ThisType","thisType","ConditionalType","conditionalType","NamedTupleMember","namedTupleType","ConstructorType","OptionalType","RestType","InferType","MappedType","ImportType","ExpressionWithTypeArguments","JSDocTypeExpression","JSDocAllType","JSDocUnknownType","JSDocNonNullableType","JSDocNullableType","JSDocOptionalType","JSDocFunctionType","JSDocVariadicType","JSDocNamepathType","JSDocSignature","JSDocTypeLiteral","unimplementedSchema","UnImplementedSchema","AnyKeyword","BigIntKeyword","BooleanKeyword","IntrinsicKeyword","NeverKeyword","NumberKeyword","ObjectKeyword","StringKeyword","SymbolKeyword","UndefinedKeyword","UnknownKeyword","VoidKeyword","types","pMapSeries","type","typeSchema","TypeIntersectionSchema","TypeUnionSchema","members","member","typeElementToSchema","TypeLiteralSchema","name","typeName","resolveType","typeArguments","TypeRefSchema","args","arg","typeArgs","params","getParams","parameters","returnType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","displaySig","getQuickInfoDisplayString","exprName","TypeQuerySchema","elementType","TypeArraySchema","operatorName","getOperatorName","operator","TypeOperatorSchema","KeyOfKeyword","UniqueKeyword","ReadonlyKeyword","Error","elements","elem","TupleTypeSchema","ParenthesizedTypeSchema","parameterName","isIdentifier","undefined","hasAssertsModifier","Boolean","assertsModifier","TypePredicateSchema","objectType","indexType","IndexedAccessSchema","templateSpans","span","head","text","TemplateLiteralTypeSchema","literal","TemplateLiteralTypeSpanSchema","ThisTypeSchema","checkType","extendsType","trueType","falseType","ConditionalTypeSchema","NamedTupleSchema"],"sources":["type-node-to-schema.ts"],"sourcesContent":["import {\n TypeNode,\n SyntaxKind,\n KeywordTypeNode,\n FunctionTypeNode,\n TypeQueryNode,\n TypeReferenceNode,\n ArrayTypeNode,\n TypeOperatorNode,\n TupleTypeNode,\n IntersectionTypeNode,\n UnionTypeNode,\n TypeLiteralNode,\n ParenthesizedTypeNode,\n TypePredicateNode,\n isIdentifier,\n IndexedAccessTypeNode,\n TemplateLiteralTypeNode,\n TemplateLiteralTypeSpan,\n ThisTypeNode,\n ConditionalTypeNode,\n NamedTupleMember,\n} from 'typescript';\nimport {\n SchemaNode,\n TypeRefSchema,\n TypeIntersectionSchema,\n TypeUnionSchema,\n TypeLiteralSchema,\n TypeQuerySchema,\n LiteralTypeSchema,\n KeywordTypeSchema,\n TypeArraySchema,\n TypeOperatorSchema,\n TupleTypeSchema,\n FunctionLikeSchema,\n ParenthesizedTypeSchema,\n TypePredicateSchema,\n IndexedAccessSchema,\n TemplateLiteralTypeSpanSchema,\n TemplateLiteralTypeSchema,\n ThisTypeSchema,\n Modifier,\n ConditionalTypeSchema,\n NamedTupleSchema,\n UnImplementedSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { typeElementToSchema } from './type-element-to-schema';\n\n// eslint-disable-next-line complexity\nexport async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const location = context.getLocation(node);\n if (isKeywordType(node)) {\n return new KeywordTypeSchema(location, node.getText());\n }\n switch (node.kind) {\n case SyntaxKind.IntersectionType:\n return intersectionType(node as IntersectionTypeNode, context);\n case SyntaxKind.UnionType:\n return unionType(node as UnionTypeNode, context);\n case SyntaxKind.TypeReference:\n return typeReference(node as TypeReferenceNode, context);\n case SyntaxKind.TypeLiteral:\n return typeLiteral(node as TypeLiteralNode, context);\n case SyntaxKind.LiteralType: // e.g. string/boolean\n return new LiteralTypeSchema(location, node.getText());\n case SyntaxKind.FunctionType:\n return functionType(node as FunctionTypeNode, context);\n case SyntaxKind.TypeQuery:\n return typeQuery(node as TypeQueryNode, context);\n case SyntaxKind.ArrayType:\n return arrayType(node as ArrayTypeNode, context);\n case SyntaxKind.TypeOperator:\n return typeOperator(node as TypeOperatorNode, context);\n case SyntaxKind.TupleType:\n return tupleType(node as TupleTypeNode, context);\n case SyntaxKind.ParenthesizedType:\n return parenthesizedType(node as ParenthesizedTypeNode, context);\n case SyntaxKind.TypePredicate:\n return typePredicate(node as TypePredicateNode, context);\n case SyntaxKind.IndexedAccessType:\n return indexedAccessType(node as IndexedAccessTypeNode, context);\n case SyntaxKind.TemplateLiteralTypeSpan:\n return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);\n case SyntaxKind.TemplateLiteralType:\n return templateLiteralType(node as TemplateLiteralTypeNode, context);\n case SyntaxKind.ThisType:\n return thisType(node as ThisTypeNode, context);\n case SyntaxKind.ConditionalType:\n return conditionalType(node as ConditionalTypeNode, context);\n case SyntaxKind.NamedTupleMember:\n return namedTupleType(node as NamedTupleMember, context);\n case SyntaxKind.ConstructorType:\n case SyntaxKind.OptionalType:\n case SyntaxKind.RestType:\n case SyntaxKind.InferType:\n case SyntaxKind.MappedType:\n case SyntaxKind.ImportType:\n case SyntaxKind.ExpressionWithTypeArguments:\n case SyntaxKind.JSDocTypeExpression:\n case SyntaxKind.JSDocAllType:\n case SyntaxKind.JSDocUnknownType:\n case SyntaxKind.JSDocNonNullableType:\n case SyntaxKind.JSDocNullableType:\n case SyntaxKind.JSDocOptionalType:\n case SyntaxKind.JSDocFunctionType:\n case SyntaxKind.JSDocVariadicType:\n case SyntaxKind.JSDocNamepathType:\n case SyntaxKind.JSDocSignature:\n case SyntaxKind.JSDocTypeLiteral:\n return unimplementedSchema(node, context);\n default:\n return unimplementedSchema(node, context);\n }\n}\n\nfunction unimplementedSchema(node: TypeNode, context: SchemaExtractorContext) {\n return new UnImplementedSchema(context.getLocation(node), node.getText(), SyntaxKind[node.kind]);\n}\n/**\n * whether it's kind of `ts.KeywordTypeSyntaxKind`\n */\nfunction isKeywordType(node: TypeNode): node is KeywordTypeNode {\n switch (node.kind) {\n case SyntaxKind.AnyKeyword:\n case SyntaxKind.BigIntKeyword:\n case SyntaxKind.BooleanKeyword:\n case SyntaxKind.IntrinsicKeyword:\n case SyntaxKind.NeverKeyword:\n case SyntaxKind.NumberKeyword:\n case SyntaxKind.ObjectKeyword:\n case SyntaxKind.StringKeyword:\n case SyntaxKind.SymbolKeyword:\n case SyntaxKind.UndefinedKeyword:\n case SyntaxKind.UnknownKeyword:\n case SyntaxKind.VoidKeyword:\n return true;\n default:\n return false;\n }\n}\n\nasync function intersectionType(node: IntersectionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeIntersectionSchema(location, types);\n}\n\nasync function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeUnionSchema(location, types);\n}\n\n/**\n * not to be confused with \"LiteralType\", which is string/boolean/null.\n * this \"TypeLiteral\" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.\n */\nasync function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {\n const members = await pMapSeries(node.members, (member) => typeElementToSchema(member, context));\n const location = context.getLocation(node);\n return new TypeLiteralSchema(location, members);\n}\n\n/**\n * In the following example, `AriaButtonProps` is a type reference\n * ```ts\n * import type { AriaButtonProps } from '@react-types/button';\n * export type ButtonProps = AriaButtonProps & { a: string };\n * ```\n */\nasync function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {\n const name = node.typeName.getText();\n const type = await context.resolveType(node, name, false);\n if (node.typeArguments && type instanceof TypeRefSchema) {\n const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));\n type.typeArgs = args;\n }\n return type;\n}\n\nasync function functionType(node: FunctionTypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = node.name?.getText() || '';\n const params = await getParams(node.parameters, context);\n const returnType = await typeNodeToSchema(node.type, context);\n const location = context.getLocation(node);\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await context.jsDocToDocSchema(node);\n return new FunctionLikeSchema(location, name, params, returnType, '', modifiers as Modifier[], doc);\n}\n\n/**\n * e.g. `typeof Foo`\n */\nasync function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {\n const displaySig = await context.getQuickInfoDisplayString(node.exprName);\n const type = await context.resolveType(node.exprName, node.exprName.getText(), false);\n const location = context.getLocation(node);\n return new TypeQuerySchema(location, type, displaySig);\n}\n\nasync function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.elementType, context);\n const location = context.getLocation(node);\n return new TypeArraySchema(location, type);\n}\n\n/**\n * e.g. keyof typeof Foo\n */\nasync function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {\n const operatorName = getOperatorName(node.operator);\n const type = await typeNodeToSchema(node.type, context);\n return new TypeOperatorSchema(context.getLocation(node), operatorName, type);\n}\n\nfunction getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {\n switch (operator) {\n case SyntaxKind.KeyOfKeyword:\n return 'keyof';\n case SyntaxKind.UniqueKeyword:\n return 'unique';\n case SyntaxKind.ReadonlyKeyword:\n return 'readonly';\n default:\n throw new Error(`getOperatorName: unable to find operator name for ${operator}`);\n }\n}\n\nasync function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {\n const elements = await pMapSeries(node.elements, async (elem) => {\n const typeSchema = await typeNodeToSchema(elem, context);\n return typeSchema;\n });\n return new TupleTypeSchema(context.getLocation(node), elements);\n}\n\nasync function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n return new ParenthesizedTypeSchema(context.getLocation(node), type);\n}\n\nasync function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {\n const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';\n const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;\n const hasAssertsModifier = Boolean(node.assertsModifier);\n return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);\n}\n\nasync function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {\n const objectType = await typeNodeToSchema(node.objectType, context);\n const indexType = await typeNodeToSchema(node.indexType, context);\n return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);\n}\n\nasync function templateLiteralType(node: TemplateLiteralTypeNode, context: SchemaExtractorContext) {\n const templateSpans = await pMapSeries(node.templateSpans, (span) => templateLiteralTypeSpan(span, context));\n const head = node.head.text;\n return new TemplateLiteralTypeSchema(context.getLocation(node), head, templateSpans);\n}\n\nasync function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n const literal = node.literal.text;\n return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);\n}\n\nasync function thisType(node: ThisTypeNode, context: SchemaExtractorContext) {\n return new ThisTypeSchema(context.getLocation(node));\n}\n\nasync function conditionalType(node: ConditionalTypeNode, context: SchemaExtractorContext) {\n const checkType = await typeNodeToSchema(node.checkType, context);\n const extendsType = await typeNodeToSchema(node.extendsType, context);\n const trueType = await typeNodeToSchema(node.trueType, context);\n const falseType = await typeNodeToSchema(node.falseType, context);\n return new ConditionalTypeSchema(context.getLocation(node), checkType, extendsType, trueType, falseType);\n}\n\nasync function namedTupleType(node: NamedTupleMember, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const location = context.getLocation(node);\n const type = await typeNodeToSchema(node.type, context);\n return new NamedTupleSchema(location, type, name);\n}\n"],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AE;EAC3E,OAAO,KAAI2I,mCAAc,EAAC3I,OAAO,CAACE,WAAW,CAACH,IAAI,CAAC,CAAC;AACtD;AAEA,eAAe0C,eAAe,CAAC1C,IAAyB,EAAEC,OAA+B,EAAE;EACzF,MAAM4I,SAAS,GAAG,MAAM9I,gBAAgB,CAACC,IAAI,CAAC6I,SAAS,EAAE5I,OAAO,CAAC;EACjE,MAAM6I,WAAW,GAAG,MAAM/I,gBAAgB,CAACC,IAAI,CAAC8I,WAAW,EAAE7I,OAAO,CAAC;EACrE,MAAM8I,QAAQ,GAAG,MAAMhJ,gBAAgB,CAACC,IAAI,CAAC+I,QAAQ,EAAE9I,OAAO,CAAC;EAC/D,MAAM+I,SAAS,GAAG,MAAMjJ,gBAAgB,CAACC,IAAI,CAACgJ,SAAS,EAAE/I,OAAO,CAAC;EACjE,OAAO,KAAIgJ,0CAAqB,EAAChJ,OAAO,CAACE,WAAW,CAACH,IAAI,CAAC,EAAE6I,SAAS,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,CAAC;AAC1G;AAEA,eAAepG,cAAc,CAAC5C,IAAsB,EAAEC,OAA+B,EAAE;EACrF,MAAMsF,IAAI,GAAGvF,IAAI,CAACuF,IAAI,CAACjF,OAAO,EAAE;EAChC,MAAMJ,QAAQ,GAAGD,OAAO,CAACE,WAAW,CAACH,IAAI,CAAC;EAC1C,MAAM+E,IAAI,GAAG,MAAMhF,gBAAgB,CAACC,IAAI,CAAC+E,IAAI,EAAE9E,OAAO,CAAC;EACvD,OAAO,KAAIiJ,qCAAgB,EAAChJ,QAAQ,EAAE6E,IAAI,EAAEQ,IAAI,CAAC;AACnD"}
|
|
Binary file
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typescript';
|
|
3
|
-
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
|
-
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
-
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
-
import { toFunctionLikeSchema } from './utils/to-function-like-schema';
|
|
7
|
-
|
|
8
|
-
export class FunctionDeclaration implements SchemaTransformer {
|
|
9
|
-
predicate(node: Node) {
|
|
10
|
-
return node.kind === ts.SyntaxKind.FunctionDeclaration || node.kind === ts.SyntaxKind.ArrowFunction;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// need to check for anonymous functions assigned for vars, const and let.
|
|
14
|
-
async getIdentifiers(funcDec: FunctionDeclarationNode) {
|
|
15
|
-
return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private getName(funcDec: FunctionDeclarationNode) {
|
|
19
|
-
return funcDec.name?.getText() || '';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
23
|
-
return toFunctionLikeSchema(funcDec, context);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClassElement,
|
|
3
|
-
ConstructorDeclaration,
|
|
4
|
-
GetAccessorDeclaration,
|
|
5
|
-
IndexSignatureDeclaration,
|
|
6
|
-
MethodDeclaration,
|
|
7
|
-
PropertyDeclaration,
|
|
8
|
-
SetAccessorDeclaration,
|
|
9
|
-
SyntaxKind,
|
|
10
|
-
} from 'typescript';
|
|
11
|
-
import { ConstructorSchema, SchemaNode, VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
12
|
-
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
13
|
-
import { getParams } from './get-params';
|
|
14
|
-
import { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';
|
|
15
|
-
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
16
|
-
import { toFunctionLikeSchema } from './to-function-like-schema';
|
|
17
|
-
|
|
18
|
-
export async function classElementToSchema(
|
|
19
|
-
node: ClassElement,
|
|
20
|
-
context: SchemaExtractorContext
|
|
21
|
-
): Promise<SchemaNode | null> {
|
|
22
|
-
switch (node.kind) {
|
|
23
|
-
case SyntaxKind.Constructor:
|
|
24
|
-
return constructor(node as ConstructorDeclaration, context);
|
|
25
|
-
case SyntaxKind.PropertyDeclaration:
|
|
26
|
-
return propertyDeclaration(node as PropertyDeclaration, context);
|
|
27
|
-
case SyntaxKind.MethodDeclaration:
|
|
28
|
-
return methodDeclaration(node as MethodDeclaration, context);
|
|
29
|
-
case SyntaxKind.GetAccessor:
|
|
30
|
-
return getAccessor(node as GetAccessorDeclaration, context);
|
|
31
|
-
case SyntaxKind.SetAccessor:
|
|
32
|
-
return setAccessor(node as SetAccessorDeclaration, context);
|
|
33
|
-
case SyntaxKind.IndexSignature:
|
|
34
|
-
return indexSignature(node as IndexSignatureDeclaration, context);
|
|
35
|
-
case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need
|
|
36
|
-
case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon
|
|
37
|
-
return null;
|
|
38
|
-
default:
|
|
39
|
-
// should never be here unless typescript added new class elements
|
|
40
|
-
throw new Error(`unrecognized ClassElement type. got ${node.kind}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {
|
|
45
|
-
const args = await getParams(node.parameters, context);
|
|
46
|
-
const info = await context.getQuickInfo(node);
|
|
47
|
-
const displaySig = info?.body?.displayString;
|
|
48
|
-
return new ConstructorSchema(context.getLocation(node), args, displaySig);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {
|
|
52
|
-
const name = node.name.getText();
|
|
53
|
-
const info = await context.getQuickInfo(node.name);
|
|
54
|
-
const displaySig = info?.body?.displayString;
|
|
55
|
-
const typeStr = parseTypeFromQuickInfo(info);
|
|
56
|
-
const type = await context.resolveType(node, typeStr);
|
|
57
|
-
const isOptional = Boolean(node.questionToken);
|
|
58
|
-
const doc = await context.jsDocToDocSchema(node);
|
|
59
|
-
return new VariableLikeSchema(context.getLocation(node), name, displaySig || '', type, isOptional, doc);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
|
|
63
|
-
return toFunctionLikeSchema(node, context);
|
|
64
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
InferenceTypeSchema,
|
|
3
|
-
ParameterSchema,
|
|
4
|
-
TupleTypeSchema,
|
|
5
|
-
TypeLiteralSchema,
|
|
6
|
-
SchemaNode,
|
|
7
|
-
} from '@teambit/semantics.entities.semantic-schema';
|
|
8
|
-
import pMapSeries from 'p-map-series';
|
|
9
|
-
import {
|
|
10
|
-
SyntaxKind,
|
|
11
|
-
ParameterDeclaration,
|
|
12
|
-
NodeArray,
|
|
13
|
-
isIdentifier,
|
|
14
|
-
BindingElement,
|
|
15
|
-
ArrayBindingElement,
|
|
16
|
-
} from 'typescript';
|
|
17
|
-
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
18
|
-
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
19
|
-
import { typeNodeToSchema } from './type-node-to-schema';
|
|
20
|
-
|
|
21
|
-
export async function getParams(
|
|
22
|
-
parameterNodes: NodeArray<ParameterDeclaration>,
|
|
23
|
-
context: SchemaExtractorContext
|
|
24
|
-
): Promise<ParameterSchema[]> {
|
|
25
|
-
return pMapSeries(parameterNodes, async (param) => {
|
|
26
|
-
return new ParameterSchema(
|
|
27
|
-
context.getLocation(param),
|
|
28
|
-
getParamName(param),
|
|
29
|
-
await getParamType(param, context),
|
|
30
|
-
Boolean(param.questionToken),
|
|
31
|
-
param.initializer ? param.initializer.getText() : undefined,
|
|
32
|
-
undefined,
|
|
33
|
-
await getParamObjectBindingNodes(param, context)
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getParamName(param: ParameterDeclaration): string {
|
|
39
|
-
if (isIdentifier(param.name)) {
|
|
40
|
-
return param.name.getText();
|
|
41
|
-
}
|
|
42
|
-
// it's binding pattern, either an array or an object
|
|
43
|
-
const elements = param.name.elements.map((elem) => elem.getText());
|
|
44
|
-
const elementsStr = elements.join(', ');
|
|
45
|
-
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
46
|
-
return `[ ${elementsStr} ]`;
|
|
47
|
-
}
|
|
48
|
-
// it's an object binding
|
|
49
|
-
return `{ ${elementsStr} }`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function getParamObjectBindingNodes(
|
|
53
|
-
param: ParameterDeclaration,
|
|
54
|
-
context: SchemaExtractorContext
|
|
55
|
-
): Promise<SchemaNode[] | undefined> {
|
|
56
|
-
if (param.name.kind !== SyntaxKind.ObjectBindingPattern) return undefined;
|
|
57
|
-
return pMapSeries(param.name.elements, async (elem: BindingElement) => {
|
|
58
|
-
const info = await context.getQuickInfo(elem.name);
|
|
59
|
-
const parsed = parseTypeFromQuickInfo(info);
|
|
60
|
-
return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
65
|
-
if (param.type) {
|
|
66
|
-
const type = param.type;
|
|
67
|
-
return typeNodeToSchema(type, context);
|
|
68
|
-
}
|
|
69
|
-
if (isIdentifier(param.name)) {
|
|
70
|
-
const info = await context.getQuickInfo(param.name);
|
|
71
|
-
const parsed = parseTypeFromQuickInfo(info);
|
|
72
|
-
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
73
|
-
}
|
|
74
|
-
// it's binding pattern, either an array or an object
|
|
75
|
-
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
76
|
-
const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {
|
|
77
|
-
const info = await context.getQuickInfo(elem);
|
|
78
|
-
const parsed = parseTypeFromQuickInfo(info);
|
|
79
|
-
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
80
|
-
});
|
|
81
|
-
return new TupleTypeSchema(context.getLocation(param), elements);
|
|
82
|
-
}
|
|
83
|
-
if (param.name.kind === SyntaxKind.ObjectBindingPattern) {
|
|
84
|
-
const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {
|
|
85
|
-
const info = await context.getQuickInfo(elem.name);
|
|
86
|
-
const parsed = parseTypeFromQuickInfo(info);
|
|
87
|
-
return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());
|
|
88
|
-
});
|
|
89
|
-
return new TypeLiteralSchema(context.getLocation(param), elements);
|
|
90
|
-
}
|
|
91
|
-
throw new Error(`unknown param type`);
|
|
92
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { SignatureDeclaration, SyntaxKind } from 'typescript';
|
|
2
|
-
import { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
-
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
4
|
-
import { getParams } from './get-params';
|
|
5
|
-
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
6
|
-
|
|
7
|
-
export async function toFunctionLikeSchema(
|
|
8
|
-
node: SignatureDeclaration,
|
|
9
|
-
context: SchemaExtractorContext,
|
|
10
|
-
funcName?: string
|
|
11
|
-
) {
|
|
12
|
-
const name = funcName || node.name?.getText() || '';
|
|
13
|
-
const getQuickInfoFromDefaultModifier = async () => {
|
|
14
|
-
const defaultModifier = node.modifiers?.find((modifier) => modifier.kind === SyntaxKind.DefaultKeyword);
|
|
15
|
-
if (defaultModifier) return context.getQuickInfo(defaultModifier);
|
|
16
|
-
if (node.kind === SyntaxKind.ArrowFunction) return context.getQuickInfo(node.equalsGreaterThanToken);
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
const info = node.name ? await context.getQuickInfo(node.name) : await getQuickInfoFromDefaultModifier();
|
|
20
|
-
const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';
|
|
21
|
-
const displaySig = info?.body?.displayString || '';
|
|
22
|
-
const args = await getParams(node.parameters, context);
|
|
23
|
-
|
|
24
|
-
const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
|
|
25
|
-
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
26
|
-
const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());
|
|
27
|
-
const location = context.getLocation(node);
|
|
28
|
-
const doc = await context.jsDocToDocSchema(node);
|
|
29
|
-
return new FunctionLikeSchema(
|
|
30
|
-
location,
|
|
31
|
-
name,
|
|
32
|
-
args,
|
|
33
|
-
returnType,
|
|
34
|
-
displaySig,
|
|
35
|
-
modifiers as Modifier[],
|
|
36
|
-
doc,
|
|
37
|
-
typeParameters
|
|
38
|
-
);
|
|
39
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import ts, {
|
|
2
|
-
SyntaxKind,
|
|
3
|
-
TypeElement,
|
|
4
|
-
MethodSignature,
|
|
5
|
-
isComputedPropertyName,
|
|
6
|
-
IndexSignatureDeclaration,
|
|
7
|
-
GetAccessorDeclaration,
|
|
8
|
-
SetAccessorDeclaration,
|
|
9
|
-
ConstructSignatureDeclaration,
|
|
10
|
-
CallSignatureDeclaration,
|
|
11
|
-
} from 'typescript';
|
|
12
|
-
import {
|
|
13
|
-
GetAccessorSchema,
|
|
14
|
-
IndexSignatureSchema,
|
|
15
|
-
SchemaNode,
|
|
16
|
-
SetAccessorSchema,
|
|
17
|
-
VariableLikeSchema,
|
|
18
|
-
} from '@teambit/semantics.entities.semantic-schema';
|
|
19
|
-
import { toFunctionLikeSchema } from './to-function-like-schema';
|
|
20
|
-
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
21
|
-
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
22
|
-
import { typeNodeToSchema } from './type-node-to-schema';
|
|
23
|
-
import { getParams } from './get-params';
|
|
24
|
-
|
|
25
|
-
export async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
26
|
-
switch (node.kind) {
|
|
27
|
-
case SyntaxKind.MethodSignature:
|
|
28
|
-
return toFunctionLikeSchema(node as MethodSignature, context);
|
|
29
|
-
case SyntaxKind.ConstructSignature:
|
|
30
|
-
return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');
|
|
31
|
-
case SyntaxKind.CallSignature:
|
|
32
|
-
return callSignature(node as CallSignatureDeclaration, context);
|
|
33
|
-
case SyntaxKind.PropertySignature:
|
|
34
|
-
return propertySignature(node as ts.PropertySignature, context);
|
|
35
|
-
case SyntaxKind.IndexSignature:
|
|
36
|
-
return indexSignature(node as IndexSignatureDeclaration, context);
|
|
37
|
-
case SyntaxKind.GetAccessor:
|
|
38
|
-
return getAccessor(node as GetAccessorDeclaration, context);
|
|
39
|
-
case SyntaxKind.SetAccessor:
|
|
40
|
-
return setAccessor(node as SetAccessorDeclaration, context);
|
|
41
|
-
default:
|
|
42
|
-
throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {
|
|
47
|
-
const name = node.name.getText();
|
|
48
|
-
const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);
|
|
49
|
-
const displaySig = info?.body?.displayString || '';
|
|
50
|
-
const typeStr = parseTypeFromQuickInfo(info);
|
|
51
|
-
const type = await context.resolveType(node, typeStr);
|
|
52
|
-
const isOptional = Boolean(node.questionToken);
|
|
53
|
-
const doc = await context.jsDocToDocSchema(node);
|
|
54
|
-
return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, isOptional, doc);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {
|
|
58
|
-
const params = await getParams(node.parameters, context);
|
|
59
|
-
const type = await typeNodeToSchema(node.type, context);
|
|
60
|
-
return new IndexSignatureSchema(context.getLocation(node), params, type);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
64
|
-
const info = await context.getQuickInfo(node.name);
|
|
65
|
-
const displaySig = info?.body?.displayString || '';
|
|
66
|
-
const typeStr = parseTypeFromQuickInfo(info);
|
|
67
|
-
const type = await context.resolveType(node, typeStr);
|
|
68
|
-
return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
72
|
-
const params = await getParams(node.parameters, context);
|
|
73
|
-
const displaySig = await context.getQuickInfoDisplayString(node.name);
|
|
74
|
-
return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {
|
|
78
|
-
return toFunctionLikeSchema(node, context);
|
|
79
|
-
}
|