@teambit/typescript 0.0.730 → 0.0.731
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/schema-extractor-context.d.ts +6 -4
- package/dist/schema-extractor-context.js +83 -25
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/class-deceleration.js +21 -6
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/function-declaration.js +4 -3
- package/dist/transformers/function-declaration.js.map +1 -1
- package/dist/transformers/index-signature.js +11 -1
- package/dist/transformers/index-signature.js.map +1 -1
- package/dist/transformers/index.d.ts +0 -4
- package/dist/transformers/index.js +0 -64
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/method-declaration.js +6 -6
- package/dist/transformers/method-declaration.js.map +1 -1
- package/dist/transformers/method-signature.js +2 -2
- package/dist/transformers/method-signature.js.map +1 -1
- package/dist/transformers/property-declaration.js +2 -3
- package/dist/transformers/property-declaration.js.map +1 -1
- package/dist/transformers/property-signature.js +3 -4
- package/dist/transformers/property-signature.js.map +1 -1
- package/dist/transformers/type-alias.js +11 -2
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/utils/get-params.d.ts +2 -2
- package/dist/transformers/utils/get-params.js +14 -12
- package/dist/transformers/utils/get-params.js.map +1 -1
- package/dist/transformers/utils/parse-type-from-quick-info.d.ts +35 -2
- package/dist/transformers/utils/parse-type-from-quick-info.js +93 -7
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
- package/dist/transformers/utils/type-node-to-schema.d.ts +4 -0
- package/dist/transformers/utils/type-node-to-schema.js +251 -0
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -0
- package/dist/transformers/variable-declaration.js +2 -2
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/typescript.main.runtime.js +1 -1
- package/dist/typescript.main.runtime.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.731.tgz +0 -0
- package/package.json +15 -15
- package/{preview-1652325916507.js → preview-1652498684867.js} +2 -2
- package/transformers/class-deceleration.ts +8 -4
- package/transformers/function-declaration.ts +4 -3
- package/transformers/index-signature.ts +2 -1
- package/transformers/index.ts +0 -4
- package/transformers/method-declaration.ts +6 -6
- package/transformers/method-signature.ts +2 -2
- package/transformers/property-declaration.ts +2 -3
- package/transformers/property-signature.ts +3 -4
- package/transformers/type-alias.ts +3 -3
- package/transformers/utils/get-params.ts +11 -12
- package/transformers/utils/parse-type-from-quick-info.ts +79 -7
- package/transformers/utils/type-node-to-schema.ts +205 -0
- package/transformers/variable-declaration.ts +2 -2
- package/dist/transformers/type-intersection.d.ts +0 -9
- package/dist/transformers/type-intersection.js +0 -63
- package/dist/transformers/type-intersection.js.map +0 -1
- package/dist/transformers/type-literal.d.ts +0 -14
- package/dist/transformers/type-literal.js +0 -67
- package/dist/transformers/type-literal.js.map +0 -1
- package/dist/transformers/type-reference.d.ts +0 -8
- package/dist/transformers/type-reference.js +0 -41
- package/dist/transformers/type-reference.js.map +0 -1
- package/dist/transformers/type-union.d.ts +0 -9
- package/dist/transformers/type-union.js +0 -63
- package/dist/transformers/type-union.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.730.tgz +0 -0
- package/transformers/type-intersection.ts +0 -23
- package/transformers/type-literal.ts +0 -28
- package/transformers/type-reference.ts +0 -19
- package/transformers/type-union.ts +0 -23
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TsserverClient } from '@teambit/ts-server';
|
|
2
|
-
import ts, { ExportDeclaration, Node } from 'typescript';
|
|
2
|
+
import ts, { ExportDeclaration, Node, TypeNode } from 'typescript';
|
|
3
3
|
import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
4
4
|
import { Component } from '@teambit/component';
|
|
5
|
-
import {
|
|
5
|
+
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
6
6
|
import { TypeScriptExtractor } from './typescript.extractor';
|
|
7
7
|
import { ExportList } from './export-list';
|
|
8
8
|
export declare class SchemaExtractorContext {
|
|
@@ -35,6 +35,7 @@ export declare class SchemaExtractorContext {
|
|
|
35
35
|
* think if we don't need this because of type ref
|
|
36
36
|
*/
|
|
37
37
|
getQuickInfo(node: Node): Promise<import("typescript/lib/protocol").QuickInfoResponse | undefined>;
|
|
38
|
+
getQuickInfoDisplayString(node: Node): Promise<string>;
|
|
38
39
|
/**
|
|
39
40
|
* returns the type definition for a type.
|
|
40
41
|
*/
|
|
@@ -64,10 +65,11 @@ export declare class SchemaExtractorContext {
|
|
|
64
65
|
_exports: ExportList | undefined;
|
|
65
66
|
setExports(exports: ExportList): this;
|
|
66
67
|
getExportedIdentifiers(node: Node): Promise<import("./export-identifier").ExportIdentifier[]>;
|
|
67
|
-
private isNative;
|
|
68
68
|
jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined>;
|
|
69
69
|
/**
|
|
70
70
|
* resolve a type by a node and its identifier.
|
|
71
71
|
*/
|
|
72
|
-
resolveType(node: Node
|
|
72
|
+
resolveType(node: Node & {
|
|
73
|
+
type?: TypeNode;
|
|
74
|
+
}, typeStr: string, isTypeStrFromQuickInfo?: boolean): Promise<SchemaNode>;
|
|
73
75
|
}
|
|
@@ -73,6 +73,36 @@ function _semanticsEntities() {
|
|
|
73
73
|
return data;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
function _typeNodeToSchema() {
|
|
77
|
+
const data = require("./transformers/utils/type-node-to-schema");
|
|
78
|
+
|
|
79
|
+
_typeNodeToSchema = function () {
|
|
80
|
+
return data;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function _exceptions() {
|
|
87
|
+
const data = require("./exceptions");
|
|
88
|
+
|
|
89
|
+
_exceptions = function () {
|
|
90
|
+
return data;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function _parseTypeFromQuickInfo() {
|
|
97
|
+
const data = require("./transformers/utils/parse-type-from-quick-info");
|
|
98
|
+
|
|
99
|
+
_parseTypeFromQuickInfo = function () {
|
|
100
|
+
return data;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
|
|
76
106
|
class SchemaExtractorContext {
|
|
77
107
|
constructor(tsserver, component, extractor) {
|
|
78
108
|
this.tsserver = tsserver;
|
|
@@ -136,6 +166,13 @@ class SchemaExtractorContext {
|
|
|
136
166
|
getQuickInfo(node) {
|
|
137
167
|
return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
|
|
138
168
|
}
|
|
169
|
+
|
|
170
|
+
async getQuickInfoDisplayString(node) {
|
|
171
|
+
var _quickInfo$body;
|
|
172
|
+
|
|
173
|
+
const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
|
|
174
|
+
return (quickInfo === null || quickInfo === void 0 ? void 0 : (_quickInfo$body = quickInfo.body) === null || _quickInfo$body === void 0 ? void 0 : _quickInfo$body.displayString) || '';
|
|
175
|
+
}
|
|
139
176
|
/**
|
|
140
177
|
* returns the type definition for a type.
|
|
141
178
|
*/
|
|
@@ -173,7 +210,14 @@ class SchemaExtractorContext {
|
|
|
173
210
|
return `${pkgParts[0]}/${pkgParts[1]}`;
|
|
174
211
|
}
|
|
175
212
|
|
|
176
|
-
|
|
213
|
+
const pkgName = pkgParts[0];
|
|
214
|
+
|
|
215
|
+
if (pkgName === 'typescript') {
|
|
216
|
+
// it's a built-in type, such as "string".
|
|
217
|
+
return '';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return pkgName;
|
|
177
221
|
}
|
|
178
222
|
/**
|
|
179
223
|
* return the file if part of the component.
|
|
@@ -268,42 +312,46 @@ class SchemaExtractorContext {
|
|
|
268
312
|
return this.extractor.computeExportedIdentifiers(node, this);
|
|
269
313
|
}
|
|
270
314
|
|
|
271
|
-
isNative(typeName) {
|
|
272
|
-
return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
315
|
async jump(file, start) {
|
|
276
316
|
const sourceFile = this.extractor.parseSourceFile(file);
|
|
277
317
|
const pos = this.getPosition(sourceFile, start.line, start.offset);
|
|
278
318
|
const nodeAtPos = (0, _tsutils().getTokenAtPosition)(sourceFile, pos);
|
|
279
|
-
if (!nodeAtPos) return undefined;
|
|
319
|
+
if (!nodeAtPos) return undefined; // this causes some infinite loops. it's helpful for getting more data from types that are not exported.
|
|
320
|
+
// e.g.
|
|
321
|
+
// ```ts
|
|
322
|
+
// class Bar {}
|
|
323
|
+
// export const getBar = () => new Bar();
|
|
324
|
+
// ```
|
|
325
|
+
// if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {
|
|
326
|
+
// // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`
|
|
327
|
+
// return this.visitDefinition(nodeAtPos);
|
|
328
|
+
// }
|
|
329
|
+
|
|
330
|
+
try {
|
|
331
|
+
return await this.visit(nodeAtPos);
|
|
332
|
+
} catch (err) {
|
|
333
|
+
if (err instanceof _exceptions().TransformerNotFound) {
|
|
334
|
+
return undefined;
|
|
335
|
+
}
|
|
280
336
|
|
|
281
|
-
|
|
282
|
-
// @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`
|
|
283
|
-
return this.visitDefinition(nodeAtPos);
|
|
337
|
+
throw err;
|
|
284
338
|
}
|
|
285
|
-
|
|
286
|
-
return this.visit(nodeAtPos);
|
|
287
339
|
}
|
|
288
340
|
/**
|
|
289
341
|
* resolve a type by a node and its identifier.
|
|
290
342
|
*/
|
|
291
343
|
|
|
292
344
|
|
|
293
|
-
async resolveType(node, typeStr) {
|
|
345
|
+
async resolveType(node, typeStr, isTypeStrFromQuickInfo = true) {
|
|
294
346
|
var _this$_exports;
|
|
295
347
|
|
|
296
|
-
|
|
297
|
-
// explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have "type"
|
|
298
|
-
// @ts-ignore
|
|
299
|
-
node = node.type || node;
|
|
300
|
-
if (this.isNative(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
|
|
348
|
+
if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
|
|
301
349
|
|
|
302
|
-
if (node.
|
|
303
|
-
|
|
350
|
+
if (node.type && _typescript().default.isTypeNode(node.type)) {
|
|
351
|
+
// if a node has "type" prop, it has the type data of the node. this normally happens when the code has the type
|
|
352
|
+
// explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have "type"
|
|
353
|
+
return (0, _typeNodeToSchema().typeNodeToSchema)(node.type, this);
|
|
304
354
|
}
|
|
305
|
-
|
|
306
|
-
if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
|
|
307
355
|
/**
|
|
308
356
|
* tsserver has two different calls: "definition" and "typeDefinition".
|
|
309
357
|
* normally, we need the "typeDefinition" to get the type data of a node.
|
|
@@ -312,6 +360,7 @@ class SchemaExtractorContext {
|
|
|
312
360
|
* "definition" but it's not clear when/why).
|
|
313
361
|
*/
|
|
314
362
|
|
|
363
|
+
|
|
315
364
|
const getDef = async () => {
|
|
316
365
|
const typeDefinition = await this.typeDefinition(node);
|
|
317
366
|
const headTypeDefinition = (0, _lodash().head)(typeDefinition === null || typeDefinition === void 0 ? void 0 : typeDefinition.body);
|
|
@@ -326,10 +375,18 @@ class SchemaExtractorContext {
|
|
|
326
375
|
|
|
327
376
|
const definition = await getDef(); // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.
|
|
328
377
|
|
|
329
|
-
const unknownExactType =
|
|
378
|
+
const unknownExactType = async () => {
|
|
379
|
+
if (isTypeStrFromQuickInfo) {
|
|
380
|
+
return new (_semanticsEntities().InferenceTypeSchema)(typeStr);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const info = await this.getQuickInfo(node);
|
|
384
|
+
const type = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
385
|
+
return new (_semanticsEntities().InferenceTypeSchema)(type);
|
|
386
|
+
};
|
|
330
387
|
|
|
331
388
|
if (!definition) {
|
|
332
|
-
return unknownExactType;
|
|
389
|
+
return unknownExactType();
|
|
333
390
|
} // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location
|
|
334
391
|
|
|
335
392
|
|
|
@@ -346,10 +403,11 @@ class SchemaExtractorContext {
|
|
|
346
403
|
|
|
347
404
|
if (file) {
|
|
348
405
|
if (isDefInSameLocation()) {
|
|
349
|
-
return unknownExactType;
|
|
406
|
+
return unknownExactType();
|
|
350
407
|
}
|
|
351
408
|
|
|
352
|
-
|
|
409
|
+
const schemaNode = await this.jump(file, definition.start);
|
|
410
|
+
return schemaNode || unknownExactType();
|
|
353
411
|
}
|
|
354
412
|
|
|
355
413
|
const pkgName = this.parsePackageNameFromPath(definition.file); // TODO: find component id is exists, otherwise add the package name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","fileName","getQuickInfo","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","body","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","isNative","typeName","jump","kind","ts","SyntaxKind","Identifier","resolveType","typeStr","type","TypeRefSchema","LiteralType","literal","getDef","headTypeDefinition","unknownExactType","isDefInSameLocation","loc","pkgName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIO,MAAMA,sBAAN,CAA6B;AAClCC,EAAAA,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIT;AAAA,SAHSF,QAGT,GAHSA,QAGT;AAAA,SAFSC,SAET,GAFSA,SAET;AAAA,SADSC,SACT,GADSA,SACT;AAAA,sDAuKiCC,SAvKjC;AAAE;;AAEJC,EAAAA,aAAa,CAACC,IAAD,EAAa;AACxB,WAAO,KAAKH,SAAL,CAAeE,aAAf,CAA6BC,IAA7B,EAAmC,IAAnC,CAAP;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,WAAW,CAACD,IAAD,EAAaE,gBAAb,EAA+C;AACxD,UAAMC,UAAU,GAAGD,gBAAgB,IAAIF,IAAI,CAACI,aAAL,EAAvC;AACA,UAAMC,QAAQ,GAAGF,UAAU,CAACG,6BAAX,CAAyCN,IAAI,CAACO,QAAL,EAAzC,CAAjB;AACA,UAAMC,IAAI,GAAGH,QAAQ,CAACG,IAAT,GAAgB,CAA7B;AACA,UAAMC,SAAS,GAAGJ,QAAQ,CAACI,SAAT,GAAqB,CAAvC;AAEA,WAAO;AACLD,MAAAA,IADK;AAELC,MAAAA;AAFK,KAAP;AAID;AAED;AACF;AACA;;;AACoB,QAAZC,YAAY,CAACV,IAAD,EAAa;AAC7B,WAAO,KAAKL,QAAL,CAAcgB,gBAAd,CAA+B,KA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AAvD,CAAP;AACD;;AACD,UAAMwC,OAAO,GAAG,KAAKzD,wBAAL,CAA8Be,UAAU,CAACvB,IAAzC,CAAhB,CAnDqE,CAoDrE;;AACA,WAAO,KAAIyD,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsC6F,OAAtC,CAAP;AACD;;AAhQiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, LiteralTypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile) {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n line,\n character,\n };\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n return pkgParts[0];\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n private isNative(typeName: string) {\n return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n return this.visitDefinition(nodeAtPos);\n }\n return this.visit(nodeAtPos);\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(node: Node, typeStr: string): Promise<TypeRefSchema> {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n // @ts-ignore\n node = node.type || node;\n if (this.isNative(typeStr)) return new TypeRefSchema(typeStr);\n if (node.kind === ts.SyntaxKind.LiteralType) {\n return new TypeRefSchema((node as LiteralTypeNode).literal.getText());\n }\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = new TypeRefSchema(typeStr);\n if (!definition) {\n return unknownExactType;\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType;\n }\n return new TypeRefSchema(typeStr, undefined, undefined, await this.jump(file, definition.start));\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(typeStr, undefined, pkgName);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","fileName","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","isDefInSameLocation","loc","schemaNode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,sBAAN,CAA6B;AAClCC,EAAAA,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIT;AAAA,SAHSF,QAGT,GAHSA,QAGT;AAAA,SAFSC,SAET,GAFSA,SAET;AAAA,SADSC,SACT,GADSA,SACT;AAAA,sDAiLiCC,SAjLjC;AAAE;;AAEJC,EAAAA,aAAa,CAACC,IAAD,EAAa;AACxB,WAAO,KAAKH,SAAL,CAAeE,aAAf,CAA6BC,IAA7B,EAAmC,IAAnC,CAAP;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,WAAW,CAACD,IAAD,EAAaE,gBAAb,EAA+C;AACx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uBO,IAAvB,CAAb;AACA,aAAO,KAAID,wCAAJ,EAAwBN,IAAxB,CAAP;AACD,KAPD;;AAQA,QAAI,CAAC/B,UAAL,EAAiB;AACf,aAAOoC,gBAAgB,EAAvB;AACD,KApCoB,CAsCrB;;;AACA,UAAMG,mBAAmB,GAAG,MAAM;AAChC,UAAIvC,UAAU,CAACvB,IAAX,KAAoB9B,IAAI,CAACI,aAAL,GAAqBY,QAA7C,EAAuD;AACrD,eAAO,KAAP;AACD;;AACD,YAAM6E,GAAG,GAAG,KAAK5F,WAAL,CAAiBD,IAAjB,CAAZ;AACA,aAAO6F,GAAG,CAACrF,IAAJ,KAAa6C,UAAU,CAACE,KAAX,CAAiB/C,IAA9B,IAAsCqF,GAAG,CAACpF,SAAJ,KAAkB4C,UAAU,CAACE,KAAX,CAAiBzC,MAAhF;AACD,KAND;;AAQA,UAAMgB,IAAI,GAAG,KAAKL,mBAAL,CAAyB4B,UAAU,CAACvB,IAApC,CAAb;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAI8D,mBAAmB,EAAvB,EAA2B;AACzB,eAAOH,gBAAgB,EAAvB;AACD;;AACD,YAAMK,UAAU,GAAG,MAAM,KAAKjB,IAAL,CAAU/C,IAAV,EAAgBuB,UAAU,CAACE,KAA3B,CAAzB;AACA,aAAOuC,UAAU,IAAIL,gBAAgB,EAArC;AACD;;AACD,UAAM1C,OAAO,GAAG,KAAKT,wBAAL,CAA8Be,UAAU,CAACvB,IAAzC,CAAhB,CAvDqB,CAwDrB;;AACA,WAAO,KAAIqD,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsCiD,OAAtC,CAAP;AACD;;AA5RiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile) {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n line,\n character,\n };\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(typeStr, undefined, pkgName);\n }\n}\n"]}
|
|
@@ -19,6 +19,16 @@ function _pMapSeries() {
|
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function _lodash() {
|
|
23
|
+
const data = require("lodash");
|
|
24
|
+
|
|
25
|
+
_lodash = function () {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
function _semanticsEntities() {
|
|
23
33
|
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
24
34
|
|
|
@@ -88,6 +98,14 @@ class ClassDecelerationTransformer {
|
|
|
88
98
|
async transform(node, context) {
|
|
89
99
|
const className = this.getName(node);
|
|
90
100
|
const members = await (0, _pMapSeries().default)(node.members, async member => {
|
|
101
|
+
var _member$modifiers;
|
|
102
|
+
|
|
103
|
+
const isPrivate = (_member$modifiers = member.modifiers) === null || _member$modifiers === void 0 ? void 0 : _member$modifiers.some(modifier => modifier.kind === _typescript().default.SyntaxKind.PrivateKeyword);
|
|
104
|
+
|
|
105
|
+
if (isPrivate) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
91
109
|
switch (member.kind) {
|
|
92
110
|
case _typescript().default.SyntaxKind.GetAccessor:
|
|
93
111
|
{
|
|
@@ -96,19 +114,16 @@ class ClassDecelerationTransformer {
|
|
|
96
114
|
const getter = member;
|
|
97
115
|
const info = await context.getQuickInfo(getter.name);
|
|
98
116
|
const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
|
|
99
|
-
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(
|
|
117
|
+
const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
100
118
|
const type = await context.resolveType(getter, typeStr);
|
|
101
119
|
return new (_semanticsEntities().GetAccessorSchema)(getter.name.getText(), type, displaySig);
|
|
102
120
|
}
|
|
103
121
|
|
|
104
122
|
case _typescript().default.SyntaxKind.SetAccessor:
|
|
105
123
|
{
|
|
106
|
-
var _info$body2;
|
|
107
|
-
|
|
108
124
|
const setter = member;
|
|
109
125
|
const params = await (0, _getParams().getParams)(setter.parameters, context);
|
|
110
|
-
const
|
|
111
|
-
const displaySig = (info === null || info === void 0 ? void 0 : (_info$body2 = info.body) === null || _info$body2 === void 0 ? void 0 : _info$body2.displayString) || '';
|
|
126
|
+
const displaySig = await context.getQuickInfoDisplayString(setter.name);
|
|
112
127
|
return new (_semanticsEntities().SetAccessorSchema)(setter.name.getText(), params[0], displaySig);
|
|
113
128
|
}
|
|
114
129
|
|
|
@@ -116,7 +131,7 @@ class ClassDecelerationTransformer {
|
|
|
116
131
|
return context.computeSchema(member);
|
|
117
132
|
}
|
|
118
133
|
});
|
|
119
|
-
return new (_semanticsEntities().ClassSchema)(className, members);
|
|
134
|
+
return new (_semanticsEntities().ClassSchema)(className, (0, _lodash().compact)(members));
|
|
120
135
|
}
|
|
121
136
|
|
|
122
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","SetAccessor","setter","params","parameters","SetAccessorSchema","computeSchema","ClassSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,4BAAN,CAAgE;AACrEC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,gBAAnC;AACD,GAHoE,CAKrE;;;AACQC,EAAAA,OAAO,CAACL,IAAD,EAAyB;AAAA;;AACtC,WAAO,eAAAA,IAAI,CAACM,IAAL,0DAAWC,OAAX,OAAwB,SAA/B;AACD;;AAEmB,QAAdC,cAAc,CAACR,IAAD,EAAyB;AAC3C,WAAO,CAAC,KAAIS,oCAAJ,EAAqB,KAAKJ,OAAL,CAAaL,IAAb,CAArB,EAAyCA,IAAI,CAACU,aAAL,GAAqBC,QAA9D,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACZ,IAAD,EAAyBa,OAAzB,EAA0D;AACvE,UAAMC,SAAS,GAAG,KAAKT,OAAL,CAAaL,IAAb,CAAlB;AACA,UAAMe,OAAO,GAAG,MAAM,2BAAWf,IAAI,CAACe,OAAhB,EAAyB,MAAOC,MAAP,IAAkB;AAC/D,
|
|
1
|
+
{"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","isPrivate","modifiers","some","modifier","PrivateKeyword","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","SetAccessor","setter","params","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,4BAAN,CAAgE;AACrEC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcC,gBAAnC;AACD,GAHoE,CAKrE;;;AACQC,EAAAA,OAAO,CAACL,IAAD,EAAy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AA7C,EAAmDJ,UAAnD,CAAP;AACD;;AACD,aAAKxB,sBAAGC,UAAH,CAAc8B,WAAnB;AAAgC;AAC9B,kBAAMC,MAAM,GAAGlB,MAAf;AACA,kBAAMmB,MAAM,GAAG,MAAM,4BAAUD,MAAM,CAACE,UAAjB,EAA6BvB,OAA7B,CAArB;AACA,kBAAMa,UAAU,GAAG,MAAMb,OAAO,CAACwB,yBAAR,CAAkCH,MAAM,CAAC5B,IAAzC,CAAzB;AACA,mBAAO,KAAIgC,sCAAJ,EAAsBJ,MAAM,CAAC5B,IAAP,CAAYC,OAAZ,EAAtB,EAA6C4B,MAAM,CAAC,CAAD,CAAnD,EAAwDT,UAAxD,CAAP;AACD;;AACD;AACE,iBAAOb,OAAO,CAAC0B,aAAR,CAAsBvB,MAAtB,CAAP;AAhBJ;AAkBD,KAvBqB,CAAtB;AAwBA,WAAO,KAAIwB,gCAAJ,EAAgB1B,SAAhB,EAA2B,uBAAQC,OAAR,CAA3B,CAAP;AACD;;AAzCoE","sourcesContent":["import pMapSeries from 'p-map-series';\nimport { compact } from 'lodash';\nimport { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { getParams } from './utils/get-params';\n\nexport class ClassDecelerationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.ClassDeclaration;\n }\n\n // @todo: in case of `export default class` the class has no name.\n private getName(node: ClassDeclaration) {\n return node.name?.getText() || 'default';\n }\n\n async getIdentifiers(node: ClassDeclaration) {\n return [new ExportIdentifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\n const members = await pMapSeries(node.members, async (member) => {\n const isPrivate = member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword);\n if (isPrivate) {\n return null;\n }\n switch (member.kind) {\n case ts.SyntaxKind.GetAccessor: {\n const getter = member as ts.GetAccessorDeclaration;\n const info = await context.getQuickInfo(getter.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(getter, typeStr);\n return new GetAccessorSchema(getter.name.getText(), type, displaySig);\n }\n case ts.SyntaxKind.SetAccessor: {\n const setter = member as ts.SetAccessorDeclaration;\n const params = await getParams(setter.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(setter.name);\n return new SetAccessorSchema(setter.name.getText(), params[0], displaySig);\n }\n default:\n return context.computeSchema(member);\n }\n });\n return new ClassSchema(className, compact(members));\n }\n}\n"]}
|
|
@@ -76,16 +76,17 @@ class FunctionDeclaration {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
async transform(funcDec, context) {
|
|
79
|
-
var _info$body;
|
|
79
|
+
var _info$body, _funcDec$modifiers;
|
|
80
80
|
|
|
81
81
|
const name = this.getName(funcDec); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
82
82
|
|
|
83
83
|
const info = await context.getQuickInfo(funcDec.name);
|
|
84
|
+
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
84
85
|
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
85
|
-
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(displaySig);
|
|
86
86
|
const args = await (0, _getParams().getParams)(funcDec.parameters, context);
|
|
87
87
|
const returnType = await context.resolveType(funcDec, returnTypeStr);
|
|
88
|
-
|
|
88
|
+
const modifiers = ((_funcDec$modifiers = funcDec.modifiers) === null || _funcDec$modifiers === void 0 ? void 0 : _funcDec$modifiers.map(modifier => modifier.getText())) || [];
|
|
89
|
+
return new (_semanticsEntities().FunctionSchema)(name, args, returnType, displaySig || '', modifiers);
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context","info","getQuickInfo","displaySig","body","displayString","
|
|
1
|
+
{"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context","info","getQuickInfo","returnTypeStr","displaySig","body","displayString","args","parameters","returnType","resolveType","modifiers","map","modifier","FunctionSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD,GAH2D,CAK5D;;;AACoB,QAAdM,cAAc,CAACC,OAAD,EAAmC;AACrD,WAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;AACD;;AAEOF,EAAAA,OAAO,CAACF,OAAD,EAAmC;AAAA;;AAChD,WAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;AACD;;AAEc,QAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;AAAA;;AACtG,UAAMH,IAAI,GAAG,KAAKH,OAAL,CAAaF,OAAb,CAAb,CADsG,CAEtG;;AACA,UAAMS,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBV,OAAO,CAACK,IAA7B,CAAnB;AACA,UAAMM,aAAa,GAAG,sDAAuBF,IAAvB,CAAtB;AACA,UAAMG,UAAU,GAAGH,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEI,IAAT,+CAAG,WAAYC,aAA/B;AACA,UAAMC,IAAI,GAAG,MAAM,4BAAUf,OAAO,CAACgB,UAAlB,EAA8BR,OAA9B,CAAnB;AACA,UAAMS,UAAU,GAAG,MAAMT,OAAO,CAACU,WAAR,CAAoBlB,OAApB,EAA6BW,aAA7B,CAAzB;AACA,UAAMQ,SAAS,GAAG,uBAAAnB,OAAO,CAACmB,SAAR,0EAAmBC,GAAnB,CAAwBC,QAAD,IAAcA,QAAQ,CAACf,OAAT,EAArC,MAA4D,EAA9E;AAEA,WAAO,KAAIgB,mCAAJ,EAAmBjB,IAAnB,EAAyBU,IAAzB,EAA+BE,UAA/B,EAA2CL,UAAU,IAAI,EAAzD,EAA6DO,SAA7D,CAAP;AACD;;AAzB2D","sourcesContent":["import { SchemaNode, FunctionSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\nexport class FunctionDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.FunctionDeclaration;\n }\n\n // need to check for anonymous functions assigned for vars, const and let.\n async getIdentifiers(funcDec: FunctionDeclarationNode) {\n return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];\n }\n\n private getName(funcDec: FunctionDeclarationNode) {\n return funcDec.name?.getText() || '';\n }\n\n async transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(funcDec);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const info = await context.getQuickInfo(funcDec.name!);\n const returnTypeStr = parseTypeFromQuickInfo(info);\n const displaySig = info?.body?.displayString;\n const args = await getParams(funcDec.parameters, context);\n const returnType = await context.resolveType(funcDec, returnTypeStr);\n const modifiers = funcDec.modifiers?.map((modifier) => modifier.getText()) || [];\n\n return new FunctionSchema(name, args, returnType, displaySig || '', modifiers as Modifier[]);\n }\n}\n"]}
|
|
@@ -39,6 +39,16 @@ function _getParams() {
|
|
|
39
39
|
return data;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function _typeNodeToSchema() {
|
|
43
|
+
const data = require("./utils/type-node-to-schema");
|
|
44
|
+
|
|
45
|
+
_typeNodeToSchema = function () {
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
class IndexSignature {
|
|
43
53
|
predicate(node) {
|
|
44
54
|
return node.kind === _typescript().default.SyntaxKind.IndexSignature;
|
|
@@ -50,7 +60,7 @@ class IndexSignature {
|
|
|
50
60
|
|
|
51
61
|
async transform(indexSig, context) {
|
|
52
62
|
const params = await (0, _getParams().getParams)(indexSig.parameters, context);
|
|
53
|
-
const type = await
|
|
63
|
+
const type = await (0, _typeNodeToSchema().typeNodeToSchema)(indexSig.type, context);
|
|
54
64
|
return new (_semanticsEntities().IndexSignatureSchema)(params, type);
|
|
55
65
|
}
|
|
56
66
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","
|
|
1
|
+
{"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","IndexSignatureSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAM,0CAAiBJ,QAAQ,CAACI,IAA1B,EAAgCH,OAAhC,CAAnB;AACA,WAAO,KAAII,yCAAJ,EAAyBH,MAAzB,EAAiCE,IAAjC,CAAP;AACD;;AAbsD","sourcesContent":["import { SchemaNode, IndexSignatureSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, IndexSignatureDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { getParams } from './utils/get-params';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class IndexSignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.IndexSignature;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(indexSig: IndexSignatureDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const params = await getParams(indexSig.parameters, context);\n const type = await typeNodeToSchema(indexSig.type, context);\n return new IndexSignatureSchema(params, type);\n }\n}\n"]}
|
|
@@ -7,12 +7,8 @@ export { VariableDeclaration } from './variable-declaration';
|
|
|
7
7
|
export { SourceFileTransformer } from './source-file-transformer';
|
|
8
8
|
export { TypeAliasTransformer } from './type-alias';
|
|
9
9
|
export { ClassDecelerationTransformer } from './class-deceleration';
|
|
10
|
-
export { TypeIntersectionTransformer } from './type-intersection';
|
|
11
10
|
export { Constructor } from './constructor';
|
|
12
|
-
export { TypeReferenceTransformer } from './type-reference';
|
|
13
|
-
export { TypeLiteralTransformer } from './type-literal';
|
|
14
11
|
export { PropertySignature } from './property-signature';
|
|
15
|
-
export { TypeUnionTransformer } from './type-union';
|
|
16
12
|
export { LiteralTypeTransformer } from './literal-type';
|
|
17
13
|
export { IndexSignature } from './index-signature';
|
|
18
14
|
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
@@ -81,30 +81,6 @@ Object.defineProperty(exports, "TypeAliasTransformer", {
|
|
|
81
81
|
return _typeAlias().TypeAliasTransformer;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
-
Object.defineProperty(exports, "TypeIntersectionTransformer", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _typeIntersection().TypeIntersectionTransformer;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "TypeLiteralTransformer", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _typeLiteral().TypeLiteralTransformer;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(exports, "TypeReferenceTransformer", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return _typeReference().TypeReferenceTransformer;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(exports, "TypeUnionTransformer", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
get: function () {
|
|
105
|
-
return _typeUnion().TypeUnionTransformer;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
84
|
Object.defineProperty(exports, "VariableDeclaration", {
|
|
109
85
|
enumerable: true,
|
|
110
86
|
get: function () {
|
|
@@ -208,16 +184,6 @@ function _classDeceleration() {
|
|
|
208
184
|
return data;
|
|
209
185
|
}
|
|
210
186
|
|
|
211
|
-
function _typeIntersection() {
|
|
212
|
-
const data = require("./type-intersection");
|
|
213
|
-
|
|
214
|
-
_typeIntersection = function () {
|
|
215
|
-
return data;
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
return data;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
187
|
function _constructor() {
|
|
222
188
|
const data = require("./constructor");
|
|
223
189
|
|
|
@@ -228,26 +194,6 @@ function _constructor() {
|
|
|
228
194
|
return data;
|
|
229
195
|
}
|
|
230
196
|
|
|
231
|
-
function _typeReference() {
|
|
232
|
-
const data = require("./type-reference");
|
|
233
|
-
|
|
234
|
-
_typeReference = function () {
|
|
235
|
-
return data;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
return data;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function _typeLiteral() {
|
|
242
|
-
const data = require("./type-literal");
|
|
243
|
-
|
|
244
|
-
_typeLiteral = function () {
|
|
245
|
-
return data;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
return data;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
197
|
function _propertySignature() {
|
|
252
198
|
const data = require("./property-signature");
|
|
253
199
|
|
|
@@ -258,16 +204,6 @@ function _propertySignature() {
|
|
|
258
204
|
return data;
|
|
259
205
|
}
|
|
260
206
|
|
|
261
|
-
function _typeUnion() {
|
|
262
|
-
const data = require("./type-union");
|
|
263
|
-
|
|
264
|
-
_typeUnion = function () {
|
|
265
|
-
return data;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
return data;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
207
|
function _literalType() {
|
|
272
208
|
const data = require("./literal-type");
|
|
273
209
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { MethodDeclaration } from './method-declaration';\nexport { PropertyDeclaration } from './property-declaration';\nexport { VariableStatementTransformer } from './variable-statement';\nexport { VariableDeclaration } from './variable-declaration';\nexport { SourceFileTransformer } from './source-file-transformer';\nexport { TypeAliasTransformer } from './type-alias';\nexport { ClassDecelerationTransformer } from './class-deceleration';\nexport { Constructor } from './constructor';\nexport { PropertySignature } from './property-signature';\nexport { LiteralTypeTransformer } from './literal-type';\nexport { IndexSignature } from './index-signature';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { MethodSignatureTransformer } from './method-signature';\n"]}
|
|
@@ -75,16 +75,16 @@ class MethodDeclaration {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
async transform(methodDec, context) {
|
|
78
|
-
var _info$body;
|
|
79
|
-
|
|
80
|
-
const name = this.getName(methodDec); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
78
|
+
var _info$body, _methodDec$modifiers;
|
|
81
79
|
|
|
80
|
+
const name = this.getName(methodDec);
|
|
82
81
|
const info = await context.getQuickInfo(methodDec.name);
|
|
83
82
|
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
84
|
-
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(
|
|
85
|
-
const
|
|
83
|
+
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
|
|
84
|
+
const params = await (0, _getParams().getParams)(methodDec.parameters, context);
|
|
85
|
+
const modifiers = ((_methodDec$modifiers = methodDec.modifiers) === null || _methodDec$modifiers === void 0 ? void 0 : _methodDec$modifiers.map(modifier => modifier.getText())) || [];
|
|
86
86
|
const returnType = await context.resolveType(methodDec, returnTypeStr);
|
|
87
|
-
return new (_semanticsEntities().FunctionSchema)(name
|
|
87
|
+
return new (_semanticsEntities().FunctionSchema)(name, params, returnType, displaySig || '', modifiers);
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
}
|