@teambit/typescript 0.0.585 → 0.0.589

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/exceptions/index.d.ts +1 -0
  2. package/dist/exceptions/index.js +23 -0
  3. package/dist/exceptions/index.js.map +1 -0
  4. package/dist/exceptions/transformer-not-found.d.ts +7 -0
  5. package/dist/exceptions/transformer-not-found.js +19 -0
  6. package/dist/exceptions/transformer-not-found.js.map +1 -0
  7. package/dist/export-identifier.d.ts +5 -0
  8. package/dist/export-identifier.js +18 -0
  9. package/dist/export-identifier.js.map +1 -0
  10. package/dist/export-list.d.ts +6 -0
  11. package/dist/export-list.js +21 -0
  12. package/dist/export-list.js.map +1 -0
  13. package/dist/schema-extractor-context.d.ts +44 -0
  14. package/dist/schema-extractor-context.js +225 -0
  15. package/dist/schema-extractor-context.js.map +1 -0
  16. package/dist/schema-transformer.d.ts +15 -0
  17. package/dist/schema-transformer.js +3 -0
  18. package/dist/schema-transformer.js.map +1 -0
  19. package/dist/schema-transformer.plugin.d.ts +9 -0
  20. package/dist/schema-transformer.plugin.js +35 -0
  21. package/dist/schema-transformer.plugin.js.map +1 -0
  22. package/dist/transformers/export-declaration-type.d.ts +0 -0
  23. package/dist/transformers/export-declaration-type.js +3 -0
  24. package/dist/transformers/export-declaration-type.js.map +1 -0
  25. package/dist/transformers/export-declaration.d.ts +9 -0
  26. package/dist/transformers/export-declaration.js +87 -0
  27. package/dist/transformers/export-declaration.js.map +1 -0
  28. package/dist/transformers/function-declaration.d.ts +13 -0
  29. package/dist/transformers/function-declaration.js +101 -0
  30. package/dist/transformers/function-declaration.js.map +1 -0
  31. package/dist/transformers/index.d.ts +5 -0
  32. package/dist/transformers/index.js +87 -0
  33. package/dist/transformers/index.js.map +1 -0
  34. package/dist/transformers/source-file-transformer.d.ts +13 -0
  35. package/dist/transformers/source-file-transformer.js +82 -0
  36. package/dist/transformers/source-file-transformer.js.map +1 -0
  37. package/dist/transformers/type-alias.d.ts +8 -0
  38. package/dist/transformers/type-alias.js +49 -0
  39. package/dist/transformers/type-alias.js.map +1 -0
  40. package/dist/transformers/variable-statement.d.ts +8 -0
  41. package/dist/transformers/variable-statement.js +51 -0
  42. package/dist/transformers/variable-statement.js.map +1 -0
  43. package/dist/typescript.compiler.js +2 -2
  44. package/dist/typescript.compiler.spec.js +2 -2
  45. package/dist/typescript.extractor.d.ts +24 -4
  46. package/dist/typescript.extractor.js +132 -26
  47. package/dist/typescript.extractor.js.map +1 -1
  48. package/dist/typescript.main.runtime.d.ts +11 -5
  49. package/dist/typescript.main.runtime.js +61 -18
  50. package/dist/typescript.main.runtime.js.map +1 -1
  51. package/dist/typescript.parser.d.ts +2 -1
  52. package/dist/typescript.parser.js +7 -7
  53. package/dist/typescript.parser.js.map +1 -1
  54. package/exceptions/index.ts +1 -0
  55. package/exceptions/transformer-not-found.ts +12 -0
  56. package/package-tar/teambit-typescript-0.0.589.tgz +0 -0
  57. package/package.json +23 -19
  58. package/transformers/export-declaration-type.ts +0 -0
  59. package/transformers/export-declaration.ts +53 -0
  60. package/transformers/function-declaration.ts +54 -0
  61. package/transformers/index.ts +5 -0
  62. package/transformers/source-file-transformer.ts +60 -0
  63. package/transformers/type-alias.ts +17 -0
  64. package/transformers/variable-statement.ts +19 -0
  65. package/package-tar/teambit-typescript-0.0.585.tgz +0 -0
package/package.json CHANGED
@@ -1,36 +1,40 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.585",
3
+ "version": "0.0.589",
4
4
  "homepage": "https://bit.dev/teambit/typescript/typescript",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.typescript",
8
8
  "name": "typescript",
9
- "version": "0.0.585"
9
+ "version": "0.0.589"
10
10
  },
11
11
  "dependencies": {
12
+ "lodash": "4.17.21",
13
+ "tsutils": "3.21.0",
14
+ "typescript": "4.4.2",
12
15
  "@teambit/harmony": "0.2.11",
13
16
  "fs-extra": "10.0.0",
14
- "typescript": "4.4.2",
15
- "typedoc": "0.22.5",
16
17
  "p-map-series": "2.1.0",
17
18
  "chalk": "2.4.2",
18
19
  "@babel/runtime": "7.12.18",
19
20
  "core-js": "^3.0.0",
20
- "@teambit/compiler": "0.0.585",
21
- "@teambit/typescript.modules.ts-config-mutator": "0.0.58",
22
- "@teambit/bit-error": "0.0.387",
23
- "@teambit/builder": "0.0.585",
24
- "@teambit/isolator": "0.0.585",
25
- "@teambit/logger": "0.0.489",
26
- "@teambit/component": "0.0.585",
27
- "@teambit/schema": "0.0.585",
28
- "@teambit/cli": "0.0.401",
29
- "@teambit/pkg": "0.0.585",
30
- "@teambit/ts-server": "0.0.24",
31
- "@teambit/workspace": "0.0.585"
21
+ "@teambit/compiler": "0.0.589",
22
+ "@teambit/typescript.modules.ts-config-mutator": "0.0.61",
23
+ "@teambit/component": "0.0.589",
24
+ "@teambit/semantics.entities.semantic-schema": "0.0.1",
25
+ "@teambit/ts-server": "0.0.28",
26
+ "@teambit/aspect-loader": "0.0.589",
27
+ "@teambit/bit-error": "0.0.390",
28
+ "@teambit/builder": "0.0.589",
29
+ "@teambit/isolator": "0.0.589",
30
+ "@teambit/logger": "0.0.492",
31
+ "@teambit/schema": "0.0.589",
32
+ "@teambit/cli": "0.0.404",
33
+ "@teambit/pkg": "0.0.589",
34
+ "@teambit/workspace": "0.0.589"
32
35
  },
33
36
  "devDependencies": {
37
+ "@types/lodash": "4.14.165",
34
38
  "chai": "4.3.0",
35
39
  "@types/chai": "4.2.15",
36
40
  "@types/fs-extra": "9.0.7",
@@ -40,10 +44,10 @@
40
44
  "@types/jest": "^26.0.0",
41
45
  "@types/react-dom": "^17.0.5",
42
46
  "@types/node": "12.20.4",
43
- "@teambit/typescript.aspect-docs.typescript": "0.0.123"
47
+ "@teambit/typescript.aspect-docs.typescript": "0.0.126"
44
48
  },
45
49
  "peerDependencies": {
46
- "@teambit/legacy": "1.0.187",
50
+ "@teambit/legacy": "1.0.190",
47
51
  "react-dom": "^16.8.0 || ^17.0.0",
48
52
  "react": "^16.8.0 || ^17.0.0"
49
53
  },
@@ -71,7 +75,7 @@
71
75
  "react": "-"
72
76
  },
73
77
  "peerDependencies": {
74
- "@teambit/legacy": "1.0.187",
78
+ "@teambit/legacy": "1.0.190",
75
79
  "react-dom": "^16.8.0 || ^17.0.0",
76
80
  "react": "^16.8.0 || ^17.0.0"
77
81
  }
File without changes
@@ -0,0 +1,53 @@
1
+ import ts, { Node, SyntaxKind, ExportDeclaration as ExportDeclarationNode, NamedExports } from 'typescript';
2
+ import { SchemaExtractorContext } from '../schema-extractor-context';
3
+ import { SchemaTransformer } from '../schema-transformer';
4
+ import { ExportIdentifier } from '../export-identifier';
5
+
6
+ export class ExportDeclaration implements SchemaTransformer {
7
+ predicate(node: Node) {
8
+ return node.kind === SyntaxKind.ExportDeclaration;
9
+ }
10
+
11
+ async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {
12
+ if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {
13
+ exportDec.exportClause as NamedExports;
14
+ return exportDec.exportClause.elements.map((elm) => {
15
+ return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);
16
+ });
17
+ }
18
+
19
+ if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {
20
+ return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];
21
+ }
22
+
23
+ if (exportDec.moduleSpecifier) {
24
+ return context.getFileExports(exportDec);
25
+ }
26
+
27
+ return [];
28
+ }
29
+
30
+ async transform(node: Node, context: SchemaExtractorContext) {
31
+ const exportDec = node as ExportDeclarationNode;
32
+ // sourceFile.sear
33
+ const exportClause = exportDec.exportClause;
34
+ if (exportClause?.kind === SyntaxKind.NamedExports) {
35
+ exportClause as NamedExports;
36
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
+ const exports = await Promise.all(
38
+ exportClause.elements.map(async (element) => {
39
+ // const sig = await context.visitDefinition(element.name);
40
+ await context.visitDefinition(element.name);
41
+ return element.name;
42
+ })
43
+ );
44
+
45
+ return [];
46
+ // return exports.map((identifier) => {
47
+ // // const type = context.resolveType(identifier);
48
+ // });
49
+ }
50
+
51
+ return {};
52
+ }
53
+ }
@@ -0,0 +1,54 @@
1
+ import { SchemaNode, FunctionSchema } from '@teambit/semantics.entities.semantic-schema';
2
+ import ts, { 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
+
7
+ export class FunctionDeclaration implements SchemaTransformer {
8
+ predicate(node: Node) {
9
+ return node.kind === ts.SyntaxKind.FunctionDeclaration;
10
+ }
11
+
12
+ // need to check for anonymous functions assigned for vars, const and let.
13
+ async getIdentifiers(funcDec: FunctionDeclarationNode) {
14
+ return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];
15
+ }
16
+
17
+ private getName(funcDec: FunctionDeclarationNode) {
18
+ return funcDec.name?.getText() || '';
19
+ }
20
+
21
+ private async getArgs(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext) {
22
+ return Promise.all(
23
+ funcDec.parameters.map(async (param) => {
24
+ const type = param.type;
25
+ return {
26
+ name: param.name.getText(),
27
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
+ type: await context.resolveType(type!, type?.getText() || 'any'),
29
+ };
30
+ })
31
+ );
32
+ }
33
+
34
+ private parseReturnValue(displayString?: string) {
35
+ if (!displayString) return '';
36
+ const array = displayString.split(':');
37
+ return array[array.length - 1].trim();
38
+ }
39
+
40
+ async transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {
41
+ const funcDec = node as FunctionDeclarationNode;
42
+ const name = this.getName(funcDec);
43
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
+ const info = await context.getQuickInfo(funcDec.name!);
45
+ const displaySig = info?.body?.displayString;
46
+ const returnTypeStr = this.parseReturnValue(displaySig);
47
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
+ const args = await this.getArgs(funcDec, context);
49
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
50
+ const returnType = await context.resolveType(funcDec.name!, returnTypeStr);
51
+
52
+ return new FunctionSchema(name || '', [], returnType);
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ export { ExportDeclaration } from './export-declaration';
2
+ export { FunctionDeclaration } from './function-declaration';
3
+ export { VariableStatementTransformer } from './variable-statement';
4
+ export { SourceFileTransformer } from './source-file-transformer';
5
+ export { TypeAliasTransformer } from './type-alias';
@@ -0,0 +1,60 @@
1
+ import ts, { Node, SourceFile } from 'typescript';
2
+ import { compact, flatten } from 'lodash';
3
+ import { SchemaTransformer } from '../schema-transformer';
4
+ import { ExportIdentifier } from '../export-identifier';
5
+ import { SchemaExtractorContext } from '../schema-extractor-context';
6
+
7
+ export class SourceFileTransformer implements SchemaTransformer {
8
+ predicate(node: Node) {
9
+ return node.kind === ts.SyntaxKind.SourceFile;
10
+ }
11
+
12
+ async getIdentifiers(sourceFile: SourceFile, context: SchemaExtractorContext) {
13
+ const exports = this.listExports(sourceFile);
14
+
15
+ const exportNames = await Promise.all(
16
+ exports.map((node: Node) => {
17
+ return context.getExportedIdentifiers(node);
18
+ })
19
+ );
20
+
21
+ const exportIds = flatten(exportNames).reduce<ExportIdentifier[]>((acc, current) => {
22
+ const item = acc.find((exportName) => exportName.id === current.id);
23
+ if (!item) acc.push(current);
24
+ return acc;
25
+ }, []);
26
+
27
+ return exportIds;
28
+ }
29
+
30
+ async transform(node: SourceFile, context: SchemaExtractorContext) {
31
+ const exports = this.listExports(node);
32
+ const schemas = await Promise.all(
33
+ exports.map((exportNode) => {
34
+ return context.computeSchema(exportNode);
35
+ })
36
+ );
37
+
38
+ return schemas;
39
+ }
40
+
41
+ /**
42
+ * list all exports of a source file.
43
+ */
44
+ private listExports(ast: SourceFile): Node[] {
45
+ return compact(
46
+ ast.statements.map((statement) => {
47
+ if (statement.kind === ts.SyntaxKind.ExportDeclaration) return statement;
48
+ const isExport = Boolean(
49
+ statement.modifiers?.find((modifier) => {
50
+ return modifier.kind === ts.SyntaxKind.ExportKeyword;
51
+ })
52
+ );
53
+
54
+ // eslint-disable-next-line consistent-return
55
+ if (!isExport) return;
56
+ return statement;
57
+ })
58
+ );
59
+ }
60
+ }
@@ -0,0 +1,17 @@
1
+ import ts, { Node, TypeAliasDeclaration } from 'typescript';
2
+ import { SchemaTransformer } from '../schema-transformer';
3
+ import { ExportIdentifier } from '../export-identifier';
4
+
5
+ export class TypeAliasTransformer implements SchemaTransformer {
6
+ predicate(node: Node) {
7
+ return node.kind === ts.SyntaxKind.TypeAliasDeclaration;
8
+ }
9
+
10
+ async getIdentifiers(node: TypeAliasDeclaration) {
11
+ return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];
12
+ }
13
+
14
+ async transform() {
15
+ return {};
16
+ }
17
+ }
@@ -0,0 +1,19 @@
1
+ import ts, { Node, VariableStatement } from 'typescript';
2
+ import { SchemaTransformer } from '../schema-transformer';
3
+ import { ExportIdentifier } from '../export-identifier';
4
+
5
+ export class VariableStatementTransformer implements SchemaTransformer {
6
+ predicate(node: Node) {
7
+ return node.kind === ts.SyntaxKind.VariableStatement;
8
+ }
9
+
10
+ async getIdentifiers(node: VariableStatement) {
11
+ return node.declarationList.declarations.map((dec) => {
12
+ return new ExportIdentifier(dec.name.getText(), dec.getSourceFile().fileName);
13
+ });
14
+ }
15
+
16
+ async transform() {
17
+ return {};
18
+ }
19
+ }