@teambit/typescript 0.0.738 → 0.0.739

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 (38) hide show
  1. package/dist/exceptions/transformer-not-found.d.ts +2 -1
  2. package/dist/exceptions/transformer-not-found.js +3 -2
  3. package/dist/exceptions/transformer-not-found.js.map +1 -1
  4. package/dist/schema-extractor-context.d.ts +4 -1
  5. package/dist/schema-extractor-context.js +20 -2
  6. package/dist/schema-extractor-context.js.map +1 -1
  7. package/dist/transformers/class-deceleration.js +9 -1
  8. package/dist/transformers/class-deceleration.js.map +1 -1
  9. package/dist/transformers/enum-declaration.d.ts +10 -0
  10. package/dist/transformers/enum-declaration.js +60 -0
  11. package/dist/transformers/enum-declaration.js.map +1 -0
  12. package/dist/transformers/index.d.ts +1 -0
  13. package/dist/transformers/index.js +16 -0
  14. package/dist/transformers/index.js.map +1 -1
  15. package/dist/transformers/utils/get-params.js +53 -7
  16. package/dist/transformers/utils/get-params.js.map +1 -1
  17. package/dist/transformers/utils/parse-type-from-quick-info.d.ts +1 -0
  18. package/dist/transformers/utils/parse-type-from-quick-info.js +12 -3
  19. package/dist/transformers/utils/parse-type-from-quick-info.js.map +1 -1
  20. package/dist/transformers/utils/type-node-to-schema.js +34 -4
  21. package/dist/transformers/utils/type-node-to-schema.js.map +1 -1
  22. package/dist/typescript.extractor.d.ts +7 -1
  23. package/dist/typescript.extractor.js +30 -9
  24. package/dist/typescript.extractor.js.map +1 -1
  25. package/dist/typescript.main.runtime.d.ts +11 -2
  26. package/dist/typescript.main.runtime.js +17 -6
  27. package/dist/typescript.main.runtime.js.map +1 -1
  28. package/exceptions/transformer-not-found.ts +4 -2
  29. package/package-tar/teambit-typescript-0.0.739.tgz +0 -0
  30. package/package.json +12 -11
  31. package/{preview-1653227849497.js → preview-1653362849981.js} +2 -2
  32. package/transformers/class-deceleration.ts +4 -1
  33. package/transformers/enum-declaration.ts +20 -0
  34. package/transformers/index.ts +1 -0
  35. package/transformers/utils/get-params.ts +53 -9
  36. package/transformers/utils/parse-type-from-quick-info.ts +9 -1
  37. package/transformers/utils/type-node-to-schema.ts +37 -4
  38. package/package-tar/teambit-typescript-0.0.738.tgz +0 -0
@@ -1,7 +1,8 @@
1
1
  import { Node } from 'typescript';
2
2
  import { Component } from '@teambit/component';
3
+ import { Location } from '@teambit/semantics.entities.semantic-schema';
3
4
  export declare class TransformerNotFound extends Error {
4
5
  readonly node: Node;
5
6
  readonly component: Component;
6
- constructor(node: Node, component: Component);
7
+ constructor(node: Node, component: Component, location: Location);
7
8
  }
@@ -18,9 +18,10 @@ function _typescript() {
18
18
  }
19
19
 
20
20
  class TransformerNotFound extends Error {
21
- constructor(node, component) {
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
- node text: ${node.getText()}`);
23
+ location: ${location.file}, line: ${location.line}, character: ${location.character}.
24
+ node-text: ${node.getText()}`);
24
25
  this.node = node;
25
26
  this.component = component;
26
27
  }
@@ -1 +1 @@
1
- {"version":3,"names":["TransformerNotFound","Error","constructor","node","component","kind","ts","SyntaxKind","id","toString","getText"],"sources":["transformer-not-found.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { Component } from '@teambit/component';\n\nexport class TransformerNotFound extends Error {\n constructor(readonly node: Node, readonly component: Component) {\n super(\n `typescript: could not find schema transformer for node of kind ${node.kind} (${\n ts.SyntaxKind[node.kind]\n }) in component ${component.id.toString()}.\nnode text: ${node.getText()}`\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGO,MAAMA,mBAAN,SAAkCC,KAAlC,CAAwC;EAC7CC,WAAW,CAAUC,IAAV,EAA+BC,SAA/B,EAAqD;IAC9D,MACG,kEAAiED,IAAI,CAACE,IAAK,KAC1EC,qBAAA,CAAGC,UAAH,CAAcJ,IAAI,CAACE,IAAnB,CACD,kBAAiBD,SAAS,CAACI,EAAV,CAAaC,QAAb,EAAwB;AAChD,aAAaN,IAAI,CAACO,OAAL,EAAe,EAJxB;IAD8D,KAA3CP,IAA2C,GAA3CA,IAA2C;IAAA,KAAtBC,SAAsB,GAAtBA,SAAsB;EAO/D;;AAR4C"}
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"}
@@ -3,13 +3,15 @@ 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
5
  import { SchemaNode, Location } from '@teambit/semantics.entities.semantic-schema';
6
+ import { ComponentDependency } from '@teambit/dependency-resolver';
6
7
  import { TypeScriptExtractor } from './typescript.extractor';
7
8
  import { ExportList } from './export-list';
8
9
  export declare class SchemaExtractorContext {
9
10
  readonly tsserver: TsserverClient;
10
11
  readonly component: Component;
11
12
  readonly extractor: TypeScriptExtractor;
12
- constructor(tsserver: TsserverClient, component: Component, extractor: TypeScriptExtractor);
13
+ readonly componentDeps: ComponentDependency[];
14
+ constructor(tsserver: TsserverClient, component: Component, extractor: TypeScriptExtractor, componentDeps: ComponentDependency[]);
13
15
  computeSchema(node: Node): Promise<SchemaNode>;
14
16
  /**
15
17
  * returns the location of a node in a source file.
@@ -70,4 +72,5 @@ export declare class SchemaExtractorContext {
70
72
  resolveType(node: Node & {
71
73
  type?: TypeNode;
72
74
  }, typeStr: string, isTypeStrFromQuickInfo?: boolean): Promise<SchemaNode>;
75
+ private getCompIdByPkgName;
73
76
  }
@@ -104,10 +104,11 @@ function _parseTypeFromQuickInfo() {
104
104
  }
105
105
 
106
106
  class SchemaExtractorContext {
107
- constructor(tsserver, component, extractor) {
107
+ constructor(tsserver, component, extractor, componentDeps) {
108
108
  this.tsserver = tsserver;
109
109
  this.component = component;
110
110
  this.extractor = extractor;
111
+ this.componentDeps = componentDeps;
111
112
  (0, _defineProperty2().default)(this, "_exports", undefined);
112
113
  }
113
114
 
@@ -420,11 +421,28 @@ class SchemaExtractorContext {
420
421
  return schemaNode || unknownExactType();
421
422
  }
422
423
 
423
- const pkgName = this.parsePackageNameFromPath(definition.file); // TODO: find component id is exists, otherwise add the package name.
424
+ const compIdByPath = await this.extractor.getComponentIDByPath(definition.file);
425
+
426
+ if (compIdByPath) {
427
+ return new (_semanticsEntities().TypeRefSchema)(location, typeStr, compIdByPath);
428
+ }
429
+
430
+ const pkgName = this.parsePackageNameFromPath(definition.file);
431
+ const compIdByPkg = this.getCompIdByPkgName(pkgName);
432
+
433
+ if (compIdByPkg) {
434
+ return new (_semanticsEntities().TypeRefSchema)(location, typeStr, compIdByPkg);
435
+ }
424
436
 
425
437
  return new (_semanticsEntities().TypeRefSchema)(location, typeStr, undefined, pkgName);
426
438
  }
427
439
 
440
+ getCompIdByPkgName(pkgName) {
441
+ var _this$componentDeps$f;
442
+
443
+ return (_this$componentDeps$f = this.componentDeps.find(dep => dep.packageName === pkgName)) === null || _this$componentDeps$f === void 0 ? void 0 : _this$componentDeps$f.componentId;
444
+ }
445
+
428
446
  }
429
447
 
430
448
  exports.SchemaExtractorContext = SchemaExtractorContext;
@@ -1 +1 @@
1
- {"version":3,"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getPathRelativeToComponent","filePath","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","location","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode"],"sources":["schema-extractor-context.ts"],"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, relative } 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, absolutePath = false): 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: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\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 const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\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(location, typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, 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(location, typeStr, undefined, pkgName);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;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;;AAEO,MAAMA,sBAAN,CAA6B;EAClCC,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIT;IAAA,KAHSF,QAGT,GAHSA,QAGT;IAAA,KAFSC,SAET,GAFSA,SAET;IAAA,KADSC,SACT,GADSA,SACT;IAAA,kDAuLiCC,SAvLjC;EAAE;;EAEJC,aAAa,CAACC,IAAD,EAAa;IACxB,OAAO,KAAKH,SAAL,CAAeE,aAAf,CAA6BC,IAA7B,EAAmC,IAAnC,CAAP;EACD;EAED;AACF;AACA;;;EACEC,WAAW,CAACD,IAAD,EAAaE,gBAAb,EAA+CC,YAAY,GAAG,KAA9D,EAA+E;IACxF,MAAMC,UAAU,GAAGF,gBAAgB,IAAIF,IAAI,CAACK,aAAL,EAAvC;IACA,MAAMC,QAAQ,GAAGF,UAAU,CAACG,6BAAX,CAAyCP,IAAI,CAACQ,QAAL,EAAzC,CAAjB;IACA,MAAMC,IAAI,GAAGH,QAAQ,CAACG,IAAT,GAAgB,CAA7B;IACA,MAAMC,SAAS,GAAGJ,QAAQ,CAACI,SAAT,GAAqB,CAAvC;IAEA,OAAO;MACLC,IAAI,EAAER,YAAY,GAAGC,UAA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","constructor","tsserver","component","extractor","componentDeps","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getPathRelativeToComponent","filePath","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","location","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","compIdByPath","getComponentIDByPath","compIdByPkg","getCompIdByPkgName","dep","packageName","componentId"],"sources":["schema-extractor-context.ts"],"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, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\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 readonly componentDeps: ComponentDependency[]\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, absolutePath = false): 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: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\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 const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\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(location, typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, 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 compIdByPath = await this.extractor.getComponentIDByPath(definition.file);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep)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BgB,UAAU,CAAChD,IAAzC,CAAhB;IACA,MAAMiG,WAAW,GAAG,KAAKC,kBAAL,CAAwBzD,OAAxB,CAApB;;IACA,IAAIwD,WAAJ,EAAiB;MACf,OAAO,KAAIhB,kCAAJ,EAAkBD,QAAlB,EAA4BF,OAA5B,EAAqCmB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIhB,kCAAJ,EAAkBD,QAAlB,EAA4BF,OAA5B,EAAqC3F,SAArC,EAAgDsD,OAAhD,CAAP;EACD;;EAEOyD,kBAAkB,CAACzD,OAAD,EAA2C;IAAA;;IACnE,gCAAO,KAAKvD,aAAL,CAAmBsC,IAAnB,CAAyB2E,GAAD,IAASA,GAAG,CAACC,WAAJ,KAAoB3D,OAArD,CAAP,0DAAO,sBAA+D4D,WAAtE;EACD;;AAjTiC"}
@@ -40,7 +40,7 @@ function _semanticsEntities() {
40
40
  }
41
41
 
42
42
  function _typescript() {
43
- const data = _interopRequireDefault(require("typescript"));
43
+ const data = _interopRequireWildcard(require("typescript"));
44
44
 
45
45
  _typescript = function () {
46
46
  return data;
@@ -79,6 +79,10 @@ function _getParams() {
79
79
  return data;
80
80
  }
81
81
 
82
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
83
+
84
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
85
+
82
86
  class ClassDecelerationTransformer {
83
87
  predicate(node) {
84
88
  return node.kind === _typescript().default.SyntaxKind.ClassDeclaration;
@@ -106,6 +110,10 @@ class ClassDecelerationTransformer {
106
110
  return null;
107
111
  }
108
112
 
113
+ if ((0, _typescript().isSemicolonClassElement)(member)) {
114
+ return null;
115
+ }
116
+
109
117
  switch (member.kind) {
110
118
  case _typescript().default.SyntaxKind.GetAccessor:
111
119
  {
@@ -1 +1 @@
1
- {"version":3,"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","pMapSeries","member","isPrivate","modifiers","some","modifier","PrivateKeyword","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","GetAccessorSchema","getLocation","SetAccessor","setter","params","getParams","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema","compact"],"sources":["class-deceleration.ts"],"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(context.getLocation(getter), 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(context.getLocation(setter), 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"],"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;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,4BAAN,CAAgE;EACrEC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,gBAAnC;EACD,CAHoE,CAKrE;;;EACQC,OAAO,CAACL,IAAD,EAAyB;IAAA;;IACtC,OAAO,eAAAA,IAAI,CAACM,IAAL,0DAA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,CAAYC,OAAZ,EAAnD,EAA0EyB,IAA1E,EAAgFL,UAAhF,CAAP;UACD;;QACD,KAAKzB,qBAAA,CAAGC,UAAH,CAAciC,WAAnB;UAAgC;YAC9B,MAAMC,MAAM,GAAGpB,MAAf;YACA,MAAMqB,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUF,MAAM,CAACG,UAAjB,EAA6B3B,OAA7B,CAArB;YACA,MAAMc,UAAU,GAAG,MAAMd,OAAO,CAAC4B,yBAAR,CAAkCJ,MAAM,CAAC/B,IAAzC,CAAzB;YACA,OAAO,KAAIoC,sCAAJ,EAAsB7B,OAAO,CAACsB,WAAR,CAAoBE,MAApB,CAAtB,EAAmDA,MAAM,CAAC/B,IAAP,CAAYC,OAAZ,EAAnD,EAA0E+B,MAAM,CAAC,CAAD,CAAhF,EAAqFX,UAArF,CAAP;UACD;;QACD;UACE,OAAOd,OAAO,CAAC8B,aAAR,CAAsB1B,MAAtB,CAAP;MAhBJ;IAkBD,CAvBqB,CAAtB;IAwBA,OAAO,KAAI2B,gCAAJ,EAAgB9B,SAAhB,EAA2B,IAAA+B,iBAAA,EAAQ9B,OAAR,CAA3B,EAA6CF,OAAO,CAACsB,WAAR,CAAoBnC,IAApB,CAA7C,CAAP;EACD;;AAzCoE"}
1
+ {"version":3,"names":["ClassDecelerationTransformer","predicate","node","kind","ts","SyntaxKind","ClassDeclaration","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","context","className","members","pMapSeries","member","isPrivate","modifiers","some","modifier","PrivateKeyword","isSemicolonClassElement","GetAccessor","getter","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","GetAccessorSchema","getLocation","SetAccessor","setter","params","getParams","parameters","getQuickInfoDisplayString","SetAccessorSchema","computeSchema","ClassSchema","compact"],"sources":["class-deceleration.ts"],"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, isSemicolonClassElement } 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 if (isSemicolonClassElement(member)) {\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(context.getLocation(getter), 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(context.getLocation(setter), 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"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;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A,EAAQ/B,OAAR,CAA3B,EAA6CF,OAAO,CAACuB,WAAR,CAAoBpC,IAApB,CAA7C,CAAP;EACD;;AA5CoE"}
@@ -0,0 +1,10 @@
1
+ import { Node, EnumDeclaration } from 'typescript';
2
+ import { EnumSchema } 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
+ export declare class EnumDeclarationTransformer implements SchemaTransformer {
7
+ predicate(node: Node): boolean;
8
+ getIdentifiers(node: EnumDeclaration): Promise<ExportIdentifier[]>;
9
+ transform(enumDec: EnumDeclaration, context: SchemaExtractorContext): Promise<EnumSchema>;
10
+ }
@@ -0,0 +1,60 @@
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.EnumDeclarationTransformer = 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
+ class EnumDeclarationTransformer {
43
+ predicate(node) {
44
+ return node.kind === _typescript().default.SyntaxKind.EnumDeclaration;
45
+ }
46
+
47
+ async getIdentifiers(node) {
48
+ return [new (_exportIdentifier().ExportIdentifier)(node.name.getText(), node.getSourceFile().fileName)];
49
+ }
50
+
51
+ async transform(enumDec, context) {
52
+ const members = enumDec.members.map(member => member.name.getText());
53
+ return new (_semanticsEntities().EnumSchema)(context.getLocation(enumDec), enumDec.name.getText(), members);
54
+ }
55
+
56
+ }
57
+
58
+ exports.EnumDeclarationTransformer = EnumDeclarationTransformer;
59
+
60
+ //# sourceMappingURL=enum-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["EnumDeclarationTransformer","predicate","node","kind","ts","SyntaxKind","EnumDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","enumDec","context","members","map","member","EnumSchema","getLocation"],"sources":["enum-declaration.ts"],"sourcesContent":["import ts, { Node, EnumDeclaration } from 'typescript';\nimport { EnumSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class EnumDeclarationTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.EnumDeclaration;\n }\n\n async getIdentifiers(node: EnumDeclaration): Promise<ExportIdentifier[]> {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(enumDec: EnumDeclaration, context: SchemaExtractorContext) {\n const members = enumDec.members.map((member) => member.name.getText());\n return new EnumSchema(context.getLocation(enumDec), enumDec.name.getText(), members);\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;;AAEO,MAAMA,0BAAN,CAA8D;EACnEC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,eAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAAqD;IACvE,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACC,OAAD,EAA2BC,OAA3B,EAA4D;IACzE,MAAMC,OAAO,GAAGF,OAAO,CAACE,OAAR,CAAgBC,GAAhB,CAAqBC,MAAD,IAAYA,MAAM,CAACT,IAAP,CAAYC,OAAZ,EAAhC,CAAhB;IACA,OAAO,KAAIS,+BAAJ,EAAeJ,OAAO,CAACK,WAAR,CAAoBN,OAApB,CAAf,EAA6CA,OAAO,CAACL,IAAR,CAAaC,OAAb,EAA7C,EAAqEM,OAArE,CAAP;EACD;;AAZkE"}
@@ -13,3 +13,4 @@ export { LiteralTypeTransformer } from './literal-type';
13
13
  export { IndexSignature } from './index-signature';
14
14
  export { InterfaceDeclarationTransformer } from './interface-declaration';
15
15
  export { MethodSignatureTransformer } from './method-signature';
16
+ export { EnumDeclarationTransformer } from './enum-declaration';
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "Constructor", {
15
15
  return _constructor().Constructor;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "EnumDeclarationTransformer", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _enumDeclaration().EnumDeclarationTransformer;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "ExportDeclaration", {
19
25
  enumerable: true,
20
26
  get: function () {
@@ -244,4 +250,14 @@ function _methodSignature() {
244
250
  return data;
245
251
  }
246
252
 
253
+ function _enumDeclaration() {
254
+ const data = require("./enum-declaration");
255
+
256
+ _enumDeclaration = function () {
257
+ return data;
258
+ };
259
+
260
+ return data;
261
+ }
262
+
247
263
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"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"],"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;;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 { 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';\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;;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"}
@@ -29,6 +29,16 @@ function _pMapSeries() {
29
29
  return data;
30
30
  }
31
31
 
32
+ function _typescript() {
33
+ const data = require("typescript");
34
+
35
+ _typescript = function () {
36
+ return data;
37
+ };
38
+
39
+ return data;
40
+ }
41
+
32
42
  function _parseTypeFromQuickInfo() {
33
43
  const data = require("./parse-type-from-quick-info");
34
44
 
@@ -51,13 +61,26 @@ function _typeNodeToSchema() {
51
61
 
52
62
  async function getParams(parameterNodes, context) {
53
63
  return (0, _pMapSeries().default)(parameterNodes, async param => {
54
- return new (_semanticsEntities().ParameterSchema)(context.getLocation(param), param.name.getText(), await getParamType(param, context), param.initializer ? param.initializer.getText() : undefined);
64
+ return new (_semanticsEntities().ParameterSchema)(context.getLocation(param), getParamName(param), await getParamType(param, context), param.initializer ? param.initializer.getText() : undefined);
55
65
  });
56
66
  }
57
- /**
58
- * @todo: probably not needed. just call context.resolveType instead.
59
- */
60
67
 
68
+ function getParamName(param) {
69
+ if ((0, _typescript().isIdentifier)(param.name)) {
70
+ return param.name.getText();
71
+ } // it's binding pattern, either an array or an object
72
+
73
+
74
+ const elements = param.name.elements.map(elem => elem.getText());
75
+ const elementsStr = elements.join(', ');
76
+
77
+ if (param.name.kind === _typescript().SyntaxKind.ArrayBindingPattern) {
78
+ return `[ ${elementsStr} ]`;
79
+ } // it's an object binding
80
+
81
+
82
+ return `{ ${elementsStr} }`;
83
+ }
61
84
 
62
85
  async function getParamType(param, context) {
63
86
  if (param.type) {
@@ -65,9 +88,32 @@ async function getParamType(param, context) {
65
88
  return (0, _typeNodeToSchema().typeNodeToSchema)(type, context);
66
89
  }
67
90
 
68
- const info = await context.getQuickInfo(param.name);
69
- const parsed = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
70
- return new (_semanticsEntities().TypeRefSchema)(context.getLocation(param), parsed || 'any');
91
+ if ((0, _typescript().isIdentifier)(param.name)) {
92
+ const info = await context.getQuickInfo(param.name);
93
+ const parsed = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
94
+ return new (_semanticsEntities().InferenceTypeSchema)(context.getLocation(param), parsed);
95
+ } // it's binding pattern, either an array or an object
96
+
97
+
98
+ if (param.name.kind === _typescript().SyntaxKind.ArrayBindingPattern) {
99
+ const elements = await (0, _pMapSeries().default)(param.name.elements, async elem => {
100
+ const info = await context.getQuickInfo(elem);
101
+ const parsed = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
102
+ return new (_semanticsEntities().InferenceTypeSchema)(context.getLocation(param), parsed);
103
+ });
104
+ return new (_semanticsEntities().TupleTypeSchema)(context.getLocation(param), elements);
105
+ }
106
+
107
+ if (param.name.kind === _typescript().SyntaxKind.ObjectBindingPattern) {
108
+ const elements = await (0, _pMapSeries().default)(param.name.elements, async elem => {
109
+ const info = await context.getQuickInfo(elem.name);
110
+ const parsed = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
111
+ return new (_semanticsEntities().InferenceTypeSchema)(context.getLocation(param), parsed, elem.name.getText());
112
+ });
113
+ return new (_semanticsEntities().TypeLiteralSchema)(context.getLocation(param), elements);
114
+ }
115
+
116
+ throw new Error(`unknown param type`);
71
117
  }
72
118
 
73
119
  //# sourceMappingURL=get-params.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getParams","parameterNodes","context","pMapSeries","param","ParameterSchema","getLocation","name","getText","getParamType","initializer","undefined","type","typeNodeToSchema","info","getQuickInfo","parsed","parseTypeFromQuickInfo","TypeRefSchema"],"sources":["get-params.ts"],"sourcesContent":["import { ParameterSchema, SchemaNode, TypeRefSchema } from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { ParameterDeclaration, NodeArray } 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 param.name.getText(),\n await getParamType(param, context),\n param.initializer ? param.initializer.getText() : undefined\n );\n });\n}\n\n/**\n * @todo: probably not needed. just call context.resolveType instead.\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 const info = await context.getQuickInfo(param.name);\n const parsed = parseTypeFromQuickInfo(info);\n return new TypeRefSchema(context.getLocation(param), parsed || 'any');\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;;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,EAELA,KAAK,CAACG,IAAN,CAAWC,OAAX,EAFK,EAGL,MAAMC,YAAY,CAACL,KAAD,EAAQF,OAAR,CAHb,EAILE,KAAK,CAACM,WAAN,GAAoBN,KAAK,CAACM,WAAN,CAAkBF,OAAlB,EAApB,GAAkDG,SAJ7C,CAAP;EAMD,CAPM,CAAP;AAQD;AAED;AACA;AACA;;;AACA,eAAeF,YAAf,CAA4BL,KAA5B,EAAyDF,OAAzD,EAA+G;EAC7G,IAAIE,KAAK,CAACQ,IAAV,EAAgB;IACd,MAAMA,IAAI,GAAGR,KAAK,CAACQ,IAAnB;IACA,OAAO,IAAAC,oCAAA,EAAiBD,IAAjB,EAAuBV,OAAvB,CAAP;EACD;;EACD,MAAMY,IAAI,GAAG,MAAMZ,OAAO,CAACa,YAAR,CAAqBX,KAAK,CAACG,IAA3B,CAAnB;EACA,MAAMS,MAAM,GAAG,IAAAC,gDAAA,EAAuBH,IAAvB,CAAf;EACA,OAAO,KAAII,kCAAJ,EAAkBhB,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAAlB,EAA8CY,MAAM,IAAI,KAAxD,CAAP;AACD"}
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,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,EAILE,KAAK,CAACK,WAAN,GAAoBL,KAAK,CAACK,WAAN,CAAkBC,OAAlB,EAApB,GAAkDC,SAJ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Q,GAAG,MAAM,IAAAX,qBAAA,EAAWC,KAAK,CAACS,IAAN,CAAWC,QAAtB,EAAgC,MAAOE,IAAP,IAAqC;MAC1F,MAAMQ,IAAI,GAAG,MAAMtB,OAAO,CAACuB,YAAR,CAAqBT,IAArB,CAAnB;MACA,MAAMU,MAAM,GAAG,IAAAC,gDAAA,EAAuBH,IAAvB,CAAf;MACA,OAAO,KAAII,wCAAJ,EAAwB1B,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAAxB,EAAoDsB,MAApD,CAAP;IACD,CAJsB,CAAvB;IAKA,OAAO,KAAIG,oCAAJ,EAAoB3B,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAApB,EAAgDU,QAAhD,CAAP;EACD;;EACD,IAAIV,KAAK,CAACS,IAAN,CAAWM,IAAX,KAAoBC,wBAAA,CAAWU,oBAAnC,EAAyD;IACvD,MAAMhB,QAAQ,GAAG,MAAM,IAAAX,qBAAA,EAAWC,KAAK,CAACS,IAAN,CAAWC,QAAtB,EAAgC,MAAOE,IAAP,IAAgC;MACrF,MAAMQ,IAAI,GAAG,MAAMtB,OAAO,CAACuB,YAAR,CAAqBT,IAAI,CAACH,IAA1B,CAAnB;MACA,MAAMa,MAAM,GAAG,IAAAC,gDAAA,EAAuBH,IAAvB,CAAf;MACA,OAAO,KAAII,wCAAJ,EAAwB1B,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAAxB,EAAoDsB,MAApD,EAA4DV,IAAI,CAACH,IAAL,CAAUH,OAAV,EAA5D,CAAP;IACD,CAJsB,CAAvB;IAKA,OAAO,KAAIqB,sCAAJ,EAAsB7B,OAAO,CAACI,WAAR,CAAoBF,KAApB,CAAtB,EAAkDU,QAAlD,CAAP;EACD;;EACD,MAAM,IAAIkB,KAAJ,CAAW,oBAAX,CAAN;AACD"}
@@ -1,4 +1,5 @@
1
1
  import protocol from 'typescript/lib/protocol';
2
+ export declare const UNRESOLVED = "<<unresolved>>";
2
3
  /**
3
4
  * try to parse the type from the quickinfo.
4
5
  * this is an error-prone process, we do our best here.
@@ -9,11 +9,11 @@ require("core-js/modules/es.string.trim.js");
9
9
  Object.defineProperty(exports, "__esModule", {
10
10
  value: true
11
11
  });
12
+ exports.UNRESOLVED = void 0;
12
13
  exports.parseReturnTypeFromQuickInfo = parseReturnTypeFromQuickInfo;
13
14
  exports.parseTypeFromQuickInfo = parseTypeFromQuickInfo;
14
-
15
15
  // eslint-disable-next-line import/no-unresolved
16
-
16
+ const UNRESOLVED = '<<unresolved>>';
17
17
  /**
18
18
  * try to parse the type from the quickinfo.
19
19
  * this is an error-prone process, we do our best here.
@@ -46,6 +46,9 @@ exports.parseTypeFromQuickInfo = parseTypeFromQuickInfo;
46
46
  * b: number;
47
47
  * }
48
48
  */
49
+
50
+ exports.UNRESOLVED = UNRESOLVED;
51
+
49
52
  function parseTypeFromQuickInfo(quickInfo) {
50
53
  var _quickInfo$body;
51
54
 
@@ -69,7 +72,13 @@ function parseTypeFromQuickInfo(quickInfo) {
69
72
  const split = displayString.split('): ');
70
73
 
71
74
  if (split.length !== 2) {
72
- throw new Error(`quickinfo of a function below was not implemented.\n${displayString}`);
75
+ // it's hard to determine where the return-type is. so it's better to show unresolved.
76
+ // maybe, in the UI, in this case, it's best to show the signature.
77
+ // e.g.
78
+ // (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {
79
+ // new (): T;
80
+ // }): T | undefined
81
+ return UNRESOLVED;
73
82
  }
74
83
 
75
84
  return split[1].trim();
@@ -1 +1 @@
1
- {"version":3,"names":["parseTypeFromQuickInfo","quickInfo","body","displayString","splitByColon","split","kind","tail","join","trim","length","Error","firstLine","splitBySpace","typeName","splitByEqual","parseReturnTypeFromQuickInfo","typeStr","array"],"sources":["parse-type-from-quick-info.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n\n/**\n * try to parse the type from the quickinfo.\n * this is an error-prone process, we do our best here.\n *\n * an example of a function with many \":\"\n * `export function getObj(a: string, func: (b: number) => {}) { return { a: 1, b: 2 } };`\n * which produce the following quickinfo:\n * ```ts\n * function getObj(a: string, func: (b: number) => {}): {\n * a: number;\n * b: number;\n * }\n * ```\n *\n * some examples of quickinfo:\n *\n * function ts.signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags): SymbolDisplayPart[]\n *\n * const enum ts.TypeFormatFlags\n *\n * (method) ts.TypeChecker.writeSignature(signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags | undefined, kind?: SignatureKind | undefined, writer?: EmitTextWriter | undefined): string\n *\n * const obj: {\n * a: number;\n * b: number;\n * }\n *\n * function getObj(a: string): {\n * a: number;\n * b: number;\n * }\n */\nexport function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo?.body?.displayString) return '';\n const displayString = quickInfo.body.displayString;\n const splitByColon = displayString.split(':');\n switch (quickInfo.body.kind) {\n case 'const':\n case 'property':\n case 'let':\n case 'var': {\n const [, ...tail] = splitByColon;\n return tail.join(':').trim();\n }\n case 'method':\n case 'function': {\n const split = displayString.split('): ');\n if (split.length !== 2) {\n throw new Error(`quickinfo of a function below was not implemented.\\n${displayString}`);\n }\n return split[1].trim();\n }\n case 'alias': {\n // e.g. (alias) class BuilderService\\nimport BuilderService\n // e.g. '(alias) type Serializable = {\\n' +\n // ' toString(): string;\\n' +\n // '}\\n' +\n // 'import Serializable'\n const firstLine = displayString.split('\\n')[0];\n const splitBySpace = firstLine.trim().split(' ');\n // first two are alias keyword and alias type\n const [, , typeName] = splitBySpace;\n return typeName;\n }\n case 'type': {\n // e.g. `type TaskSlot = SlotRegistry<BuildTask[]>`\n const splitByEqual = displayString.split('=');\n const [, ...tail] = splitByEqual;\n return tail.join('=').trim();\n }\n default:\n return splitByColon[splitByColon.length - 1].trim();\n }\n}\n\nexport function parseReturnTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo) return '';\n const typeStr = parseTypeFromQuickInfo(quickInfo);\n const array = typeStr.split('=>');\n return array[array.length - 1].trim();\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAgCC,SAAhC,EAA2F;EAAA;;EAChG,IAAI,EAACA,SAAD,aAACA,SAAD,kCAACA,SAAS,CAAEC,IAAZ,4CAAC,gBAAiBC,aAAlB,CAAJ,EAAqC,OAAO,EAAP;EACrC,MAAMA,aAAa,GAAGF,SAAS,CAACC,IAAV,CAAeC,aAArC;EACA,MAAMC,YAAY,GAAGD,aAAa,CAACE,KAAd,CAAoB,GAApB,CAArB;;EACA,QAAQJ,SAAS,CAACC,IAAV,CAAeI,IAAvB;IACE,KAAK,OAAL;IACA,KAAK,UAAL;IACA,KAAK,KAAL;IACA,KAAK,KAAL;MAAY;QACV,MAAM,GAAG,GAAGC,IAAN,IAAcH,YAApB;QACA,OAAOG,IAAI,CAACC,IAAL,CAAU,GAAV,EAAeC,IAAf,EAAP;MACD;;IACD,KAAK,QAAL;IACA,KAAK,UAAL;MAAiB;QACf,MAAMJ,KAAK,GAAGF,aAAa,CAACE,KAAd,CAAoB,KAApB,CAAd;;QACA,IAAIA,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;UACtB,MAAM,IAAIC,KAAJ,CAAW,uDAAsDR,aAAc,EAA/E,CAAN;QACD;;QACD,OAAOE,KAAK,CAAC,CAAD,CAAL,CAASI,IAAT,EAAP;MACD;;IACD,KAAK,OAAL;MAAc;QACZ;QACA;QACA;QACA;QACA;QACA,MAAMG,SAAS,GAAGT,aAAa,CAACE,KAAd,CAAoB,IAApB,EAA0B,CAA1B,CAAlB;QACA,MAAMQ,YAAY,GAAGD,SAAS,CAACH,IAAV,GAAiBJ,KAAjB,CAAuB,GAAvB,CAArB,CAPY,CAQZ;;QACA,MAAM,IAAKS,QAAL,IAAiBD,YAAvB;QACA,OAAOC,QAAP;MACD;;IACD,KAAK,MAAL;MAAa;QACX;QACA,MAAMC,YAAY,GAAGZ,aAAa,CAACE,KAAd,CAAoB,GAApB,CAArB;QACA,MAAM,GAAG,GAAGE,IAAN,IAAcQ,YAApB;QACA,OAAOR,IAAI,CAACC,IAAL,CAAU,GAAV,EAAeC,IAAf,EAAP;MACD;;IACD;MACE,OAAOL,YAAY,CAACA,YAAY,CAACM,MAAb,GAAsB,CAAvB,CAAZ,CAAsCD,IAAtC,EAAP;EAnCJ;AAqCD;;AAEM,SAASO,4BAAT,CAAsCf,SAAtC,EAAiG;EACtG,IAAI,CAACA,SAAL,EAAgB,OAAO,EAAP;EAChB,MAAMgB,OAAO,GAAGjB,sBAAsB,CAACC,SAAD,CAAtC;EACA,MAAMiB,KAAK,GAAGD,OAAO,CAACZ,KAAR,CAAc,IAAd,CAAd;EACA,OAAOa,KAAK,CAACA,KAAK,CAACR,MAAN,GAAe,CAAhB,CAAL,CAAwBD,IAAxB,EAAP;AACD"}
1
+ {"version":3,"names":["UNRESOLVED","parseTypeFromQuickInfo","quickInfo","body","displayString","splitByColon","split","kind","tail","join","trim","length","firstLine","splitBySpace","typeName","splitByEqual","parseReturnTypeFromQuickInfo","typeStr","array"],"sources":["parse-type-from-quick-info.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n\nexport const UNRESOLVED = '<<unresolved>>';\n\n/**\n * try to parse the type from the quickinfo.\n * this is an error-prone process, we do our best here.\n *\n * an example of a function with many \":\"\n * `export function getObj(a: string, func: (b: number) => {}) { return { a: 1, b: 2 } };`\n * which produce the following quickinfo:\n * ```ts\n * function getObj(a: string, func: (b: number) => {}): {\n * a: number;\n * b: number;\n * }\n * ```\n *\n * some examples of quickinfo:\n *\n * function ts.signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags): SymbolDisplayPart[]\n *\n * const enum ts.TypeFormatFlags\n *\n * (method) ts.TypeChecker.writeSignature(signature: Signature, enclosingDeclaration?: Node | undefined, flags?: TypeFormatFlags | undefined, kind?: SignatureKind | undefined, writer?: EmitTextWriter | undefined): string\n *\n * const obj: {\n * a: number;\n * b: number;\n * }\n *\n * function getObj(a: string): {\n * a: number;\n * b: number;\n * }\n */\nexport function parseTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo?.body?.displayString) return '';\n const displayString = quickInfo.body.displayString;\n const splitByColon = displayString.split(':');\n switch (quickInfo.body.kind) {\n case 'const':\n case 'property':\n case 'let':\n case 'var': {\n const [, ...tail] = splitByColon;\n return tail.join(':').trim();\n }\n case 'method':\n case 'function': {\n const split = displayString.split('): ');\n if (split.length !== 2) {\n // it's hard to determine where the return-type is. so it's better to show unresolved.\n // maybe, in the UI, in this case, it's best to show the signature.\n // e.g.\n // (method) IssuesList.getIssue<T extends ComponentIssue>(IssueClass: {\n // new (): T;\n // }): T | undefined\n return UNRESOLVED;\n }\n return split[1].trim();\n }\n case 'alias': {\n // e.g. (alias) class BuilderService\\nimport BuilderService\n // e.g. '(alias) type Serializable = {\\n' +\n // ' toString(): string;\\n' +\n // '}\\n' +\n // 'import Serializable'\n const firstLine = displayString.split('\\n')[0];\n const splitBySpace = firstLine.trim().split(' ');\n // first two are alias keyword and alias type\n const [, , typeName] = splitBySpace;\n return typeName;\n }\n case 'type': {\n // e.g. `type TaskSlot = SlotRegistry<BuildTask[]>`\n const splitByEqual = displayString.split('=');\n const [, ...tail] = splitByEqual;\n return tail.join('=').trim();\n }\n default:\n return splitByColon[splitByColon.length - 1].trim();\n }\n}\n\nexport function parseReturnTypeFromQuickInfo(quickInfo: protocol.QuickInfoResponse | undefined): string {\n if (!quickInfo) return '';\n const typeStr = parseTypeFromQuickInfo(quickInfo);\n const array = typeStr.split('=>');\n return array[array.length - 1].trim();\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAGO,MAAMA,UAAU,GAAG,gBAAnB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,SAASC,sBAAT,CAAgCC,SAAhC,EAA2F;EAAA;;EAChG,IAAI,EAACA,SAAD,aAACA,SAAD,kCAACA,SAAS,CAAEC,IAAZ,4CAAC,gBAAiBC,aAAlB,CAAJ,EAAqC,OAAO,EAAP;EACrC,MAAMA,aAAa,GAAGF,SAAS,CAACC,IAAV,CAAeC,aAArC;EACA,MAAMC,YAAY,GAAGD,aAAa,CAACE,KAAd,CAAoB,GAApB,CAArB;;EACA,QAAQJ,SAAS,CAACC,IAAV,CAAeI,IAAvB;IACE,KAAK,OAAL;IACA,KAAK,UAAL;IACA,KAAK,KAAL;IACA,KAAK,KAAL;MAAY;QACV,MAAM,GAAG,GAAGC,IAAN,IAAcH,YAApB;QACA,OAAOG,IAAI,CAACC,IAAL,CAAU,GAAV,EAAeC,IAAf,EAAP;MACD;;IACD,KAAK,QAAL;IACA,KAAK,UAAL;MAAiB;QACf,MAAMJ,KAAK,GAAGF,aAAa,CAACE,KAAd,CAAoB,KAApB,CAAd;;QACA,IAAIA,KAAK,CAACK,MAAN,KAAiB,CAArB,EAAwB;UACtB;UACA;UACA;UACA;UACA;UACA;UACA,OAAOX,UAAP;QACD;;QACD,OAAOM,KAAK,CAAC,CAAD,CAAL,CAASI,IAAT,EAAP;MACD;;IACD,KAAK,OAAL;MAAc;QACZ;QACA;QACA;QACA;QACA;QACA,MAAME,SAAS,GAAGR,aAAa,CAACE,KAAd,CAAoB,IAApB,EAA0B,CAA1B,CAAlB;QACA,MAAMO,YAAY,GAAGD,SAAS,CAACF,IAAV,GAAiBJ,KAAjB,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