@teambit/typescript 0.0.740 → 0.0.743

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.
Files changed (73) hide show
  1. package/dist/schema-extractor-context.d.ts +4 -6
  2. package/dist/schema-extractor-context.js +37 -27
  3. package/dist/schema-extractor-context.js.map +1 -1
  4. package/dist/transformers/class-deceleration.js +10 -40
  5. package/dist/transformers/class-deceleration.js.map +1 -1
  6. package/dist/transformers/export-declaration.js +9 -2
  7. package/dist/transformers/export-declaration.js.map +1 -1
  8. package/dist/transformers/index.d.ts +0 -6
  9. package/dist/transformers/index.js +0 -96
  10. package/dist/transformers/index.js.map +1 -1
  11. package/dist/transformers/interface-declaration.js +13 -6
  12. package/dist/transformers/interface-declaration.js.map +1 -1
  13. package/dist/transformers/type-alias.js +2 -5
  14. package/dist/transformers/type-alias.js.map +1 -1
  15. package/dist/transformers/utils/class-element-to-schema.d.ts +4 -0
  16. package/dist/transformers/utils/class-element-to-schema.js +122 -0
  17. package/dist/transformers/utils/class-element-to-schema.js.map +1 -0
  18. package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +4 -0
  19. package/dist/transformers/utils/jsdoc-to-doc-schema.js +163 -0
  20. package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -0
  21. package/dist/transformers/utils/to-function-schema.d.ts +1 -1
  22. package/dist/transformers/utils/to-function-schema.js +17 -7
  23. package/dist/transformers/utils/to-function-schema.js.map +1 -1
  24. package/dist/transformers/utils/type-element-to-schema.d.ts +7 -0
  25. package/dist/transformers/utils/type-element-to-schema.js +134 -0
  26. package/dist/transformers/utils/type-element-to-schema.js.map +1 -0
  27. package/dist/transformers/utils/type-node-to-schema.js +50 -9
  28. package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
  29. package/dist/transformers/variable-declaration.js +15 -1
  30. package/dist/transformers/variable-declaration.js.map +1 -1
  31. package/dist/typescript.extractor.js +1 -1
  32. package/dist/typescript.extractor.js.map +1 -1
  33. package/dist/typescript.main.runtime.js +1 -1
  34. package/dist/typescript.main.runtime.js.map +1 -1
  35. package/package-tar/teambit-typescript-0.0.743.tgz +0 -0
  36. package/package.json +16 -16
  37. package/{preview-1653449228788.js → preview-1653708349111.js} +2 -2
  38. package/transformers/class-deceleration.ts +7 -26
  39. package/transformers/export-declaration.ts +7 -2
  40. package/transformers/index.ts +0 -6
  41. package/transformers/interface-declaration.ts +4 -6
  42. package/transformers/type-alias.ts +2 -3
  43. package/transformers/utils/class-element-to-schema.ts +61 -0
  44. package/transformers/utils/jsdoc-to-doc-schema.ts +81 -0
  45. package/transformers/utils/to-function-schema.ts +12 -8
  46. package/transformers/utils/type-element-to-schema.ts +72 -0
  47. package/transformers/utils/type-node-to-schema.ts +35 -8
  48. package/transformers/variable-declaration.ts +5 -2
  49. package/dist/transformers/constructor.d.ts +0 -10
  50. package/dist/transformers/constructor.js +0 -70
  51. package/dist/transformers/constructor.js.map +0 -1
  52. package/dist/transformers/index-signature.d.ts +0 -9
  53. package/dist/transformers/index-signature.js +0 -71
  54. package/dist/transformers/index-signature.js.map +0 -1
  55. package/dist/transformers/method-declaration.d.ts +0 -11
  56. package/dist/transformers/method-declaration.js +0 -65
  57. package/dist/transformers/method-declaration.js.map +0 -1
  58. package/dist/transformers/method-signature.d.ts +0 -10
  59. package/dist/transformers/method-signature.js +0 -53
  60. package/dist/transformers/method-signature.js.map +0 -1
  61. package/dist/transformers/property-declaration.d.ts +0 -11
  62. package/dist/transformers/property-declaration.js +0 -80
  63. package/dist/transformers/property-declaration.js.map +0 -1
  64. package/dist/transformers/property-signature.d.ts +0 -10
  65. package/dist/transformers/property-signature.js +0 -87
  66. package/dist/transformers/property-signature.js.map +0 -1
  67. package/package-tar/teambit-typescript-0.0.740.tgz +0 -0
  68. package/transformers/constructor.ts +0 -22
  69. package/transformers/index-signature.ts +0 -22
  70. package/transformers/method-declaration.ts +0 -24
  71. package/transformers/method-signature.ts +0 -23
  72. package/transformers/property-declaration.ts +0 -30
  73. package/transformers/property-signature.ts +0 -34
@@ -1,13 +1,14 @@
1
- import ts, { Node, InterfaceDeclaration } from 'typescript';
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 === ts.SyntaxKind.InterfaceDeclaration;
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, async (member) => {
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
  }
@@ -20,8 +20,7 @@ export class TypeAliasTransformer implements SchemaTransformer {
20
20
 
21
21
  async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {
22
22
  const type = await typeNodeToSchema(typeAlias.type, context);
23
- const info = await context.getQuickInfo(typeAlias.name);
24
- const displaySig = info?.body?.displayString;
25
- return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
23
+ const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
24
+ return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig);
26
25
  }
27
26
  }
@@ -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(node: SignatureDeclaration, context: SchemaExtractorContext) {
8
- const name = node.name?.getText() || '';
9
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10
- const info = await context.getQuickInfo(node.name!);
11
- const returnTypeStr = parseTypeFromQuickInfo(info);
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
+ }
@@ -15,6 +15,9 @@ import {
15
15
  TypePredicateNode,
16
16
  isIdentifier,
17
17
  IndexedAccessTypeNode,
18
+ TemplateLiteralTypeNode,
19
+ TemplateLiteralTypeSpan,
20
+ ThisTypeNode,
18
21
  } from 'typescript';
19
22
  import {
20
23
  SchemaNode,
@@ -32,10 +35,16 @@ import {
32
35
  ParenthesizedTypeSchema,
33
36
  TypePredicateSchema,
34
37
  IndexedAccessSchema,
38
+ TemplateLiteralTypeSpanSchema,
39
+ TemplateLiteralTypeSchema,
40
+ ThisTypeSchema,
41
+ Modifier,
35
42
  } from '@teambit/semantics.entities.semantic-schema';
36
43
  import pMapSeries from 'p-map-series';
37
44
  import { SchemaExtractorContext } from '../../schema-extractor-context';
38
45
  import { getParams } from './get-params';
46
+ import { typeElementToSchema } from './type-element-to-schema';
47
+ import { jsDocToDocSchema } from './jsdoc-to-doc-schema';
39
48
 
40
49
  // eslint-disable-next-line complexity
41
50
  export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {
@@ -70,16 +79,19 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
70
79
  return typePredicate(node as TypePredicateNode, context);
71
80
  case SyntaxKind.IndexedAccessType:
72
81
  return indexedAccessType(node as IndexedAccessTypeNode, context);
82
+ case SyntaxKind.TemplateLiteralTypeSpan:
83
+ return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);
84
+ case SyntaxKind.TemplateLiteralType:
85
+ return templateLiteralType(node as TemplateLiteralTypeNode, context);
86
+ case SyntaxKind.ThisType:
87
+ return thisType(node as ThisTypeNode, context);
73
88
  case SyntaxKind.ConstructorType:
74
89
  case SyntaxKind.NamedTupleMember:
75
90
  case SyntaxKind.OptionalType:
76
91
  case SyntaxKind.RestType:
77
92
  case SyntaxKind.ConditionalType:
78
93
  case SyntaxKind.InferType:
79
- case SyntaxKind.ThisType:
80
94
  case SyntaxKind.MappedType:
81
- case SyntaxKind.TemplateLiteralType:
82
- case SyntaxKind.TemplateLiteralTypeSpan:
83
95
  case SyntaxKind.ImportType:
84
96
  case SyntaxKind.ExpressionWithTypeArguments:
85
97
  case SyntaxKind.JSDocTypeExpression:
@@ -147,10 +159,7 @@ async function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {
147
159
  * this "TypeLiteral" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.
148
160
  */
149
161
  async function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {
150
- const members = await pMapSeries(node.members, async (member) => {
151
- const typeSchema = await context.computeSchema(member);
152
- return typeSchema;
153
- });
162
+ const members = await pMapSeries(node.members, (member) => typeElementToSchema(member, context));
154
163
  const location = context.getLocation(node);
155
164
  return new TypeLiteralSchema(location, members);
156
165
  }
@@ -177,7 +186,9 @@ async function functionType(node: FunctionTypeNode, context: SchemaExtractorCont
177
186
  const params = await getParams(node.parameters, context);
178
187
  const returnType = await typeNodeToSchema(node.type, context);
179
188
  const location = context.getLocation(node);
180
- return new FunctionLikeSchema(location, name, params, returnType, '');
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);
181
192
  }
182
193
 
183
194
  /**
@@ -243,3 +254,19 @@ async function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExt
243
254
  const indexType = await typeNodeToSchema(node.indexType, context);
244
255
  return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);
245
256
  }
257
+
258
+ async function templateLiteralType(node: TemplateLiteralTypeNode, context: SchemaExtractorContext) {
259
+ const templateSpans = await pMapSeries(node.templateSpans, (span) => templateLiteralTypeSpan(span, context));
260
+ const head = node.head.text;
261
+ return new TemplateLiteralTypeSchema(context.getLocation(node), head, templateSpans);
262
+ }
263
+
264
+ async function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: SchemaExtractorContext) {
265
+ const type = await typeNodeToSchema(node.type, context);
266
+ const literal = node.literal.text;
267
+ return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);
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
- return new FunctionLikeSchema(location, name, args, returnType, displaySig);
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
- }
@@ -1,71 +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.IndexSignature = 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 _getParams() {
33
- const data = require("./utils/get-params");
34
-
35
- _getParams = function () {
36
- return data;
37
- };
38
-
39
- return data;
40
- }
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
-
52
- class IndexSignature {
53
- predicate(node) {
54
- return node.kind === _typescript().default.SyntaxKind.IndexSignature;
55
- }
56
-
57
- async getIdentifiers() {
58
- return [];
59
- }
60
-
61
- async transform(indexSig, context) {
62
- const params = await (0, _getParams().getParams)(indexSig.parameters, context);
63
- const type = await (0, _typeNodeToSchema().typeNodeToSchema)(indexSig.type, context);
64
- return new (_semanticsEntities().IndexSignatureSchema)(context.getLocation(indexSig), params, type);
65
- }
66
-
67
- }
68
-
69
- exports.IndexSignature = IndexSignature;
70
-
71
- //# sourceMappingURL=index-signature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","getParams","parameters","type","typeNodeToSchema","IndexSignatureSchema","getLocation"],"sources":["index-signature.ts"],"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(context.getLocation(indexSig), params, type);\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,cAAN,CAAkD;EACvDC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,cAAnC;EACD;;EAEmB,MAAdM,cAAc,GAAG;IACrB,OAAO,EAAP;EACD;;EAEc,MAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;IACzG,MAAMC,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUH,QAAQ,CAACI,UAAnB,EAA+BH,OAA/B,CAArB;IACA,MAAMI,IAAI,GAAG,MAAM,IAAAC,oCAAA,EAAiBN,QAAQ,CAACK,IAA1B,EAAgCJ,OAAhC,CAAnB;IACA,OAAO,KAAIM,yCAAJ,EAAyBN,OAAO,CAACO,WAAR,CAAoBR,QAApB,CAAzB,EAAwDE,MAAxD,EAAgEG,IAAhE,CAAP;EACD;;AAbsD"}
@@ -1,11 +0,0 @@
1
- import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
2
- import { Node, MethodDeclaration as MethodDeclarationNode } 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 MethodDeclaration implements SchemaTransformer {
7
- predicate(node: Node): boolean;
8
- getIdentifiers(funcDec: MethodDeclarationNode): Promise<ExportIdentifier[]>;
9
- private getName;
10
- transform(methodDec: MethodDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode>;
11
- }
@@ -1,65 +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.MethodDeclaration = void 0;
11
-
12
- function _typescript() {
13
- const data = _interopRequireDefault(require("typescript"));
14
-
15
- _typescript = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
- function _exportIdentifier() {
23
- const data = require("../export-identifier");
24
-
25
- _exportIdentifier = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
31
-
32
- function _toFunctionSchema() {
33
- const data = require("./utils/to-function-schema");
34
-
35
- _toFunctionSchema = function () {
36
- return data;
37
- };
38
-
39
- return data;
40
- }
41
-
42
- class MethodDeclaration {
43
- predicate(node) {
44
- return node.kind === _typescript().default.SyntaxKind.MethodDeclaration;
45
- }
46
-
47
- async getIdentifiers(funcDec) {
48
- return [new (_exportIdentifier().ExportIdentifier)(this.getName(funcDec), funcDec.getSourceFile().fileName)];
49
- }
50
-
51
- getName(funcDec) {
52
- var _funcDec$name;
53
-
54
- return ((_funcDec$name = funcDec.name) === null || _funcDec$name === void 0 ? void 0 : _funcDec$name.getText()) || '';
55
- }
56
-
57
- async transform(methodDec, context) {
58
- return (0, _toFunctionSchema().toFunctionLikeSchema)(methodDec, context);
59
- }
60
-
61
- }
62
-
63
- exports.MethodDeclaration = MethodDeclaration;
64
-
65
- //# sourceMappingURL=method-declaration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["MethodDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","methodDec","context","toFunctionLikeSchema"],"sources":["method-declaration.ts"],"sourcesContent":["import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, MethodDeclaration as MethodDeclarationNode } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { toFunctionLikeSchema } from './utils/to-function-schema';\n\nexport class MethodDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.MethodDeclaration;\n }\n\n async getIdentifiers(funcDec: MethodDeclarationNode) {\n return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];\n }\n\n private getName(funcDec: MethodDeclarationNode) {\n return funcDec.name?.getText() || '';\n }\n\n async transform(methodDec: MethodDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n return toFunctionLikeSchema(methodDec, context);\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,iBAAnC;EACD;;EAEmB,MAAdM,cAAc,CAACC,OAAD,EAAiC;IACnD,OAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;EACD;;EAEOF,OAAO,CAACF,OAAD,EAAiC;IAAA;;IAC9C,OAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;EACD;;EAEc,MAATC,SAAS,CAACC,SAAD,EAAmCC,OAAnC,EAAyF;IACtG,OAAO,IAAAC,wCAAA,EAAqBF,SAArB,EAAgCC,OAAhC,CAAP;EACD;;AAfyD"}