@teambit/typescript 0.0.742 → 0.0.745
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/transformers/class-deceleration.js +10 -40
- package/dist/transformers/class-deceleration.js.map +1 -1
- package/dist/transformers/index.d.ts +0 -6
- package/dist/transformers/index.js +0 -96
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/interface-declaration.js +13 -6
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/utils/class-element-to-schema.d.ts +4 -0
- package/dist/transformers/utils/class-element-to-schema.js +122 -0
- package/dist/transformers/utils/class-element-to-schema.js.map +1 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +4 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +163 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -0
- package/dist/transformers/utils/to-function-schema.d.ts +1 -1
- package/dist/transformers/utils/to-function-schema.js +17 -7
- package/dist/transformers/utils/to-function-schema.js.map +1 -1
- package/dist/transformers/utils/type-element-to-schema.d.ts +7 -0
- package/dist/transformers/utils/type-element-to-schema.js +134 -0
- package/dist/transformers/utils/type-element-to-schema.js.map +1 -0
- package/dist/transformers/utils/type-node-to-schema.js +32 -7
- package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.js +15 -1
- 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.745.tgz +0 -0
- package/package.json +17 -17
- package/{preview-1653535588073.js → preview-1653836960096.js} +2 -2
- package/transformers/class-deceleration.ts +7 -26
- package/transformers/index.ts +0 -6
- package/transformers/interface-declaration.ts +4 -6
- package/transformers/utils/class-element-to-schema.ts +61 -0
- package/transformers/utils/jsdoc-to-doc-schema.ts +81 -0
- package/transformers/utils/to-function-schema.ts +12 -8
- package/transformers/utils/type-element-to-schema.ts +72 -0
- package/transformers/utils/type-node-to-schema.ts +15 -6
- package/transformers/variable-declaration.ts +5 -2
- package/dist/transformers/constructor.d.ts +0 -10
- package/dist/transformers/constructor.js +0 -70
- package/dist/transformers/constructor.js.map +0 -1
- package/dist/transformers/index-signature.d.ts +0 -9
- package/dist/transformers/index-signature.js +0 -71
- package/dist/transformers/index-signature.js.map +0 -1
- package/dist/transformers/method-declaration.d.ts +0 -11
- package/dist/transformers/method-declaration.js +0 -65
- package/dist/transformers/method-declaration.js.map +0 -1
- package/dist/transformers/method-signature.d.ts +0 -10
- package/dist/transformers/method-signature.js +0 -53
- package/dist/transformers/method-signature.js.map +0 -1
- package/dist/transformers/property-declaration.d.ts +0 -11
- package/dist/transformers/property-declaration.js +0 -80
- package/dist/transformers/property-declaration.js.map +0 -1
- package/dist/transformers/property-signature.d.ts +0 -10
- package/dist/transformers/property-signature.js +0 -72
- package/dist/transformers/property-signature.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.742.tgz +0 -0
- package/transformers/constructor.ts +0 -22
- package/transformers/index-signature.ts +0 -22
- package/transformers/method-declaration.ts +0 -24
- package/transformers/method-signature.ts +0 -23
- package/transformers/property-declaration.ts +0 -30
- package/transformers/property-signature.ts +0 -28
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.745",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/typescript/typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.typescript",
|
|
8
8
|
"name": "typescript",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.745"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -18,21 +18,21 @@
|
|
|
18
18
|
"@babel/runtime": "7.12.18",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
20
20
|
"@teambit/harmony": "0.3.3",
|
|
21
|
-
"@teambit/compiler": "0.0.
|
|
21
|
+
"@teambit/compiler": "0.0.745",
|
|
22
22
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.68",
|
|
23
|
-
"@teambit/component": "0.0.
|
|
24
|
-
"@teambit/dependency-resolver": "0.0.
|
|
25
|
-
"@teambit/semantics.entities.semantic-schema": "0.0.
|
|
23
|
+
"@teambit/component": "0.0.745",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.745",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.16",
|
|
26
26
|
"@teambit/ts-server": "0.0.32",
|
|
27
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.745",
|
|
28
28
|
"@teambit/bit-error": "0.0.394",
|
|
29
|
-
"@teambit/builder": "0.0.
|
|
30
|
-
"@teambit/isolator": "0.0.
|
|
31
|
-
"@teambit/logger": "0.0.
|
|
32
|
-
"@teambit/schema": "0.0.
|
|
33
|
-
"@teambit/workspace": "0.0.
|
|
34
|
-
"@teambit/cli": "0.0.
|
|
35
|
-
"@teambit/pkg": "0.0.
|
|
29
|
+
"@teambit/builder": "0.0.745",
|
|
30
|
+
"@teambit/isolator": "0.0.745",
|
|
31
|
+
"@teambit/logger": "0.0.586",
|
|
32
|
+
"@teambit/schema": "0.0.745",
|
|
33
|
+
"@teambit/workspace": "0.0.745",
|
|
34
|
+
"@teambit/cli": "0.0.493",
|
|
35
|
+
"@teambit/pkg": "0.0.745"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash": "4.14.165",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"@types/jest": "^26.0.0",
|
|
46
46
|
"@types/react-dom": "^17.0.5",
|
|
47
47
|
"@types/node": "12.20.4",
|
|
48
|
-
"@teambit/typescript.aspect-docs.typescript": "0.0.
|
|
48
|
+
"@teambit/typescript.aspect-docs.typescript": "0.0.138"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@teambit/legacy": "1.0.
|
|
51
|
+
"@teambit/legacy": "1.0.273",
|
|
52
52
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
53
53
|
"react": "^16.8.0 || ^17.0.0"
|
|
54
54
|
},
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"react": "-"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@teambit/legacy": "1.0.
|
|
79
|
+
"@teambit/legacy": "1.0.273",
|
|
80
80
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
81
81
|
"react": "^16.8.0 || ^17.0.0"
|
|
82
82
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.745/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.745/dist/typescript.docs.mdx')]
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import pMapSeries from 'p-map-series';
|
|
2
2
|
import { compact } from 'lodash';
|
|
3
|
-
import { ClassSchema
|
|
4
|
-
import ts, { Node, ClassDeclaration
|
|
3
|
+
import { ClassSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
+
import ts, { Node, ClassDeclaration } from 'typescript';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
7
7
|
import { ExportIdentifier } from '../export-identifier';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';
|
|
9
|
+
import { classElementToSchema } from './utils/class-element-to-schema';
|
|
10
10
|
|
|
11
11
|
export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
12
12
|
predicate(node: Node) {
|
|
@@ -29,28 +29,9 @@ export class ClassDecelerationTransformer implements SchemaTransformer {
|
|
|
29
29
|
if (isPrivate) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
switch (member.kind) {
|
|
36
|
-
case ts.SyntaxKind.GetAccessor: {
|
|
37
|
-
const getter = member as ts.GetAccessorDeclaration;
|
|
38
|
-
const info = await context.getQuickInfo(getter.name);
|
|
39
|
-
const displaySig = info?.body?.displayString || '';
|
|
40
|
-
const typeStr = parseTypeFromQuickInfo(info);
|
|
41
|
-
const type = await context.resolveType(getter, typeStr);
|
|
42
|
-
return new GetAccessorSchema(context.getLocation(getter), getter.name.getText(), type, displaySig);
|
|
43
|
-
}
|
|
44
|
-
case ts.SyntaxKind.SetAccessor: {
|
|
45
|
-
const setter = member as ts.SetAccessorDeclaration;
|
|
46
|
-
const params = await getParams(setter.parameters, context);
|
|
47
|
-
const displaySig = await context.getQuickInfoDisplayString(setter.name);
|
|
48
|
-
return new SetAccessorSchema(context.getLocation(setter), setter.name.getText(), params[0], displaySig);
|
|
49
|
-
}
|
|
50
|
-
default:
|
|
51
|
-
return context.computeSchema(member);
|
|
52
|
-
}
|
|
32
|
+
return classElementToSchema(member, context);
|
|
53
33
|
});
|
|
54
|
-
|
|
34
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
35
|
+
return new ClassSchema(className, compact(members), context.getLocation(node), doc);
|
|
55
36
|
}
|
|
56
37
|
}
|
package/transformers/index.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
export { ExportDeclaration } from './export-declaration';
|
|
2
2
|
export { FunctionDeclaration } from './function-declaration';
|
|
3
|
-
export { MethodDeclaration } from './method-declaration';
|
|
4
|
-
export { PropertyDeclaration } from './property-declaration';
|
|
5
3
|
export { VariableStatementTransformer } from './variable-statement';
|
|
6
4
|
export { VariableDeclaration } from './variable-declaration';
|
|
7
5
|
export { SourceFileTransformer } from './source-file-transformer';
|
|
8
6
|
export { TypeAliasTransformer } from './type-alias';
|
|
9
7
|
export { ClassDecelerationTransformer } from './class-deceleration';
|
|
10
|
-
export { Constructor } from './constructor';
|
|
11
|
-
export { PropertySignature } from './property-signature';
|
|
12
8
|
export { LiteralTypeTransformer } from './literal-type';
|
|
13
|
-
export { IndexSignature } from './index-signature';
|
|
14
9
|
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
15
|
-
export { MethodSignatureTransformer } from './method-signature';
|
|
16
10
|
export { EnumDeclarationTransformer } from './enum-declaration';
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Node, InterfaceDeclaration, SyntaxKind } from 'typescript';
|
|
2
2
|
import pMapSeries from 'p-map-series';
|
|
3
3
|
import { InterfaceSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
4
|
import { SchemaTransformer } from '../schema-transformer';
|
|
5
5
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
6
|
import { ExportIdentifier } from '../export-identifier';
|
|
7
|
+
import { typeElementToSchema } from './utils/type-element-to-schema';
|
|
7
8
|
|
|
8
9
|
export class InterfaceDeclarationTransformer implements SchemaTransformer {
|
|
9
10
|
predicate(node: Node) {
|
|
10
|
-
return node.kind ===
|
|
11
|
+
return node.kind === SyntaxKind.InterfaceDeclaration;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
async getIdentifiers(node: InterfaceDeclaration): Promise<ExportIdentifier[]> {
|
|
@@ -15,10 +16,7 @@ export class InterfaceDeclarationTransformer implements SchemaTransformer {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
async transform(interfaceDec: InterfaceDeclaration, context: SchemaExtractorContext) {
|
|
18
|
-
const members = await pMapSeries(interfaceDec.members,
|
|
19
|
-
const typeSchema = await context.computeSchema(member);
|
|
20
|
-
return typeSchema;
|
|
21
|
-
});
|
|
19
|
+
const members = await pMapSeries(interfaceDec.members, (member) => typeElementToSchema(member, context));
|
|
22
20
|
return new InterfaceSchema(context.getLocation(interfaceDec), interfaceDec.name.getText(), members);
|
|
23
21
|
}
|
|
24
22
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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, VariableSchema } 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-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
|
+
return new ConstructorSchema(context.getLocation(node), args);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {
|
|
50
|
+
const name = node.name.getText();
|
|
51
|
+
const info = await context.getQuickInfo(node.name);
|
|
52
|
+
const displaySig = info?.body?.displayString;
|
|
53
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
54
|
+
const type = await context.resolveType(node, typeStr);
|
|
55
|
+
|
|
56
|
+
return new VariableSchema(context.getLocation(node), name, displaySig || '', type);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
|
|
60
|
+
return toFunctionLikeSchema(node, context);
|
|
61
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* eslint-disable no-fallthrough */
|
|
2
|
+
import { getTextOfJSDocComment, JSDocReturnTag, JSDocTag, Node, SyntaxKind } from 'typescript';
|
|
3
|
+
import { getJsDoc, canHaveJsDoc } from 'tsutils';
|
|
4
|
+
import pMapSeries from 'p-map-series';
|
|
5
|
+
import { DocSchema, ReturnTagSchema, TagName, TagSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
6
|
+
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
7
|
+
import { typeNodeToSchema } from './type-node-to-schema';
|
|
8
|
+
|
|
9
|
+
export async function jsDocToDocSchema(node: Node, context: SchemaExtractorContext): Promise<DocSchema | undefined> {
|
|
10
|
+
if (!canHaveJsDoc(node)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const jsDocs = getJsDoc(node);
|
|
14
|
+
if (!jsDocs.length) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
// not sure how common it is to have multiple JSDocs. never seen it before.
|
|
18
|
+
// regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)
|
|
19
|
+
const jsDoc = jsDocs[0];
|
|
20
|
+
const location = context.getLocation(jsDoc);
|
|
21
|
+
const comment = getTextOfJSDocComment(jsDoc.comment);
|
|
22
|
+
const tags = jsDoc.tags ? await pMapSeries(jsDoc.tags, (tag) => tagParser(tag, context)) : undefined;
|
|
23
|
+
return new DocSchema(location, comment, tags);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function tagParser(tag: JSDocTag, context: SchemaExtractorContext): Promise<TagSchema> {
|
|
27
|
+
let tagName: TagName | string = tag.tagName.getText();
|
|
28
|
+
switch (tag.kind) {
|
|
29
|
+
case SyntaxKind.JSDocReturnTag:
|
|
30
|
+
return returnTag(tag as JSDocReturnTag, context);
|
|
31
|
+
case SyntaxKind.JSDocAugmentsTag:
|
|
32
|
+
tagName = TagName.augments;
|
|
33
|
+
case SyntaxKind.JSDocAuthorTag:
|
|
34
|
+
tagName = TagName.author;
|
|
35
|
+
case SyntaxKind.JSDocClassTag:
|
|
36
|
+
tagName = TagName.class;
|
|
37
|
+
case SyntaxKind.JSDocCallbackTag:
|
|
38
|
+
tagName = TagName.callback;
|
|
39
|
+
case SyntaxKind.JSDocPublicTag:
|
|
40
|
+
tagName = TagName.public;
|
|
41
|
+
case SyntaxKind.JSDocPrivateTag:
|
|
42
|
+
tagName = TagName.private;
|
|
43
|
+
case SyntaxKind.JSDocProtectedTag:
|
|
44
|
+
tagName = TagName.protected;
|
|
45
|
+
case SyntaxKind.JSDocReadonlyTag:
|
|
46
|
+
tagName = TagName.readonly;
|
|
47
|
+
case SyntaxKind.JSDocOverrideTag:
|
|
48
|
+
tagName = TagName.override;
|
|
49
|
+
case SyntaxKind.JSDocDeprecatedTag:
|
|
50
|
+
tagName = TagName.deprecated;
|
|
51
|
+
case SyntaxKind.JSDocSeeTag:
|
|
52
|
+
tagName = TagName.see;
|
|
53
|
+
case SyntaxKind.JSDocEnumTag:
|
|
54
|
+
tagName = TagName.enum;
|
|
55
|
+
case SyntaxKind.JSDocParameterTag:
|
|
56
|
+
tagName = TagName.parameter;
|
|
57
|
+
case SyntaxKind.JSDocThisTag:
|
|
58
|
+
tagName = TagName.this;
|
|
59
|
+
case SyntaxKind.JSDocTypeTag:
|
|
60
|
+
tagName = TagName.type;
|
|
61
|
+
case SyntaxKind.JSDocTemplateTag:
|
|
62
|
+
tagName = TagName.template;
|
|
63
|
+
case SyntaxKind.JSDocTypedefTag:
|
|
64
|
+
tagName = TagName.typedef;
|
|
65
|
+
case SyntaxKind.JSDocPropertyTag:
|
|
66
|
+
tagName = TagName.property;
|
|
67
|
+
case SyntaxKind.JSDocImplementsTag:
|
|
68
|
+
tagName = TagName.implements;
|
|
69
|
+
default:
|
|
70
|
+
return simpleTag(tag, tagName, context);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function simpleTag(tag: JSDocTag, tagName: TagName | string, context: SchemaExtractorContext): TagSchema {
|
|
75
|
+
return new TagSchema(context.getLocation(tag), tagName, getTextOfJSDocComment(tag.comment));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function returnTag(tag: JSDocReturnTag, context: SchemaExtractorContext) {
|
|
79
|
+
const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;
|
|
80
|
+
return new ReturnTagSchema(context.getLocation(tag), TagName.return, getTextOfJSDocComment(tag.comment), type);
|
|
81
|
+
}
|
|
@@ -3,17 +3,21 @@ import { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semant
|
|
|
3
3
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
4
4
|
import { getParams } from './get-params';
|
|
5
5
|
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
6
|
+
import { jsDocToDocSchema } from './jsdoc-to-doc-schema';
|
|
6
7
|
|
|
7
|
-
export async function toFunctionLikeSchema(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export async function toFunctionLikeSchema(
|
|
9
|
+
node: SignatureDeclaration,
|
|
10
|
+
context: SchemaExtractorContext,
|
|
11
|
+
funcName?: string
|
|
12
|
+
) {
|
|
13
|
+
const name = funcName || node.name?.getText() || '';
|
|
14
|
+
const info = node.name ? await context.getQuickInfo(node.name) : null;
|
|
15
|
+
const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';
|
|
12
16
|
const displaySig = info?.body?.displayString || '';
|
|
13
17
|
const args = await getParams(node.parameters, context);
|
|
14
|
-
const returnType = await context.resolveType(node, returnTypeStr);
|
|
18
|
+
const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
|
|
15
19
|
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
16
20
|
const location = context.getLocation(node);
|
|
17
|
-
|
|
18
|
-
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[]);
|
|
21
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
22
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);
|
|
19
23
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts, {
|
|
2
|
+
SyntaxKind,
|
|
3
|
+
TypeElement,
|
|
4
|
+
MethodSignature,
|
|
5
|
+
isComputedPropertyName,
|
|
6
|
+
IndexSignatureDeclaration,
|
|
7
|
+
GetAccessorDeclaration,
|
|
8
|
+
SetAccessorDeclaration,
|
|
9
|
+
ConstructSignatureDeclaration,
|
|
10
|
+
} from 'typescript';
|
|
11
|
+
import {
|
|
12
|
+
GetAccessorSchema,
|
|
13
|
+
IndexSignatureSchema,
|
|
14
|
+
SchemaNode,
|
|
15
|
+
SetAccessorSchema,
|
|
16
|
+
VariableSchema,
|
|
17
|
+
} from '@teambit/semantics.entities.semantic-schema';
|
|
18
|
+
import { toFunctionLikeSchema } from './to-function-schema';
|
|
19
|
+
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
20
|
+
import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
|
|
21
|
+
import { typeNodeToSchema } from './type-node-to-schema';
|
|
22
|
+
import { getParams } from './get-params';
|
|
23
|
+
|
|
24
|
+
export async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
25
|
+
switch (node.kind) {
|
|
26
|
+
case SyntaxKind.MethodSignature:
|
|
27
|
+
return toFunctionLikeSchema(node as MethodSignature, context);
|
|
28
|
+
case SyntaxKind.ConstructSignature:
|
|
29
|
+
return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');
|
|
30
|
+
case SyntaxKind.CallSignature:
|
|
31
|
+
throw new Error(`CallSignature was not implemented yet`);
|
|
32
|
+
case SyntaxKind.PropertySignature:
|
|
33
|
+
return propertySignature(node as ts.PropertySignature, context);
|
|
34
|
+
case SyntaxKind.IndexSignature:
|
|
35
|
+
return indexSignature(node as IndexSignatureDeclaration, context);
|
|
36
|
+
case SyntaxKind.GetAccessor:
|
|
37
|
+
return getAccessor(node as GetAccessorDeclaration, context);
|
|
38
|
+
case SyntaxKind.SetAccessor:
|
|
39
|
+
return setAccessor(node as SetAccessorDeclaration, context);
|
|
40
|
+
default:
|
|
41
|
+
throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {
|
|
46
|
+
const name = node.name.getText();
|
|
47
|
+
const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);
|
|
48
|
+
const displaySig = info?.body?.displayString || '';
|
|
49
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
50
|
+
const type = await context.resolveType(node, typeStr);
|
|
51
|
+
return new VariableSchema(context.getLocation(node), name, displaySig, type);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {
|
|
55
|
+
const params = await getParams(node.parameters, context);
|
|
56
|
+
const type = await typeNodeToSchema(node.type, context);
|
|
57
|
+
return new IndexSignatureSchema(context.getLocation(node), params, type);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
61
|
+
const info = await context.getQuickInfo(node.name);
|
|
62
|
+
const displaySig = info?.body?.displayString || '';
|
|
63
|
+
const typeStr = parseTypeFromQuickInfo(info);
|
|
64
|
+
const type = await context.resolveType(node, typeStr);
|
|
65
|
+
return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {
|
|
69
|
+
const params = await getParams(node.parameters, context);
|
|
70
|
+
const displaySig = await context.getQuickInfoDisplayString(node.name);
|
|
71
|
+
return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);
|
|
72
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
IndexedAccessTypeNode,
|
|
18
18
|
TemplateLiteralTypeNode,
|
|
19
19
|
TemplateLiteralTypeSpan,
|
|
20
|
+
ThisTypeNode,
|
|
20
21
|
} from 'typescript';
|
|
21
22
|
import {
|
|
22
23
|
SchemaNode,
|
|
@@ -36,10 +37,14 @@ import {
|
|
|
36
37
|
IndexedAccessSchema,
|
|
37
38
|
TemplateLiteralTypeSpanSchema,
|
|
38
39
|
TemplateLiteralTypeSchema,
|
|
40
|
+
ThisTypeSchema,
|
|
41
|
+
Modifier,
|
|
39
42
|
} from '@teambit/semantics.entities.semantic-schema';
|
|
40
43
|
import pMapSeries from 'p-map-series';
|
|
41
44
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
42
45
|
import { getParams } from './get-params';
|
|
46
|
+
import { typeElementToSchema } from './type-element-to-schema';
|
|
47
|
+
import { jsDocToDocSchema } from './jsdoc-to-doc-schema';
|
|
43
48
|
|
|
44
49
|
// eslint-disable-next-line complexity
|
|
45
50
|
export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
@@ -78,13 +83,14 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
|
|
|
78
83
|
return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);
|
|
79
84
|
case SyntaxKind.TemplateLiteralType:
|
|
80
85
|
return templateLiteralType(node as TemplateLiteralTypeNode, context);
|
|
86
|
+
case SyntaxKind.ThisType:
|
|
87
|
+
return thisType(node as ThisTypeNode, context);
|
|
81
88
|
case SyntaxKind.ConstructorType:
|
|
82
89
|
case SyntaxKind.NamedTupleMember:
|
|
83
90
|
case SyntaxKind.OptionalType:
|
|
84
91
|
case SyntaxKind.RestType:
|
|
85
92
|
case SyntaxKind.ConditionalType:
|
|
86
93
|
case SyntaxKind.InferType:
|
|
87
|
-
case SyntaxKind.ThisType:
|
|
88
94
|
case SyntaxKind.MappedType:
|
|
89
95
|
case SyntaxKind.ImportType:
|
|
90
96
|
case SyntaxKind.ExpressionWithTypeArguments:
|
|
@@ -153,10 +159,7 @@ async function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {
|
|
|
153
159
|
* this "TypeLiteral" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.
|
|
154
160
|
*/
|
|
155
161
|
async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {
|
|
156
|
-
const members = await pMapSeries(node.members,
|
|
157
|
-
const typeSchema = await context.computeSchema(member);
|
|
158
|
-
return typeSchema;
|
|
159
|
-
});
|
|
162
|
+
const members = await pMapSeries(node.members, (member) => typeElementToSchema(member, context));
|
|
160
163
|
const location = context.getLocation(node);
|
|
161
164
|
return new TypeLiteralSchema(location, members);
|
|
162
165
|
}
|
|
@@ -183,7 +186,9 @@ async function functionType(node: FunctionTypeNode, context: SchemaExtractorCont
|
|
|
183
186
|
const params = await getParams(node.parameters, context);
|
|
184
187
|
const returnType = await typeNodeToSchema(node.type, context);
|
|
185
188
|
const location = context.getLocation(node);
|
|
186
|
-
|
|
189
|
+
const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
190
|
+
const doc = await jsDocToDocSchema(node, context);
|
|
191
|
+
return new FunctionLikeSchema(location, name, params, returnType, '', modifiers as Modifier[], doc);
|
|
187
192
|
}
|
|
188
193
|
|
|
189
194
|
/**
|
|
@@ -261,3 +266,7 @@ async function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: S
|
|
|
261
266
|
const literal = node.literal.text;
|
|
262
267
|
return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);
|
|
263
268
|
}
|
|
269
|
+
|
|
270
|
+
async function thisType(node: ThisTypeNode, context: SchemaExtractorContext) {
|
|
271
|
+
return new ThisTypeSchema(context.getLocation(node));
|
|
272
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { SchemaNode, VariableSchema, FunctionLikeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
1
|
+
import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';
|
|
2
2
|
import ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
4
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
5
|
import { ExportIdentifier } from '../export-identifier';
|
|
6
6
|
import { getParams } from './utils/get-params';
|
|
7
7
|
import { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
|
|
8
|
+
import { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';
|
|
8
9
|
|
|
9
10
|
export class VariableDeclaration implements SchemaTransformer {
|
|
10
11
|
predicate(node: Node) {
|
|
@@ -28,7 +29,9 @@ export class VariableDeclaration implements SchemaTransformer {
|
|
|
28
29
|
const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);
|
|
29
30
|
const typeStr = parseReturnTypeFromQuickInfo(info);
|
|
30
31
|
const returnType = await context.resolveType(varDec, typeStr);
|
|
31
|
-
|
|
32
|
+
const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
33
|
+
const doc = await jsDocToDocSchema(varDec, context);
|
|
34
|
+
return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);
|
|
32
35
|
}
|
|
33
36
|
const typeStr = parseTypeFromQuickInfo(info);
|
|
34
37
|
const type = await context.resolveType(varDec, typeStr);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import { Node, ConstructorDeclaration } from 'typescript';
|
|
3
|
-
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
|
-
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
-
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
-
export declare class Constructor implements SchemaTransformer {
|
|
7
|
-
predicate(node: Node): boolean;
|
|
8
|
-
getIdentifiers(node: ConstructorDeclaration): Promise<ExportIdentifier[]>;
|
|
9
|
-
transform(constructorDec: ConstructorDeclaration, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
10
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/es.promise.js");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.Constructor = void 0;
|
|
11
|
-
|
|
12
|
-
function _semanticsEntities() {
|
|
13
|
-
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
14
|
-
|
|
15
|
-
_semanticsEntities = function () {
|
|
16
|
-
return data;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _typescript() {
|
|
23
|
-
const data = _interopRequireDefault(require("typescript"));
|
|
24
|
-
|
|
25
|
-
_typescript = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function _exportIdentifier() {
|
|
33
|
-
const data = require("../export-identifier");
|
|
34
|
-
|
|
35
|
-
_exportIdentifier = function () {
|
|
36
|
-
return data;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return data;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function _getParams() {
|
|
43
|
-
const data = require("./utils/get-params");
|
|
44
|
-
|
|
45
|
-
_getParams = function () {
|
|
46
|
-
return data;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return data;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class Constructor {
|
|
53
|
-
predicate(node) {
|
|
54
|
-
return node.kind === _typescript().default.SyntaxKind.Constructor;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async getIdentifiers(node) {
|
|
58
|
-
return [new (_exportIdentifier().ExportIdentifier)('constructor', node.getSourceFile().fileName)];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async transform(constructorDec, context) {
|
|
62
|
-
const args = await (0, _getParams().getParams)(constructorDec.parameters, context);
|
|
63
|
-
return new (_semanticsEntities().ConstructorSchema)(context.getLocation(constructorDec), args);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
exports.Constructor = Constructor;
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=constructor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Constructor","predicate","node","kind","ts","SyntaxKind","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","constructorDec","context","args","getParams","parameters","ConstructorSchema","getLocation"],"sources":["constructor.ts"],"sourcesContent":["import { SchemaNode, ConstructorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ConstructorDeclaration } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\n\nexport class Constructor implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.Constructor;\n }\n\n async getIdentifiers(node: ConstructorDeclaration) {\n return [new ExportIdentifier('constructor', node.getSourceFile().fileName)];\n }\n\n async transform(constructorDec: ConstructorDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const args = await getParams(constructorDec.parameters, context);\n\n return new ConstructorSchema(context.getLocation(constructorDec), args);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,WAAN,CAA+C;EACpDC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,WAAnC;EACD;;EAEmB,MAAdM,cAAc,CAACJ,IAAD,EAA+B;IACjD,OAAO,CAAC,KAAIK,oCAAJ,EAAqB,aAArB,EAAoCL,IAAI,CAACM,aAAL,GAAqBC,QAAzD,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,cAAD,EAAyCC,OAAzC,EAA+F;IAC5G,MAAMC,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAUH,cAAc,CAACI,UAAzB,EAAqCH,OAArC,CAAnB;IAEA,OAAO,KAAII,sCAAJ,EAAsBJ,OAAO,CAACK,WAAR,CAAoBN,cAApB,CAAtB,EAA2DE,IAA3D,CAAP;EACD;;AAbmD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import { Node, IndexSignatureDeclaration } from 'typescript';
|
|
3
|
-
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
-
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
-
export declare class IndexSignature implements SchemaTransformer {
|
|
6
|
-
predicate(node: Node): boolean;
|
|
7
|
-
getIdentifiers(): Promise<never[]>;
|
|
8
|
-
transform(indexSig: IndexSignatureDeclaration, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
9
|
-
}
|