@teambit/typescript 0.0.588 → 0.0.592
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/index.d.ts +1 -0
- package/dist/exceptions/index.js +23 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/transformer-not-found.d.ts +7 -0
- package/dist/exceptions/transformer-not-found.js +19 -0
- package/dist/exceptions/transformer-not-found.js.map +1 -0
- package/dist/export-identifier.d.ts +5 -0
- package/dist/export-identifier.js +18 -0
- package/dist/export-identifier.js.map +1 -0
- package/dist/export-list.d.ts +6 -0
- package/dist/export-list.js +21 -0
- package/dist/export-list.js.map +1 -0
- package/dist/schema-extractor-context.d.ts +44 -0
- package/dist/schema-extractor-context.js +225 -0
- package/dist/schema-extractor-context.js.map +1 -0
- package/dist/schema-transformer.d.ts +15 -0
- package/dist/schema-transformer.js +3 -0
- package/dist/schema-transformer.js.map +1 -0
- package/dist/schema-transformer.plugin.d.ts +9 -0
- package/dist/schema-transformer.plugin.js +35 -0
- package/dist/schema-transformer.plugin.js.map +1 -0
- package/dist/transformers/export-declaration-type.d.ts +0 -0
- package/dist/transformers/export-declaration-type.js +3 -0
- package/dist/transformers/export-declaration-type.js.map +1 -0
- package/dist/transformers/export-declaration.d.ts +9 -0
- package/dist/transformers/export-declaration.js +87 -0
- package/dist/transformers/export-declaration.js.map +1 -0
- package/dist/transformers/function-declaration.d.ts +13 -0
- package/dist/transformers/function-declaration.js +101 -0
- package/dist/transformers/function-declaration.js.map +1 -0
- package/dist/transformers/index.d.ts +5 -0
- package/dist/transformers/index.js +87 -0
- package/dist/transformers/index.js.map +1 -0
- package/dist/transformers/source-file-transformer.d.ts +13 -0
- package/dist/transformers/source-file-transformer.js +82 -0
- package/dist/transformers/source-file-transformer.js.map +1 -0
- package/dist/transformers/type-alias.d.ts +8 -0
- package/dist/transformers/type-alias.js +49 -0
- package/dist/transformers/type-alias.js.map +1 -0
- package/dist/transformers/variable-statement.d.ts +8 -0
- package/dist/transformers/variable-statement.js +51 -0
- package/dist/transformers/variable-statement.js.map +1 -0
- package/dist/typescript.compiler.js +2 -2
- package/dist/typescript.compiler.spec.js +2 -2
- package/dist/typescript.extractor.d.ts +24 -4
- package/dist/typescript.extractor.js +132 -26
- package/dist/typescript.extractor.js.map +1 -1
- package/dist/typescript.main.runtime.d.ts +11 -5
- package/dist/typescript.main.runtime.js +61 -18
- package/dist/typescript.main.runtime.js.map +1 -1
- package/dist/typescript.parser.d.ts +2 -1
- package/dist/typescript.parser.js +7 -7
- package/dist/typescript.parser.js.map +1 -1
- package/exceptions/index.ts +1 -0
- package/exceptions/transformer-not-found.ts +12 -0
- package/package-tar/teambit-typescript-0.0.592.tgz +0 -0
- package/package.json +23 -19
- package/transformers/export-declaration-type.ts +0 -0
- package/transformers/export-declaration.ts +53 -0
- package/transformers/function-declaration.ts +54 -0
- package/transformers/index.ts +5 -0
- package/transformers/source-file-transformer.ts +60 -0
- package/transformers/type-alias.ts +17 -0
- package/transformers/variable-statement.ts +19 -0
- package/package-tar/teambit-typescript-0.0.588.tgz +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TransformerNotFound } from './transformer-not-found';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "TransformerNotFound", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _transformerNotFound().TransformerNotFound;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function _transformerNotFound() {
|
|
14
|
+
const data = require("./transformer-not-found");
|
|
15
|
+
|
|
16
|
+
_transformerNotFound = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { TransformerNotFound } from './transformer-not-found';\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TransformerNotFound = void 0;
|
|
7
|
+
|
|
8
|
+
class TransformerNotFound extends Error {
|
|
9
|
+
constructor(node, component) {
|
|
10
|
+
super(`typescript: could not find schema transformer for node of kind ${node.kind} in component ${component.id.toString()}`);
|
|
11
|
+
this.node = node;
|
|
12
|
+
this.component = component;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.TransformerNotFound = TransformerNotFound;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=transformer-not-found.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["transformer-not-found.ts"],"names":["TransformerNotFound","Error","constructor","node","component","kind","id","toString"],"mappings":";;;;;;;AAGO,MAAMA,mBAAN,SAAkCC,KAAlC,CAAwC;AAC7CC,EAAAA,WAAW,CAAUC,IAAV,EAA+BC,SAA/B,EAAqD;AAC9D,UACG,kEACCD,IAAI,CAACE,IACN,iBAAgBD,SAAS,CAACE,EAAV,CAAaC,QAAb,EAAwB,EAH3C;AAD8D,SAA3CJ,IAA2C,GAA3CA,IAA2C;AAAA,SAAtBC,SAAsB,GAAtBA,SAAsB;AAM/D;;AAP4C","sourcesContent":["import { Node } from 'typescript';\nimport { Component } from '@teambit/component';\n\nexport class TransformerNotFound extends Error {\n constructor(readonly node: Node, readonly component: Component) {\n super(\n `typescript: could not find schema transformer for node of kind ${\n node.kind\n } in component ${component.id.toString()}`\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ExportIdentifier = void 0;
|
|
7
|
+
|
|
8
|
+
class ExportIdentifier {
|
|
9
|
+
constructor(id, filePath) {
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.filePath = filePath;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.ExportIdentifier = ExportIdentifier;
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=export-identifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["export-identifier.ts"],"names":["ExportIdentifier","constructor","id","filePath"],"mappings":";;;;;;;AAAO,MAAMA,gBAAN,CAAuB;AAC5BC,EAAAA,WAAW,CAAUC,EAAV,EAA+BC,QAA/B,EAAiD;AAAA,SAAvCD,EAAuC,GAAvCA,EAAuC;AAAA,SAAlBC,QAAkB,GAAlBA,QAAkB;AAAE;;AADlC","sourcesContent":["export class ExportIdentifier {\n constructor(readonly id: string, readonly filePath: string) {}\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ExportList = void 0;
|
|
7
|
+
|
|
8
|
+
class ExportList {
|
|
9
|
+
constructor(exports) {
|
|
10
|
+
this.exports = exports;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
includes(id) {
|
|
14
|
+
return Boolean(this.exports.find(exportId => exportId.id === id));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.ExportList = ExportList;
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=export-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["export-list.ts"],"names":["ExportList","constructor","exports","includes","id","Boolean","find","exportId"],"mappings":";;;;;;;AAEO,MAAMA,UAAN,CAAiB;AACtBC,EAAAA,WAAW,CAAUC,OAAV,EAAuC;AAAA,SAA7BA,OAA6B,GAA7BA,OAA6B;AAAE;;AAEpDC,EAAAA,QAAQ,CAACC,EAAD,EAAa;AACnB,WAAOC,OAAO,CAAC,KAAKH,OAAL,CAAaI,IAAb,CAAmBC,QAAD,IAAcA,QAAQ,CAACH,EAAT,KAAgBA,EAAhD,CAAD,CAAd;AACD;;AALqB","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"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TsserverClient } from '@teambit/ts-server';
|
|
2
|
+
import ts, { ExportDeclaration, Node } from 'typescript';
|
|
3
|
+
import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
|
|
4
|
+
import { Component } from '@teambit/component';
|
|
5
|
+
import { TypeRefSchema, SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
6
|
+
import { TypeScriptExtractor } from './typescript.extractor';
|
|
7
|
+
import { ExportList } from './export-list';
|
|
8
|
+
export declare class SchemaExtractorContext {
|
|
9
|
+
readonly tsserver: TsserverClient;
|
|
10
|
+
readonly component: Component;
|
|
11
|
+
readonly extractor: TypeScriptExtractor;
|
|
12
|
+
constructor(tsserver: TsserverClient, component: Component, extractor: TypeScriptExtractor);
|
|
13
|
+
computeSchema(node: Node): Promise<SchemaNode | undefined>;
|
|
14
|
+
getLocation(node: Node, targetSourceFile?: ts.SourceFile): {
|
|
15
|
+
line: number;
|
|
16
|
+
character: number;
|
|
17
|
+
};
|
|
18
|
+
getSignature(node: Node): Promise<import("typescript/lib/protocol").SignatureHelpResponse | undefined>;
|
|
19
|
+
getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number;
|
|
20
|
+
getPath(node: Node): string;
|
|
21
|
+
createRef(): {};
|
|
22
|
+
getQuickInfo(node: Node): Promise<import("typescript/lib/protocol").QuickInfoResponse | undefined>;
|
|
23
|
+
typeDefinition(node: Node): Promise<import("typescript/lib/protocol").TypeDefinitionResponse | undefined>;
|
|
24
|
+
visitTypeDefinition(): void;
|
|
25
|
+
private findFileInComponent;
|
|
26
|
+
/**
|
|
27
|
+
* return the file if part of the component.
|
|
28
|
+
* otherwise, a reference to the target package and the type name.
|
|
29
|
+
*/
|
|
30
|
+
private getSourceFile;
|
|
31
|
+
definition(node: Node): Promise<Node | undefined>;
|
|
32
|
+
visitDefinition(node: Node): Promise<SchemaNode | undefined>;
|
|
33
|
+
visit(node: Node): Promise<SchemaNode | undefined>;
|
|
34
|
+
references(): void;
|
|
35
|
+
isExported(): void;
|
|
36
|
+
isFromComponent(): void;
|
|
37
|
+
getFileExports(exportDec: ExportDeclaration): Promise<import("./export-identifier").ExportIdentifier[]>;
|
|
38
|
+
_exports: ExportList | undefined;
|
|
39
|
+
setExports(exports: ExportList): this;
|
|
40
|
+
getExportedIdentifiers(node: Node): Promise<import("./export-identifier").ExportIdentifier[]>;
|
|
41
|
+
private isNative;
|
|
42
|
+
jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined>;
|
|
43
|
+
resolveType(node: Node, typeStr: string, type?: boolean): Promise<TypeRefSchema>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.array.iterator.js");
|
|
6
|
+
|
|
7
|
+
require("core-js/modules/es.promise.js");
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "__esModule", {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
exports.SchemaExtractorContext = void 0;
|
|
13
|
+
|
|
14
|
+
function _defineProperty2() {
|
|
15
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
|
|
17
|
+
_defineProperty2 = function () {
|
|
18
|
+
return data;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function _tsutils() {
|
|
25
|
+
const data = require("tsutils");
|
|
26
|
+
|
|
27
|
+
_tsutils = function () {
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _lodash() {
|
|
35
|
+
const data = require("lodash");
|
|
36
|
+
|
|
37
|
+
_lodash = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function _path() {
|
|
45
|
+
const data = require("path");
|
|
46
|
+
|
|
47
|
+
_path = function () {
|
|
48
|
+
return data;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _semanticsEntities() {
|
|
55
|
+
const data = require("@teambit/semantics.entities.semantic-schema");
|
|
56
|
+
|
|
57
|
+
_semanticsEntities = function () {
|
|
58
|
+
return data;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class SchemaExtractorContext {
|
|
65
|
+
constructor(tsserver, component, extractor) {
|
|
66
|
+
this.tsserver = tsserver;
|
|
67
|
+
this.component = component;
|
|
68
|
+
this.extractor = extractor;
|
|
69
|
+
(0, _defineProperty2().default)(this, "_exports", undefined);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
computeSchema(node) {
|
|
73
|
+
return this.extractor.computeSchema(node, this);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getLocation(node, targetSourceFile) {
|
|
77
|
+
const sourceFile = targetSourceFile || node.getSourceFile();
|
|
78
|
+
const position = sourceFile.getLineAndCharacterOfPosition(node.pos);
|
|
79
|
+
const line = position.line + 1;
|
|
80
|
+
const character = position.character + 2; // need to verify why a 2 char difference here.
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
line,
|
|
84
|
+
character
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async getSignature(node) {
|
|
89
|
+
return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getPosition(sourceFile, line, offset) {
|
|
93
|
+
return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 2);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getPath(node) {
|
|
97
|
+
const sourceFile = node.getSourceFile();
|
|
98
|
+
return sourceFile.fileName;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
createRef() {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getQuickInfo(node) {
|
|
106
|
+
return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
typeDefinition(node) {
|
|
110
|
+
return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
visitTypeDefinition() {}
|
|
114
|
+
|
|
115
|
+
findFileInComponent(filePath) {
|
|
116
|
+
return this.component.filesystem.files.find(file => {
|
|
117
|
+
// TODO: fix this line to support further extensions.
|
|
118
|
+
if (file.path.includes(filePath)) {
|
|
119
|
+
const strings = ['ts', 'tsx', 'js', 'jsx'].map(format => {
|
|
120
|
+
if (filePath.endsWith(format)) return filePath;
|
|
121
|
+
return `${filePath}.${format}`;
|
|
122
|
+
});
|
|
123
|
+
return strings.find(string => string === file.path);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return false;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* return the file if part of the component.
|
|
131
|
+
* otherwise, a reference to the target package and the type name.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
getSourceFile(filePath) {
|
|
136
|
+
const file = this.findFileInComponent(filePath);
|
|
137
|
+
if (!file) return undefined;
|
|
138
|
+
return this.extractor.parseSourceFile(file);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async definition(node) {
|
|
142
|
+
const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));
|
|
143
|
+
const firstDef = (0, _lodash().head)(def.body);
|
|
144
|
+
if (!firstDef) return undefined;
|
|
145
|
+
const startPosition = firstDef.start;
|
|
146
|
+
const sourceFile = this.getSourceFile(firstDef.file);
|
|
147
|
+
if (!sourceFile) return undefined; // learn how to return a reference to a different component here.
|
|
148
|
+
|
|
149
|
+
const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);
|
|
150
|
+
const nodeAtPos = (0, _tsutils().getTokenAtPosition)(sourceFile, pos);
|
|
151
|
+
return nodeAtPos;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async visitDefinition(node) {
|
|
155
|
+
const definition = await this.definition(node);
|
|
156
|
+
if (!definition) return undefined;
|
|
157
|
+
return this.visit(definition.parent);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async visit(node) {
|
|
161
|
+
return this.extractor.computeSchema(node, this);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
references() {}
|
|
165
|
+
|
|
166
|
+
isExported() {}
|
|
167
|
+
|
|
168
|
+
isFromComponent() {}
|
|
169
|
+
|
|
170
|
+
async getFileExports(exportDec) {
|
|
171
|
+
var _exportDec$moduleSpec;
|
|
172
|
+
|
|
173
|
+
const file = exportDec.getSourceFile().fileName;
|
|
174
|
+
const specifierPathStr = ((_exportDec$moduleSpec = exportDec.moduleSpecifier) === null || _exportDec$moduleSpec === void 0 ? void 0 : _exportDec$moduleSpec.getText()) || '';
|
|
175
|
+
const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);
|
|
176
|
+
const absPath = (0, _path().resolve)(file, '..', specifierPath);
|
|
177
|
+
const sourceFile = this.getSourceFile(absPath);
|
|
178
|
+
if (!sourceFile) return [];
|
|
179
|
+
return this.extractor.computeExportedIdentifiers(sourceFile, this);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
setExports(exports) {
|
|
183
|
+
this._exports = exports;
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
getExportedIdentifiers(node) {
|
|
188
|
+
return this.extractor.computeExportedIdentifiers(node, this);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
isNative(typeName) {
|
|
192
|
+
return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async jump(file, start) {
|
|
196
|
+
const sourceFile = this.extractor.parseSourceFile(file);
|
|
197
|
+
const pos = this.getPosition(sourceFile, start.line, start.offset);
|
|
198
|
+
const nodeAtPos = (0, _tsutils().getTokenAtPosition)(sourceFile, pos);
|
|
199
|
+
if (!nodeAtPos) return undefined;
|
|
200
|
+
return this.visit(nodeAtPos);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async resolveType(node, typeStr, type = true) {
|
|
204
|
+
var _this$_exports, _typeDef$body;
|
|
205
|
+
|
|
206
|
+
if (this.isNative(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
|
|
207
|
+
if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
|
|
208
|
+
const typeDef = type ? await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node)) : await this.typeDefinition(node);
|
|
209
|
+
const def = await Promise.all((typeDef === null || typeDef === void 0 ? void 0 : (_typeDef$body = typeDef.body) === null || _typeDef$body === void 0 ? void 0 : _typeDef$body.map(async definition => {
|
|
210
|
+
const file = this.findFileInComponent(definition.file); // TODO: find component id is exists, otherwise add the package name.
|
|
211
|
+
|
|
212
|
+
if (!file) return new (_semanticsEntities().TypeRefSchema)(typeStr, undefined, '');
|
|
213
|
+
if (file) return new (_semanticsEntities().TypeRefSchema)(typeStr, undefined, undefined, this.jump(file, definition.start));
|
|
214
|
+
return undefined;
|
|
215
|
+
})) || []);
|
|
216
|
+
const headDef = (0, _lodash().head)(def);
|
|
217
|
+
if (headDef) return headDef;
|
|
218
|
+
return new (_semanticsEntities().TypeRefSchema)('any');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
exports.SchemaExtractorContext = SchemaExtractorContext;
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=schema-extractor-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","pos","line","character","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","fileName","createRef","getQuickInfo","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","file","path","includes","strings","map","format","endsWith","string","parseSourceFile","definition","def","getDefinition","firstDef","body","startPosition","start","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","length","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","isNative","typeName","jump","resolveType","typeStr","type","TypeRefSchema","typeDef","Promise","all","headDef"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;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KAA3B,CAAjD,CAAP;AACV,aAAO5C,SAAP;AACD,KAND,MAMM,EAPU,CAAlB;AAUA,UAAM4E,OAAO,GAAG,oBAAKrC,GAAL,CAAhB;AACA,QAAIqC,OAAJ,EAAa,OAAOA,OAAP;AACb,WAAO,KAAIJ,kCAAJ,EAAkB,KAAlB,CAAP;AACD;;AAhKiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n getLocation(node: Node, targetSourceFile?: ts.SourceFile) {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.pos);\n const line = position.line + 1;\n const character = position.character + 2; // need to verify why a 2 char difference here.\n\n return {\n line,\n character,\n };\n }\n\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 2);\n }\n\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n createRef() {\n return {};\n }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) return undefined;\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) return undefined; // learn how to return a reference to a different component here.\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) return undefined;\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode | undefined> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n private isNative(typeName: string) {\n return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);\n }\n\n async jump(file: AbstractVinyl, start: any) {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n return this.visit(nodeAtPos);\n }\n\n async resolveType(node: Node, typeStr: string, type = true): Promise<TypeRefSchema> {\n if (this.isNative(typeStr)) return new TypeRefSchema(typeStr);\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n\n const typeDef = type\n ? await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node))\n : await this.typeDefinition(node);\n\n const def = await Promise.all(\n typeDef?.body?.map(async (definition) => {\n const file = this.findFileInComponent(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n if (!file) return new TypeRefSchema(typeStr, undefined, '');\n if (file) return new TypeRefSchema(typeStr, undefined, undefined, this.jump(file, definition.start));\n return undefined;\n }) || []\n );\n\n const headDef = head(def);\n if (headDef) return headDef;\n return new TypeRefSchema('any');\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Node } from 'typescript';
|
|
2
|
+
import { SchemaNode } from '@teambit/semantics.entities.semantic-schema';
|
|
3
|
+
import { SchemaExtractorContext } from './schema-extractor-context';
|
|
4
|
+
import { ExportIdentifier } from './export-identifier';
|
|
5
|
+
export declare type SchemaTransformer = {
|
|
6
|
+
/**
|
|
7
|
+
* determine whether to apply schema on given node.
|
|
8
|
+
*/
|
|
9
|
+
predicate(node: Node): boolean;
|
|
10
|
+
getIdentifiers(node: Node, context: SchemaExtractorContext): Promise<ExportIdentifier[]>;
|
|
11
|
+
/**
|
|
12
|
+
* transform the node into JSONSchema.
|
|
13
|
+
*/
|
|
14
|
+
transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PluginDefinition } from '@teambit/aspect-loader';
|
|
2
|
+
import { SchemaTransformerSlot } from './typescript.main.runtime';
|
|
3
|
+
export declare class SchemaTransformerPlugin implements PluginDefinition {
|
|
4
|
+
private schemaTransformerSlot;
|
|
5
|
+
constructor(schemaTransformerSlot: SchemaTransformerSlot);
|
|
6
|
+
pattern: string;
|
|
7
|
+
runtimes: string[];
|
|
8
|
+
register(object: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.SchemaTransformerPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
function _defineProperty2() {
|
|
11
|
+
const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
|
|
13
|
+
_defineProperty2 = function () {
|
|
14
|
+
return data;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class SchemaTransformerPlugin {
|
|
21
|
+
constructor(schemaTransformerSlot) {
|
|
22
|
+
this.schemaTransformerSlot = schemaTransformerSlot;
|
|
23
|
+
(0, _defineProperty2().default)(this, "pattern", '*.schema-extractor.*');
|
|
24
|
+
(0, _defineProperty2().default)(this, "runtimes", ['main']);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
register(object) {
|
|
28
|
+
return this.schemaTransformerSlot.register([object]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.SchemaTransformerPlugin = SchemaTransformerPlugin;
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=schema-transformer.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["schema-transformer.plugin.ts"],"names":["SchemaTransformerPlugin","constructor","schemaTransformerSlot","register","object"],"mappings":";;;;;;;;;;;;;;;;;;;AAGO,MAAMA,uBAAN,CAA0D;AAC/DC,EAAAA,WAAW,CAASC,qBAAT,EAAuD;AAAA,SAA9CA,qBAA8C,GAA9CA,qBAA8C;AAAA,qDAExD,sBAFwD;AAAA,sDAIvD,CAAC,MAAD,CAJuD;AAAE;;AAMpEC,EAAAA,QAAQ,CAACC,MAAD,EAAc;AACpB,WAAO,KAAKF,qBAAL,CAA2BC,QAA3B,CAAoC,CAACC,MAAD,CAApC,CAAP;AACD;;AAT8D","sourcesContent":["import { PluginDefinition } from '@teambit/aspect-loader';\nimport { SchemaTransformerSlot } from './typescript.main.runtime';\n\nexport class SchemaTransformerPlugin implements PluginDefinition {\n constructor(private schemaTransformerSlot: SchemaTransformerSlot) {}\n\n pattern = '*.schema-extractor.*';\n\n runtimes = ['main'];\n\n register(object: any) {\n return this.schemaTransformerSlot.register([object]);\n }\n}\n"]}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Node, ExportDeclaration as ExportDeclarationNode } from 'typescript';
|
|
2
|
+
import { SchemaExtractorContext } from '../schema-extractor-context';
|
|
3
|
+
import { SchemaTransformer } from '../schema-transformer';
|
|
4
|
+
import { ExportIdentifier } from '../export-identifier';
|
|
5
|
+
export declare class ExportDeclaration implements SchemaTransformer {
|
|
6
|
+
predicate(node: Node): boolean;
|
|
7
|
+
getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<ExportIdentifier[]>;
|
|
8
|
+
transform(node: Node, context: SchemaExtractorContext): Promise<{}>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/es.array.iterator.js");
|
|
4
|
+
|
|
5
|
+
require("core-js/modules/es.promise.js");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.ExportDeclaration = void 0;
|
|
11
|
+
|
|
12
|
+
function _typescript() {
|
|
13
|
+
const data = _interopRequireWildcard(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 _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
class ExportDeclaration {
|
|
37
|
+
predicate(node) {
|
|
38
|
+
return node.kind === _typescript().SyntaxKind.ExportDeclaration;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getIdentifiers(exportDec, context) {
|
|
42
|
+
var _exportDec$exportClau, _exportDec$exportClau2;
|
|
43
|
+
|
|
44
|
+
if (((_exportDec$exportClau = exportDec.exportClause) === null || _exportDec$exportClau === void 0 ? void 0 : _exportDec$exportClau.kind) === _typescript().default.SyntaxKind.NamedExports) {
|
|
45
|
+
exportDec.exportClause;
|
|
46
|
+
return exportDec.exportClause.elements.map(elm => {
|
|
47
|
+
return new (_exportIdentifier().ExportIdentifier)(elm.name.getText(), elm.getSourceFile().fileName);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (((_exportDec$exportClau2 = exportDec.exportClause) === null || _exportDec$exportClau2 === void 0 ? void 0 : _exportDec$exportClau2.kind) === _typescript().default.SyntaxKind.NamespaceExport) {
|
|
52
|
+
return [new (_exportIdentifier().ExportIdentifier)(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (exportDec.moduleSpecifier) {
|
|
56
|
+
return context.getFileExports(exportDec);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async transform(node, context) {
|
|
63
|
+
const exportDec = node; // sourceFile.sear
|
|
64
|
+
|
|
65
|
+
const exportClause = exportDec.exportClause;
|
|
66
|
+
|
|
67
|
+
if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamedExports) {
|
|
68
|
+
exportClause; // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
+
|
|
70
|
+
const exports = await Promise.all(exportClause.elements.map(async element => {
|
|
71
|
+
// const sig = await context.visitDefinition(element.name);
|
|
72
|
+
await context.visitDefinition(element.name);
|
|
73
|
+
return element.name;
|
|
74
|
+
}));
|
|
75
|
+
return []; // return exports.map((identifier) => {
|
|
76
|
+
// // const type = context.resolveType(identifier);
|
|
77
|
+
// });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.ExportDeclaration = ExportDeclaration;
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=export-declaration.js.map
|
|
@@ -0,0 +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","exports","Promise","all","element","visitDefinition"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;AAC1DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,yBAAWJ,iBAAhC;AACD;;AAEmB,QAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;AAAA;;AACtF,QAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,sBAAGL,UAAH,CAAcM,YAAnD,EAAiE;AAC/DJ,MAAAA,SAAS,CAACE,YAAV;AACA,aAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;AAClD,eAAO,KAAIC,oCAAJ,EAAqBD,GAAG,CAACE,IAAJ,CAASC,OAAT,EAArB,EAAyCH,GAAG,CAACI,aAAJ,GAAoBC,QAA7D,CAAP;AACD,OAFM,CAAP;AAGD;;AAED,QAAI,2BAAAZ,SAAS,CAACE,YAAV,kFAAwBL,IAAxB,MAAiCM,sBAAGL,UAAH,CAAce,eAAnD,EAAoE;AAClE,aAAO,CAAC,KAAIL,oCAAJ,EAAqBR,SAAS,CAACE,YAAV,CAAuBO,IAAvB,CAA4BC,OAA5B,EAArB,EAA4DV,SAAS,CAACW,aAAV,GAA0BC,QAAtF,CAAD,CAAP;AACD;;AAED,QAAIZ,SAAS,CAACc,eAAd,EAA+B;AAC7B,aAAOb,OAAO,CAACc,cAAR,CAAuBf,SAAvB,CAAP;AACD;;AAED,WAAO,EAAP;AACD;;AAEc,QAATgB,SAAS,CAACpB,IAAD,EAAaK,OAAb,EAA8C;AAC3D,UAAMD,SAAS,GAAGJ,IAAlB,CAD2D,CAE3D;;AACA,UAAMM,YAAY,GAAGF,SAAS,CAACE,YAA/B;;AACA,QAAI,CAAAA,YAAY,SAAZ,IAAAA,YAAY,WAAZ,YAAAA,YAAY,CAAEL,IAAd,MAAuBC,yBAAWM,YAAtC,EAAoD;AAClDF,MAAAA,YAAY,CADsC,CAElD;;AACA,YAAMe,OAAO,GAAG,MAAMC,OAAO,CAACC,GAAR,CACpBjB,YAAY,CAACG,QAAb,CAAsBC,GAAtB,CAA0B,MAAOc,OAAP,IAAmB;AAC3C;AACA,cAAMnB,OAAO,CAACoB,eAAR,CAAwBD,OAAO,CAACX,IAAhC,CAAN;AACA,eAAOW,OAAO,CAACX,IAAf;AACD,OAJD,CADoB,CAAtB;AAQA,aAAO,EAAP,CAXkD,CAYlD;AACA;AACA;AACD;;AAED,WAAO,EAAP;AACD;;AA9CyD","sourcesContent":["import ts, { Node, SyntaxKind, ExportDeclaration as ExportDeclarationNode, NamedExports } 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) {\n const exportDec = node as ExportDeclarationNode;\n // sourceFile.sear\n const exportClause = exportDec.exportClause;\n if (exportClause?.kind === SyntaxKind.NamedExports) {\n exportClause as NamedExports;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const exports = await Promise.all(\n exportClause.elements.map(async (element) => {\n // const sig = await context.visitDefinition(element.name);\n await context.visitDefinition(element.name);\n return element.name;\n })\n );\n\n return [];\n // return exports.map((identifier) => {\n // // const type = context.resolveType(identifier);\n // });\n }\n\n return {};\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
private getArgs;
|
|
11
|
+
private parseReturnValue;
|
|
12
|
+
transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
|
|
13
|
+
}
|