@teambit/typescript 0.0.965 → 0.0.967
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/export-identifier.d.ts +5 -4
- package/dist/export-identifier.js +23 -4
- package/dist/export-identifier.js.map +1 -1
- package/dist/identifier-list.d.ts +7 -0
- package/dist/identifier-list.js +21 -0
- package/dist/identifier-list.js.map +1 -0
- package/dist/identifier.d.ts +9 -0
- package/dist/identifier.js +30 -0
- package/dist/identifier.js.map +1 -0
- package/dist/{preview-1674271762484.js → preview-1674617375675.js} +2 -2
- package/dist/schema-extractor-context.d.ts +40 -8
- package/dist/schema-extractor-context.js +243 -101
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/schema-transformer.d.ts +2 -2
- package/dist/schema-transformer.js.map +1 -1
- package/dist/transformers/array-type.d.ts +10 -0
- package/dist/transformers/array-type.js +38 -0
- package/dist/transformers/array-type.js.map +1 -0
- package/dist/transformers/binding-element.d.ts +2 -2
- package/dist/transformers/binding-element.js +7 -7
- package/dist/transformers/binding-element.js.map +1 -1
- package/dist/transformers/class-declaration.d.ts +2 -2
- package/dist/transformers/class-declaration.js +6 -20
- package/dist/transformers/class-declaration.js.map +1 -1
- package/dist/transformers/conditional-type.d.ts +10 -0
- package/dist/transformers/conditional-type.js +39 -0
- package/dist/transformers/conditional-type.js.map +1 -0
- package/dist/transformers/constructor.d.ts +10 -0
- package/dist/transformers/constructor.js +50 -0
- package/dist/transformers/constructor.js.map +1 -0
- package/dist/transformers/enum-declaration.d.ts +2 -2
- package/dist/transformers/enum-declaration.js +4 -4
- package/dist/transformers/enum-declaration.js.map +1 -1
- package/dist/transformers/{export-assignment-declaration.d.ts → export-assignment.d.ts} +7 -2
- package/dist/transformers/export-assignment.js +41 -0
- package/dist/transformers/export-assignment.js.map +1 -0
- package/dist/transformers/export-declaration.d.ts +2 -3
- package/dist/transformers/export-declaration.js +21 -10
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-like.d.ts +11 -0
- package/dist/transformers/function-like.js +82 -0
- package/dist/transformers/function-like.js.map +1 -0
- package/dist/transformers/get-accessor.d.ts +10 -0
- package/dist/transformers/get-accessor.js +48 -0
- package/dist/transformers/get-accessor.js.map +1 -0
- package/dist/transformers/import-declaration.d.ts +10 -0
- package/dist/transformers/import-declaration.js +74 -0
- package/dist/transformers/import-declaration.js.map +1 -0
- package/dist/transformers/index-signature.d.ts +10 -0
- package/dist/transformers/index-signature.js +45 -0
- package/dist/transformers/index-signature.js.map +1 -0
- package/dist/transformers/index.d.ts +28 -3
- package/dist/transformers/index.js +337 -12
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/indexed-access-type.d.ts +10 -0
- package/dist/transformers/indexed-access-type.js +37 -0
- package/dist/transformers/indexed-access-type.js.map +1 -0
- package/dist/transformers/interface-declaration.d.ts +2 -2
- package/dist/transformers/interface-declaration.js +6 -20
- package/dist/transformers/interface-declaration.js.map +1 -1
- package/dist/transformers/intersection-type.d.ts +10 -0
- package/dist/transformers/intersection-type.js +48 -0
- package/dist/transformers/intersection-type.js.map +1 -0
- package/dist/transformers/keyword-type.d.ts +13 -0
- package/dist/transformers/keyword-type.js +55 -0
- package/dist/transformers/keyword-type.js.map +1 -0
- package/dist/transformers/literal-type.d.ts +13 -0
- package/dist/transformers/literal-type.js +40 -0
- package/dist/transformers/literal-type.js.map +1 -0
- package/dist/transformers/named-tuple.d.ts +10 -0
- package/dist/transformers/named-tuple.js +38 -0
- package/dist/transformers/named-tuple.js.map +1 -0
- package/dist/transformers/parameter.d.ts +13 -0
- package/dist/transformers/parameter.js +112 -0
- package/dist/transformers/parameter.js.map +1 -0
- package/dist/transformers/parenthesized-type.d.ts +10 -0
- package/dist/transformers/parenthesized-type.js +36 -0
- package/dist/transformers/parenthesized-type.js.map +1 -0
- package/dist/transformers/property-declaration.d.ts +11 -0
- package/dist/transformers/property-declaration.js +57 -0
- package/dist/transformers/property-declaration.js.map +1 -0
- package/dist/transformers/set-accessor.d.ts +10 -0
- package/dist/transformers/set-accessor.js +45 -0
- package/dist/transformers/set-accessor.js.map +1 -0
- package/dist/transformers/source-file-transformer.d.ts +3 -2
- package/dist/transformers/source-file-transformer.js +44 -15
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/template-literal-type-span.d.ts +10 -0
- package/dist/transformers/template-literal-type-span.js +37 -0
- package/dist/transformers/template-literal-type-span.js.map +1 -0
- package/dist/transformers/template-literal-type.d.ts +10 -0
- package/dist/transformers/template-literal-type.js +45 -0
- package/dist/transformers/template-literal-type.js.map +1 -0
- package/dist/transformers/this-type.d.ts +10 -0
- package/dist/transformers/this-type.js +35 -0
- package/dist/transformers/this-type.js.map +1 -0
- package/dist/transformers/tuple-type.d.ts +10 -0
- package/dist/transformers/tuple-type.js +47 -0
- package/dist/transformers/tuple-type.js.map +1 -0
- package/dist/transformers/type-alias.d.ts +2 -2
- package/dist/transformers/type-alias.js +5 -12
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/type-literal.d.ts +14 -0
- package/dist/transformers/type-literal.js +49 -0
- package/dist/transformers/type-literal.js.map +1 -0
- package/dist/transformers/type-operator.d.ts +14 -0
- package/dist/transformers/type-operator.js +52 -0
- package/dist/transformers/type-operator.js.map +1 -0
- package/dist/transformers/type-predicate.d.ts +10 -0
- package/dist/transformers/type-predicate.js +38 -0
- package/dist/transformers/type-predicate.js.map +1 -0
- package/dist/transformers/type-query.d.ts +13 -0
- package/dist/transformers/type-query.js +42 -0
- package/dist/transformers/type-query.js.map +1 -0
- package/dist/transformers/type-reference.d.ts +16 -0
- package/dist/transformers/type-reference.js +56 -0
- package/dist/transformers/type-reference.js.map +1 -0
- package/dist/transformers/union-type.d.ts +10 -0
- package/dist/transformers/union-type.js +48 -0
- package/dist/transformers/union-type.js.map +1 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +2 -10
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
- package/dist/transformers/variable-declaration.d.ts +2 -2
- package/dist/transformers/variable-declaration.js +11 -11
- package/dist/transformers/variable-declaration.js.map +1 -1
- package/dist/transformers/variable-statement.d.ts +2 -2
- package/dist/transformers/variable-statement.js +5 -5
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.extractor.d.ts +10 -4
- package/dist/typescript.extractor.js +70 -17
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +4 -2
- package/dist/typescript.main.runtime.js +5 -11
- package/dist/typescript.main.runtime.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.967.tgz +0 -0
- package/package.json +17 -17
- package/transformers/array-type.ts +21 -0
- package/transformers/binding-element.ts +2 -2
- package/transformers/class-declaration.ts +4 -6
- package/transformers/conditional-type.ts +23 -0
- package/transformers/constructor.ts +40 -0
- package/transformers/enum-declaration.ts +3 -3
- package/transformers/{export-assignment-declaration.ts → export-assignment.ts} +9 -3
- package/transformers/export-declaration.ts +35 -8
- package/transformers/function-like.ts +65 -0
- package/transformers/get-accessor.ts +24 -0
- package/transformers/import-declaration.ts +56 -0
- package/transformers/index-signature.ts +24 -0
- package/transformers/index.ts +28 -3
- package/transformers/indexed-access-type.ts +21 -0
- package/transformers/interface-declaration.ts +5 -7
- package/transformers/intersection-type.ts +25 -0
- package/transformers/keyword-type.ts +39 -0
- package/transformers/literal-type.ts +23 -0
- package/transformers/named-tuple.ts +22 -0
- package/transformers/parameter.ts +110 -0
- package/transformers/parenthesized-type.ts +20 -0
- package/transformers/property-declaration.ts +33 -0
- package/transformers/set-accessor.ts +25 -0
- package/transformers/source-file-transformer.ts +56 -24
- package/transformers/template-literal-type-span.ts +21 -0
- package/transformers/template-literal-type.ts +24 -0
- package/transformers/this-type.ts +19 -0
- package/transformers/tuple-type.ts +24 -0
- package/transformers/type-alias.ts +3 -4
- package/transformers/type-literal.ts +26 -0
- package/transformers/type-operator.ts +37 -0
- package/transformers/type-predicate.ts +22 -0
- package/transformers/type-query.ts +25 -0
- package/transformers/type-reference.ts +33 -0
- package/transformers/union-type.ts +25 -0
- package/transformers/utils/jsdoc-to-doc-schema.ts +2 -4
- package/transformers/variable-declaration.ts +7 -4
- package/transformers/variable-statement.ts +3 -3
- package/dist/export-list.d.ts +0 -6
- package/dist/export-list.js +0 -17
- package/dist/export-list.js.map +0 -1
- package/dist/transformers/export-assignment-declaration.js +0 -29
- package/dist/transformers/export-assignment-declaration.js.map +0 -1
- package/dist/transformers/function-declaration.d.ts +0 -11
- package/dist/transformers/function-declaration.js +0 -49
- package/dist/transformers/function-declaration.js.map +0 -1
- package/dist/transformers/utils/class-element-to-schema.d.ts +0 -4
- package/dist/transformers/utils/class-element-to-schema.js +0 -95
- package/dist/transformers/utils/class-element-to-schema.js.map +0 -1
- package/dist/transformers/utils/get-params.d.ts +0 -4
- package/dist/transformers/utils/get-params.js +0 -100
- package/dist/transformers/utils/get-params.js.map +0 -1
- package/dist/transformers/utils/to-function-like-schema.d.ts +0 -4
- package/dist/transformers/utils/to-function-like-schema.js +0 -58
- package/dist/transformers/utils/to-function-like-schema.js.map +0 -1
- package/dist/transformers/utils/type-element-to-schema.d.ts +0 -7
- package/dist/transformers/utils/type-element-to-schema.js +0 -106
- package/dist/transformers/utils/type-element-to-schema.js.map +0 -1
- package/dist/transformers/utils/type-node-to-schema.d.ts +0 -4
- package/dist/transformers/utils/type-node-to-schema.js +0 -274
- package/dist/transformers/utils/type-node-to-schema.js.map +0 -1
- package/package-tar/teambit-typescript-0.0.965.tgz +0 -0
- package/transformers/function-declaration.ts +0 -25
- package/transformers/utils/class-element-to-schema.ts +0 -64
- package/transformers/utils/get-params.ts +0 -92
- package/transformers/utils/to-function-like-schema.ts +0 -39
- package/transformers/utils/type-element-to-schema.ts +0 -79
- package/transformers/utils/type-node-to-schema.ts +0 -294
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import ts, { Node, SourceFile } from 'typescript';
|
|
2
|
-
import {
|
|
2
|
+
import { flatten } from 'lodash';
|
|
3
3
|
import pMapSeries from 'p-map-series';
|
|
4
4
|
import { ModuleSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { ExportIdentifier } from '../export-identifier';
|
|
7
7
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
8
|
+
import { Identifier } from '../identifier';
|
|
8
9
|
|
|
9
10
|
export class SourceFileTransformer implements SchemaTransformer {
|
|
10
11
|
predicate(node: Node) {
|
|
@@ -13,48 +14,79 @@ export class SourceFileTransformer implements SchemaTransformer {
|
|
|
13
14
|
|
|
14
15
|
async getIdentifiers(sourceFile: SourceFile, context: SchemaExtractorContext) {
|
|
15
16
|
const exports = this.listExports(sourceFile);
|
|
17
|
+
const internals = this.listInternalNodes(sourceFile);
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// change to pMap series
|
|
20
|
+
const exportIdentifiers = flatten(
|
|
21
|
+
await pMapSeries(exports, (node) => {
|
|
22
|
+
return context.getIdentifiers(node);
|
|
20
23
|
})
|
|
21
|
-
)
|
|
24
|
+
).reduce<ExportIdentifier[]>((acc, current) => {
|
|
25
|
+
const item = acc.find((exportIdentifier) => exportIdentifier.isEqual(current));
|
|
26
|
+
if (!item) acc.push(new ExportIdentifier(current.id, current.filePath, current.aliasId, current.sourceFilePath));
|
|
27
|
+
return acc;
|
|
28
|
+
}, []);
|
|
22
29
|
|
|
23
|
-
const
|
|
24
|
-
|
|
30
|
+
const internalIdentifiers = flatten(
|
|
31
|
+
await pMapSeries(internals, (node) => {
|
|
32
|
+
return context.getIdentifiers(node);
|
|
33
|
+
})
|
|
34
|
+
).reduce<Identifier[]>((acc, current) => {
|
|
35
|
+
const item = acc.find((internalIdentifier) => internalIdentifier.isEqual(current));
|
|
25
36
|
if (!item) acc.push(current);
|
|
26
37
|
return acc;
|
|
27
38
|
}, []);
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
const identifiers = [...exportIdentifiers, ...internalIdentifiers];
|
|
41
|
+
|
|
42
|
+
return identifiers;
|
|
30
43
|
}
|
|
31
44
|
|
|
32
45
|
async transform(node: SourceFile, context: SchemaExtractorContext) {
|
|
33
46
|
const exports = this.listExports(node);
|
|
34
|
-
const
|
|
47
|
+
const internals = this.listInternalNodes(node).filter(
|
|
48
|
+
(internal) => internal.kind !== ts.SyntaxKind.ImportDeclaration
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const exportDeclarations = await pMapSeries(exports, (exportNode) => {
|
|
35
52
|
return context.computeSchema(exportNode);
|
|
36
53
|
});
|
|
37
54
|
|
|
38
|
-
|
|
55
|
+
const internalDeclarations = await pMapSeries(internals, (internalNode) => {
|
|
56
|
+
return context.computeSchema(internalNode);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return new ModuleSchema(context.getLocation(node), exportDeclarations, internalDeclarations);
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
/**
|
|
42
63
|
* list all exports of a source file.
|
|
43
64
|
*/
|
|
44
65
|
private listExports(ast: SourceFile): Node[] {
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
66
|
+
return ast.statements.filter((statement) => {
|
|
67
|
+
if (statement.kind === ts.SyntaxKind.ExportDeclaration || statement.kind === ts.SyntaxKind.ExportAssignment)
|
|
68
|
+
return true;
|
|
69
|
+
const isExport = Boolean(
|
|
70
|
+
statement.modifiers?.find((modifier) => {
|
|
71
|
+
return modifier.kind === ts.SyntaxKind.ExportKeyword;
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
return isExport;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private listInternalNodes(ast: SourceFile): Node[] {
|
|
79
|
+
return ast.statements.filter((statement) => {
|
|
80
|
+
if (
|
|
81
|
+
!(statement.kind === ts.SyntaxKind.ExportDeclaration || statement.kind === ts.SyntaxKind.ExportAssignment) &&
|
|
82
|
+
!statement.modifiers?.find((modifier) => {
|
|
83
|
+
return modifier.kind === ts.SyntaxKind.ExportKeyword;
|
|
84
|
+
})
|
|
85
|
+
) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false;
|
|
90
|
+
});
|
|
59
91
|
}
|
|
60
92
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Node, SyntaxKind, TemplateLiteralTypeSpan } from 'typescript';
|
|
2
|
+
import { TemplateLiteralTypeSpanSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
|
|
7
|
+
export class TemplateLiteralTypeSpanTransformer implements SchemaTransformer {
|
|
8
|
+
predicate(node: Node) {
|
|
9
|
+
return node.kind === SyntaxKind.TemplateLiteralTypeSpan;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async transform(node: TemplateLiteralTypeSpan, context: SchemaExtractorContext) {
|
|
17
|
+
const type = await context.computeSchema(node.type);
|
|
18
|
+
const literal = node.literal.text;
|
|
19
|
+
return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Node, SyntaxKind, TemplateLiteralTypeNode } from 'typescript';
|
|
2
|
+
import pMapSeries from 'p-map-series';
|
|
3
|
+
import { TemplateLiteralTypeSchema, TemplateLiteralTypeSpanSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
|
+
import { Identifier } from '../identifier';
|
|
7
|
+
|
|
8
|
+
export class TemplateLiteralTypeTransformer implements SchemaTransformer {
|
|
9
|
+
predicate(node: Node) {
|
|
10
|
+
return node.kind === SyntaxKind.TemplateLiteralType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async transform(node: TemplateLiteralTypeNode, context: SchemaExtractorContext) {
|
|
18
|
+
const templateSpans = (await pMapSeries(node.templateSpans, (span) =>
|
|
19
|
+
context.computeSchema(span)
|
|
20
|
+
)) as TemplateLiteralTypeSpanSchema[];
|
|
21
|
+
const head = node.head.text;
|
|
22
|
+
return new TemplateLiteralTypeSchema(context.getLocation(node), head, templateSpans);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Node, SyntaxKind, ThisTypeNode } from 'typescript';
|
|
2
|
+
import { ThisTypeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
|
|
7
|
+
export class ThisTypeTransformer implements SchemaTransformer {
|
|
8
|
+
predicate(node: Node) {
|
|
9
|
+
return node.kind === SyntaxKind.ThisType;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async transform(node: ThisTypeNode, context: SchemaExtractorContext) {
|
|
17
|
+
return new ThisTypeSchema(context.getLocation(node));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Node, SyntaxKind, TupleTypeNode } from 'typescript';
|
|
2
|
+
import pMapSeries from 'p-map-series';
|
|
3
|
+
import { TupleTypeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
4
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
|
+
import { Identifier } from '../identifier';
|
|
7
|
+
|
|
8
|
+
export class TupleTypeTransformer implements SchemaTransformer {
|
|
9
|
+
predicate(node: Node) {
|
|
10
|
+
return node.kind === SyntaxKind.TupleType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async transform(node: TupleTypeNode, context: SchemaExtractorContext) {
|
|
18
|
+
const elements = await pMapSeries(node.elements, async (elem) => {
|
|
19
|
+
const typeSchema = await context.computeSchema(elem);
|
|
20
|
+
return typeSchema;
|
|
21
|
+
});
|
|
22
|
+
return new TupleTypeSchema(context.getLocation(node), elements);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -2,8 +2,7 @@ import ts, { Node, TypeAliasDeclaration } from 'typescript';
|
|
|
2
2
|
import { TypeSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
3
|
import { SchemaTransformer } from '../schema-transformer';
|
|
4
4
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
-
import {
|
|
6
|
-
import { typeNodeToSchema } from './utils/type-node-to-schema';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
7
6
|
|
|
8
7
|
export class TypeAliasTransformer implements SchemaTransformer {
|
|
9
8
|
predicate(node: Node) {
|
|
@@ -11,7 +10,7 @@ export class TypeAliasTransformer implements SchemaTransformer {
|
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
async getIdentifiers(node: TypeAliasDeclaration) {
|
|
14
|
-
return [new
|
|
13
|
+
return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
private getName(node: TypeAliasDeclaration): string {
|
|
@@ -19,7 +18,7 @@ export class TypeAliasTransformer implements SchemaTransformer {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {
|
|
22
|
-
const type = await
|
|
21
|
+
const type = await context.computeSchema(typeAlias.type);
|
|
23
22
|
const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
|
|
24
23
|
const doc = await context.jsDocToDocSchema(typeAlias);
|
|
25
24
|
return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig, doc);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import ts, { Node, TypeLiteralNode } from 'typescript';
|
|
2
|
+
import { TypeLiteralSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import pMapSeries from 'p-map-series';
|
|
4
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
|
+
import { Identifier } from '../identifier';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* not to be confused with "LiteralType", which is string/boolean/null.
|
|
10
|
+
* this "TypeLiteral" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.
|
|
11
|
+
*/
|
|
12
|
+
export class TypeLiteralTransformer implements SchemaTransformer {
|
|
13
|
+
predicate(node: Node) {
|
|
14
|
+
return node.kind === ts.SyntaxKind.TypeLiteral;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async transform(node: TypeLiteralNode, context: SchemaExtractorContext) {
|
|
22
|
+
const members = await pMapSeries(node.members, (member) => context.computeSchema(member));
|
|
23
|
+
const location = context.getLocation(node);
|
|
24
|
+
return new TypeLiteralSchema(location, members);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Node, TypeOperatorNode, SyntaxKind } from 'typescript';
|
|
2
|
+
import { TypeOperatorSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* e.g. keyof typeof Foo
|
|
9
|
+
*/
|
|
10
|
+
export class TypeOperatorTransformer implements SchemaTransformer {
|
|
11
|
+
predicate(node: Node) {
|
|
12
|
+
return node.kind === SyntaxKind.TypeOperator;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async transform(node: TypeOperatorNode, context: SchemaExtractorContext) {
|
|
20
|
+
const operatorName = this.getOperatorName(node.operator);
|
|
21
|
+
const type = await context.computeSchema(node.type);
|
|
22
|
+
return new TypeOperatorSchema(context.getLocation(node), operatorName, type);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {
|
|
26
|
+
switch (operator) {
|
|
27
|
+
case SyntaxKind.KeyOfKeyword:
|
|
28
|
+
return 'keyof';
|
|
29
|
+
case SyntaxKind.UniqueKeyword:
|
|
30
|
+
return 'unique';
|
|
31
|
+
case SyntaxKind.ReadonlyKeyword:
|
|
32
|
+
return 'readonly';
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(`getOperatorName: unable to find operator name for ${operator}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isIdentifier, Node, SyntaxKind, TypePredicateNode } from 'typescript';
|
|
2
|
+
import { TypePredicateSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
|
|
7
|
+
export class TypePredicateTransformer implements SchemaTransformer {
|
|
8
|
+
predicate(node: Node) {
|
|
9
|
+
return node.kind === SyntaxKind.TypePredicate;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async transform(node: TypePredicateNode, context: SchemaExtractorContext) {
|
|
17
|
+
const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';
|
|
18
|
+
const type = node.type ? await context.computeSchema(node.type) : undefined;
|
|
19
|
+
const hasAssertsModifier = Boolean(node.assertsModifier);
|
|
20
|
+
return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ts, { Node, TypeQueryNode } from 'typescript';
|
|
2
|
+
import { TypeQuerySchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
5
|
+
import { Identifier } from '../identifier';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* e.g. `typeof Foo`
|
|
9
|
+
*/
|
|
10
|
+
export class TypeQueryTransformer implements SchemaTransformer {
|
|
11
|
+
predicate(node: Node) {
|
|
12
|
+
return node.kind === ts.SyntaxKind.TypeQuery;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async transform(node: TypeQueryNode, context: SchemaExtractorContext) {
|
|
20
|
+
const displaySig = await context.getQuickInfoDisplayString(node.exprName);
|
|
21
|
+
const type = await context.resolveType(node.exprName, node.exprName.getText(), false);
|
|
22
|
+
const location = context.getLocation(node);
|
|
23
|
+
return new TypeQuerySchema(location, type, displaySig);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ts, { Node, TypeReferenceNode } from 'typescript';
|
|
2
|
+
import { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import pMapSeries from 'p-map-series';
|
|
4
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
|
+
import { Identifier } from '../identifier';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* In the following example, `AriaButtonProps` is a type reference
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { AriaButtonProps } from '@react-types/button';
|
|
12
|
+
* export type ButtonProps = AriaButtonProps & { a: string };
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class TypeReferenceTransformer implements SchemaTransformer {
|
|
16
|
+
predicate(node: Node) {
|
|
17
|
+
return node.kind === ts.SyntaxKind.TypeReference;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async transform(node: TypeReferenceNode, context: SchemaExtractorContext) {
|
|
25
|
+
const name = node.typeName.getText();
|
|
26
|
+
const type = await context.resolveType(node, name, false);
|
|
27
|
+
if (node.typeArguments && type instanceof TypeRefSchema) {
|
|
28
|
+
const args = await pMapSeries(node.typeArguments, (arg) => context.computeSchema(arg));
|
|
29
|
+
type.typeArgs = args;
|
|
30
|
+
}
|
|
31
|
+
return type;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ts, { Node, UnionTypeNode } from 'typescript';
|
|
2
|
+
import { TypeUnionSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import pMapSeries from 'p-map-series';
|
|
4
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
6
|
+
import { Identifier } from '../identifier';
|
|
7
|
+
|
|
8
|
+
export class UnionTypeTransformer implements SchemaTransformer {
|
|
9
|
+
predicate(node: Node) {
|
|
10
|
+
return node.kind === ts.SyntaxKind.UnionType;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async getIdentifiers(): Promise<Identifier[]> {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async transform(node: UnionTypeNode, context: SchemaExtractorContext) {
|
|
18
|
+
const types = await pMapSeries(node.types, async (type) => {
|
|
19
|
+
const typeSchema = context.computeSchema(type);
|
|
20
|
+
return typeSchema;
|
|
21
|
+
});
|
|
22
|
+
const location = context.getLocation(node);
|
|
23
|
+
return new TypeUnionSchema(location, types);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
} from '@teambit/semantics.entities.semantic-schema';
|
|
17
17
|
import { Formatter } from '@teambit/formatter';
|
|
18
18
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
19
|
-
import { typeNodeToSchema } from './type-node-to-schema';
|
|
20
19
|
|
|
21
20
|
export async function tagParser(
|
|
22
21
|
tag: JSDocTag,
|
|
@@ -24,7 +23,6 @@ export async function tagParser(
|
|
|
24
23
|
formatter?: Formatter
|
|
25
24
|
): Promise<TagSchema> {
|
|
26
25
|
// for some reason, in some cases, if `tag.getSourceFile()` is not provided to the `getText()`, it throws "Cannot read property 'text' of undefined"
|
|
27
|
-
|
|
28
26
|
switch (tag.kind) {
|
|
29
27
|
case SyntaxKind.JSDocReturnTag:
|
|
30
28
|
return returnTag(tag as JSDocReturnTag, context);
|
|
@@ -88,12 +86,12 @@ function simpleTag(tag: JSDocTag, tagName: TagName | string, context: SchemaExtr
|
|
|
88
86
|
}
|
|
89
87
|
|
|
90
88
|
async function returnTag(tag: JSDocReturnTag, context: SchemaExtractorContext) {
|
|
91
|
-
const type = tag.typeExpression?.type ? await
|
|
89
|
+
const type = tag.typeExpression?.type ? await context.computeSchema(tag.typeExpression?.type) : undefined;
|
|
92
90
|
return new ReturnTagSchema(context.getLocation(tag), getTextOfJSDocComment(tag.comment), type);
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
async function propertyLikeTag(tag: JSDocPropertyLikeTag, context: SchemaExtractorContext) {
|
|
96
|
-
const type = tag.typeExpression?.type ? await
|
|
94
|
+
const type = tag.typeExpression?.type ? await context.computeSchema(tag.typeExpression?.type) : undefined;
|
|
97
95
|
return new PropertyLikeTagSchema(
|
|
98
96
|
context.getLocation(tag),
|
|
99
97
|
tag.name.getText(),
|
|
@@ -3,13 +3,14 @@ import {
|
|
|
3
3
|
VariableLikeSchema,
|
|
4
4
|
FunctionLikeSchema,
|
|
5
5
|
Modifier,
|
|
6
|
+
ParameterSchema,
|
|
6
7
|
} from '@teambit/semantics.entities.semantic-schema';
|
|
7
8
|
import ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';
|
|
9
|
+
import pMapSeries from 'p-map-series';
|
|
8
10
|
import { SchemaTransformer } from '../schema-transformer';
|
|
9
11
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
10
|
-
import { ExportIdentifier } from '../export-identifier';
|
|
11
|
-
import { getParams } from './utils/get-params';
|
|
12
12
|
import { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
|
|
13
|
+
import { Identifier } from '../identifier';
|
|
13
14
|
|
|
14
15
|
export class VariableDeclaration implements SchemaTransformer {
|
|
15
16
|
predicate(node: Node) {
|
|
@@ -21,7 +22,7 @@ export class VariableDeclaration implements SchemaTransformer {
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
async getIdentifiers(node: VariableDeclarationNode) {
|
|
24
|
-
return [new
|
|
25
|
+
return [new Identifier(node.name.getText(), node.getSourceFile().fileName)];
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {
|
|
@@ -32,7 +33,9 @@ export class VariableDeclaration implements SchemaTransformer {
|
|
|
32
33
|
const doc = await context.jsDocToDocSchema(varDec);
|
|
33
34
|
const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];
|
|
34
35
|
if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {
|
|
35
|
-
const args = await
|
|
36
|
+
const args = (await pMapSeries((varDec.initializer as ArrowFunction).parameters, async (param) =>
|
|
37
|
+
context.computeSchema(param)
|
|
38
|
+
)) as ParameterSchema[];
|
|
36
39
|
// example => export const useLanesContext: () => LanesContextModel | undefined = () => {
|
|
37
40
|
if (varDec.type) {
|
|
38
41
|
const funcType = await context.resolveType(varDec, '');
|
|
@@ -4,7 +4,7 @@ import pMapSeries from 'p-map-series';
|
|
|
4
4
|
import ts, { Node, VariableStatement } from 'typescript';
|
|
5
5
|
import { SchemaTransformer } from '../schema-transformer';
|
|
6
6
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
7
|
-
import {
|
|
7
|
+
import { Identifier } from '../identifier';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* variable statement is a collection of variable declarations.
|
|
@@ -17,7 +17,7 @@ export class VariableStatementTransformer implements SchemaTransformer {
|
|
|
17
17
|
|
|
18
18
|
async getIdentifiers(node: VariableStatement) {
|
|
19
19
|
return node.declarationList.declarations.map((dec) => {
|
|
20
|
-
return new
|
|
20
|
+
return new Identifier(dec.name.getText(), dec.getSourceFile().fileName);
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -27,6 +27,6 @@ export class VariableStatementTransformer implements SchemaTransformer {
|
|
|
27
27
|
const schema = await context.visitDefinition(dec.name);
|
|
28
28
|
return schema;
|
|
29
29
|
});
|
|
30
|
-
return new ModuleSchema(context.getLocation(node), compact(schemas));
|
|
30
|
+
return new ModuleSchema(context.getLocation(node), compact(schemas), []);
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/export-list.d.ts
DELETED
package/dist/export-list.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ExportList = void 0;
|
|
7
|
-
class ExportList {
|
|
8
|
-
constructor(exports) {
|
|
9
|
-
this.exports = exports;
|
|
10
|
-
}
|
|
11
|
-
includes(id) {
|
|
12
|
-
return Boolean(this.exports.find(exportId => exportId.id === id));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.ExportList = ExportList;
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=export-list.js.map
|
package/dist/export-list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["ExportList","constructor","exports","includes","id","Boolean","find","exportId"],"sources":["export-list.ts"],"sourcesContent":["import { ExportIdentifier } from './export-identifier';\n\nexport class ExportList {\n constructor(readonly exports: ExportIdentifier[]) {}\n\n includes(id: string) {\n return Boolean(this.exports.find((exportId) => exportId.id === id));\n }\n}\n"],"mappings":";;;;;;AAEO,MAAMA,UAAU,CAAC;EACtBC,WAAW,CAAUC,OAA2B,EAAE;IAAA,KAA7BA,OAA2B,GAA3BA,OAA2B;EAAG;EAEnDC,QAAQ,CAACC,EAAU,EAAE;IACnB,OAAOC,OAAO,CAAC,IAAI,CAACH,OAAO,CAACI,IAAI,CAAEC,QAAQ,IAAKA,QAAQ,CAACH,EAAE,KAAKA,EAAE,CAAC,CAAC;EACrE;AACF;AAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.promise.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.ExportAssignmentDeclaration = void 0;
|
|
8
|
-
function _typescript() {
|
|
9
|
-
const data = require("typescript");
|
|
10
|
-
_typescript = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
class ExportAssignmentDeclaration {
|
|
16
|
-
predicate(node) {
|
|
17
|
-
return node.kind === _typescript().SyntaxKind.ExportAssignment;
|
|
18
|
-
}
|
|
19
|
-
async getIdentifiers(exportDec, context) {
|
|
20
|
-
return context.getFileExports(exportDec);
|
|
21
|
-
}
|
|
22
|
-
async transform(exportDec, context) {
|
|
23
|
-
const specifier = exportDec.expression;
|
|
24
|
-
return context.computeSchema(specifier);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ExportAssignmentDeclaration = ExportAssignmentDeclaration;
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=export-assignment-declaration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["ExportAssignmentDeclaration","predicate","node","kind","SyntaxKind","ExportAssignment","getIdentifiers","exportDec","context","getFileExports","transform","specifier","expression","computeSchema"],"sources":["export-assignment-declaration.ts"],"sourcesContent":["import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';\nimport { Node, SyntaxKind, ExportAssignment as ExportAssignmentNode } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\n\nexport class ExportAssignmentDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportAssignment;\n }\n\n async getIdentifiers(exportDec: ExportAssignmentNode, context: SchemaExtractorContext) {\n return context.getFileExports(exportDec);\n }\n\n async transform(exportDec: ExportAssignmentNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const specifier = exportDec.expression;\n return context.computeSchema(specifier);\n }\n}\n"],"mappings":";;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAIO,MAAMA,2BAA2B,CAA8B;EACpEC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,wBAAU,CAACC,gBAAgB;EAClD;EAEA,MAAMC,cAAc,CAACC,SAA+B,EAAEC,OAA+B,EAAE;IACrF,OAAOA,OAAO,CAACC,cAAc,CAACF,SAAS,CAAC;EAC1C;EAEA,MAAMG,SAAS,CAACH,SAA+B,EAAEC,OAA+B,EAAuB;IACrG,MAAMG,SAAS,GAAGJ,SAAS,CAACK,UAAU;IACtC,OAAOJ,OAAO,CAACK,aAAa,CAACF,SAAS,CAAC;EACzC;AACF;AAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typescript';
|
|
3
|
-
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
4
|
-
import { SchemaTransformer } from '../schema-transformer';
|
|
5
|
-
import { ExportIdentifier } from '../export-identifier';
|
|
6
|
-
export declare class FunctionDeclaration implements SchemaTransformer {
|
|
7
|
-
predicate(node: Node): boolean;
|
|
8
|
-
getIdentifiers(funcDec: FunctionDeclarationNode): Promise<ExportIdentifier[]>;
|
|
9
|
-
private getName;
|
|
10
|
-
transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
11
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
require("core-js/modules/es.promise.js");
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.FunctionDeclaration = void 0;
|
|
9
|
-
function _typescript() {
|
|
10
|
-
const data = _interopRequireDefault(require("typescript"));
|
|
11
|
-
_typescript = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
return data;
|
|
15
|
-
}
|
|
16
|
-
function _exportIdentifier() {
|
|
17
|
-
const data = require("../export-identifier");
|
|
18
|
-
_exportIdentifier = function () {
|
|
19
|
-
return data;
|
|
20
|
-
};
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
function _toFunctionLikeSchema() {
|
|
24
|
-
const data = require("./utils/to-function-like-schema");
|
|
25
|
-
_toFunctionLikeSchema = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
class FunctionDeclaration {
|
|
31
|
-
predicate(node) {
|
|
32
|
-
return node.kind === _typescript().default.SyntaxKind.FunctionDeclaration || node.kind === _typescript().default.SyntaxKind.ArrowFunction;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// need to check for anonymous functions assigned for vars, const and let.
|
|
36
|
-
async getIdentifiers(funcDec) {
|
|
37
|
-
return [new (_exportIdentifier().ExportIdentifier)(this.getName(funcDec), funcDec.getSourceFile().fileName)];
|
|
38
|
-
}
|
|
39
|
-
getName(funcDec) {
|
|
40
|
-
var _funcDec$name;
|
|
41
|
-
return ((_funcDec$name = funcDec.name) === null || _funcDec$name === void 0 ? void 0 : _funcDec$name.getText()) || '';
|
|
42
|
-
}
|
|
43
|
-
async transform(funcDec, context) {
|
|
44
|
-
return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(funcDec, context);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.FunctionDeclaration = FunctionDeclaration;
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=function-declaration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","ArrowFunction","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context","toFunctionLikeSchema"],"sources":["function-declaration.ts"],"sourcesContent":["import { SchemaNode } 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 { toFunctionLikeSchema } from './utils/to-function-like-schema';\n\nexport class FunctionDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.FunctionDeclaration || node.kind === ts.SyntaxKind.ArrowFunction;\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 return toFunctionLikeSchema(funcDec, 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,mBAAmB,CAA8B;EAC5DC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACL,mBAAmB,IAAIE,IAAI,CAACC,IAAI,KAAKC,qBAAE,CAACC,UAAU,CAACC,aAAa;EACrG;;EAEA;EACA,MAAMC,cAAc,CAACC,OAAgC,EAAE;IACrD,OAAO,CAAC,KAAIC,oCAAgB,EAAC,IAAI,CAACC,OAAO,CAACF,OAAO,CAAC,EAAEA,OAAO,CAACG,aAAa,EAAE,CAACC,QAAQ,CAAC,CAAC;EACxF;EAEQF,OAAO,CAACF,OAAgC,EAAE;IAAA;IAChD,OAAO,kBAAAA,OAAO,CAACK,IAAI,kDAAZ,cAAcC,OAAO,EAAE,KAAI,EAAE;EACtC;EAEA,MAAMC,SAAS,CAACP,OAAgC,EAAEQ,OAA+B,EAAuB;IACtG,OAAO,IAAAC,4CAAoB,EAACT,OAAO,EAAEQ,OAAO,CAAC;EAC/C;AACF;AAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ClassElement } from 'typescript';
|
|
2
|
-
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
-
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
4
|
-
export declare function classElementToSchema(node: ClassElement, context: SchemaExtractorContext): Promise<SchemaNode | null>;
|