@teambit/typescript 0.0.726 → 0.0.729
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/exceptions/transformer-not-found.js +14 -1
- package/dist/exceptions/transformer-not-found.js.map +1 -1
- package/dist/schema-extractor-context.d.ts +33 -4
- package/dist/schema-extractor-context.js +163 -24
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/class-deceleration.d.ts +11 -0
- package/dist/transformers/class-deceleration.js +126 -0
- package/dist/transformers/class-deceleration.js.map +1 -0
- package/dist/transformers/constructor.d.ts +10 -0
- package/dist/transformers/constructor.js +70 -0
- package/dist/transformers/constructor.js.map +1 -0
- package/dist/transformers/export-declaration.d.ts +2 -1
- package/dist/transformers/export-declaration.js +64 -13
- package/dist/transformers/export-declaration.js.map +1 -1
- package/dist/transformers/function-declaration.d.ts +1 -3
- package/dist/transformers/function-declaration.js +25 -31
- package/dist/transformers/function-declaration.js.map +1 -1
- package/dist/transformers/index-signature.d.ts +9 -0
- package/dist/transformers/index-signature.js +61 -0
- package/dist/transformers/index-signature.js.map +1 -0
- package/dist/transformers/index.d.ts +14 -0
- package/dist/transformers/index.js +224 -0
- package/dist/transformers/index.js.map +1 -1
- package/dist/transformers/interface-declaration.d.ts +10 -0
- package/dist/transformers/interface-declaration.js +73 -0
- package/dist/transformers/interface-declaration.js.map +1 -0
- package/dist/transformers/literal-type.d.ts +8 -0
- package/dist/transformers/literal-type.js +50 -0
- package/dist/transformers/literal-type.js.map +1 -0
- package/dist/transformers/method-declaration.d.ts +11 -0
- package/dist/transformers/method-declaration.js +94 -0
- package/dist/transformers/method-declaration.js.map +1 -0
- package/dist/transformers/method-signature.d.ts +10 -0
- package/dist/transformers/method-signature.js +81 -0
- package/dist/transformers/method-signature.js.map +1 -0
- package/dist/transformers/property-declaration.d.ts +11 -0
- package/dist/transformers/property-declaration.js +81 -0
- package/dist/transformers/property-declaration.js.map +1 -0
- package/dist/transformers/property-signature.d.ts +10 -0
- package/dist/transformers/property-signature.js +91 -0
- package/dist/transformers/property-signature.js.map +1 -0
- package/dist/transformers/source-file-transformer.d.ts +2 -1
- package/dist/transformers/source-file-transformer.js +23 -3
- package/dist/transformers/source-file-transformer.js.map +1 -1
- package/dist/transformers/type-alias.d.ts +4 -1
- package/dist/transformers/type-alias.js +22 -2
- package/dist/transformers/type-alias.js.map +1 -1
- package/dist/transformers/type-intersection.d.ts +9 -0
- package/dist/transformers/type-intersection.js +63 -0
- package/dist/transformers/type-intersection.js.map +1 -0
- package/dist/transformers/type-literal.d.ts +14 -0
- package/dist/transformers/type-literal.js +67 -0
- package/dist/transformers/type-literal.js.map +1 -0
- package/dist/transformers/type-reference.d.ts +8 -0
- package/dist/transformers/type-reference.js +41 -0
- package/dist/transformers/type-reference.js.map +1 -0
- package/dist/transformers/type-union.d.ts +9 -0
- package/dist/transformers/type-union.js +63 -0
- package/dist/transformers/type-union.js.map +1 -0
- package/dist/transformers/utils/get-params.d.ts +4 -0
- package/dist/transformers/utils/get-params.js +67 -0
- package/dist/transformers/utils/get-params.js.map +1 -0
- package/dist/transformers/utils/parse-type-from-quick-info.d.ts +2 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js +26 -0
- package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -0
- package/dist/transformers/variable-declaration.d.ts +11 -0
- package/dist/transformers/variable-declaration.js +98 -0
- package/dist/transformers/variable-declaration.js.map +1 -0
- package/dist/transformers/variable-statement.d.ts +7 -1
- package/dist/transformers/variable-statement.js +42 -2
- package/dist/transformers/variable-statement.js.map +1 -1
- package/dist/typescript.extractor.d.ts +3 -3
- package/dist/typescript.extractor.js +7 -4
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.js +1 -1
- package/dist/typescript.main.runtime.js.map +1 -1
- package/exceptions/transformer-not-found.ts +5 -4
- package/package-tar/teambit-typescript-0.0.729.tgz +0 -0
- package/package.json +15 -15
- package/{preview-1651721125153.js → preview-1652239597845.js} +2 -2
- package/transformers/class-deceleration.ts +49 -0
- package/transformers/constructor.ts +22 -0
- package/transformers/export-declaration.ts +42 -13
- package/transformers/function-declaration.ts +7 -27
- package/transformers/index-signature.ts +21 -0
- package/transformers/index.ts +14 -0
- package/transformers/interface-declaration.ts +24 -0
- package/transformers/literal-type.ts +18 -0
- package/transformers/method-declaration.ts +32 -0
- package/transformers/method-signature.ts +30 -0
- package/transformers/property-declaration.ts +31 -0
- package/transformers/property-signature.ts +38 -0
- package/transformers/source-file-transformer.ts +6 -6
- package/transformers/type-alias.ts +12 -2
- package/transformers/type-intersection.ts +23 -0
- package/transformers/type-literal.ts +28 -0
- package/transformers/type-reference.ts +19 -0
- package/transformers/type-union.ts +23 -0
- package/transformers/utils/get-params.ts +30 -0
- package/transformers/utils/parse-type-from-quick-info.ts +12 -0
- package/transformers/variable-declaration.ts +36 -0
- package/transformers/variable-statement.ts +16 -2
- package/package-tar/teambit-typescript-0.0.726.tgz +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
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)(args);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.Constructor = Constructor;
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=constructor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["constructor.ts"],"names":["Constructor","predicate","node","kind","ts","SyntaxKind","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","constructorDec","context","args","parameters","ConstructorSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,WAAN,CAA+C;AACpDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,WAAnC;AACD;;AAEmB,QAAdM,cAAc,CAACJ,IAAD,EAA+B;AACjD,WAAO,CAAC,KAAIK,oCAAJ,EAAqB,aAArB,EAAoCL,IAAI,CAACM,aAAL,GAAqBC,QAAzD,CAAD,CAAP;AACD;;AAEc,QAATC,SAAS,CAACC,cAAD,EAAyCC,OAAzC,EAA+F;AAC5G,UAAMC,IAAI,GAAG,MAAM,4BAAUF,cAAc,CAACG,UAAzB,EAAqCF,OAArC,CAAnB;AAEA,WAAO,KAAIG,sCAAJ,EAAsBF,IAAtB,CAAP;AACD;;AAbmD","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(args);\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
1
2
|
import { Node, ExportDeclaration as ExportDeclarationNode } from 'typescript';
|
|
2
3
|
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
3
4
|
import { SchemaTransformer } from '../schema-transformer';
|
|
@@ -5,5 +6,5 @@ import { ExportIdentifier } from '../export-identifier';
|
|
|
5
6
|
export declare class ExportDeclaration implements SchemaTransformer {
|
|
6
7
|
predicate(node: Node): boolean;
|
|
7
8
|
getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<ExportIdentifier[]>;
|
|
8
|
-
transform(node: Node, context: SchemaExtractorContext): Promise<
|
|
9
|
+
transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
9
10
|
}
|
|
@@ -9,6 +9,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
});
|
|
10
10
|
exports.ExportDeclaration = void 0;
|
|
11
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 _lodash() {
|
|
23
|
+
const data = require("lodash");
|
|
24
|
+
|
|
25
|
+
_lodash = function () {
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
function _typescript() {
|
|
13
33
|
const data = _interopRequireWildcard(require("typescript"));
|
|
14
34
|
|
|
@@ -60,24 +80,55 @@ class ExportDeclaration {
|
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
async transform(node, context) {
|
|
63
|
-
const exportDec = node;
|
|
64
|
-
|
|
65
|
-
const exportClause = exportDec.exportClause;
|
|
83
|
+
const exportDec = node;
|
|
84
|
+
const exportClause = exportDec.exportClause; // e.g. `export { button1, button2 } as Composition from './button';
|
|
66
85
|
|
|
67
86
|
if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamedExports) {
|
|
68
|
-
exportClause;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// const sig = await context.visitDefinition(element.name);
|
|
72
|
-
await context.visitDefinition(element.name);
|
|
73
|
-
return element.name;
|
|
87
|
+
exportClause;
|
|
88
|
+
const schemas = await Promise.all(exportClause.elements.map(async element => {
|
|
89
|
+
return context.visitDefinition(element.name);
|
|
74
90
|
}));
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
return new (_semanticsEntities().Module)((0, _lodash().compact)(schemas));
|
|
92
|
+
} // e.g. `export * as Composition from './button';
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamespaceExport) {
|
|
96
|
+
exportClause;
|
|
97
|
+
const namespace = exportClause.name.getText();
|
|
98
|
+
const sourceFile = await context.getSourceFileFromNode(exportClause.name);
|
|
99
|
+
|
|
100
|
+
if (!sourceFile) {
|
|
101
|
+
throw new Error(`unable to find the source-file for "${namespace}"`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const result = await context.computeSchema(sourceFile);
|
|
105
|
+
|
|
106
|
+
if (!(result instanceof _semanticsEntities().Module)) {
|
|
107
|
+
throw new Error(`expect result to be instance of Module`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
result.namespace = namespace;
|
|
111
|
+
return result;
|
|
112
|
+
} // it's export-all, e.g. `export * from './button'`;
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if (!exportClause) {
|
|
116
|
+
const specifier = exportDec.moduleSpecifier;
|
|
117
|
+
|
|
118
|
+
if (!specifier) {
|
|
119
|
+
throw new Error(`fatal: no specifier`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const sourceFile = await context.getSourceFileFromNode(specifier);
|
|
123
|
+
|
|
124
|
+
if (!sourceFile) {
|
|
125
|
+
throw new Error(`unable to find the source-file`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return context.computeSchema(sourceFile);
|
|
78
129
|
}
|
|
79
130
|
|
|
80
|
-
|
|
131
|
+
throw new Error('unrecognized export type');
|
|
81
132
|
}
|
|
82
133
|
|
|
83
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["export-declaration.ts"],"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","
|
|
1
|
+
{"version":3,"sources":["export-declaration.ts"],"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","schemas","Promise","all","element","visitDefinition","Module","namespace","sourceFile","getSourceFileFromNode","Error","result","computeSchema","specifier"],"mappings":"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","sourcesContent":["import { SchemaNode, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { compact } from 'lodash';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportDec = node as ExportDeclarationNode;\n const exportClause = exportDec.exportClause;\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause?.kind === SyntaxKind.NamedExports) {\n exportClause as NamedExports;\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return context.visitDefinition(element.name);\n })\n );\n\n return new Module(compact(schemas));\n }\n // e.g. `export * as Composition from './button';\n if (exportClause?.kind === SyntaxKind.NamespaceExport) {\n exportClause as NamespaceExport;\n const namespace = exportClause.name.getText();\n const sourceFile = await context.getSourceFileFromNode(exportClause.name);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file for \"${namespace}\"`);\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n }\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n throw new Error('unrecognized export type');\n }\n}\n"]}
|
|
@@ -7,7 +7,5 @@ export declare class FunctionDeclaration implements SchemaTransformer {
|
|
|
7
7
|
predicate(node: Node): boolean;
|
|
8
8
|
getIdentifiers(funcDec: FunctionDeclarationNode): Promise<ExportIdentifier[]>;
|
|
9
9
|
private getName;
|
|
10
|
-
|
|
11
|
-
private parseReturnValue;
|
|
12
|
-
transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
10
|
+
transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
13
11
|
}
|
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
require("core-js/modules/es.array.iterator.js");
|
|
6
|
-
|
|
7
5
|
require("core-js/modules/es.promise.js");
|
|
8
6
|
|
|
9
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/es.string.trim.js");
|
|
12
|
-
|
|
13
7
|
Object.defineProperty(exports, "__esModule", {
|
|
14
8
|
value: true
|
|
15
9
|
});
|
|
@@ -45,6 +39,26 @@ function _exportIdentifier() {
|
|
|
45
39
|
return data;
|
|
46
40
|
}
|
|
47
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
|
+
function _parseTypeFromQuickInfo() {
|
|
53
|
+
const data = require("./utils/parse-type-from-quick-info");
|
|
54
|
+
|
|
55
|
+
_parseTypeFromQuickInfo = function () {
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
class FunctionDeclaration {
|
|
49
63
|
predicate(node) {
|
|
50
64
|
return node.kind === _typescript().default.SyntaxKind.FunctionDeclaration;
|
|
@@ -61,37 +75,17 @@ class FunctionDeclaration {
|
|
|
61
75
|
return ((_funcDec$name = funcDec.name) === null || _funcDec$name === void 0 ? void 0 : _funcDec$name.getText()) || '';
|
|
62
76
|
}
|
|
63
77
|
|
|
64
|
-
async
|
|
65
|
-
return Promise.all(funcDec.parameters.map(async param => {
|
|
66
|
-
const type = param.type;
|
|
67
|
-
return {
|
|
68
|
-
name: param.name.getText(),
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
70
|
-
type: await context.resolveType(type, (type === null || type === void 0 ? void 0 : type.getText()) || 'any')
|
|
71
|
-
};
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
parseReturnValue(displayString) {
|
|
76
|
-
if (!displayString) return '';
|
|
77
|
-
const array = displayString.split(':');
|
|
78
|
-
return array[array.length - 1].trim();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async transform(node, context) {
|
|
78
|
+
async transform(funcDec, context) {
|
|
82
79
|
var _info$body;
|
|
83
80
|
|
|
84
|
-
const funcDec = node;
|
|
85
81
|
const name = this.getName(funcDec); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
86
82
|
|
|
87
83
|
const info = await context.getQuickInfo(funcDec.name);
|
|
88
84
|
const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
|
|
89
|
-
const returnTypeStr =
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
const returnType = await context.resolveType(funcDec.name, returnTypeStr);
|
|
94
|
-
return new (_semanticsEntities().FunctionSchema)(name || '', [], returnType);
|
|
85
|
+
const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(displaySig);
|
|
86
|
+
const args = await (0, _getParams().getParams)(funcDec.parameters, context);
|
|
87
|
+
const returnType = await context.resolveType(funcDec, returnTypeStr);
|
|
88
|
+
return new (_semanticsEntities().FunctionSchema)(name || '', args, returnType, displaySig || '');
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","
|
|
1
|
+
{"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context","info","getQuickInfo","displaySig","body","displayString","returnTypeStr","args","parameters","returnType","resolveType","FunctionSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD,GAH2D,CAK5D;;;AACoB,QAAdM,cAAc,CAACC,OAAD,EAAmC;AACrD,WAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;AACD;;AAEOF,EAAAA,OAAO,CAACF,OAAD,EAAmC;AAAA;;AAChD,WAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;AACD;;AAEc,QAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;AAAA;;AACtG,UAAMH,IAAI,GAAG,KAAKH,OAAL,CAAaF,OAAb,CAAb,CADsG,CAEtG;;AACA,UAAMS,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBV,OAAO,CAACK,IAA7B,CAAnB;AACA,UAAMM,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,UAAMC,aAAa,GAAG,sDAAuBH,UAAvB,CAAtB;AACA,UAAMI,IAAI,GAAG,MAAM,4BAAUf,OAAO,CAACgB,UAAlB,EAA8BR,OAA9B,CAAnB;AACA,UAAMS,UAAU,GAAG,MAAMT,OAAO,CAACU,WAAR,CAAoBlB,OAApB,EAA6Bc,aAA7B,CAAzB;AAEA,WAAO,KAAIK,mCAAJ,EAAmBd,IAAI,IAAI,EAA3B,EAA+BU,IAA/B,EAAqCE,UAArC,EAAiDN,UAAU,IAAI,EAA/D,CAAP;AACD;;AAxB2D","sourcesContent":["import { SchemaNode, FunctionSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\nexport class FunctionDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.FunctionDeclaration;\n }\n\n // need to check for anonymous functions assigned for vars, const and let.\n async getIdentifiers(funcDec: FunctionDeclarationNode) {\n return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];\n }\n\n private getName(funcDec: FunctionDeclarationNode) {\n return funcDec.name?.getText() || '';\n }\n\n async transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(funcDec);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const info = await context.getQuickInfo(funcDec.name!);\n const displaySig = info?.body?.displayString;\n const returnTypeStr = parseTypeFromQuickInfo(displaySig);\n const args = await getParams(funcDec.parameters, context);\n const returnType = await context.resolveType(funcDec, returnTypeStr);\n\n return new FunctionSchema(name || '', args, returnType, displaySig || '');\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
class IndexSignature {
|
|
43
|
+
predicate(node) {
|
|
44
|
+
return node.kind === _typescript().default.SyntaxKind.IndexSignature;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getIdentifiers() {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async transform(indexSig, context) {
|
|
52
|
+
const params = await (0, _getParams().getParams)(indexSig.parameters, context);
|
|
53
|
+
const type = await context.resolveType(indexSig, indexSig.type.getText());
|
|
54
|
+
return new (_semanticsEntities().IndexSignatureSchema)(params, type);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.IndexSignature = IndexSignature;
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=index-signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","resolveType","getText","IndexSignatureSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAMH,OAAO,CAACI,WAAR,CAAoBL,QAApB,EAA8BA,QAAQ,CAACI,IAAT,CAAcE,OAAd,EAA9B,CAAnB;AACA,WAAO,KAAIC,yCAAJ,EAAyBL,MAAzB,EAAiCE,IAAjC,CAAP;AACD;;AAbsD","sourcesContent":["import { SchemaNode, IndexSignatureSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, IndexSignatureDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { getParams } from './utils/get-params';\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 context.resolveType(indexSig, indexSig.type.getText());\n return new IndexSignatureSchema(params, type);\n }\n}\n"]}
|
|
@@ -1,5 +1,19 @@
|
|
|
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';
|
|
3
5
|
export { VariableStatementTransformer } from './variable-statement';
|
|
6
|
+
export { VariableDeclaration } from './variable-declaration';
|
|
4
7
|
export { SourceFileTransformer } from './source-file-transformer';
|
|
5
8
|
export { TypeAliasTransformer } from './type-alias';
|
|
9
|
+
export { ClassDecelerationTransformer } from './class-deceleration';
|
|
10
|
+
export { TypeIntersectionTransformer } from './type-intersection';
|
|
11
|
+
export { Constructor } from './constructor';
|
|
12
|
+
export { TypeReferenceTransformer } from './type-reference';
|
|
13
|
+
export { TypeLiteralTransformer } from './type-literal';
|
|
14
|
+
export { PropertySignature } from './property-signature';
|
|
15
|
+
export { TypeUnionTransformer } from './type-union';
|
|
16
|
+
export { LiteralTypeTransformer } from './literal-type';
|
|
17
|
+
export { IndexSignature } from './index-signature';
|
|
18
|
+
export { InterfaceDeclarationTransformer } from './interface-declaration';
|
|
19
|
+
export { MethodSignatureTransformer } from './method-signature';
|