@teambit/typescript 0.0.736 → 0.0.739
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/cmds/check-types.cmd.js.map +1 -1
- package/dist/cmds/init.cmd.js.map +1 -1
- package/dist/compiler-options.js.map +1 -1
- package/dist/exceptions/index.js.map +1 -1
- package/dist/exceptions/transformer-not-found.d.ts +2 -1
- package/dist/exceptions/transformer-not-found.js +3 -2
- package/dist/exceptions/transformer-not-found.js.map +1 -1
- package/dist/export-identifier.js.map +1 -1
- package/dist/export-list.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/schema-extractor-context.d.ts +6 -2
- package/dist/schema-extractor-context.js +35 -8
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/schema-transformer.js.map +1 -1
- package/dist/schema-transformer.plugin.js.map +1 -1
- package/dist/transformers/class-deceleration.js +11 -3
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/constructor.js +1 -1
- package/dist/transformers/constructor.js.map +1 -1
- package/dist/transformers/enum-declaration.d.ts +10 -0
- package/dist/transformers/enum-declaration.js +60 -0
- package/dist/transformers/enum-declaration.js.map +1 -0
- package/dist/transformers/export-declaration.js +1 -1
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-declaration.js.map +1 -1
- package/dist/transformers/index-signature.js +1 -1
- package/dist/transformers/index-signature.js.map +1 -1
- package/dist/transformers/index.d.ts +1 -0
- package/dist/transformers/index.js +16 -0
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/interface-declaration.js +1 -1
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/literal-type.d.ts +2 -1
- package/dist/transformers/literal-type.js +2 -2
- package/dist/transformers/literal-type.js.map +1 -1
- package/dist/transformers/method-declaration.js.map +1 -1
- package/dist/transformers/method-signature.js.map +1 -1
- package/dist/transformers/property-declaration.js +1 -1
- package/dist/transformers/property-declaration.js.map +1 -1
- package/dist/transformers/property-signature.js +1 -1
- package/dist/transformers/property-signature.js.map +1 -1
- package/dist/transformers/source-file-transformer.js +1 -1
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/type-alias.js +1 -1
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/utils/get-params.js +54 -4
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.d.ts +1 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js +12 -3
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/utils/to-function-schema.js +2 -2
- package/dist/transformers/utils/to-function-schema.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.js +51 -14
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +3 -3
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/transformers/variable-statement.js +2 -3
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.aspect.js.map +1 -1
- package/dist/typescript.compiler.js.map +1 -1
- package/dist/typescript.compiler.spec.js.map +1 -1
- package/dist/typescript.composition.js.map +1 -1
- package/dist/typescript.extractor.d.ts +7 -1
- package/dist/typescript.extractor.js +33 -12
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +11 -2
- package/dist/typescript.main.runtime.js +17 -6
- package/dist/typescript.main.runtime.js.map +1 -1
- package/dist/typescript.parser.d.ts +2 -2
- package/dist/typescript.parser.js +4 -4
- package/dist/typescript.parser.js.map +1 -1
- package/dist/typescript.parser.spec.js.map +1 -1
- package/exceptions/transformer-not-found.ts +4 -2
- package/package-tar/teambit-typescript-0.0.739.tgz +0 -0
- package/package.json +12 -11
- package/{preview-1652844422371.js → preview-1653362849981.js} +2 -2
- package/transformers/class-deceleration.ts +6 -3
- package/transformers/constructor.ts +1 -1
- package/transformers/enum-declaration.ts +20 -0
- package/transformers/export-declaration.ts +1 -1
- package/transformers/index-signature.ts +1 -1
- package/transformers/index.ts +1 -0
- package/transformers/interface-declaration.ts +1 -1
- package/transformers/literal-type.ts +3 -2
- package/transformers/property-declaration.ts +1 -1
- package/transformers/property-signature.ts +1 -1
- package/transformers/source-file-transformer.ts +1 -1
- package/transformers/type-alias.ts +1 -1
- package/transformers/utils/get-params.ts +54 -6
- package/transformers/utils/parse-type-from-quick-info.ts +9 -1
- package/transformers/utils/to-function-schema.ts +2 -2
- package/transformers/utils/type-node-to-schema.ts +53 -14
- package/transformers/variable-declaration.ts +3 -3
- package/transformers/variable-statement.ts +1 -2
- package/tsconfig.json +1 -1
- package/dist/transformers/export-declaration-type.d.ts +0 -0
- package/dist/transformers/export-declaration-type.js +0 -3
- package/dist/transformers/export-declaration-type.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.736.tgz +0 -0
- package/transformers/export-declaration-type.ts +0 -0
|
@@ -22,6 +22,6 @@ export class TypeAliasTransformer implements SchemaTransformer {
|
|
|
22
22
|
const type = await typeNodeToSchema(typeAlias.type, context);
|
|
23
23
|
const info = await context.getQuickInfo(typeAlias.name);
|
|
24
24
|
const displaySig = info?.body?.displayString;
|
|
25
|
-
return new TypeSchema(this.getName(typeAlias), type, displaySig
|
|
25
|
+
return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
InferenceTypeSchema,
|
|
3
|
+
ParameterSchema,
|
|
4
|
+
TupleTypeSchema,
|
|
5
|
+
TypeLiteralSchema,
|
|
6
|
+
SchemaNode,
|
|
7
|
+
} from '@teambit/semantics.entities.semantic-schema';
|
|
2
8
|
import pMapSeries from 'p-map-series';
|
|
3
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
SyntaxKind,
|
|
11
|
+
ParameterDeclaration,
|
|
12
|
+
NodeArray,
|
|
13
|
+
isIdentifier,
|
|
14
|
+
BindingElement,
|
|
15
|
+
ArrayBindingElement,
|
|
16
|
+
} from 'typescript';
|
|
4
17
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
5
18
|
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
6
19
|
import { typeNodeToSchema } from './type-node-to-schema';
|
|
@@ -11,19 +24,54 @@ export async function getParams(
|
|
|
11
24
|
): Promise<ParameterSchema[]> {
|
|
12
25
|
return pMapSeries(parameterNodes, async (param) => {
|
|
13
26
|
return new ParameterSchema(
|
|
14
|
-
|
|
27
|
+
context.getLocation(param),
|
|
28
|
+
getParamName(param),
|
|
15
29
|
await getParamType(param, context),
|
|
16
30
|
param.initializer ? param.initializer.getText() : undefined
|
|
17
31
|
);
|
|
18
32
|
});
|
|
19
33
|
}
|
|
20
34
|
|
|
35
|
+
function getParamName(param: ParameterDeclaration): string {
|
|
36
|
+
if (isIdentifier(param.name)) {
|
|
37
|
+
return param.name.getText();
|
|
38
|
+
}
|
|
39
|
+
// it's binding pattern, either an array or an object
|
|
40
|
+
const elements = param.name.elements.map((elem) => elem.getText());
|
|
41
|
+
const elementsStr = elements.join(', ');
|
|
42
|
+
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
43
|
+
return `[ ${elementsStr} ]`;
|
|
44
|
+
}
|
|
45
|
+
// it's an object binding
|
|
46
|
+
return `{ ${elementsStr} }`;
|
|
47
|
+
}
|
|
48
|
+
|
|
21
49
|
async function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
22
50
|
if (param.type) {
|
|
23
51
|
const type = param.type;
|
|
24
52
|
return typeNodeToSchema(type, context);
|
|
25
53
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
54
|
+
if (isIdentifier(param.name)) {
|
|
55
|
+
const info = await context.getQuickInfo(param.name);
|
|
56
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
57
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
58
|
+
}
|
|
59
|
+
// it's binding pattern, either an array or an object
|
|
60
|
+
if (param.name.kind === SyntaxKind.ArrayBindingPattern) {
|
|
61
|
+
const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {
|
|
62
|
+
const info = await context.getQuickInfo(elem);
|
|
63
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
64
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed);
|
|
65
|
+
});
|
|
66
|
+
return new TupleTypeSchema(context.getLocation(param), elements);
|
|
67
|
+
}
|
|
68
|
+
if (param.name.kind === SyntaxKind.ObjectBindingPattern) {
|
|
69
|
+
const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {
|
|
70
|
+
const info = await context.getQuickInfo(elem.name);
|
|
71
|
+
const parsed = parseTypeFromQuickInfo(info);
|
|
72
|
+
return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());
|
|
73
|
+
});
|
|
74
|
+
return new TypeLiteralSchema(context.getLocation(param), elements);
|
|
75
|
+
}
|
|
76
|
+
throw new Error(`unknown param type`);
|
|
29
77
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-unresolved
|
|
2
2
|
import protocol from 'typescript/lib/protocol';
|
|
3
3
|
|
|
4
|
+
export const UNRESOLVED = '<<unresolved>>';
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* try to parse the type from the quickinfo.
|
|
6
8
|
* this is an error-prone process, we do our best here.
|
|
@@ -49,7 +51,13 @@ export function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | u
|
|
|
49
51
|
case 'function': {
|
|
50
52
|
const split = displayString.split('): ');
|
|
51
53
|
if (split.length !== 2) {
|
|
52
|
-
|
|
54
|
+
// it's hard to determine where the return-type is. so it's better to show unresolved.
|
|
55
|
+
// maybe, in the UI, in this case, it's best to show the signature.
|
|
56
|
+
// e.g.
|
|
57
|
+
// (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {
|
|
58
|
+
// new (): T;
|
|
59
|
+
// }): T | undefined
|
|
60
|
+
return UNRESOLVED;
|
|
53
61
|
}
|
|
54
62
|
return split[1].trim();
|
|
55
63
|
}
|
|
@@ -9,11 +9,11 @@ export async function toFunctionLikeSchema(node: SignatureDeclaration, context:
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
10
10
|
const info = await context.getQuickInfo(node.name!);
|
|
11
11
|
const returnTypeStr = parseTypeFromQuickInfo(info);
|
|
12
|
-
const displaySig = info?.body?.displayString;
|
|
12
|
+
const displaySig = info?.body?.displayString || '';
|
|
13
13
|
const args = await getParams(node.parameters, context);
|
|
14
14
|
const returnType = await context.resolveType(node, returnTypeStr);
|
|
15
15
|
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
16
16
|
const location = context.getLocation(node);
|
|
17
17
|
|
|
18
|
-
return new FunctionLikeSchema(name, args, returnType, displaySig
|
|
18
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[]);
|
|
19
19
|
}
|
|
@@ -11,9 +11,14 @@ import {
|
|
|
11
11
|
IntersectionTypeNode,
|
|
12
12
|
UnionTypeNode,
|
|
13
13
|
TypeLiteralNode,
|
|
14
|
+
ParenthesizedTypeNode,
|
|
15
|
+
TypePredicateNode,
|
|
16
|
+
isIdentifier,
|
|
17
|
+
IndexedAccessTypeNode,
|
|
14
18
|
} from 'typescript';
|
|
15
19
|
import {
|
|
16
20
|
SchemaNode,
|
|
21
|
+
TypeRefSchema,
|
|
17
22
|
TypeIntersectionSchema,
|
|
18
23
|
TypeUnionSchema,
|
|
19
24
|
TypeLiteralSchema,
|
|
@@ -24,6 +29,9 @@ import {
|
|
|
24
29
|
TypeOperatorSchema,
|
|
25
30
|
TupleTypeSchema,
|
|
26
31
|
FunctionLikeSchema,
|
|
32
|
+
ParenthesizedTypeSchema,
|
|
33
|
+
TypePredicateSchema,
|
|
34
|
+
IndexedAccessSchema,
|
|
27
35
|
} from '@teambit/semantics.entities.semantic-schema';
|
|
28
36
|
import pMapSeries from 'p-map-series';
|
|
29
37
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
@@ -31,8 +39,9 @@ import { getParams } from './get-params';
|
|
|
31
39
|
|
|
32
40
|
// eslint-disable-next-line complexity
|
|
33
41
|
export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
42
|
+
const location = context.getLocation(node);
|
|
34
43
|
if (isKeywordType(node)) {
|
|
35
|
-
return new KeywordTypeSchema(node.getText());
|
|
44
|
+
return new KeywordTypeSchema(location, node.getText());
|
|
36
45
|
}
|
|
37
46
|
switch (node.kind) {
|
|
38
47
|
case SyntaxKind.IntersectionType:
|
|
@@ -44,7 +53,7 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
|
|
|
44
53
|
case SyntaxKind.TypeLiteral:
|
|
45
54
|
return typeLiteral(node as TypeLiteralNode, context);
|
|
46
55
|
case SyntaxKind.LiteralType: // e.g. string/boolean
|
|
47
|
-
return new LiteralTypeSchema(node.getText());
|
|
56
|
+
return new LiteralTypeSchema(location, node.getText());
|
|
48
57
|
case SyntaxKind.FunctionType:
|
|
49
58
|
return functionType(node as FunctionTypeNode, context);
|
|
50
59
|
case SyntaxKind.TypeQuery:
|
|
@@ -55,16 +64,19 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
|
|
|
55
64
|
return typeOperator(node as TypeOperatorNode, context);
|
|
56
65
|
case SyntaxKind.TupleType:
|
|
57
66
|
return tupleType(node as TupleTypeNode, context);
|
|
67
|
+
case SyntaxKind.ParenthesizedType:
|
|
68
|
+
return parenthesizedType(node as ParenthesizedTypeNode, context);
|
|
58
69
|
case SyntaxKind.TypePredicate:
|
|
70
|
+
return typePredicate(node as TypePredicateNode, context);
|
|
71
|
+
case SyntaxKind.IndexedAccessType:
|
|
72
|
+
return indexedAccessType(node as IndexedAccessTypeNode, context);
|
|
59
73
|
case SyntaxKind.ConstructorType:
|
|
60
74
|
case SyntaxKind.NamedTupleMember:
|
|
61
75
|
case SyntaxKind.OptionalType:
|
|
62
76
|
case SyntaxKind.RestType:
|
|
63
77
|
case SyntaxKind.ConditionalType:
|
|
64
78
|
case SyntaxKind.InferType:
|
|
65
|
-
case SyntaxKind.ParenthesizedType:
|
|
66
79
|
case SyntaxKind.ThisType:
|
|
67
|
-
case SyntaxKind.IndexedAccessType:
|
|
68
80
|
case SyntaxKind.MappedType:
|
|
69
81
|
case SyntaxKind.TemplateLiteralType:
|
|
70
82
|
case SyntaxKind.TemplateLiteralTypeSpan:
|
|
@@ -81,10 +93,10 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
|
|
|
81
93
|
case SyntaxKind.JSDocNamepathType:
|
|
82
94
|
case SyntaxKind.JSDocSignature:
|
|
83
95
|
case SyntaxKind.JSDocTypeLiteral:
|
|
84
|
-
throw new Error(`TypeNode
|
|
96
|
+
throw new Error(`TypeNode ${node.kind} (probably ${SyntaxKind[node.kind]}) was not implemented yet.
|
|
85
97
|
context: ${node.getText()}`);
|
|
86
98
|
default:
|
|
87
|
-
throw new Error(`Node
|
|
99
|
+
throw new Error(`Node ${node.kind} (probably ${SyntaxKind[node.kind]}) is not a TypeNode.
|
|
88
100
|
context: ${node.getText()}`);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
@@ -117,7 +129,8 @@ async function intersectionType(node: IntersectionTypeNode, context: SchemaExtra
|
|
|
117
129
|
const typeSchema = await typeNodeToSchema(type, context);
|
|
118
130
|
return typeSchema;
|
|
119
131
|
});
|
|
120
|
-
|
|
132
|
+
const location = context.getLocation(node);
|
|
133
|
+
return new TypeIntersectionSchema(location, types);
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
async function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {
|
|
@@ -125,7 +138,8 @@ async function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {
|
|
|
125
138
|
const typeSchema = await typeNodeToSchema(type, context);
|
|
126
139
|
return typeSchema;
|
|
127
140
|
});
|
|
128
|
-
|
|
141
|
+
const location = context.getLocation(node);
|
|
142
|
+
return new TypeUnionSchema(location, types);
|
|
129
143
|
}
|
|
130
144
|
|
|
131
145
|
/**
|
|
@@ -137,7 +151,8 @@ async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContex
|
|
|
137
151
|
const typeSchema = await context.computeSchema(member);
|
|
138
152
|
return typeSchema;
|
|
139
153
|
});
|
|
140
|
-
|
|
154
|
+
const location = context.getLocation(node);
|
|
155
|
+
return new TypeLiteralSchema(location, members);
|
|
141
156
|
}
|
|
142
157
|
|
|
143
158
|
/**
|
|
@@ -150,6 +165,10 @@ async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContex
|
|
|
150
165
|
async function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {
|
|
151
166
|
const name = node.typeName.getText();
|
|
152
167
|
const type = await context.resolveType(node, name, false);
|
|
168
|
+
if (node.typeArguments && type instanceof TypeRefSchema) {
|
|
169
|
+
const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));
|
|
170
|
+
type.typeArgs = args;
|
|
171
|
+
}
|
|
153
172
|
return type;
|
|
154
173
|
}
|
|
155
174
|
|
|
@@ -158,7 +177,7 @@ async function functionType(node: FunctionTypeNode, context: SchemaExtractorCont
|
|
|
158
177
|
const params = await getParams(node.parameters, context);
|
|
159
178
|
const returnType = await typeNodeToSchema(node.type, context);
|
|
160
179
|
const location = context.getLocation(node);
|
|
161
|
-
return new FunctionLikeSchema(name, params, returnType, ''
|
|
180
|
+
return new FunctionLikeSchema(location, name, params, returnType, '');
|
|
162
181
|
}
|
|
163
182
|
|
|
164
183
|
/**
|
|
@@ -167,12 +186,14 @@ async function functionType(node: FunctionTypeNode, context: SchemaExtractorCont
|
|
|
167
186
|
async function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {
|
|
168
187
|
const displaySig = await context.getQuickInfoDisplayString(node.exprName);
|
|
169
188
|
const type = await context.resolveType(node.exprName, node.exprName.getText(), false);
|
|
170
|
-
|
|
189
|
+
const location = context.getLocation(node);
|
|
190
|
+
return new TypeQuerySchema(location, type, displaySig);
|
|
171
191
|
}
|
|
172
192
|
|
|
173
193
|
async function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {
|
|
174
194
|
const type = await typeNodeToSchema(node.elementType, context);
|
|
175
|
-
|
|
195
|
+
const location = context.getLocation(node);
|
|
196
|
+
return new TypeArraySchema(location, type);
|
|
176
197
|
}
|
|
177
198
|
|
|
178
199
|
/**
|
|
@@ -181,7 +202,7 @@ async function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {
|
|
|
181
202
|
async function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {
|
|
182
203
|
const operatorName = getOperatorName(node.operator);
|
|
183
204
|
const type = await typeNodeToSchema(node.type, context);
|
|
184
|
-
return new TypeOperatorSchema(operatorName, type);
|
|
205
|
+
return new TypeOperatorSchema(context.getLocation(node), operatorName, type);
|
|
185
206
|
}
|
|
186
207
|
|
|
187
208
|
function getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {
|
|
@@ -202,5 +223,23 @@ async function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {
|
|
|
202
223
|
const typeSchema = await typeNodeToSchema(elem, context);
|
|
203
224
|
return typeSchema;
|
|
204
225
|
});
|
|
205
|
-
return new TupleTypeSchema(elements);
|
|
226
|
+
return new TupleTypeSchema(context.getLocation(node), elements);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {
|
|
230
|
+
const type = await typeNodeToSchema(node.type, context);
|
|
231
|
+
return new ParenthesizedTypeSchema(context.getLocation(node), type);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {
|
|
235
|
+
const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';
|
|
236
|
+
const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;
|
|
237
|
+
const hasAssertsModifier = Boolean(node.assertsModifier);
|
|
238
|
+
return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {
|
|
242
|
+
const objectType = await typeNodeToSchema(node.objectType, context);
|
|
243
|
+
const indexType = await typeNodeToSchema(node.indexType, context);
|
|
244
|
+
return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);
|
|
206
245
|
}
|
|
@@ -23,15 +23,15 @@ export class VariableDeclaration implements SchemaTransformer {
|
|
|
23
23
|
const name = this.getName(varDec);
|
|
24
24
|
const info = await context.getQuickInfo(varDec.name);
|
|
25
25
|
const displaySig = info?.body?.displayString || '';
|
|
26
|
+
const location = context.getLocation(varDec);
|
|
26
27
|
if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {
|
|
27
28
|
const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);
|
|
28
29
|
const typeStr = parseReturnTypeFromQuickInfo(info);
|
|
29
30
|
const returnType = await context.resolveType(varDec, typeStr);
|
|
30
|
-
|
|
31
|
-
return new FunctionLikeSchema(name, args, returnType, displaySig, location);
|
|
31
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig);
|
|
32
32
|
}
|
|
33
33
|
const typeStr = parseTypeFromQuickInfo(info);
|
|
34
34
|
const type = await context.resolveType(varDec, typeStr);
|
|
35
|
-
return new VariableSchema(name, displaySig, type);
|
|
35
|
+
return new VariableSchema(location, name, displaySig, type);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -27,7 +27,6 @@ export class VariableStatementTransformer implements SchemaTransformer {
|
|
|
27
27
|
const schema = await context.visitDefinition(dec.name);
|
|
28
28
|
return schema;
|
|
29
29
|
});
|
|
30
|
-
|
|
31
|
-
return new Module(compact(schemas));
|
|
30
|
+
return new Module(context.getLocation(node), compact(schemas));
|
|
32
31
|
}
|
|
33
32
|
}
|
package/tsconfig.json
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"declaration": true,
|
|
16
16
|
"sourceMap": true,
|
|
17
17
|
"skipLibCheck": true,
|
|
18
|
+
"experimentalDecorators": true,
|
|
18
19
|
"outDir": "dist",
|
|
19
20
|
"moduleResolution": "node",
|
|
20
21
|
"esModuleInterop": true,
|
|
21
22
|
"rootDir": ".",
|
|
22
23
|
"resolveJsonModule": true,
|
|
23
24
|
"emitDeclarationOnly": true,
|
|
24
|
-
"experimentalDecorators": true,
|
|
25
25
|
"emitDecoratorMetadata": true,
|
|
26
26
|
"allowSyntheticDefaultImports": true,
|
|
27
27
|
"strictPropertyInitialization": false,
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
Binary file
|
|
File without changes
|