@teambit/typescript 0.0.730 → 0.0.733

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 (72) hide show
  1. package/dist/schema-extractor-context.d.ts +7 -8
  2. package/dist/schema-extractor-context.js +84 -25
  3. package/dist/schema-extractor-context.js.map +1 -1
  4. package/dist/transformers/class-deceleration.js +21 -6
  5. package/dist/transformers/class-deceleration.js.map +1 -1
  6. package/dist/transformers/function-declaration.js +4 -33
  7. package/dist/transformers/function-declaration.js.map +1 -1
  8. package/dist/transformers/index-signature.js +11 -1
  9. package/dist/transformers/index-signature.js.map +1 -1
  10. package/dist/transformers/index.d.ts +0 -4
  11. package/dist/transformers/index.js +0 -64
  12. package/dist/transformers/index.js.map +1 -1
  13. package/dist/transformers/method-declaration.js +4 -33
  14. package/dist/transformers/method-declaration.js.map +1 -1
  15. package/dist/transformers/method-signature.js +4 -32
  16. package/dist/transformers/method-signature.js.map +1 -1
  17. package/dist/transformers/property-declaration.js +2 -3
  18. package/dist/transformers/property-declaration.js.map +1 -1
  19. package/dist/transformers/property-signature.js +9 -13
  20. package/dist/transformers/property-signature.js.map +1 -1
  21. package/dist/transformers/type-alias.js +11 -2
  22. package/dist/transformers/type-alias.js.map +1 -1
  23. package/dist/transformers/utils/get-params.d.ts +2 -2
  24. package/dist/transformers/utils/get-params.js +14 -12
  25. package/dist/transformers/utils/get-params.js.map +1 -1
  26. package/dist/transformers/utils/parse-type-from-quick-info.d.ts +35 -2
  27. package/dist/transformers/utils/parse-type-from-quick-info.js +93 -7
  28. package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
  29. package/dist/transformers/utils/to-function-schema.d.ts +4 -0
  30. package/dist/transformers/utils/to-function-schema.js +55 -0
  31. package/dist/transformers/utils/to-function-schema.js.map +1 -0
  32. package/dist/transformers/utils/type-node-to-schema.d.ts +4 -0
  33. package/dist/transformers/utils/type-node-to-schema.js +252 -0
  34. package/dist/transformers/utils/type-node-to-schema.js.map +1 -0
  35. package/dist/transformers/variable-declaration.js +4 -3
  36. package/dist/transformers/variable-declaration.js.map +1 -1
  37. package/dist/typescript.main.runtime.js +1 -1
  38. package/dist/typescript.main.runtime.js.map +1 -1
  39. package/package-tar/teambit-typescript-0.0.733.tgz +0 -0
  40. package/package.json +16 -16
  41. package/{preview-1652325916507.js → preview-1652757984397.js} +2 -2
  42. package/transformers/class-deceleration.ts +8 -4
  43. package/transformers/function-declaration.ts +3 -12
  44. package/transformers/index-signature.ts +2 -1
  45. package/transformers/index.ts +0 -4
  46. package/transformers/method-declaration.ts +3 -11
  47. package/transformers/method-signature.ts +3 -10
  48. package/transformers/property-declaration.ts +2 -3
  49. package/transformers/property-signature.ts +6 -10
  50. package/transformers/type-alias.ts +3 -3
  51. package/transformers/utils/get-params.ts +11 -12
  52. package/transformers/utils/parse-type-from-quick-info.ts +79 -7
  53. package/transformers/utils/to-function-schema.ts +19 -0
  54. package/transformers/utils/type-node-to-schema.ts +206 -0
  55. package/transformers/variable-declaration.ts +5 -4
  56. package/dist/transformers/type-intersection.d.ts +0 -9
  57. package/dist/transformers/type-intersection.js +0 -63
  58. package/dist/transformers/type-intersection.js.map +0 -1
  59. package/dist/transformers/type-literal.d.ts +0 -14
  60. package/dist/transformers/type-literal.js +0 -67
  61. package/dist/transformers/type-literal.js.map +0 -1
  62. package/dist/transformers/type-reference.d.ts +0 -8
  63. package/dist/transformers/type-reference.js +0 -41
  64. package/dist/transformers/type-reference.js.map +0 -1
  65. package/dist/transformers/type-union.d.ts +0 -9
  66. package/dist/transformers/type-union.js +0 -63
  67. package/dist/transformers/type-union.js.map +0 -1
  68. package/package-tar/teambit-typescript-0.0.730.tgz +0 -0
  69. package/transformers/type-intersection.ts +0 -23
  70. package/transformers/type-literal.ts +0 -28
  71. package/transformers/type-reference.ts +0 -19
  72. package/transformers/type-union.ts +0 -23
@@ -1,8 +1,8 @@
1
1
  import { TsserverClient } from '@teambit/ts-server';
2
- import ts, { ExportDeclaration, Node } from 'typescript';
2
+ import ts, { ExportDeclaration, Node, TypeNode } from 'typescript';
3
3
  import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
4
4
  import { Component } from '@teambit/component';
5
- import { TypeRefSchema, SchemaNode } from '@teambit/semantics.entities.semantic-schema';
5
+ import { SchemaNode, Location } from '@teambit/semantics.entities.semantic-schema';
6
6
  import { TypeScriptExtractor } from './typescript.extractor';
7
7
  import { ExportList } from './export-list';
8
8
  export declare class SchemaExtractorContext {
@@ -14,10 +14,7 @@ export declare class SchemaExtractorContext {
14
14
  /**
15
15
  * returns the location of a node in a source file.
16
16
  */
17
- getLocation(node: Node, targetSourceFile?: ts.SourceFile): {
18
- line: number;
19
- character: number;
20
- };
17
+ getLocation(node: Node, targetSourceFile?: ts.SourceFile): Location;
21
18
  /**
22
19
  * returns a signature for a node.
23
20
  */
@@ -35,6 +32,7 @@ export declare class SchemaExtractorContext {
35
32
  * think if we don't need this because of type ref
36
33
  */
37
34
  getQuickInfo(node: Node): Promise<import("typescript/lib/protocol").QuickInfoResponse | undefined>;
35
+ getQuickInfoDisplayString(node: Node): Promise<string>;
38
36
  /**
39
37
  * returns the type definition for a type.
40
38
  */
@@ -64,10 +62,11 @@ export declare class SchemaExtractorContext {
64
62
  _exports: ExportList | undefined;
65
63
  setExports(exports: ExportList): this;
66
64
  getExportedIdentifiers(node: Node): Promise<import("./export-identifier").ExportIdentifier[]>;
67
- private isNative;
68
65
  jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined>;
69
66
  /**
70
67
  * resolve a type by a node and its identifier.
71
68
  */
72
- resolveType(node: Node, typeStr: string): Promise<TypeRefSchema>;
69
+ resolveType(node: Node & {
70
+ type?: TypeNode;
71
+ }, typeStr: string, isTypeStrFromQuickInfo?: boolean): Promise<SchemaNode>;
73
72
  }
@@ -73,6 +73,36 @@ function _semanticsEntities() {
73
73
  return data;
74
74
  }
75
75
 
76
+ function _typeNodeToSchema() {
77
+ const data = require("./transformers/utils/type-node-to-schema");
78
+
79
+ _typeNodeToSchema = function () {
80
+ return data;
81
+ };
82
+
83
+ return data;
84
+ }
85
+
86
+ function _exceptions() {
87
+ const data = require("./exceptions");
88
+
89
+ _exceptions = function () {
90
+ return data;
91
+ };
92
+
93
+ return data;
94
+ }
95
+
96
+ function _parseTypeFromQuickInfo() {
97
+ const data = require("./transformers/utils/parse-type-from-quick-info");
98
+
99
+ _parseTypeFromQuickInfo = function () {
100
+ return data;
101
+ };
102
+
103
+ return data;
104
+ }
105
+
76
106
  class SchemaExtractorContext {
77
107
  constructor(tsserver, component, extractor) {
78
108
  this.tsserver = tsserver;
@@ -95,6 +125,7 @@ class SchemaExtractorContext {
95
125
  const line = position.line + 1;
96
126
  const character = position.character + 1;
97
127
  return {
128
+ file: sourceFile.fileName,
98
129
  line,
99
130
  character
100
131
  };
@@ -136,6 +167,13 @@ class SchemaExtractorContext {
136
167
  getQuickInfo(node) {
137
168
  return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
138
169
  }
170
+
171
+ async getQuickInfoDisplayString(node) {
172
+ var _quickInfo$body;
173
+
174
+ const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
175
+ return (quickInfo === null || quickInfo === void 0 ? void 0 : (_quickInfo$body = quickInfo.body) === null || _quickInfo$body === void 0 ? void 0 : _quickInfo$body.displayString) || '';
176
+ }
139
177
  /**
140
178
  * returns the type definition for a type.
141
179
  */
@@ -173,7 +211,14 @@ class SchemaExtractorContext {
173
211
  return `${pkgParts[0]}/${pkgParts[1]}`;
174
212
  }
175
213
 
176
- return pkgParts[0];
214
+ const pkgName = pkgParts[0];
215
+
216
+ if (pkgName === 'typescript') {
217
+ // it's a built-in type, such as "string".
218
+ return '';
219
+ }
220
+
221
+ return pkgName;
177
222
  }
178
223
  /**
179
224
  * return the file if part of the component.
@@ -268,42 +313,46 @@ class SchemaExtractorContext {
268
313
  return this.extractor.computeExportedIdentifiers(node, this);
269
314
  }
270
315
 
271
- isNative(typeName) {
272
- return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);
273
- }
274
-
275
316
  async jump(file, start) {
276
317
  const sourceFile = this.extractor.parseSourceFile(file);
277
318
  const pos = this.getPosition(sourceFile, start.line, start.offset);
278
319
  const nodeAtPos = (0, _tsutils().getTokenAtPosition)(sourceFile, pos);
279
- if (!nodeAtPos) return undefined;
320
+ if (!nodeAtPos) return undefined; // this causes some infinite loops. it's helpful for getting more data from types that are not exported.
321
+ // e.g.
322
+ // ```ts
323
+ // class Bar {}
324
+ // export const getBar = () => new Bar();
325
+ // ```
326
+ // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {
327
+ // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`
328
+ // return this.visitDefinition(nodeAtPos);
329
+ // }
330
+
331
+ try {
332
+ return await this.visit(nodeAtPos);
333
+ } catch (err) {
334
+ if (err instanceof _exceptions().TransformerNotFound) {
335
+ return undefined;
336
+ }
280
337
 
281
- if (nodeAtPos.kind === _typescript().default.SyntaxKind.Identifier) {
282
- // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`
283
- return this.visitDefinition(nodeAtPos);
338
+ throw err;
284
339
  }
285
-
286
- return this.visit(nodeAtPos);
287
340
  }
288
341
  /**
289
342
  * resolve a type by a node and its identifier.
290
343
  */
291
344
 
292
345
 
293
- async resolveType(node, typeStr) {
346
+ async resolveType(node, typeStr, isTypeStrFromQuickInfo = true) {
294
347
  var _this$_exports;
295
348
 
296
- // if a node has "type" prop, it has the type data of the node. this normally happens when the code has the type
297
- // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have "type"
298
- // @ts-ignore
299
- node = node.type || node;
300
- if (this.isNative(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
349
+ if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
301
350
 
302
- if (node.kind === _typescript().default.SyntaxKind.LiteralType) {
303
- return new (_semanticsEntities().TypeRefSchema)(node.literal.getText());
351
+ if (node.type && _typescript().default.isTypeNode(node.type)) {
352
+ // if a node has "type" prop, it has the type data of the node. this normally happens when the code has the type
353
+ // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have "type"
354
+ return (0, _typeNodeToSchema().typeNodeToSchema)(node.type, this);
304
355
  }
305
-
306
- if ((_this$_exports = this._exports) !== null && _this$_exports !== void 0 && _this$_exports.includes(typeStr)) return new (_semanticsEntities().TypeRefSchema)(typeStr);
307
356
  /**
308
357
  * tsserver has two different calls: "definition" and "typeDefinition".
309
358
  * normally, we need the "typeDefinition" to get the type data of a node.
@@ -312,6 +361,7 @@ class SchemaExtractorContext {
312
361
  * "definition" but it's not clear when/why).
313
362
  */
314
363
 
364
+
315
365
  const getDef = async () => {
316
366
  const typeDefinition = await this.typeDefinition(node);
317
367
  const headTypeDefinition = (0, _lodash().head)(typeDefinition === null || typeDefinition === void 0 ? void 0 : typeDefinition.body);
@@ -326,10 +376,18 @@ class SchemaExtractorContext {
326
376
 
327
377
  const definition = await getDef(); // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.
328
378
 
329
- const unknownExactType = new (_semanticsEntities().TypeRefSchema)(typeStr);
379
+ const unknownExactType = async () => {
380
+ if (isTypeStrFromQuickInfo) {
381
+ return new (_semanticsEntities().InferenceTypeSchema)(typeStr);
382
+ }
383
+
384
+ const info = await this.getQuickInfo(node);
385
+ const type = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
386
+ return new (_semanticsEntities().InferenceTypeSchema)(type);
387
+ };
330
388
 
331
389
  if (!definition) {
332
- return unknownExactType;
390
+ return unknownExactType();
333
391
  } // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location
334
392
 
335
393
 
@@ -346,10 +404,11 @@ class SchemaExtractorContext {
346
404
 
347
405
  if (file) {
348
406
  if (isDefInSameLocation()) {
349
- return unknownExactType;
407
+ return unknownExactType();
350
408
  }
351
409
 
352
- return new (_semanticsEntities().TypeRefSchema)(typeStr, undefined, undefined, await this.jump(file, definition.start));
410
+ const schemaNode = await this.jump(file, definition.start);
411
+ return schemaNode || unknownExactType();
353
412
  }
354
413
 
355
414
  const pkgName = this.parsePackageNameFromPath(definition.file); // TODO: find component id is exists, otherwise add the package name.
@@ -1 +1 @@
1
- {"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","fileName","getQuickInfo","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","body","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","isNative","typeName","jump","kind","ts","SyntaxKind","Identifier","resolveType","typeStr","type","TypeRefSchema","LiteralType","literal","getDef","headTypeDefinition","unknownExactType","isDefInSameLocation","loc","pkgName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAIO,MAAMA,sBAAN,CAA6B;AAClCC,EAAAA,WAAW,CACAC,QADA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kCAAJ,EAAkBF,OAAlB,CAAzB;;AACA,QAAI,CAAChC,UAAL,EAAiB;AACf,aAAOuC,gBAAP;AACD,KAjCoE,CAmCrE;;;AACA,UAAMC,mBAAmB,GAAG,MAAM;AAChC,UAAIxC,UAAU,CAACvB,IAAX,KAAoB1B,IAAI,CAACI,aAAL,GAAqBY,QAA7C,EAAuD;AACrD,eAAO,KAAP;AACD;;AACD,YAAM0E,GAAG,GAAG,KAAKzF,WAAL,CAAiBD,IAAjB,CAAZ;AACA,aAAO0F,GAAG,CAAClF,IAAJ,KAAayC,UAAU,CAACE,KAAX,CAAiB3C,IAA9B,IAAsCkF,GAAG,CAACjF,SAAJ,KAAkBwC,UAAU,CAACE,KAAX,CAAiBrC,MAAhF;AACD,KAND;;AAQA,UAAMY,IAAI,GAAG,KAAKL,mBAAL,CAAyB4B,UAAU,CAACvB,IAApC,CAAb;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAI+D,mBAAmB,EAAvB,EAA2B;AACzB,eAAOD,gBAAP;AACD;;AACD,aAAO,KAAIL,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsCA,SAAtC,EAAiD,MAAM,KAAK6E,IAAL,CAAUjD,IAAV,EAAgBuB,UAAU,CAACE,KAA3B,CAAvD,CAAP;AACD;;AACD,UAAMwC,OAAO,GAAG,KAAKzD,wBAAL,CAA8Be,UAAU,CAACvB,IAAzC,CAAhB,CAnDqE,CAoDrE;;AACA,WAAO,KAAIyD,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsC6F,OAAtC,CAAP;AACD;;AAhQiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, LiteralTypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile) {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n line,\n character,\n };\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n return pkgParts[0];\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n private isNative(typeName: string) {\n return ['string', 'number', 'bool', 'boolean', 'object', 'any', 'void'].includes(typeName);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n return this.visitDefinition(nodeAtPos);\n }\n return this.visit(nodeAtPos);\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(node: Node, typeStr: string): Promise<TypeRefSchema> {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n // @ts-ignore\n node = node.type || node;\n if (this.isNative(typeStr)) return new TypeRefSchema(typeStr);\n if (node.kind === ts.SyntaxKind.LiteralType) {\n return new TypeRefSchema((node as LiteralTypeNode).literal.getText());\n }\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = new TypeRefSchema(typeStr);\n if (!definition) {\n return unknownExactType;\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType;\n }\n return new TypeRefSchema(typeStr, undefined, undefined, await this.jump(file, definition.start));\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(typeStr, undefined, pkgName);\n }\n}\n"]}
1
+ {"version":3,"sources":["schema-extractor-context.ts"],"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","filePath","filesystem","files","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","definition","startPosition","start","pos","nodeAtPos","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","isDefInSameLocation","loc","schemaNode"],"mappings":";;;;;;;;;;;;;;;;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C,UAAU,CAACE,KAAX,CAAiB/C,IAA9B,IAAsCqF,GAAG,CAACpF,SAAJ,KAAkB4C,UAAU,CAACE,KAAX,CAAiBvC,MAAhF;AACD,KAND;;AAQA,UAAMN,IAAI,GAAG,KAAKgB,mBAAL,CAAyB2B,UAAU,CAAC3C,IAApC,CAAb;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAIkF,mBAAmB,EAAvB,EAA2B;AACzB,eAAOH,gBAAgB,EAAvB;AACD;;AACD,YAAMK,UAAU,GAAG,MAAM,KAAKjB,IAAL,CAAUnE,IAAV,EAAgB2C,UAAU,CAACE,KAA3B,CAAzB;AACA,aAAOuC,UAAU,IAAIL,gBAAgB,EAArC;AACD;;AACD,UAAM1C,OAAO,GAAG,KAAKT,wBAAL,CAA8Be,UAAU,CAAC3C,IAAzC,CAAhB,CAvDqB,CAwDrB;;AACA,WAAO,KAAIyE,kCAAJ,EAAkBF,OAAlB,EAA2BnF,SAA3B,EAAsCiD,OAAtC,CAAP;AACD;;AA7RiC","sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep } from 'path';\nimport { Component } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: sourceFile.fileName,\n line,\n character,\n };\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n if (this._exports?.includes(typeStr)) return new TypeRefSchema(typeStr);\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n // TODO: find component id is exists, otherwise add the package name.\n return new TypeRefSchema(typeStr, undefined, pkgName);\n }\n}\n"]}
@@ -19,6 +19,16 @@ function _pMapSeries() {
19
19
  return data;
20
20
  }
21
21
 
22
+ function _lodash() {
23
+ const data = require("lodash");
24
+
25
+ _lodash = function () {
26
+ return data;
27
+ };
28
+
29
+ return data;
30
+ }
31
+
22
32
  function _semanticsEntities() {
23
33
  const data = require("@teambit/semantics.entities.semantic-schema");
24
34
 
@@ -88,6 +98,14 @@ class ClassDecelerationTransformer {
88
98
  async transform(node, context) {
89
99
  const className = this.getName(node);
90
100
  const members = await (0, _pMapSeries().default)(node.members, async member => {
101
+ var _member$modifiers;
102
+
103
+ const isPrivate = (_member$modifiers = member.modifiers) === null || _member$modifiers === void 0 ? void 0 : _member$modifiers.some(modifier => modifier.kind === _typescript().default.SyntaxKind.PrivateKeyword);
104
+
105
+ if (isPrivate) {
106
+ return null;
107
+ }
108
+
91
109
  switch (member.kind) {
92
110
  case _typescript().default.SyntaxKind.GetAccessor:
93
111
  {
@@ -96,19 +114,16 @@ class ClassDecelerationTransformer {
96
114
  const getter = member;
97
115
  const info = await context.getQuickInfo(getter.name);
98
116
  const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
99
- const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(displaySig);
117
+ const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
100
118
  const type = await context.resolveType(getter, typeStr);
101
119
  return new (_semanticsEntities().GetAccessorSchema)(getter.name.getText(), type, displaySig);
102
120
  }
103
121
 
104
122
  case _typescript().default.SyntaxKind.SetAccessor:
105
123
  {
106
- var _info$body2;
107
-
108
124
  const setter = member;
109
125
  const params = await (0, _getParams().getParams)(setter.parameters, context);
110
- const info = await context.getQuickInfo(setter.name);
111
- const displaySig = (info === null || info === void 0 ? void 0 : (_info$body2 = info.body) === null || _info$body2 === void 0 ? void 0 : _info$body2.displayString) || '';
126
+ const displaySig = await context.getQuickInfoDisplayString(setter.name);
112
127
  return new (_semanticsEntities().SetAccessorSchema)(setter.name.getText(), params[0], displaySig);
113
128
  }
114
129
 
@@ -116,7 +131,7 @@ class ClassDecelerationTransformer {
116
131
  return context.computeSchema(member);
117
132
  }
118
133
  });
119
- return new (_semanticsEntities().ClassSchema)(className, members);
134
+ return new (_semanticsEntities().ClassSchema)(className, (0, _lodash().compact)(members), context.getLocation(node));
120
135
  }
121
136
 
122
137
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","SetAccessor","setter","params","parameters","SetAccessorSchema","computeSchema","ClassSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;A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A,kBAAMI,IAAI,GAAG,MAAMZ,OAAO,CAACa,WAAR,CAAoBR,MAApB,EAA4BM,OAA5B,CAAnB;AACA,mBAAO,KAAIG,sCAAJ,EAAsBT,MAAM,CAACZ,IAAP,CAAYC,OAAZ,EAAtB,EAA6CkB,IAA7C,EAAmDJ,UAAnD,CAAP;AACD;;AACD,aAAKnB,sBAAGC,UAAH,CAAcyB,WAAnB;AAAgC;AAAA;;AAC9B,kBAAMC,MAAM,GAAGb,MAAf;AACA,kBAAMc,MAAM,GAAG,MAAM,4BAAUD,MAAM,CAACE,UAAjB,EAA6BlB,OAA7B,CAArB;AACA,kBAAMM,IAAI,GAAG,MAAMN,OAAO,CAACO,YAAR,CAAqBS,MAAM,CAACvB,IAA5B,CAAnB;AACA,kBAAMe,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,2BAAAA,IAAI,CAAEG,IAAN,4DAAYC,aAAZ,KAA6B,EAAhD;AACA,mBAAO,KAAIS,sCAAJ,EAAsBH,MAAM,CAACvB,IAAP,CAAYC,OAAZ,EAAtB,EAA6CuB,MAAM,CAAC,CAAD,CAAnD,EAAwDT,UAAxD,CAAP;AACD;;AACD;AACE,iBAAOR,OAAO,CAACoB,aAAR,CAAsBjB,MAAtB,CAAP;AAjBJ;AAmBD,KApBqB,CAAtB;AAqBA,WAAO,KAAIkB,gCAAJ,EAAgBpB,SAAhB,EAA2BC,OAA3B,CAAP;AACD;;AAtCoE","sourcesContent":["import pMapSeries from 'p-map-series';\nimport { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\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';\nimport { getParams } from './utils/get-params';\n\nexport class ClassDecelerationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.ClassDeclaration;\n }\n\n // @todo: in case of `export default class` the class has no name.\n private getName(node: ClassDeclaration) {\n return node.name?.getText() || 'default';\n }\n\n async getIdentifiers(node: ClassDeclaration) {\n return [new ExportIdentifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\n const members = await pMapSeries(node.members, async (member) => {\n switch (member.kind) {\n case ts.SyntaxKind.GetAccessor: {\n const getter = member as ts.GetAccessorDeclaration;\n const info = await context.getQuickInfo(getter.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(displaySig);\n const type = await context.resolveType(getter, typeStr);\n return new GetAccessorSchema(getter.name.getText(), type, displaySig);\n }\n case ts.SyntaxKind.SetAccessor: {\n const setter = member as ts.SetAccessorDeclaration;\n const params = await getParams(setter.parameters, context);\n const info = await context.getQuickInfo(setter.name);\n const displaySig = info?.body?.displayString || '';\n return new SetAccessorSchema(setter.name.getText(), params[0], displaySig);\n }\n default:\n return context.computeSchema(member);\n }\n });\n return new ClassSchema(className, members);\n }\n}\n"]}
1
+ {"version":3,"sources":["class-deceleration.ts"],"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","member","isPrivate","modifiers","some","modifier","PrivateKeyword","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","type","resolveType","GetAccessorSchema","SetAccessor","setter","params","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema","getLocation"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAA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AAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;AACA,kBAAMC,OAAO,GAAG,sDAAuBL,IAAvB,CAAhB;AACA,kBAAMM,IAAI,GAAG,MAAMjB,OAAO,CAACkB,WAAR,CAAoBR,MAApB,EAA4BM,OAA5B,CAAnB;AACA,mBAAO,KAAIG,sCAAJ,EAAsBT,MAAM,CAACjB,IAAP,CAAYC,OAAZ,EAAtB,EAA6CuB,IAA7C,EAAmDJ,UAAnD,CAAP;AACD;;AACD,aAAKxB,sBAAGC,UAAH,CAAc8B,WAAnB;AAAgC;AAC9B,kBAAMC,MAAM,GAAGlB,MAAf;AACA,kBAAMmB,MAAM,GAAG,MAAM,4BAAUD,MAAM,CAACE,UAAjB,EAA6BvB,OAA7B,CAArB;AACA,kBAAMa,UAAU,GAAG,MAAMb,OAAO,CAACwB,yBAAR,CAAkCH,MAAM,CAAC5B,IAAzC,CAAzB;AACA,mBAAO,KAAIgC,sCAAJ,EAAsBJ,MAAM,CAAC5B,IAAP,CAAYC,OAAZ,EAAtB,EAA6C4B,MAAM,CAAC,CAAD,CAAnD,EAAwDT,UAAxD,CAAP;AACD;;AACD;AACE,iBAAOb,OAAO,CAAC0B,aAAR,CAAsBvB,MAAtB,CAAP;AAhBJ;AAkBD,KAvBqB,CAAtB;AAwBA,WAAO,KAAIwB,gCAAJ,EAAgB1B,SAAhB,EAA2B,uBAAQC,OAAR,CAA3B,EAA6CF,OAAO,CAAC4B,WAAR,CAAoBzC,IAApB,CAA7C,CAAP;AACD;;AAzCoE","sourcesContent":["import pMapSeries from 'p-map-series';\nimport { compact } from 'lodash';\nimport { ClassSchema, GetAccessorSchema, SetAccessorSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, ClassDeclaration } from 'typescript';\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';\nimport { getParams } from './utils/get-params';\n\nexport class ClassDecelerationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.ClassDeclaration;\n }\n\n // @todo: in case of `export default class` the class has no name.\n private getName(node: ClassDeclaration) {\n return node.name?.getText() || 'default';\n }\n\n async getIdentifiers(node: ClassDeclaration) {\n return [new ExportIdentifier(this.getName(node), node.getSourceFile().fileName)];\n }\n\n async transform(node: ClassDeclaration, context: SchemaExtractorContext) {\n const className = this.getName(node);\n const members = await pMapSeries(node.members, async (member) => {\n const isPrivate = member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword);\n if (isPrivate) {\n return null;\n }\n switch (member.kind) {\n case ts.SyntaxKind.GetAccessor: {\n const getter = member as ts.GetAccessorDeclaration;\n const info = await context.getQuickInfo(getter.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(getter, typeStr);\n return new GetAccessorSchema(getter.name.getText(), type, displaySig);\n }\n case ts.SyntaxKind.SetAccessor: {\n const setter = member as ts.SetAccessorDeclaration;\n const params = await getParams(setter.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(setter.name);\n return new SetAccessorSchema(setter.name.getText(), params[0], displaySig);\n }\n default:\n return context.computeSchema(member);\n }\n });\n return new ClassSchema(className, compact(members), context.getLocation(node));\n }\n}\n"]}
@@ -9,16 +9,6 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.FunctionDeclaration = void 0;
11
11
 
12
- function _semanticsEntities() {
13
- const data = require("@teambit/semantics.entities.semantic-schema");
14
-
15
- _semanticsEntities = function () {
16
- return data;
17
- };
18
-
19
- return data;
20
- }
21
-
22
12
  function _typescript() {
23
13
  const data = _interopRequireDefault(require("typescript"));
24
14
 
@@ -39,20 +29,10 @@ function _exportIdentifier() {
39
29
  return data;
40
30
  }
41
31
 
42
- function _getParams() {
43
- const data = require("./utils/get-params");
44
-
45
- _getParams = function () {
46
- return data;
47
- };
48
-
49
- return data;
50
- }
51
-
52
- function _parseTypeFromQuickInfo() {
53
- const data = require("./utils/parse-type-from-quick-info");
32
+ function _toFunctionSchema() {
33
+ const data = require("./utils/to-function-schema");
54
34
 
55
- _parseTypeFromQuickInfo = function () {
35
+ _toFunctionSchema = function () {
56
36
  return data;
57
37
  };
58
38
 
@@ -76,16 +56,7 @@ class FunctionDeclaration {
76
56
  }
77
57
 
78
58
  async transform(funcDec, context) {
79
- var _info$body;
80
-
81
- const name = this.getName(funcDec); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
82
-
83
- const info = await context.getQuickInfo(funcDec.name);
84
- const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
85
- const returnTypeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(displaySig);
86
- const args = await (0, _getParams().getParams)(funcDec.parameters, context);
87
- const returnType = await context.resolveType(funcDec, returnTypeStr);
88
- return new (_semanticsEntities().FunctionSchema)(name || '', args, returnType, displaySig || '');
59
+ return (0, _toFunctionSchema().toFunctionLikeSchema)(funcDec, context);
89
60
  }
90
61
 
91
62
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context","info","getQuickInfo","displaySig","body","displayString","returnTypeStr","args","parameters","returnType","resolveType","FunctionSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD,GAH2D,CAK5D;;;AACoB,QAAdM,cAAc,CAACC,OAAD,EAAmC;AACrD,WAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;AACD;;AAEOF,EAAAA,OAAO,CAACF,OAAD,EAAmC;AAAA;;AAChD,WAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;AACD;;AAEc,QAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;AAAA;;AACtG,UAAMH,IAAI,GAAG,KAAKH,OAAL,CAAaF,OAAb,CAAb,CADsG,CAEtG;;AACA,UAAMS,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBV,OAAO,CAACK,IAA7B,CAAnB;AACA,UAAMM,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;AACA,UAAMC,aAAa,GAAG,sDAAuBH,UAAvB,CAAtB;AACA,UAAMI,IAAI,GAAG,MAAM,4BAAUf,OAAO,CAACgB,UAAlB,EAA8BR,OAA9B,CAAnB;AACA,UAAMS,UAAU,GAAG,MAAMT,OAAO,CAACU,WAAR,CAAoBlB,OAApB,EAA6Bc,aAA7B,CAAzB;AAEA,WAAO,KAAIK,mCAAJ,EAAmBd,IAAI,IAAI,EAA3B,EAA+BU,IAA/B,EAAqCE,UAArC,EAAiDN,UAAU,IAAI,EAA/D,CAAP;AACD;;AAxB2D","sourcesContent":["import { SchemaNode, FunctionSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, FunctionDeclaration as FunctionDeclarationNode } from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\nexport class FunctionDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.FunctionDeclaration;\n }\n\n // need to check for anonymous functions assigned for vars, const and let.\n async getIdentifiers(funcDec: FunctionDeclarationNode) {\n return [new ExportIdentifier(this.getName(funcDec), funcDec.getSourceFile().fileName)];\n }\n\n private getName(funcDec: FunctionDeclarationNode) {\n return funcDec.name?.getText() || '';\n }\n\n async transform(funcDec: FunctionDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(funcDec);\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const info = await context.getQuickInfo(funcDec.name!);\n const displaySig = info?.body?.displayString;\n const returnTypeStr = parseTypeFromQuickInfo(displaySig);\n const args = await getParams(funcDec.parameters, context);\n const returnType = await context.resolveType(funcDec, returnTypeStr);\n\n return new FunctionSchema(name || '', args, returnType, displaySig || '');\n }\n}\n"]}
1
+ {"version":3,"sources":["function-declaration.ts"],"names":["FunctionDeclaration","predicate","node","kind","ts","SyntaxKind","getIdentifiers","funcDec","ExportIdentifier","getName","getSourceFile","fileName","name","getText","transform","context"],"mappings":";;;;;;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;AAC5DC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,mBAAnC;AACD,GAH2D,CAK5D;;;AACoB,QAAdM,cAAc,CAACC,OAAD,EAAmC;AACrD,WAAO,CAAC,KAAIC,oCAAJ,EAAqB,KAAKC,OAAL,CAAaF,OAAb,CAArB,EAA4CA,OAAO,CAACG,aAAR,GAAwBC,QAApE,CAAD,CAAP;AACD;;AAEOF,EAAAA,OAAO,CAACF,OAAD,EAAmC;AAAA;;AAChD,WAAO,kBAAAA,OAAO,CAACK,IAAR,gEAAcC,OAAd,OAA2B,EAAlC;AACD;;AAEc,QAATC,SAAS,CAACP,OAAD,EAAmCQ,OAAnC,EAAyF;AACtG,WAAO,8CAAqBR,OAArB,EAA8BQ,OAA9B,CAAP;AACD;;AAhB2D","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"]}
@@ -39,6 +39,16 @@ function _getParams() {
39
39
  return data;
40
40
  }
41
41
 
42
+ function _typeNodeToSchema() {
43
+ const data = require("./utils/type-node-to-schema");
44
+
45
+ _typeNodeToSchema = function () {
46
+ return data;
47
+ };
48
+
49
+ return data;
50
+ }
51
+
42
52
  class IndexSignature {
43
53
  predicate(node) {
44
54
  return node.kind === _typescript().default.SyntaxKind.IndexSignature;
@@ -50,7 +60,7 @@ class IndexSignature {
50
60
 
51
61
  async transform(indexSig, context) {
52
62
  const params = await (0, _getParams().getParams)(indexSig.parameters, context);
53
- const type = await context.resolveType(indexSig, indexSig.type.getText());
63
+ const type = await (0, _typeNodeToSchema().typeNodeToSchema)(indexSig.type, context);
54
64
  return new (_semanticsEntities().IndexSignatureSchema)(params, type);
55
65
  }
56
66
 
@@ -1 +1 @@
1
- {"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","resolveType","getText","IndexSignatureSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAMH,OAAO,CAACI,WAAR,CAAoBL,QAApB,EAA8BA,QAAQ,CAACI,IAAT,CAAcE,OAAd,EAA9B,CAAnB;AACA,WAAO,KAAIC,yCAAJ,EAAyBL,MAAzB,EAAiCE,IAAjC,CAAP;AACD;;AAbsD","sourcesContent":["import { SchemaNode, IndexSignatureSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, IndexSignatureDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { getParams } from './utils/get-params';\n\nexport class IndexSignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.IndexSignature;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(indexSig: IndexSignatureDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const params = await getParams(indexSig.parameters, context);\n const type = await context.resolveType(indexSig, indexSig.type.getText());\n return new IndexSignatureSchema(params, type);\n }\n}\n"]}
1
+ {"version":3,"sources":["index-signature.ts"],"names":["IndexSignature","predicate","node","kind","ts","SyntaxKind","getIdentifiers","transform","indexSig","context","params","parameters","type","IndexSignatureSchema"],"mappings":";;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEO,MAAMA,cAAN,CAAkD;AACvDC,EAAAA,SAAS,CAACC,IAAD,EAAa;AACpB,WAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAGC,UAAH,CAAcL,cAAnC;AACD;;AAEmB,QAAdM,cAAc,GAAG;AACrB,WAAO,EAAP;AACD;;AAEc,QAATC,SAAS,CAACC,QAAD,EAAsCC,OAAtC,EAA4F;AACzG,UAAMC,MAAM,GAAG,MAAM,4BAAUF,QAAQ,CAACG,UAAnB,EAA+BF,OAA/B,CAArB;AACA,UAAMG,IAAI,GAAG,MAAM,0CAAiBJ,QAAQ,CAACI,IAA1B,EAAgCH,OAAhC,CAAnB;AACA,WAAO,KAAII,yCAAJ,EAAyBH,MAAzB,EAAiCE,IAAjC,CAAP;AACD;;AAbsD","sourcesContent":["import { SchemaNode, IndexSignatureSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, IndexSignatureDeclaration } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { getParams } from './utils/get-params';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class IndexSignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.IndexSignature;\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(indexSig: IndexSignatureDeclaration, context: SchemaExtractorContext): Promise<SchemaNode> {\n const params = await getParams(indexSig.parameters, context);\n const type = await typeNodeToSchema(indexSig.type, context);\n return new IndexSignatureSchema(params, type);\n }\n}\n"]}
@@ -7,12 +7,8 @@ export { VariableDeclaration } from './variable-declaration';
7
7
  export { SourceFileTransformer } from './source-file-transformer';
8
8
  export { TypeAliasTransformer } from './type-alias';
9
9
  export { ClassDecelerationTransformer } from './class-deceleration';
10
- export { TypeIntersectionTransformer } from './type-intersection';
11
10
  export { Constructor } from './constructor';
12
- export { TypeReferenceTransformer } from './type-reference';
13
- export { TypeLiteralTransformer } from './type-literal';
14
11
  export { PropertySignature } from './property-signature';
15
- export { TypeUnionTransformer } from './type-union';
16
12
  export { LiteralTypeTransformer } from './literal-type';
17
13
  export { IndexSignature } from './index-signature';
18
14
  export { InterfaceDeclarationTransformer } from './interface-declaration';
@@ -81,30 +81,6 @@ Object.defineProperty(exports, "TypeAliasTransformer", {
81
81
  return _typeAlias().TypeAliasTransformer;
82
82
  }
83
83
  });
84
- Object.defineProperty(exports, "TypeIntersectionTransformer", {
85
- enumerable: true,
86
- get: function () {
87
- return _typeIntersection().TypeIntersectionTransformer;
88
- }
89
- });
90
- Object.defineProperty(exports, "TypeLiteralTransformer", {
91
- enumerable: true,
92
- get: function () {
93
- return _typeLiteral().TypeLiteralTransformer;
94
- }
95
- });
96
- Object.defineProperty(exports, "TypeReferenceTransformer", {
97
- enumerable: true,
98
- get: function () {
99
- return _typeReference().TypeReferenceTransformer;
100
- }
101
- });
102
- Object.defineProperty(exports, "TypeUnionTransformer", {
103
- enumerable: true,
104
- get: function () {
105
- return _typeUnion().TypeUnionTransformer;
106
- }
107
- });
108
84
  Object.defineProperty(exports, "VariableDeclaration", {
109
85
  enumerable: true,
110
86
  get: function () {
@@ -208,16 +184,6 @@ function _classDeceleration() {
208
184
  return data;
209
185
  }
210
186
 
211
- function _typeIntersection() {
212
- const data = require("./type-intersection");
213
-
214
- _typeIntersection = function () {
215
- return data;
216
- };
217
-
218
- return data;
219
- }
220
-
221
187
  function _constructor() {
222
188
  const data = require("./constructor");
223
189
 
@@ -228,26 +194,6 @@ function _constructor() {
228
194
  return data;
229
195
  }
230
196
 
231
- function _typeReference() {
232
- const data = require("./type-reference");
233
-
234
- _typeReference = function () {
235
- return data;
236
- };
237
-
238
- return data;
239
- }
240
-
241
- function _typeLiteral() {
242
- const data = require("./type-literal");
243
-
244
- _typeLiteral = function () {
245
- return data;
246
- };
247
-
248
- return data;
249
- }
250
-
251
197
  function _propertySignature() {
252
198
  const data = require("./property-signature");
253
199
 
@@ -258,16 +204,6 @@ function _propertySignature() {
258
204
  return data;
259
205
  }
260
206
 
261
- function _typeUnion() {
262
- const data = require("./type-union");
263
-
264
- _typeUnion = function () {
265
- return data;
266
- };
267
-
268
- return data;
269
- }
270
-
271
207
  function _literalType() {
272
208
  const data = require("./literal-type");
273
209
 
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { MethodDeclaration } from './method-declaration';\nexport { PropertyDeclaration } from './property-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 { TypeIntersectionTransformer } from './type-intersection';\nexport { Constructor } from './constructor';\nexport { TypeReferenceTransformer } from './type-reference';\nexport { TypeLiteralTransformer } from './type-literal';\nexport { PropertySignature } from './property-signature';\nexport { TypeUnionTransformer } from './type-union';\nexport { LiteralTypeTransformer } from './literal-type';\nexport { IndexSignature } from './index-signature';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { MethodSignatureTransformer } from './method-signature';\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA","sourcesContent":["export { ExportDeclaration } from './export-declaration';\nexport { FunctionDeclaration } from './function-declaration';\nexport { MethodDeclaration } from './method-declaration';\nexport { PropertyDeclaration } from './property-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 { Constructor } from './constructor';\nexport { PropertySignature } from './property-signature';\nexport { LiteralTypeTransformer } from './literal-type';\nexport { IndexSignature } from './index-signature';\nexport { InterfaceDeclarationTransformer } from './interface-declaration';\nexport { MethodSignatureTransformer } from './method-signature';\n"]}