@teambit/typescript 0.0.752 → 0.0.755

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 (45) hide show
  1. package/dist/exceptions/transformer-not-found.js +1 -1
  2. package/dist/exceptions/transformer-not-found.js.map +1 -1
  3. package/dist/transformers/binding-element.d.ts +17 -0
  4. package/dist/transformers/binding-element.js +83 -0
  5. package/dist/transformers/binding-element.js.map +1 -0
  6. package/dist/transformers/export-declaration.d.ts +1 -1
  7. package/dist/transformers/export-declaration.js +25 -25
  8. package/dist/transformers/export-declaration.js.map +1 -1
  9. package/dist/transformers/function-declaration.js +4 -4
  10. package/dist/transformers/function-declaration.js.map +1 -1
  11. package/dist/transformers/index.d.ts +1 -1
  12. package/dist/transformers/index.js +15 -15
  13. package/dist/transformers/index.js.map +1 -1
  14. package/dist/transformers/utils/class-element-to-schema.js +6 -5
  15. package/dist/transformers/utils/class-element-to-schema.js.map +1 -1
  16. package/dist/transformers/utils/get-params.js +1 -1
  17. package/dist/transformers/utils/get-params.js.map +1 -1
  18. package/dist/transformers/utils/{to-function-schema.d.ts → to-function-like-schema.d.ts} +0 -0
  19. package/dist/transformers/utils/{to-function-schema.js → to-function-like-schema.js} +1 -1
  20. package/dist/transformers/utils/to-function-like-schema.js.map +1 -0
  21. package/dist/transformers/utils/type-element-to-schema.js +8 -7
  22. package/dist/transformers/utils/type-element-to-schema.js.map +1 -1
  23. package/dist/transformers/variable-declaration.js +1 -1
  24. package/dist/transformers/variable-declaration.js.map +1 -1
  25. package/dist/typescript.main.runtime.js +1 -1
  26. package/dist/typescript.main.runtime.js.map +1 -1
  27. package/exceptions/transformer-not-found.ts +1 -1
  28. package/package-tar/teambit-typescript-0.0.755.tgz +0 -0
  29. package/package.json +16 -16
  30. package/{preview-1654399579544.js → preview-1654697373869.js} +2 -2
  31. package/transformers/binding-element.ts +32 -0
  32. package/transformers/export-declaration.ts +21 -19
  33. package/transformers/function-declaration.ts +1 -1
  34. package/transformers/index.ts +1 -1
  35. package/transformers/utils/class-element-to-schema.ts +3 -2
  36. package/transformers/utils/get-params.ts +1 -0
  37. package/transformers/utils/{to-function-schema.ts → to-function-like-schema.ts} +0 -0
  38. package/transformers/utils/type-element-to-schema.ts +3 -2
  39. package/transformers/variable-declaration.ts +1 -1
  40. package/dist/transformers/literal-type.d.ts +0 -9
  41. package/dist/transformers/literal-type.js +0 -50
  42. package/dist/transformers/literal-type.js.map +0 -1
  43. package/dist/transformers/utils/to-function-schema.js.map +0 -1
  44. package/package-tar/teambit-typescript-0.0.752.tgz +0 -0
  45. package/transformers/literal-type.ts +0 -19
@@ -20,7 +20,7 @@ function _typescript() {
20
20
  class TransformerNotFound extends Error {
21
21
  constructor(node, component, location) {
22
22
  super(`typescript: could not find schema transformer for node of kind ${node.kind} (${_typescript().default.SyntaxKind[node.kind]}) in component ${component.id.toString()}.
23
- location: ${location.file}, line: ${location.line}, character: ${location.character}.
23
+ location: ${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}.
24
24
  node-text: ${node.getText()}`);
25
25
  this.node = node;
26
26
  this.component = component;
@@ -1 +1 @@
1
- {"version":3,"names":["TransformerNotFound","Error","constructor","node","component","location","kind","ts","SyntaxKind","id","toString","file","line","character","getText"],"sources":["transformer-not-found.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { Component } from '@teambit/component';\nimport { Location } from '@teambit/semantics.entities.semantic-schema';\n\nexport class TransformerNotFound extends Error {\n constructor(readonly node: Node, readonly component: Component, location: Location) {\n super(\n `typescript: could not find schema transformer for node of kind ${node.kind} (${\n ts.SyntaxKind[node.kind]\n }) in component ${component.id.toString()}.\nlocation: ${location.file}, line: ${location.line}, character: ${location.character}.\nnode-text: ${node.getText()}`\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIO,MAAMA,mBAAN,SAAkCC,KAAlC,CAAwC;EAC7CC,WAAW,CAAUC,IAAV,EAA+BC,SAA/B,EAAqDC,QAArD,EAAyE;IAClF,MACG,kEAAiEF,IAAI,CAACG,IAAK,KAC1EC,qBAAA,CAAGC,UAAH,CAAcL,IAAI,CAACG,IAAnB,CACD,kBAAiBF,SAAS,CAACK,EAAV,CAAaC,QAAb,EAAwB;AAChD,aAAaL,QAAQ,CAACM,IAAK,WAAUN,QAAQ,CAACO,IAAK,gBAAeP,QAAQ,CAACQ,SAAU;AACrF,aAAaV,IAAI,CAACW,OAAL,EAAe,EALxB;IADkF,KAA/DX,IAA+D,GAA/DA,IAA+D;IAAA,KAA1CC,SAA0C,GAA1CA,SAA0C;EAQnF;;AAT4C"}
1
+ {"version":3,"names":["TransformerNotFound","Error","constructor","node","component","location","kind","ts","SyntaxKind","id","toString","getSourceFile","fileName","line","character","getText"],"sources":["transformer-not-found.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { Component } from '@teambit/component';\nimport { Location } from '@teambit/semantics.entities.semantic-schema';\n\nexport class TransformerNotFound extends Error {\n constructor(readonly node: Node, readonly component: Component, location: Location) {\n super(\n `typescript: could not find schema transformer for node of kind ${node.kind} (${\n ts.SyntaxKind[node.kind]\n }) in component ${component.id.toString()}.\nlocation: ${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}.\nnode-text: ${node.getText()}`\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIO,MAAMA,mBAAN,SAAkCC,KAAlC,CAAwC;EAC7CC,WAAW,CAAUC,IAAV,EAA+BC,SAA/B,EAAqDC,QAArD,EAAyE;IAClF,MACG,kEAAiEF,IAAI,CAACG,IAAK,KAC1EC,qBAAA,CAAGC,UAAH,CAAcL,IAAI,CAACG,IAAnB,CACD,kBAAiBF,SAAS,CAACK,EAAV,CAAaC,QAAb,EAAwB;AAChD,aAAaP,IAAI,CAACQ,aAAL,GAAqBC,QAAS,WAAUP,QAAQ,CAACQ,IAAK,gBAAeR,QAAQ,CAACS,SAAU;AACrG,aAAaX,IAAI,CAACY,OAAL,EAAe,EALxB;IADkF,KAA/DZ,IAA+D,GAA/DA,IAA+D;IAAA,KAA1CC,SAA0C,GAA1CA,SAA0C;EAQnF;;AAT4C"}
@@ -0,0 +1,17 @@
1
+ import { BindingElement, Node } from 'typescript';
2
+ import { VariableSchema } from '@teambit/semantics.entities.semantic-schema';
3
+ import { SchemaTransformer } from '../schema-transformer';
4
+ import { SchemaExtractorContext } from '../schema-extractor-context';
5
+ import { ExportIdentifier } from '../export-identifier';
6
+ /**
7
+ * for example:
8
+ *
9
+ * const objBindingElem = { elem1: 1, elem2: 2 };
10
+ * const { elem1 } = objBindingElem;
11
+ * export { elem1 };
12
+ */
13
+ export declare class BindingElementTransformer implements SchemaTransformer {
14
+ predicate(node: Node): boolean;
15
+ getIdentifiers(node: BindingElement): Promise<ExportIdentifier[]>;
16
+ transform(node: BindingElement, context: SchemaExtractorContext): Promise<VariableSchema>;
17
+ }
@@ -0,0 +1,83 @@
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.BindingElementTransformer = void 0;
11
+
12
+ function _typescript() {
13
+ const data = _interopRequireDefault(require("typescript"));
14
+
15
+ _typescript = function () {
16
+ return data;
17
+ };
18
+
19
+ return data;
20
+ }
21
+
22
+ function _semanticsEntities() {
23
+ const data = require("@teambit/semantics.entities.semantic-schema");
24
+
25
+ _semanticsEntities = 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 _parseTypeFromQuickInfo() {
43
+ const data = require("./utils/parse-type-from-quick-info");
44
+
45
+ _parseTypeFromQuickInfo = function () {
46
+ return data;
47
+ };
48
+
49
+ return data;
50
+ }
51
+
52
+ /**
53
+ * for example:
54
+ *
55
+ * const objBindingElem = { elem1: 1, elem2: 2 };
56
+ * const { elem1 } = objBindingElem;
57
+ * export { elem1 };
58
+ */
59
+ class BindingElementTransformer {
60
+ predicate(node) {
61
+ return node.kind === _typescript().default.SyntaxKind.BindingElement;
62
+ }
63
+
64
+ async getIdentifiers(node) {
65
+ return [new (_exportIdentifier().ExportIdentifier)(node.name.getText(), node.getSourceFile().fileName)];
66
+ }
67
+
68
+ async transform(node, context) {
69
+ var _info$body;
70
+
71
+ const name = node.name.getText();
72
+ const info = await context.getQuickInfo(node.name);
73
+ const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
74
+ const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
75
+ const type = await context.resolveType(node, typeStr);
76
+ return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type, false);
77
+ }
78
+
79
+ }
80
+
81
+ exports.BindingElementTransformer = BindingElementTransformer;
82
+
83
+ //# sourceMappingURL=binding-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["BindingElementTransformer","predicate","node","kind","ts","SyntaxKind","BindingElement","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","context","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation"],"sources":["binding-element.ts"],"sourcesContent":["import ts, { BindingElement, Node } from 'typescript';\nimport { VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\n/**\n * for example:\n *\n * const objBindingElem = { elem1: 1, elem2: 2 };\n * const { elem1 } = objBindingElem;\n * export { elem1 };\n */\nexport class BindingElementTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.BindingElement;\n }\n\n async getIdentifiers(node: BindingElement) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(node: BindingElement, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableSchema(context.getLocation(node), name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,yBAAN,CAA6D;EAClEC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,cAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAAuB;IACzC,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACX,IAAD,EAAuBY,OAAvB,EAAwD;IAAA;;IACrE,MAAML,IAAI,GAAGP,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAb;IACA,MAAMK,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBd,IAAI,CAACO,IAA1B,CAAnB;IACA,MAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBN,IAAvB,CAAhB;IACA,MAAMO,IAAI,GAAG,MAAMR,OAAO,CAACS,WAAR,CAAoBrB,IAApB,EAA0BkB,OAA1B,CAAnB;IACA,OAAO,KAAII,mCAAJ,EAAmBV,OAAO,CAACW,WAAR,CAAoBvB,IAApB,CAAnB,EAA8CO,IAA9C,EAAoDQ,UAApD,EAAgEK,IAAhE,EAAsE,KAAtE,CAAP;EACD;;AAhBiE"}
@@ -6,5 +6,5 @@ import { ExportIdentifier } from '../export-identifier';
6
6
  export declare class ExportDeclaration implements SchemaTransformer {
7
7
  predicate(node: Node): boolean;
8
8
  getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<ExportIdentifier[]>;
9
- transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode>;
9
+ transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode>;
10
10
  }
@@ -79,20 +79,36 @@ class ExportDeclaration {
79
79
  return [];
80
80
  }
81
81
 
82
- async transform(node, context) {
83
- const exportDec = node;
84
- const exportClause = exportDec.exportClause; // e.g. `export { button1, button2 } as Composition from './button';
82
+ async transform(exportDec, context) {
83
+ const exportClause = exportDec.exportClause; // it's export-all, e.g. `export * from './button'`;
85
84
 
86
- if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamedExports) {
85
+ if (!exportClause) {
86
+ const specifier = exportDec.moduleSpecifier;
87
+
88
+ if (!specifier) {
89
+ throw new Error(`fatal: no specifier`);
90
+ }
91
+
92
+ const sourceFile = await context.getSourceFileFromNode(specifier);
93
+
94
+ if (!sourceFile) {
95
+ throw new Error(`unable to find the source-file`);
96
+ }
97
+
98
+ return context.computeSchema(sourceFile);
99
+ } // e.g. `export { button1, button2 } as Composition from './button';
100
+
101
+
102
+ if (exportClause.kind === _typescript().SyntaxKind.NamedExports) {
87
103
  exportClause;
88
104
  const schemas = await Promise.all(exportClause.elements.map(async element => {
89
105
  return context.visitDefinition(element.name);
90
106
  }));
91
- return new (_semanticsEntities().Module)(context.getLocation(node), (0, _lodash().compact)(schemas));
107
+ return new (_semanticsEntities().Module)(context.getLocation(exportDec), (0, _lodash().compact)(schemas));
92
108
  } // e.g. `export * as Composition from './button';
93
109
 
94
110
 
95
- if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamespaceExport) {
111
+ if (exportClause.kind === _typescript().SyntaxKind.NamespaceExport) {
96
112
  exportClause;
97
113
  const namespace = exportClause.name.getText();
98
114
  const filePath = await context.getFilePathByNode(exportClause.name);
@@ -105,7 +121,7 @@ class ExportDeclaration {
105
121
 
106
122
  if (!sourceFile) {
107
123
  // it's a namespace from another component or an external package.
108
- return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));
124
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
109
125
  }
110
126
 
111
127
  const result = await context.computeSchema(sourceFile);
@@ -116,26 +132,10 @@ class ExportDeclaration {
116
132
 
117
133
  result.namespace = namespace;
118
134
  return result;
119
- } // it's export-all, e.g. `export * from './button'`;
135
+ } // should never reach here. exportClause can be either NamespaceExport or NamedExports
120
136
 
121
137
 
122
- if (!exportClause) {
123
- const specifier = exportDec.moduleSpecifier;
124
-
125
- if (!specifier) {
126
- throw new Error(`fatal: no specifier`);
127
- }
128
-
129
- const sourceFile = await context.getSourceFileFromNode(specifier);
130
-
131
- if (!sourceFile) {
132
- throw new Error(`unable to find the source-file`);
133
- }
134
-
135
- return context.computeSchema(sourceFile);
136
- }
137
-
138
- throw new Error('unrecognized export type');
138
+ throw new Error(`unrecognized exportClause type`);
139
139
  }
140
140
 
141
141
  }
@@ -1 +1 @@
1
- {"version":3,"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","getLocation","compact","namespace","filePath","getFilePathByNode","Error","sourceFile","getSourceFileInsideComponent","getTypeRefForExternalPath","result","computeSchema","specifier","getSourceFileFromNode"],"sources":["export-declaration.ts"],"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(context.getLocation(node), 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 filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));\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"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,wBAAA,CAAWJ,iBAAhC;EACD;;EAEmB,MAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;IAAA;;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,qBAAA,CAAGL,UAAH,CAAcM,YAAnD,EAAiE;MAC/DJ,SAAS,CAACE,YAAV;MACA,OAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;QAClD,OAAO,KAAIC,oCAAJ,EAAqBD,GAAG,CAACE,IAAJ,CAASC,OAAT,EAArB,EAAyCH,GAAG,CAACI,aAAJ,GAAoBC,QAA7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kBC,OAAlB,EAAlB;MACA,MAAMgB,QAAQ,GAAG,MAAMzB,OAAO,CAAC0B,iBAAR,CAA0BzB,YAAY,CAACO,IAAvC,CAAvB;;MACA,IAAI,CAACiB,QAAL,EAAe;QACb,MAAM,IAAIE,KAAJ,CAAW,qCAAoCH,SAAU,GAAzD,CAAN;MACD;;MACD,MAAMI,UAAU,GAAG5B,OAAO,CAAC6B,4BAAR,CAAqCJ,QAArC,CAAnB;;MACA,IAAI,CAACG,UAAL,EAAiB;QACf;QACA,OAAO5B,OAAO,CAAC8B,yBAAR,CAAkCN,SAAlC,EAA6CC,QAA7C,EAAuDzB,OAAO,CAACsB,WAAR,CAAoB3B,IAApB,CAAvD,CAAP;MACD;;MACD,MAAMoC,MAAM,GAAG,MAAM/B,OAAO,CAACgC,aAAR,CAAsBJ,UAAtB,CAArB;;MACA,IAAI,EAAEG,MAAM,YAAYV,2BAApB,CAAJ,EAAiC;QAC/B,MAAM,IAAIM,KAAJ,CAAW,wCAAX,CAAN;MACD;;MACDI,MAAM,CAACP,SAAP,GAAmBA,SAAnB;MACA,OAAOO,MAAP;IACD,CAjC+E,CAkChF;;;IACA,IAAI,CAAC9B,YAAL,EAAmB;MACjB,MAAMgC,SAAS,GAAGlC,SAAS,CAACc,eAA5B;;MACA,IAAI,CAACoB,SAAL,EAAgB;QACd,MAAM,IAAIN,KAAJ,CAAW,qBAAX,CAAN;MACD;;MACD,MAAMC,UAAU,GAAG,MAAM5B,OAAO,CAACkC,qBAAR,CAA8BD,SAA9B,CAAzB;;MACA,IAAI,CAACL,UAAL,EAAiB;QACf,MAAM,IAAID,KAAJ,CAAW,gCAAX,CAAN;MACD;;MACD,OAAO3B,OAAO,CAACgC,aAAR,CAAsBJ,UAAtB,CAAP;IACD;;IAED,MAAM,IAAID,KAAJ,CAAU,0BAAV,CAAN;EACD;;AAxEyD"}
1
+ {"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","Promise","all","element","visitDefinition","Module","getLocation","compact","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"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(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\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 // 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(context.getLocation(exportDec), 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 filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\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\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,wBAAA,CAAWJ,iBAAhC;EACD;;EAEmB,MAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;IAAA;;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,qBAAA,CAAGL,UAAH,CAAcM,YAAnD,EAAiE;MAC/DJ,SAAS,CAACE,YAAV;MACA,OAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;QAClD,OAAO,K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const data = require("./utils/to-function-schema");
32
+ function _toFunctionLikeSchema() {
33
+ const data = require("./utils/to-function-like-schema");
34
34
 
35
- _toFunctionSchema = function () {
35
+ _toFunctionLikeSchema = function () {
36
36
  return data;
37
37
  };
38
38
 
@@ -56,7 +56,7 @@ class FunctionDeclaration {
56
56
  }
57
57
 
58
58
  async transform(funcDec, context) {
59
- return (0, _toFunctionSchema().toFunctionLikeSchema)(funcDec, context);
59
+ return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(funcDec, context);
60
60
  }
61
61
 
62
62
  }
@@ -1 +1 @@
1
- {"version":3,"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","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-schema';\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 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,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD,CAH2D,CAK5D;;;EACoB,MAAdM,cAAc,CAACC,OAAD,EAAmC;IACrD,OAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;EACD;;EAEOF,OAAO,CAACF,OAAD,EAAmC;IAAA;;IAChD,OAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;EACD;;EAEc,MAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;IACtG,OAAO,IAAAC,wCAAA,EAAqBT,OAArB,EAA8BQ,OAA9B,CAAP;EACD;;AAhB2D"}
1
+ {"version":3,"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","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;\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,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD,CAH2D,CAK5D;;;EACoB,MAAdM,cAAc,CAACC,OAAD,EAAmC;IACrD,OAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;EACD;;EAEOF,OAAO,CAACF,OAAD,EAAmC;IAAA;;IAChD,OAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;EACD;;EAEc,MAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;IACtG,OAAO,IAAAC,4CAAA,EAAqBT,OAArB,EAA8BQ,OAA9B,CAAP;EACD;;AAhB2D"}
@@ -5,6 +5,6 @@ export { VariableDeclaration } from './variable-declaration';
5
5
  export { SourceFileTransformer } from './source-file-transformer';
6
6
  export { TypeAliasTransformer } from './type-alias';
7
7
  export { ClassDecelerationTransformer } from './class-deceleration';
8
- export { LiteralTypeTransformer } from './literal-type';
9
8
  export { InterfaceDeclarationTransformer } from './interface-declaration';
10
9
  export { EnumDeclarationTransformer } from './enum-declaration';
10
+ export { BindingElementTransformer } from './binding-element';
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "BindingElementTransformer", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _bindingElement().BindingElementTransformer;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "ClassDecelerationTransformer", {
7
13
  enumerable: true,
8
14
  get: function () {
@@ -33,12 +39,6 @@ Object.defineProperty(exports, "InterfaceDeclarationTransformer", {
33
39
  return _interfaceDeclaration().InterfaceDeclarationTransformer;
34
40
  }
35
41
  });
36
- Object.defineProperty(exports, "LiteralTypeTransformer", {
37
- enumerable: true,
38
- get: function () {
39
- return _literalType().LiteralTypeTransformer;
40
- }
41
- });
42
42
  Object.defineProperty(exports, "SourceFileTransformer", {
43
43
  enumerable: true,
44
44
  get: function () {
@@ -134,30 +134,30 @@ function _classDeceleration() {
134
134
  return data;
135
135
  }
136
136
 
137
- function _literalType() {
138
- const data = require("./literal-type");
137
+ function _interfaceDeclaration() {
138
+ const data = require("./interface-declaration");
139
139
 
140
- _literalType = function () {
140
+ _interfaceDeclaration = function () {
141
141
  return data;
142
142
  };
143
143
 
144
144
  return data;
145
145
  }
146
146
 
147
- function _interfaceDeclaration() {
148
- const data = require("./interface-declaration");
147
+ function _enumDeclaration() {
148
+ const data = require("./enum-declaration");
149
149
 
150
- _interfaceDeclaration = function () {
150
+ _enumDeclaration = function () {
151
151
  return data;
152
152
  };
153
153
 
154
154
  return data;
155
155
  }
156
156
 
157
- function _enumDeclaration() {
158
- const data = require("./enum-declaration");
157
+ function _bindingElement() {
158
+ const data = require("./binding-element");
159
159
 
160
- _enumDeclaration = function () {
160
+ _bindingElement = function () {
161
161
  return data;
162
162
  };
163
163
 
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { VariableStatementTransformer } from './variable-statement';\nexport { VariableDeclaration } from './variable-declaration';\nexport { SourceFileTransformer } from './source-file-transformer';\nexport { TypeAliasTransformer } from './type-alias';\nexport { ClassDecelerationTransformer } from './class-deceleration';\nexport { LiteralTypeTransformer } from './literal-type';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { EnumDeclarationTransformer } from './enum-declaration';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { VariableStatementTransformer } from './variable-statement';\nexport { VariableDeclaration } from './variable-declaration';\nexport { SourceFileTransformer } from './source-file-transformer';\nexport { TypeAliasTransformer } from './type-alias';\nexport { ClassDecelerationTransformer } from './class-deceleration';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { EnumDeclarationTransformer } from './enum-declaration';\nexport { BindingElementTransformer } from './binding-element';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
@@ -57,10 +57,10 @@ function _parseTypeFromQuickInfo() {
57
57
  return data;
58
58
  }
59
59
 
60
- function _toFunctionSchema() {
61
- const data = require("./to-function-schema");
60
+ function _toFunctionLikeSchema() {
61
+ const data = require("./to-function-like-schema");
62
62
 
63
- _toFunctionSchema = function () {
63
+ _toFunctionLikeSchema = function () {
64
64
  return data;
65
65
  };
66
66
 
@@ -112,11 +112,12 @@ async function propertyDeclaration(node, context) {
112
112
  const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
113
113
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
114
114
  const type = await context.resolveType(node, typeStr);
115
- return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig || '', type);
115
+ const isOptional = Boolean(node.questionToken);
116
+ return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig || '', type, isOptional);
116
117
  }
117
118
 
118
119
  async function methodDeclaration(node, context) {
119
- return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context);
120
+ return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context);
120
121
  }
121
122
 
122
123
  //# sourceMappingURL=class-element-to-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","ConstructorSchema","getLocation","name","getText","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","toFunctionLikeSchema"],"sources":["class-element-to-schema.ts"],"sourcesContent":["import {\n ClassElement,\n ConstructorDeclaration,\n GetAccessorDeclaration,\n IndexSignatureDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n SetAccessorDeclaration,\n SyntaxKind,\n} from 'typescript';\nimport { ConstructorSchema, SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { toFunctionLikeSchema } from './to-function-schema';\n\nexport async function classElementToSchema(\n node: ClassElement,\n context: SchemaExtractorContext\n): Promise<SchemaNode | null> {\n switch (node.kind) {\n case SyntaxKind.Constructor:\n return constructor(node as ConstructorDeclaration, context);\n case SyntaxKind.PropertyDeclaration:\n return propertyDeclaration(node as PropertyDeclaration, context);\n case SyntaxKind.MethodDeclaration:\n return methodDeclaration(node as MethodDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need\n case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon\n return null;\n default:\n // should never be here unless typescript added new class elements\n throw new Error(`unrecognized ClassElement type. got ${node.kind}`);\n }\n}\n\nasync function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await getParams(node.parameters, context);\n return new ConstructorSchema(context.getLocation(node), args);\n}\n\nasync function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString;\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n\n return new VariableSchema(context.getLocation(node), name, displaySig || '', type);\n}\n\nasync function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,oBAAf,CACLC,IADK,EAELC,OAFK,EAGuB;EAC5B,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,WAAhB;MACE,OAAOC,WAAW,CAACL,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWG,mBAAhB;MACE,OAAOC,mBAAmB,CAACP,IAAD,EAA8BC,OAA9B,CAA1B;;IACF,KAAKE,wBAAA,CAAWK,iBAAhB;MACE,OAAOC,iBAAiB,CAACT,IAAD,EAA4BC,OAA5B,CAAxB;;IACF,KAAKE,wBAAA,CAAWO,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYX,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWS,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYb,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWW,cAAhB;MACE,OAAO,IAAAC,qCAAA,EAAef,IAAf,EAAkDC,OAAlD,CAAP;;IACF,KAAKE,wBAAA,CAAWa,2BAAhB,CAbF,CAa+C;;IAC7C,KAAKb,wBAAA,CAAWc,qBAAhB;MAAuC;MACrC,OAAO,IAAP;;IACF;MACE;MACA,MAAM,IAAIC,KAAJ,CAAW,uCAAsClB,IAAI,CAACE,IAAK,EAA3D,CAAN;EAlBJ;AAoBD;;AAED,eAAeG,WAAf,CAA2BL,IAA3B,EAAyDC,OAAzD,EAA0F;EACxF,MAAMkB,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAUpB,IAAI,CAACqB,UAAf,EAA2BpB,OAA3B,CAAnB;EACA,OAAO,KAAIqB,sCAAJ,EAAsBrB,OAAO,CAACsB,WAAR,CAAoBvB,IAApB,CAAtB,EAAiDmB,IAAjD,CAAP;AACD;;AAED,eAAeZ,mBAAf,CAAmCP,IAAnC,EAA8DC,OAA9D,EAA+F;EAAA;;EAC7F,MAAMuB,IAAI,GAAGxB,IAAI,CAACwB,IAAL,CAAUC,OAAV,EAAb;EACA,MAAMC,IAAI,GAAG,MAAMzB,OAAO,CAAC0B,YAAR,CAAqB3B,IAAI,CAACwB,IAA1B,CAAnB;EACA,MAAMI,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;EACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBN,IAAvB,CAAhB;EACA,MAAMO,IAAI,GAAG,MAAMhC,OAAO,CAACiC,WAAR,CAAoBlC,IAApB,EAA0B+B,OAA1B,CAAnB;EAEA,OAAO,KAAII,mCAAJ,EAAmBlC,OAAO,CAACsB,WAAR,CAAoBvB,IAApB,CAAnB,EAA8CwB,IAA9C,EAAoDI,UAAU,IAAI,EAAlE,EAAsEK,IAAtE,CAAP;AACD;;AAED,eAAexB,iBAAf,CAAiCT,IAAjC,EAA0DC,OAA1D,EAA2F;EACzF,OAAO,IAAAmC,wCAAA,EAAqBpC,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
1
+ {"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","ConstructorSchema","getLocation","name","getText","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableSchema","toFunctionLikeSchema"],"sources":["class-element-to-schema.ts"],"sourcesContent":["import {\n ClassElement,\n ConstructorDeclaration,\n GetAccessorDeclaration,\n IndexSignatureDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n SetAccessorDeclaration,\n SyntaxKind,\n} from 'typescript';\nimport { ConstructorSchema, SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\n\nexport async function classElementToSchema(\n node: ClassElement,\n context: SchemaExtractorContext\n): Promise<SchemaNode | null> {\n switch (node.kind) {\n case SyntaxKind.Constructor:\n return constructor(node as ConstructorDeclaration, context);\n case SyntaxKind.PropertyDeclaration:\n return propertyDeclaration(node as PropertyDeclaration, context);\n case SyntaxKind.MethodDeclaration:\n return methodDeclaration(node as MethodDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need\n case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon\n return null;\n default:\n // should never be here unless typescript added new class elements\n throw new Error(`unrecognized ClassElement type. got ${node.kind}`);\n }\n}\n\nasync function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await getParams(node.parameters, context);\n return new ConstructorSchema(context.getLocation(node), args);\n}\n\nasync function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString;\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n\n return new VariableSchema(context.getLocation(node), name, displaySig || '', type, isOptional);\n}\n\nasync function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,oBAAf,CACLC,IADK,EAELC,OAFK,EAGuB;EAC5B,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,WAAhB;MACE,OAAOC,WAAW,CAACL,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWG,mBAAhB;MACE,OAAOC,mBAAmB,CAACP,IAAD,EAA8BC,OAA9B,CAA1B;;IACF,KAAKE,wBAAA,CAAWK,iBAAhB;MACE,OAAOC,iBAAiB,CAACT,IAAD,EAA4BC,OAA5B,CAAxB;;IACF,KAAKE,wBAAA,CAAWO,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYX,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWS,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYb,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWW,cAAhB;MACE,OAAO,IAAAC,qCAAA,EAAef,IAAf,EAAkDC,OAAlD,CAAP;;IACF,KAAKE,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OAAO,IAAAsC,4CAAA,EAAqBvC,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
@@ -61,7 +61,7 @@ function _typeNodeToSchema() {
61
61
 
62
62
  async function getParams(parameterNodes, context) {
63
63
  return (0, _pMapSeries().default)(parameterNodes, async param => {
64
- return new (_semanticsEntities().ParameterSchema)(context.getLocation(param), getParamName(param), await getParamType(param, context), param.initializer ? param.initializer.getText() : undefined);
64
+ return new (_semanticsEntities().ParameterSchema)(context.getLocation(param), getParamName(param), await getParamType(param, context), Boolean(param.questionToken), param.initializer ? param.initializer.getText() : undefined);
65
65
  });
66
66
  }
67
67
 
@@ -1 +1 @@
1
- {"version":3,"names":["getParams","parameterNodes","context","pMapSeries","param","ParameterSchema","getLocation","getParamName","getParamType","initializer","getText","undefined","isIdentifier","name","elements","map","elem","elementsStr","join","kind","SyntaxKind","ArrayBindingPattern","type","typeNodeToSchema","info","getQuickInfo","parsed","parseTypeFromQuickInfo","InferenceTypeSchema","TupleTypeSchema","ObjectBindingPattern","TypeLiteralSchema","Error"],"sources":["get-params.ts"],"sourcesContent":["import {\n InferenceTypeSchema,\n ParameterSchema,\n TupleTypeSchema,\n TypeLiteralSchema,\n SchemaNode,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport {\n SyntaxKind,\n ParameterDeclaration,\n NodeArray,\n isIdentifier,\n BindingElement,\n ArrayBindingElement,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function getParams(\n parameterNodes: NodeArray<ParameterDeclaration>,\n context: SchemaExtractorContext\n): Promise<ParameterSchema[]> {\n return pMapSeries(parameterNodes, async (param) => {\n return new ParameterSchema(\n context.getLocation(param),\n getParamName(param),\n await getParamType(param, context),\n param.initializer ? param.initializer.getText() : undefined\n );\n });\n}\n\nfunction getParamName(param: ParameterDeclaration): string {\n if (isIdentifier(param.name)) {\n return param.name.getText();\n }\n // it's binding pattern, either an array or an object\n const elements = param.name.elements.map((elem) => elem.getText());\n const elementsStr = elements.join(', ');\n if (param.name.kind === SyntaxKind.ArrayBindingPattern) {\n return `[ ${elementsStr} ]`;\n }\n // it's an object binding\n return `{ ${elementsStr} }`;\n}\n\nasync function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n if (param.type) {\n const type = param.type;\n return typeNodeToSchema(type, context);\n }\n if (isIdentifier(param.name)) {\n const info = await context.getQuickInfo(param.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed);\n }\n // it's binding pattern, either an array or an object\n if (param.name.kind === SyntaxKind.ArrayBindingPattern) {\n const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {\n const info = await context.getQuickInfo(elem);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed);\n });\n return new TupleTypeSchema(context.getLocation(param), elements);\n }\n if (param.name.kind === SyntaxKind.ObjectBindingPattern) {\n const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {\n const info = await context.getQuickInfo(elem.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());\n });\n return new TypeLiteralSchema(context.getLocation(param), elements);\n }\n throw new Error(`unknown param type`);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,SAAf,CACLC,cADK,EAELC,OAFK,EAGuB;EAC5B,OAAO,IAAAC,qBAAA,EAAWF,cAAX,EAA2B,MAAOG,KAAP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AJ,EAAsB7B,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAAtB,EAAkDU,QAAlD,CAAP;EACD;;EACD,MAAM,IAAIkB,KAAJ,CAAW,oBAAX,CAAN;AACD"}
1
+ {"version":3,"names":["getParams","parameterNodes","context","pMapSeries","param","ParameterSchema","getLocation","getParamName","getParamType","Boolean","questionToken","initializer","getText","undefined","isIdentifier","name","elements","map","elem","elementsStr","join","kind","SyntaxKind","ArrayBindingPattern","type","typeNodeToSchema","info","getQuickInfo","parsed","parseTypeFromQuickInfo","InferenceTypeSchema","TupleTypeSchema","ObjectBindingPattern","TypeLiteralSchema","Error"],"sources":["get-params.ts"],"sourcesContent":["import {\n InferenceTypeSchema,\n ParameterSchema,\n TupleTypeSchema,\n TypeLiteralSchema,\n SchemaNode,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport {\n SyntaxKind,\n ParameterDeclaration,\n NodeArray,\n isIdentifier,\n BindingElement,\n ArrayBindingElement,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function getParams(\n parameterNodes: NodeArray<ParameterDeclaration>,\n context: SchemaExtractorContext\n): Promise<ParameterSchema[]> {\n return pMapSeries(parameterNodes, async (param) => {\n return new ParameterSchema(\n context.getLocation(param),\n getParamName(param),\n await getParamType(param, context),\n Boolean(param.questionToken),\n param.initializer ? param.initializer.getText() : undefined\n );\n });\n}\n\nfunction getParamName(param: ParameterDeclaration): string {\n if (isIdentifier(param.name)) {\n return param.name.getText();\n }\n // it's binding pattern, either an array or an object\n const elements = param.name.elements.map((elem) => elem.getText());\n const elementsStr = elements.join(', ');\n if (param.name.kind === SyntaxKind.ArrayBindingPattern) {\n return `[ ${elementsStr} ]`;\n }\n // it's an object binding\n return `{ ${elementsStr} }`;\n}\n\nasync function getParamType(param: ParameterDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n if (param.type) {\n const type = param.type;\n return typeNodeToSchema(type, context);\n }\n if (isIdentifier(param.name)) {\n const info = await context.getQuickInfo(param.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed);\n }\n // it's binding pattern, either an array or an object\n if (param.name.kind === SyntaxKind.ArrayBindingPattern) {\n const elements = await pMapSeries(param.name.elements, async (elem: ArrayBindingElement) => {\n const info = await context.getQuickInfo(elem);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed);\n });\n return new TupleTypeSchema(context.getLocation(param), elements);\n }\n if (param.name.kind === SyntaxKind.ObjectBindingPattern) {\n const elements = await pMapSeries(param.name.elements, async (elem: BindingElement) => {\n const info = await context.getQuickInfo(elem.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(context.getLocation(param), parsed, elem.name.getText());\n });\n return new TypeLiteralSchema(context.getLocation(param), elements);\n }\n throw new Error(`unknown param type`);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,SAAf,CACLC,cADK,EAELC,OAFK,EAGuB;EAC5B,OAAO,IAAAC,qBAAA,EAAWF,cAAX,EAA2B,MAAOG,KAAP,IAAiB;IACjD,OAAO,KAAIC,oCAAJ,EACLH,OAAO,CAACI,WAAR,CAAoBF,KAApB,CADK,EAELG,YAAY,CAACH,KAAD,CAFP,EAGL,MAAMI,YAAY,CAACJ,KAAD,EAAQF,OAAR,CAHb,EAILO,OAAO,CAACL,KAAK,CAACM,aAAP,CAJF,EAKLN,KAAK,CAACO,WAAN,GAAoBP,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semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc, typeParameters);
64
64
  }
65
65
 
66
- //# sourceMappingURL=to-function-schema.js.map
66
+ //# sourceMappingURL=to-function-like-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","info","getQuickInfo","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","modifiers","map","modifier","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-like-schema.ts"],"sourcesContent":["import { SignatureDeclaration } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './jsdoc-to-doc-schema';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const info = node.name ? await context.getQuickInfo(node.name) : null;\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());\n const location = context.getLocation(node);\n const doc = await jsDocToDocSchema(node, context);\n return new FunctionLikeSchema(\n location,\n name,\n args,\n returnType,\n displaySig,\n modifiers as Modifier[],\n doc,\n typeParameters\n );\n}\n"],"mappings":";;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;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IAFK,EAGLS,IAHK,EAILG,UAJK,EAKLN,UALK,EAMLS,SANK,EAOLO,GAPK,EAQLJ,cARK,CAAP;AAUD"}
@@ -30,10 +30,10 @@ function _semanticsEntities() {
30
30
  return data;
31
31
  }
32
32
 
33
- function _toFunctionSchema() {
34
- const data = require("./to-function-schema");
33
+ function _toFunctionLikeSchema() {
34
+ const data = require("./to-function-like-schema");
35
35
 
36
- _toFunctionSchema = function () {
36
+ _toFunctionLikeSchema = function () {
37
37
  return data;
38
38
  };
39
39
 
@@ -73,10 +73,10 @@ function _getParams() {
73
73
  async function typeElementToSchema(node, context) {
74
74
  switch (node.kind) {
75
75
  case _typescript().SyntaxKind.MethodSignature:
76
- return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context);
76
+ return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context);
77
77
 
78
78
  case _typescript().SyntaxKind.ConstructSignature:
79
- return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context, 'new');
79
+ return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context, 'new');
80
80
 
81
81
  case _typescript().SyntaxKind.CallSignature:
82
82
  return callSignature(node, context);
@@ -106,7 +106,8 @@ async function propertySignature(node, context) {
106
106
  const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
107
107
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
108
108
  const type = await context.resolveType(node, typeStr);
109
- return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type);
109
+ const isOptional = Boolean(node.questionToken);
110
+ return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type, isOptional);
110
111
  }
111
112
 
112
113
  async function indexSignature(node, context) {
@@ -132,7 +133,7 @@ async function setAccessor(node, context) {
132
133
  }
133
134
 
134
135
  async function callSignature(node, context) {
135
- return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context);
136
+ return (0, _toFunctionLikeSchema().toFunctionLikeSchema)(node, context);
136
137
  }
137
138
 
138
139
  //# sourceMappingURL=type-element-to-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n CallSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableSchema(context.getLocation(node), name, displaySig, type);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,e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C,OAAV,EAAjD,EAAsEU,IAAtE,EAA4EL,UAA5E,CAAP;AACD;;AAEM,eAAeR,WAAf,CAA2BhB,IAA3B,EAAyDC,OAAzD,EAA0F;EAC/F,MAAMgC,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUlC,IAAI,CAACmC,UAAf,EAA2BlC,OAA3B,CAArB;EACA,MAAMuB,UAAU,GAAG,MAAMvB,OAAO,CAACsC,yBAAR,CAAkCvC,IAAI,CAACkB,IAAvC,CAAzB;EACA,OAAO,KAAIsB,sCAAJ,EAAsBvC,OAAO,CAAC+B,WAAR,CAAoBhC,IAApB,CAAtB,EAAiDA,IAAI,CAACkB,IAAL,CAAUC,OAAV,EAAjD,EAAsEc,MAAM,CAAC,CAAD,CAA5E,EAAiFT,UAAjF,CAAP;AACD;;AAED,eAAehB,aAAf,CAA6BR,IAA7B,EAA6DC,OAA7D,EAA8F;EAC5F,OAAO,IAAAI,wCAAA,EAAqBL,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
1
+ {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n CallSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n return new VariableSchema(context.getLocation(node), name, displaySig, type, isOptional);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,mBAAf,CAAmCC,IAAnC,EAAsDC,OAAtD,EAA4G;EACjH,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,eAAhB;MACE,OAAO,IAAAC,4CAAA,EAAqBL,IAArB,EAA8CC,OAA9C,CAAP;;IACF,KAAKE,wBAAA,CAAWG,kBAAhB;MACE,OAAO,IAAAD,4CAAA,EAAqBL,IAArB,EAA4DC,OAA5D,EAAqE,KAArE,CAAP;;IACF,KAAKE,wBAAA,CAAWI,aAAhB;MACE,OAAOC,aAAa,CAACR,IAAD,EAAmCC,OAAnC,CAApB;;IACF,KAAKE,wBAAA,CAAWM,iBAAhB;MACE,OAAOC,iBAAiB,CAACV,IAAD,EAA+BC,OAA/B,CAAxB;;IACF,KAAKE,wBAAA,CAAWQ,cAAhB;MACE,OAAOC,cAAc,CAACZ,IAAD,EAAoCC,OAApC,CAArB;;IACF,KAAKE,wBAAA,CAAWU,WAAhB;MACE,OAAOC,WAAW,CAACd,IAAD,EAAiCC,OAAjC,CAAlB;;IACF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AAAI,4CAAA,EAAqBL,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
@@ -103,7 +103,7 @@ class VariableDeclaration {
103
103
 
104
104
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
105
105
  const type = await context.resolveType(varDec, typeStr);
106
- return new (_semanticsEntities().VariableSchema)(location, name, displaySig, type);
106
+ return new (_semanticsEntities().VariableSchema)(location, name, displaySig, type, false);
107
107
  }
108
108
 
109
109
  }
@@ -1 +1 @@
1
- {"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableSchema(location, name, displaySig, type);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAAgC;IACrC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,CAACP,IAAD,EAAgC;IAClD,OAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,MAAD,EAAkCC,OAAlC,EAAwF;IAAA;;IACrG,MAAMR,IAAI,GAAG,KAAKD,OAAL,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B,QAAnB,EAA6Bd,IAA7B,EAAmCW,UAAnC,EAA+CqB,IAA/C,CAAP;EACD;;AA7B2D"}
1
+ {"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableSchema(location, name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAAgC;IACrC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,CAACP,IAAD,EAAgC;IAClD,OAAO,CAAC,KAAIQ,oCAAJ,EAAqBR,IAAI,CAACK,IAAL,CAAUC,OAAV,EAArB,EAA0CN,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,MAAD,EAAkCC,OAAlC,EAAwF;IAAA;;IACrG,MAAMR,IAAI,GAAG,KAAKD,OAAL,CAAaQ,MAAb,CAAb;IACA,MAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,MAAM,CAACP,IAA5B,CAAnB;IACA,MAAMW,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,QAAQ,GAAGN,OAAO,CAACO,WAAR,CAAoBR,MAApB,CAAjB;;IACA,IAAI,wBAAAA,MAAM,CAACS,WAAP,4EAAoBpB,IAApB,MAA6BC,qBAAA,CAAGC,UAAH,CAAcmB,aAA/C,EAA8D;MAAA;;MAC5D,MAAMC,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAWZ,MAAM,CAACS,WAAR,CAAsCI,UAAhD,EAA4DZ,OAA5D,CAAnB;MACA,MAAMa,OAAO,GAAG,IAAAC,sDAAA,EAA6Bb,IAA7B,CAAhB;MACA,MAAMc,UAAU,GAAG,MAAMf,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAzB;MACA,MAAMI,SAAS,GAAG,sBAAAlB,MAAM,CAACkB,SAAP,wEAAkBC,GAAlB,CAAuBC,QAAD,IAAcA,QAAQ,CAAC1B,OAAT,EAApC,MAA2D,EAA7E;MACA,MAAM2B,GAAG,GAAG,MAAM,IAAAC,oCAAA,EAAiBtB,MAAjB,EAAyBC,OAAzB,CAAlB;MACA,OAAO,KAAIsB,uCAAJ,EAAuBhB,QAAvB,EAAiCd,IAAjC,EAAuCkB,IAAvC,EAA6CK,UAA7C,EAAyDZ,UAAzD,EAAqEc,SAArE,EAA8FG,GAA9F,CAAP;IACD;;IACD,MAAMP,OAAO,GAAG,IAAAU,gDAAA,EAAuBtB,IAAvB,CAAhB;IACA,MAAMuB,IAAI,GAAG,MAAMxB,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAnB;IACA,OAAO,KAAIY,mCAAJ,EAAmBnB,QAAnB,EAA6Bd,IAA7B,EAAmCW,UAAnC,EAA+CqB,IAA/C,EAAqD,KAArD,CAAP;EACD;;AA7B2D"}
@@ -391,7 +391,7 @@ class TypescriptMain {
391
391
  const logger = loggerExt.createLogger(_typescript3().TypescriptAspect.id);
392
392
  aspectLoader.registerPlugins([new (_schemaTransformer().SchemaTransformerPlugin)(schemaTransformerSlot)]);
393
393
  const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);
394
- schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().LiteralTypeTransformer)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().EnumDeclarationTransformer)()]);
394
+ schemaTransformerSlot.register([new (_transformers().ExportDeclaration)(), new (_transformers().FunctionDeclaration)(), new (_transformers().VariableStatementTransformer)(), new (_transformers().VariableDeclaration)(), new (_transformers().SourceFileTransformer)(), new (_transformers().TypeAliasTransformer)(), new (_transformers().ClassDecelerationTransformer)(), new (_transformers().InterfaceDeclarationTransformer)(), new (_transformers().EnumDeclarationTransformer)(), new (_transformers().BindingElementTransformer)()]);
395
395
 
396
396
  if (workspace) {
397
397
  workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));
@@ -1 +1 @@
1
- {"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","depResolver","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","VariableStatementTransformer","VariableDeclaration","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","LiteralTypeTransformer","InterfaceDeclarationTransformer","EnumDeclarationTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","DependencyResolverAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n LiteralTypeTransformer,\n InterfaceDeclarationTransformer,\n EnumDeclarationTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace,\n private depResolver: DependencyResolverMain\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(\n tsconfig,\n this.schemaTransformerSlot,\n this,\n path || this.workspace.path,\n this.depResolver,\n this.workspace\n );\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n SchemaAspect,\n LoggerAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n CLIAspect,\n DependencyResolverAspect,\n ];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [\n SchemaMain,\n LoggerMain,\n AspectLoaderMain,\n Workspace,\n CLIMain,\n DependencyResolverMain\n ],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new LiteralTypeTransformer(),\n new InterfaceDeclarationTransformer(),\n new EnumDeclarationTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAYA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAeO,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BAAP,CAAyB6B,IAAzB,CAA8B,IAA9B,CAApC;MACAxF,SAAS,CAAC0F,sBAAV,CAAiCf,MAAM,CAAChB,iBAAP,CAAyB6B,IAAzB,CAA8B,IAA9B,CAAjC;IACD;;IAED,MAAMG,aAAa,GAAG,KAAIC,2BAAJ,EAAkBjB,MAAlB,EAA0B3E,SAA1B,EAAqCF,MAArC,CAAtB;IACAuE,GAAG,CAACO,QAAJ,CAAae,aAAb;IAEA,OAAOhB,MAAP;EACD;;AApOyB;;;gCAAf/E,c,aAkLMiG,kB;gCAlLNjG,c,kBAmLW,CACpBkG,sBADoB,EAEpBC,sBAFoB,EAGpBC,uBAHoB,EAIpBC,4BAJoB,EAKpBC,gBALoB,EAMpBC,8CANoB,C;gCAnLXvG,c,WA2LI,CAACwG,eAAA,CAAKC,QAAL,EAAD,C;;AA4CjBvF,+BAAA,CAAiBwF,UAAjB,CAA4B1G,cAA5B;;AAEO,SAASe,0BAAT,CACLqB,MADK,EAEL5B,YAAmC,GAAG,EAFjC,EAGLmG,OAHK,EAIoB;EACzB,IAAI,CAACC,KAAK,CAACC,OAAN,CAAcrG,YAAd,CAAL,EAAkC,OAAO4B,MAAP;EAClC,MAAM0E,SAAS,GAAGtG,YAAY,CAACuG,MAAb,CAAoB,CAACC,GAAD,EAAMC,WAAN,KAAsB;IAC1D,OAAOA,WAAW,CAACD,GAAD,EAAML,OAAN,CAAlB;EACD,CAFiB,EAEfvE,MAFe,CAAlB;EAGA,OAAO0E,SAAP;AACD"}
1
+ {"version":3,"names":["TypescriptMain","constructor","logger","schemaTransformerSlot","workspace","depResolver","createCompiler","options","transformers","tsModule","ts","configMutator","TypescriptConfigMutator","transformerContext","afterMutation","runTransformersWithContext","clone","TypescriptCompiler","TypescriptAspect","id","raw","getTsserverClient","tsServer","initTsserverClient","projectPath","files","TsserverClient","init","initTsserverClientFromWorkspace","Error","path","createCjsCompiler","getCjsTransformer","createEsmCompiler","getEsmTransformer","cjsTransformer","config","setModule","esmTransformer","createSchemaExtractor","tsconfig","TypeScriptExtractor","getCjsPackageJsonProps","main","types","getEsmPackageJsonProps","type","getSupportedFilesForTsserver","components","map","c","filesystem","flat","f","filter","endsWith","onPreWatch","watchOpts","spawnTSServer","verbose","checkTypes","printTypeErrors","Boolean","onComponentChange","component","results","pMapSeries","file","onFileChange","provider","schema","loggerExt","aspectLoader","cli","registerParser","TypeScriptParser","createLogger","registerPlugins","SchemaTransformerPlugin","tsMain","register","ExportDeclaration","FunctionDeclaration","VariableStatementTransformer","VariableDeclaration","SourceFileTransformer","TypeAliasTransformer","ClassDecelerationTransformer","InterfaceDeclarationTransformer","EnumDeclarationTransformer","BindingElementTransformer","registerOnPreWatch","bind","registerOnComponentChange","registerOnComponentAdd","checkTypesCmd","CheckTypesCmd","MainRuntime","SchemaAspect","LoggerAspect","AspectLoaderAspect","WorkspaceAspect","CLIAspect","DependencyResolverAspect","Slot","withType","addRuntime","context","Array","isArray","newConfig","reduce","acc","transformer"],"sources":["typescript.main.runtime.ts"],"sourcesContent":["import ts from 'typescript';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport { CLIAspect, CLIMain, MainRuntime } from '@teambit/cli';\nimport { Compiler } from '@teambit/compiler';\nimport { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';\nimport { SchemaAspect, SchemaExtractor, SchemaMain } from '@teambit/schema';\nimport { PackageJsonProps } from '@teambit/pkg';\nimport { TypescriptConfigMutator } from '@teambit/typescript.modules.ts-config-mutator';\nimport { WorkspaceAspect } from '@teambit/workspace';\nimport type { WatchOptions, Workspace } from '@teambit/workspace';\nimport { DependencyResolverAspect, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport pMapSeries from 'p-map-series';\nimport { TsserverClient, TsserverClientOpts } from '@teambit/ts-server';\nimport AspectLoaderAspect, { AspectLoaderMain } from '@teambit/aspect-loader';\nimport type { Component } from '@teambit/component';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { TypeScriptCompilerOptions } from './compiler-options';\nimport { TypescriptAspect } from './typescript.aspect';\nimport { TypescriptCompiler } from './typescript.compiler';\nimport { TypeScriptParser } from './typescript.parser';\nimport { SchemaTransformer } from './schema-transformer';\nimport { SchemaTransformerPlugin } from './schema-transformer.plugin';\nimport {\n ExportDeclaration,\n TypeAliasTransformer,\n FunctionDeclaration,\n VariableStatementTransformer,\n VariableDeclaration,\n SourceFileTransformer,\n ClassDecelerationTransformer,\n InterfaceDeclarationTransformer,\n EnumDeclarationTransformer,\n BindingElementTransformer,\n} from './transformers';\nimport { CheckTypesCmd } from './cmds/check-types.cmd';\n\nexport type TsMode = 'build' | 'dev';\n\nexport type SchemaTransformerSlot = SlotRegistry<SchemaTransformer[]>;\n\nexport type TsConfigTransformContext = {\n // mode: TsMode;\n};\n\nexport type TsConfigTransformer = (\n config: TypescriptConfigMutator,\n context: TsConfigTransformContext\n) => TypescriptConfigMutator;\n\nexport class TypescriptMain {\n constructor(\n private logger: Logger,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private workspace: Workspace,\n private depResolver: DependencyResolverMain\n ) {}\n\n private tsServer: TsserverClient;\n /**\n * create a new compiler.\n */\n createCompiler(\n options: TypeScriptCompilerOptions,\n transformers: TsConfigTransformer[] = [],\n tsModule = ts\n ): Compiler {\n const configMutator = new TypescriptConfigMutator(options);\n const transformerContext: TsConfigTransformContext = {};\n const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext);\n return new TypescriptCompiler(TypescriptAspect.id, this.logger, afterMutation.raw, tsModule);\n }\n\n /**\n * get TsserverClient instance if initiated already, otherwise, return undefined.\n */\n getTsserverClient(): TsserverClient | undefined {\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API.\n * @param projectPath absolute path of the project root directory\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClient(\n projectPath: string,\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n this.tsServer = new TsserverClient(projectPath, this.logger, options, files);\n this.tsServer.init();\n return this.tsServer;\n }\n\n /**\n * starts a tsserver process to communicate with its API. use only when running on the workspace.\n * @param options TsserverClientOpts\n * @param files optionally, if check-types is enabled, provide files to open and type check.\n * @returns TsserverClient\n */\n async initTsserverClientFromWorkspace(\n options: TsserverClientOpts = {},\n files: string[] = []\n ): Promise<TsserverClient> {\n if (!this.workspace) {\n throw new Error(`initTsserverClientFromWorkspace: workspace was not found`);\n }\n return this.initTsserverClient(this.workspace.path, options, files);\n }\n\n /**\n * Create a compiler instance and run the cjs transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createCjsCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getCjsTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a compiler instance and run the esm transformer for it\n * @param options\n * @param transformers\n * @param tsModule\n * @returns\n */\n createEsmCompiler(options: TypeScriptCompilerOptions, transformers: TsConfigTransformer[] = [], tsModule = ts) {\n return this.createCompiler(options, [this.getEsmTransformer(), ...transformers], tsModule);\n }\n\n /**\n * Create a transformer that change the ts module to CommonJS\n * @returns\n */\n getCjsTransformer(): TsConfigTransformer {\n const cjsTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('CommonJS');\n return config;\n };\n return cjsTransformer;\n }\n\n /**\n * Create a transformer that change the ts module to ES2020\n * @returns\n */\n getEsmTransformer(): TsConfigTransformer {\n const esmTransformer = (config: TypescriptConfigMutator) => {\n config.setModule('ES2020');\n return config;\n };\n return esmTransformer;\n }\n\n /**\n * create an instance of a typescript semantic schema extractor.\n */\n createSchemaExtractor(tsconfig: any, path?: string): SchemaExtractor {\n return new TypeScriptExtractor(\n tsconfig,\n this.schemaTransformerSlot,\n this,\n path || this.workspace.path,\n this.depResolver,\n this.workspace\n );\n }\n\n /**\n * add the default package json properties to the component\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getCjsPackageJsonProps(): PackageJsonProps {\n return {\n main: 'dist/{main}.js',\n types: '{main}.ts',\n };\n }\n\n /**\n * add type: module to the package.json props and the default props\n * :TODO @gilad why do we need this DSL? can't I just get the args here.\n */\n getEsmPackageJsonProps(): PackageJsonProps {\n return {\n // main: 'dist-esm/{main}.js',\n main: 'dist/{main}.js',\n type: 'module',\n types: '{main}.ts',\n };\n }\n\n public getSupportedFilesForTsserver(components: Component[]): string[] {\n const files = components\n .map((c) => c.filesystem.files)\n .flat()\n .map((f) => f.path);\n return files.filter((f) => f.endsWith('.ts') || f.endsWith('.tsx'));\n }\n\n private async onPreWatch(components: Component[], watchOpts: WatchOptions) {\n const workspace = this.workspace;\n if (!workspace || !watchOpts.spawnTSServer) {\n return;\n }\n const { verbose, checkTypes } = watchOpts;\n const files = checkTypes ? this.getSupportedFilesForTsserver(components) : [];\n const printTypeErrors = Boolean(checkTypes);\n await this.initTsserverClientFromWorkspace({ verbose, checkTypes, printTypeErrors }, files);\n }\n\n private async onComponentChange(component: Component, files: string[]) {\n if (!this.tsServer) {\n return {\n results: 'N/A',\n };\n }\n await pMapSeries(files, (file) => this.tsServer.onFileChange(file));\n return {\n results: 'succeed',\n };\n }\n\n static runtime = MainRuntime;\n static dependencies = [\n SchemaAspect,\n LoggerAspect,\n AspectLoaderAspect,\n WorkspaceAspect,\n CLIAspect,\n DependencyResolverAspect,\n ];\n static slots = [Slot.withType<SchemaTransformer[]>()];\n\n static async provider(\n [schema, loggerExt, aspectLoader, workspace, cli, depResolver]: [\n SchemaMain,\n LoggerMain,\n AspectLoaderMain,\n Workspace,\n CLIMain,\n DependencyResolverMain\n ],\n config,\n [schemaTransformerSlot]: [SchemaTransformerSlot]\n ) {\n schema.registerParser(new TypeScriptParser());\n const logger = loggerExt.createLogger(TypescriptAspect.id);\n aspectLoader.registerPlugins([new SchemaTransformerPlugin(schemaTransformerSlot)]);\n const tsMain = new TypescriptMain(logger, schemaTransformerSlot, workspace, depResolver);\n schemaTransformerSlot.register([\n new ExportDeclaration(),\n new FunctionDeclaration(),\n new VariableStatementTransformer(),\n new VariableDeclaration(),\n new SourceFileTransformer(),\n new TypeAliasTransformer(),\n new ClassDecelerationTransformer(),\n new InterfaceDeclarationTransformer(),\n new EnumDeclarationTransformer(),\n new BindingElementTransformer(),\n ]);\n\n if (workspace) {\n workspace.registerOnPreWatch(tsMain.onPreWatch.bind(this));\n workspace.registerOnComponentChange(tsMain.onComponentChange.bind(this));\n workspace.registerOnComponentAdd(tsMain.onComponentChange.bind(this));\n }\n\n const checkTypesCmd = new CheckTypesCmd(tsMain, workspace, logger);\n cli.register(checkTypesCmd);\n\n return tsMain;\n }\n}\n\nTypescriptAspect.addRuntime(TypescriptMain);\n\nexport function runTransformersWithContext(\n config: TypescriptConfigMutator,\n transformers: TsConfigTransformer[] = [],\n context: TsConfigTransformContext\n): TypescriptConfigMutator {\n if (!Array.isArray(transformers)) return config;\n const newConfig = transformers.reduce((acc, transformer) => {\n return transformer(acc, context);\n }, config);\n return newConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;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ema transformer for node of kind ${node.kind} (${
9
9
  ts.SyntaxKind[node.kind]
10
10
  }) in component ${component.id.toString()}.
11
- location: ${location.file}, line: ${location.line}, character: ${location.character}.
11
+ location: ${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}.
12
12
  node-text: ${node.getText()}`
13
13
  );
14
14
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.752",
3
+ "version": "0.0.755",
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.752"
9
+ "version": "0.0.755"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -18,21 +18,21 @@
18
18
  "@babel/runtime": "7.12.18",
19
19
  "core-js": "^3.0.0",
20
20
  "@teambit/harmony": "0.3.3",
21
- "@teambit/compiler": "0.0.752",
21
+ "@teambit/compiler": "0.0.755",
22
22
  "@teambit/typescript.modules.ts-config-mutator": "0.0.68",
23
- "@teambit/component": "0.0.752",
24
- "@teambit/dependency-resolver": "0.0.752",
25
- "@teambit/semantics.entities.semantic-schema": "0.0.17",
23
+ "@teambit/component": "0.0.755",
24
+ "@teambit/dependency-resolver": "0.0.755",
25
+ "@teambit/semantics.entities.semantic-schema": "0.0.18",
26
26
  "@teambit/ts-server": "0.0.32",
27
- "@teambit/aspect-loader": "0.0.752",
27
+ "@teambit/aspect-loader": "0.0.755",
28
28
  "@teambit/bit-error": "0.0.394",
29
- "@teambit/builder": "0.0.752",
30
- "@teambit/isolator": "0.0.752",
31
- "@teambit/logger": "0.0.589",
32
- "@teambit/schema": "0.0.752",
33
- "@teambit/workspace": "0.0.752",
34
- "@teambit/cli": "0.0.496",
35
- "@teambit/pkg": "0.0.752"
29
+ "@teambit/builder": "0.0.755",
30
+ "@teambit/isolator": "0.0.755",
31
+ "@teambit/logger": "0.0.591",
32
+ "@teambit/schema": "0.0.755",
33
+ "@teambit/workspace": "0.0.755",
34
+ "@teambit/cli": "0.0.498",
35
+ "@teambit/pkg": "0.0.755"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash": "4.14.165",
@@ -48,7 +48,7 @@
48
48
  "@teambit/typescript.aspect-docs.typescript": "0.0.138"
49
49
  },
50
50
  "peerDependencies": {
51
- "@teambit/legacy": "1.0.276",
51
+ "@teambit/legacy": "1.0.278",
52
52
  "react-dom": "^16.8.0 || ^17.0.0",
53
53
  "react": "^16.8.0 || ^17.0.0"
54
54
  },
@@ -76,7 +76,7 @@
76
76
  "react": "-"
77
77
  },
78
78
  "peerDependencies": {
79
- "@teambit/legacy": "1.0.276",
79
+ "@teambit/legacy": "1.0.278",
80
80
  "react-dom": "^16.8.0 || ^17.0.0",
81
81
  "react": "^16.8.0 || ^17.0.0"
82
82
  }
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.752/dist/typescript.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.752/dist/typescript.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.755/dist/typescript.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.755/dist/typescript.docs.mdx')]
@@ -0,0 +1,32 @@
1
+ import ts, { BindingElement, Node } from 'typescript';
2
+ import { VariableSchema } from '@teambit/semantics.entities.semantic-schema';
3
+ import { SchemaTransformer } from '../schema-transformer';
4
+ import { SchemaExtractorContext } from '../schema-extractor-context';
5
+ import { ExportIdentifier } from '../export-identifier';
6
+ import { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
7
+
8
+ /**
9
+ * for example:
10
+ *
11
+ * const objBindingElem = { elem1: 1, elem2: 2 };
12
+ * const { elem1 } = objBindingElem;
13
+ * export { elem1 };
14
+ */
15
+ export class BindingElementTransformer implements SchemaTransformer {
16
+ predicate(node: Node) {
17
+ return node.kind === ts.SyntaxKind.BindingElement;
18
+ }
19
+
20
+ async getIdentifiers(node: BindingElement) {
21
+ return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];
22
+ }
23
+
24
+ async transform(node: BindingElement, context: SchemaExtractorContext) {
25
+ const name = node.name.getText();
26
+ const info = await context.getQuickInfo(node.name);
27
+ const displaySig = info?.body?.displayString || '';
28
+ const typeStr = parseTypeFromQuickInfo(info);
29
+ const type = await context.resolveType(node, typeStr);
30
+ return new VariableSchema(context.getLocation(node), name, displaySig, type, false);
31
+ }
32
+ }
@@ -35,11 +35,24 @@ export class ExportDeclaration implements SchemaTransformer {
35
35
  return [];
36
36
  }
37
37
 
38
- async transform(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {
39
- const exportDec = node as ExportDeclarationNode;
38
+ async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {
40
39
  const exportClause = exportDec.exportClause;
40
+
41
+ // it's export-all, e.g. `export * from './button'`;
42
+ if (!exportClause) {
43
+ const specifier = exportDec.moduleSpecifier;
44
+ if (!specifier) {
45
+ throw new Error(`fatal: no specifier`);
46
+ }
47
+ const sourceFile = await context.getSourceFileFromNode(specifier);
48
+ if (!sourceFile) {
49
+ throw new Error(`unable to find the source-file`);
50
+ }
51
+ return context.computeSchema(sourceFile);
52
+ }
53
+
41
54
  // e.g. `export { button1, button2 } as Composition from './button';
42
- if (exportClause?.kind === SyntaxKind.NamedExports) {
55
+ if (exportClause.kind === SyntaxKind.NamedExports) {
43
56
  exportClause as NamedExports;
44
57
  const schemas = await Promise.all(
45
58
  exportClause.elements.map(async (element) => {
@@ -47,10 +60,10 @@ export class ExportDeclaration implements SchemaTransformer {
47
60
  })
48
61
  );
49
62
 
50
- return new Module(context.getLocation(node), compact(schemas));
63
+ return new Module(context.getLocation(exportDec), compact(schemas));
51
64
  }
52
65
  // e.g. `export * as Composition from './button';
53
- if (exportClause?.kind === SyntaxKind.NamespaceExport) {
66
+ if (exportClause.kind === SyntaxKind.NamespaceExport) {
54
67
  exportClause as NamespaceExport;
55
68
  const namespace = exportClause.name.getText();
56
69
  const filePath = await context.getFilePathByNode(exportClause.name);
@@ -60,7 +73,7 @@ export class ExportDeclaration implements SchemaTransformer {
60
73
  const sourceFile = context.getSourceFileInsideComponent(filePath);
61
74
  if (!sourceFile) {
62
75
  // it's a namespace from another component or an external package.
63
- return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));
76
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
64
77
  }
65
78
  const result = await context.computeSchema(sourceFile);
66
79
  if (!(result instanceof Module)) {
@@ -69,19 +82,8 @@ export class ExportDeclaration implements SchemaTransformer {
69
82
  result.namespace = namespace;
70
83
  return result;
71
84
  }
72
- // it's export-all, e.g. `export * from './button'`;
73
- if (!exportClause) {
74
- const specifier = exportDec.moduleSpecifier;
75
- if (!specifier) {
76
- throw new Error(`fatal: no specifier`);
77
- }
78
- const sourceFile = await context.getSourceFileFromNode(specifier);
79
- if (!sourceFile) {
80
- throw new Error(`unable to find the source-file`);
81
- }
82
- return context.computeSchema(sourceFile);
83
- }
84
85
 
85
- throw new Error('unrecognized export type');
86
+ // should never reach here. exportClause can be either NamespaceExport or NamedExports
87
+ throw new Error(`unrecognized exportClause type`);
86
88
  }
87
89
  }
@@ -3,7 +3,7 @@ import ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typesc
3
3
  import { SchemaExtractorContext } from '../schema-extractor-context';
4
4
  import { SchemaTransformer } from '../schema-transformer';
5
5
  import { ExportIdentifier } from '../export-identifier';
6
- import { toFunctionLikeSchema } from './utils/to-function-schema';
6
+ import { toFunctionLikeSchema } from './utils/to-function-like-schema';
7
7
 
8
8
  export class FunctionDeclaration implements SchemaTransformer {
9
9
  predicate(node: Node) {
@@ -5,6 +5,6 @@ export { VariableDeclaration } from './variable-declaration';
5
5
  export { SourceFileTransformer } from './source-file-transformer';
6
6
  export { TypeAliasTransformer } from './type-alias';
7
7
  export { ClassDecelerationTransformer } from './class-deceleration';
8
- export { LiteralTypeTransformer } from './literal-type';
9
8
  export { InterfaceDeclarationTransformer } from './interface-declaration';
10
9
  export { EnumDeclarationTransformer } from './enum-declaration';
10
+ export { BindingElementTransformer } from './binding-element';
@@ -13,7 +13,7 @@ import { SchemaExtractorContext } from '../../schema-extractor-context';
13
13
  import { getParams } from './get-params';
14
14
  import { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';
15
15
  import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
16
- import { toFunctionLikeSchema } from './to-function-schema';
16
+ import { toFunctionLikeSchema } from './to-function-like-schema';
17
17
 
18
18
  export async function classElementToSchema(
19
19
  node: ClassElement,
@@ -52,8 +52,9 @@ async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExt
52
52
  const displaySig = info?.body?.displayString;
53
53
  const typeStr = parseTypeFromQuickInfo(info);
54
54
  const type = await context.resolveType(node, typeStr);
55
+ const isOptional = Boolean(node.questionToken);
55
56
 
56
- return new VariableSchema(context.getLocation(node), name, displaySig || '', type);
57
+ return new VariableSchema(context.getLocation(node), name, displaySig || '', type, isOptional);
57
58
  }
58
59
 
59
60
  async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
@@ -27,6 +27,7 @@ export async function getParams(
27
27
  context.getLocation(param),
28
28
  getParamName(param),
29
29
  await getParamType(param, context),
30
+ Boolean(param.questionToken),
30
31
  param.initializer ? param.initializer.getText() : undefined
31
32
  );
32
33
  });
@@ -16,7 +16,7 @@ import {
16
16
  SetAccessorSchema,
17
17
  VariableSchema,
18
18
  } from '@teambit/semantics.entities.semantic-schema';
19
- import { toFunctionLikeSchema } from './to-function-schema';
19
+ import { toFunctionLikeSchema } from './to-function-like-schema';
20
20
  import { SchemaExtractorContext } from '../../schema-extractor-context';
21
21
  import { parseTypeFromQuickInfo } from './parse-type-from-quick-info';
22
22
  import { typeNodeToSchema } from './type-node-to-schema';
@@ -49,7 +49,8 @@ async function propertySignature(node: ts.PropertySignature, context: SchemaExtr
49
49
  const displaySig = info?.body?.displayString || '';
50
50
  const typeStr = parseTypeFromQuickInfo(info);
51
51
  const type = await context.resolveType(node, typeStr);
52
- return new VariableSchema(context.getLocation(node), name, displaySig, type);
52
+ const isOptional = Boolean(node.questionToken);
53
+ return new VariableSchema(context.getLocation(node), name, displaySig, type, isOptional);
53
54
  }
54
55
 
55
56
  export async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {
@@ -35,6 +35,6 @@ export class VariableDeclaration implements SchemaTransformer {
35
35
  }
36
36
  const typeStr = parseTypeFromQuickInfo(info);
37
37
  const type = await context.resolveType(varDec, typeStr);
38
- return new VariableSchema(location, name, displaySig, type);
38
+ return new VariableSchema(location, name, displaySig, type, false);
39
39
  }
40
40
  }
@@ -1,9 +0,0 @@
1
- import { LiteralTypeNode, Node } from 'typescript';
2
- import { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';
3
- import { SchemaTransformer } from '../schema-transformer';
4
- import { SchemaExtractorContext } from '../schema-extractor-context';
5
- export declare class LiteralTypeTransformer implements SchemaTransformer {
6
- predicate(node: Node): boolean;
7
- getIdentifiers(): Promise<never[]>;
8
- transform(literalType: LiteralTypeNode, context: SchemaExtractorContext): Promise<TypeRefSchema>;
9
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- require("core-js/modules/es.promise.js");
6
-
7
- Object.defineProperty(exports, "__esModule", {
8
- value: true
9
- });
10
- exports.LiteralTypeTransformer = void 0;
11
-
12
- function _typescript() {
13
- const data = _interopRequireDefault(require("typescript"));
14
-
15
- _typescript = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
- function _semanticsEntities() {
23
- const data = require("@teambit/semantics.entities.semantic-schema");
24
-
25
- _semanticsEntities = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
31
-
32
- class LiteralTypeTransformer {
33
- predicate(node) {
34
- return node.kind === _typescript().default.SyntaxKind.LiteralType;
35
- }
36
-
37
- async getIdentifiers() {
38
- return [];
39
- }
40
-
41
- async transform(literalType, context) {
42
- const type = literalType.literal.getText();
43
- return new (_semanticsEntities().TypeRefSchema)(context.getLocation(literalType), type);
44
- }
45
-
46
- }
47
-
48
- exports.LiteralTypeTransformer = LiteralTypeTransformer;
49
-
50
- //# sourceMappingURL=literal-type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["LiteralTypeTransformer","predicate","node","kind","ts","SyntaxKind","LiteralType","getIdentifiers","transform","literalType","context","type","literal","getText","TypeRefSchema","getLocation"],"sources":["literal-type.ts"],"sourcesContent":["import ts, { LiteralTypeNode, Node } from 'typescript';\nimport { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\n\nexport class LiteralTypeTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.LiteralType;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(literalType: LiteralTypeNode, context: SchemaExtractorContext) {\n const type = literalType.literal.getText();\n return new TypeRefSchema(context.getLocation(literalType), type);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIO,MAAMA,sBAAN,CAA0D;EAC/DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,WAAnC;EACD;;EAEmB,MAAdC,cAAc,GAAG;IACrB,OAAO,EAAP;EACD;;EAEc,MAATC,SAAS,CAACC,WAAD,EAA+BC,OAA/B,EAAgE;IAC7E,MAAMC,IAAI,GAAGF,WAAW,CAACG,OAAZ,CAAoBC,OAApB,EAAb;IACA,OAAO,KAAIC,kCAAJ,EAAkBJ,OAAO,CAACK,WAAR,CAAoBN,WAApB,CAAlB,EAAoDE,IAApD,CAAP;EACD;;AAZ8D"}
@@ -1 +0,0 @@
1
- {"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","info","getQuickInfo","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","modifiers","map","modifier","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-schema.ts"],"sourcesContent":["import { SignatureDeclaration } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './jsdoc-to-doc-schema';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const info = node.name ? await context.getQuickInfo(node.name) : null;\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());\n const location = context.getLocation(node);\n const doc = await jsDocToDocSchema(node, context);\n return new FunctionLikeSchema(\n location,\n name,\n args,\n returnType,\n displaySig,\n modifiers as Modifier[],\n doc,\n typeParameters\n );\n}\n"],"mappings":";;;;;;;;;AACA;EA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IAApB,CAAjB;EACA,MAAMyB,GAAG,GAAG,MAAM,IAAAC,oCAAA,EAAiB1B,IAAjB,EAAuBC,OAAvB,CAAlB;EACA,OAAO,KAAI0B,uCAAJ,EACLJ,QADK,EAELpB,IAFK,EAGLS,IAHK,EAILG,UAJK,EAKLN,UALK,EAMLS,SANK,EAOLO,GAPK,EAQLJ,cARK,CAAP;AAUD"}
@@ -1,19 +0,0 @@
1
- import ts, { LiteralTypeNode, Node } from 'typescript';
2
- import { TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';
3
- import { SchemaTransformer } from '../schema-transformer';
4
- import { SchemaExtractorContext } from '../schema-extractor-context';
5
-
6
- export class LiteralTypeTransformer implements SchemaTransformer {
7
- predicate(node: Node) {
8
- return node.kind === ts.SyntaxKind.LiteralType;
9
- }
10
-
11
- async getIdentifiers() {
12
- return [];
13
- }
14
-
15
- async transform(literalType: LiteralTypeNode, context: SchemaExtractorContext) {
16
- const type = literalType.literal.getText();
17
- return new TypeRefSchema(context.getLocation(literalType), type);
18
- }
19
- }