@teambit/typescript 0.0.748 → 0.0.751

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.
@@ -169,7 +169,7 @@ class SchemaExtractorContext {
169
169
  return await this.tsserver.getQuickInfo(this.getPath(node), location);
170
170
  } catch (err) {
171
171
  if (err.message === 'No content available.') {
172
- throw new Error(`unable to get quickinfo data from tsserver at ${location.file}, Ln ${location.line}, Col ${location.character}`);
172
+ throw new Error(`unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${location.character}`);
173
173
  }
174
174
 
175
175
  throw err;
@@ -1 +1 @@
1
- {"version":3,"names":["SchemaExtractorContext","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","location","err","message","Error","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","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","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","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","getTypeRefForExternalPath","getCompIdByPkgName","dep","packageName","componentId","compIdByPath","getComponentIDByPath","compIdByPkg"],"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 async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${location.file}, Ln ${location.line}, Col ${location.character}`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(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 getSourceFileInsideComponent(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 filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\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.getSourceFileInsideComponent(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.getSourceFileInsideComponent(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 || 'any');\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 return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\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"],"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;;AAIA;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,EAIAC,aAJA,EAKT;IAAA,KAJSH,QAI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QAApC,CAA3B;;IACA,IAAIqG,YAAJ,EAAkB;MAChB,OAAO,KAAInB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCqB,YAArC,CAAP;IACD;;IACD,MAAM3D,OAAO,GAAG,KAAKT,wBAAL,CAA8BjC,QAA9B,CAAhB;IACA,MAAMuG,WAAW,GAAG,KAAKN,kBAAL,CAAwBvD,OAAxB,CAApB;;IACA,IAAI6D,WAAJ,EAAiB;MACf,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCuB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqChG,SAArC,EAAgD0D,OAAhD,CAAP;EACD;;AAzTiC"}
1
+ {"version":3,"names":["SchemaExtractorContext","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","location","err","message","Error","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","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","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","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","getTypeRefForExternalPath","getCompIdByPkgName","dep","packageName","componentId","compIdByPath","getComponentIDByPath","compIdByPkg"],"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 async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${\n location.character\n }`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(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 getSourceFileInsideComponent(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 filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\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.getSourceFileInsideComponent(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.getSourceFileInsideComponent(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 || 'any');\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 return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\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"],"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;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,sB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AkBhF,QAAlB,EAAoCa,QAApC,EAAgF;IAC7G,MAAMwF,YAAY,GAAG,MAAM,KAAKvH,SAAL,CAAewH,oBAAf,CAAoCtG,QAApC,CAA3B;;IACA,IAAIqG,YAAJ,EAAkB;MAChB,OAAO,KAAInB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCqB,YAArC,CAAP;IACD;;IACD,MAAM3D,OAAO,GAAG,KAAKT,wBAAL,CAA8BjC,QAA9B,CAAhB;IACA,MAAMuG,WAAW,GAAG,KAAKN,kBAAL,CAAwBvD,OAAxB,CAApB;;IACA,IAAI6D,WAAJ,EAAiB;MACf,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCuB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqChG,SAArC,EAAgD0D,OAAhD,CAAP;EACD;;AA3TiC"}
@@ -48,7 +48,7 @@ function _jsdocToDocSchema() {
48
48
  }
49
49
 
50
50
  async function toFunctionLikeSchema(node, context, funcName) {
51
- var _node$name, _info$body, _node$modifiers;
51
+ var _node$name, _info$body, _node$modifiers, _node$typeParameters;
52
52
 
53
53
  const name = funcName || ((_node$name = node.name) === null || _node$name === void 0 ? void 0 : _node$name.getText()) || '';
54
54
  const info = node.name ? await context.getQuickInfo(node.name) : null;
@@ -57,9 +57,10 @@ async function toFunctionLikeSchema(node, context, funcName) {
57
57
  const args = await (0, _getParams().getParams)(node.parameters, context);
58
58
  const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
59
59
  const modifiers = ((_node$modifiers = node.modifiers) === null || _node$modifiers === void 0 ? void 0 : _node$modifiers.map(modifier => modifier.getText())) || [];
60
+ const typeParameters = (_node$typeParameters = node.typeParameters) === null || _node$typeParameters === void 0 ? void 0 : _node$typeParameters.map(typeParam => typeParam.name.getText());
60
61
  const location = context.getLocation(node);
61
62
  const doc = await (0, _jsdocToDocSchema().jsDocToDocSchema)(node, context);
62
- return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc);
63
+ return new (_semanticsEntities().FunctionLikeSchema)(location, name, args, returnType, displaySig, modifiers, doc, typeParameters);
63
64
  }
64
65
 
65
66
  //# sourceMappingURL=to-function-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["toFunctionLikeSchema","node","context","funcName","name","getText","info","getQuickInfo","returnTypeStr","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","modifiers","map","modifier","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-schema.ts"],"sourcesContent":["import { SignatureDeclaration } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './jsdoc-to-doc-schema';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const info = node.name ? await context.getQuickInfo(node.name) : null;\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const location = context.getLocation(node);\n const doc = await jsDocToDocSchema(node, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n}\n"],"mappings":";;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAE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","parseTypeFromQuickInfo","displaySig","body","displayString","args","getParams","parameters","returnType","resolveType","Boolean","modifiers","map","modifier","typeParameters","typeParam","location","getLocation","doc","jsDocToDocSchema","FunctionLikeSchema"],"sources":["to-function-schema.ts"],"sourcesContent":["import { SignatureDeclaration } from 'typescript';\nimport { FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './jsdoc-to-doc-schema';\n\nexport async function toFunctionLikeSchema(\n node: SignatureDeclaration,\n context: SchemaExtractorContext,\n funcName?: string\n) {\n const name = funcName || node.name?.getText() || '';\n const info = node.name ? await context.getQuickInfo(node.name) : null;\n const returnTypeStr = info ? parseTypeFromQuickInfo(info) : 'any';\n const displaySig = info?.body?.displayString || '';\n const args = await getParams(node.parameters, context);\n const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));\n const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];\n const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());\n const location = context.getLocation(node);\n const doc = await jsDocToDocSchema(node, context);\n return new FunctionLikeSchema(\n location,\n name,\n args,\n returnType,\n displaySig,\n modifiers as Modifier[],\n doc,\n typeParameters\n );\n}\n"],"mappings":";;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,oBAAf,CACLC,IADK,EAELC,OAFK,EAGLC,QAHK,EAIL;EAAA;;EACA,MAAMC,IAAI,GAAGD,QAAQ,mBAAIF,IAAI,CAACG,IAAT,+CAAI,WAAWC,OAAX,EAAJ,CAAR,IAAoC,EAAjD;EACA,MAAMC,IAAI,GAAGL,IAAI,CAACG,IAAL,GAAY,MAAMF,OAAO,CAACK,YAAR,CAAqBN,IAAI,CAACG,IAA1B,CAAlB,GAAoD,IAAjE;EACA,MAAMI,aAAa,GAAGF,IAAI,GAAG,IAAAG,gDAAA,EAAuBH,IAAvB,CAAH,GAAkC,KAA5D;EACA,MAAMI,UAAU,GAAG,CAAAJ,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEK,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;EACA,MAAMC,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAUb,IAAI,CAACc,UAAf,EAA2Bb,OAA3B,CAAnB;EACA,MAAMc,UAAU,GAAG,MAAMd,OAAO,CAACe,WAAR,CAAoBhB,IAApB,EAA0BO,aAA1B,EAAyCU,OAAO,CAACZ,IAAD,CAAhD,CAAzB;EACA,MAAMa,SAAS,GAAG,oBAAAlB,IAAI,CAACkB,SAAL,oEAAgBC,GAAhB,CAAqBC,QAAD,IAAcA,QAAQ,CAAChB,OAAT,EAAlC,MAAyD,EAA3E;EACA,MAAMiB,cAAc,2BAAGrB,IAAI,CAACqB,cAAR,yDAAG,qBAAqBF,GAArB,CAA0BG,SAAD,IAAeA,SAAS,CAACnB,IAAV,CAAeC,OAAf,EAAxC,CAAvB;EACA,MAAMmB,QAAQ,GAAGtB,OAAO,CAACuB,WAAR,CAAoBxB,IAApB,CAAjB;EACA,MAAMyB,GAAG,GAAG,MAAM,IAAAC,oCAAA,EAAiB1B,IAAjB,EAAuBC,OAAvB,CAAlB;EACA,OAAO,KAAI0B,uCAAJ,EACLJ,QADK,EAELpB,IAFK,EAGLS,IAHK,EAILG,UAJK,EAKLN,UALK,EAMLS,SANK,EAOLO,GAPK,EAQLJ,cARK,CAAP;AAUD"}
@@ -79,7 +79,7 @@ async function typeElementToSchema(node, context) {
79
79
  return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context, 'new');
80
80
 
81
81
  case _typescript().SyntaxKind.CallSignature:
82
- throw new Error(`CallSignature was not implemented yet`);
82
+ return callSignature(node, context);
83
83
 
84
84
  case _typescript().SyntaxKind.PropertySignature:
85
85
  return propertySignature(node, context);
@@ -131,4 +131,8 @@ async function setAccessor(node, context) {
131
131
  return new (_semanticsEntities().SetAccessorSchema)(context.getLocation(node), node.name.getText(), params[0], displaySig);
132
132
  }
133
133
 
134
+ async function callSignature(node, context) {
135
+ return (0, _toFunctionSchema().toFunctionLikeSchema)(node, context);
136
+ }
137
+
134
138
  //# sourceMappingURL=type-element-to-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","Error","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n throw new Error(`CallSignature was not implemented yet`);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableSchema(context.getLocation(node), name, displaySig, type);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA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B7B,IAApB,EAA0B0B,OAA1B,CAAnB;EACA,OAAO,KAAIW,sCAAJ,EAAsBpC,OAAO,CAAC8B,WAAR,CAAoB/B,IAApB,CAAtB,EAAiDA,IAAI,CAACiB,IAAL,CAAUC,OAAV,EAAjD,EAAsEU,IAAtE,EAA4EL,UAA5E,CAAP;AACD;;AAEM,eAAeP,WAAf,CAA2BhB,IAA3B,EAAyDC,OAAzD,EAA0F;EAC/F,MAAM+B,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUjC,IAAI,CAACkC,UAAf,EAA2BjC,OAA3B,CAArB;EACA,MAAMsB,UAAU,GAAG,MAAMtB,OAAO,CAACqC,yBAAR,CAAkCtC,IAAI,CAACiB,IAAvC,CAAzB;EACA,OAAO,KAAIsB,sCAAJ,EAAsBtC,OAAO,CAAC8B,WAAR,CAAoB/B,IAApB,CAAtB,EAAiDA,IAAI,CAACiB,IAAL,CAAUC,OAAV,EAAjD,EAAsEc,MAAM,CAAC,CAAD,CAA5E,EAAiFT,UAAjF,CAAP;AACD"}
1
+ {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n CallSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableSchema(context.getLocation(node), name, displaySig, type);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,mBAAf,CAAmCC,IAAnC,EAAsDC,OAAtD,EAA4G;EACjH,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,eAAhB;MACE,OAAO,IAAAC,wCAAA,EAAqBL,IAArB,EAA8CC,OAA9C,CAAP;;IACF,KAAKE,wBAAA,CAAWG,kBAAhB;MACE,OAAO,IAAAD,wCAAA,EAAqBL,IAArB,EAA4DC,OAA5D,EAAqE,KAArE,CAAP;;IACF,KAAKE,wBAAA,CAAWI,aAAhB;MACE,OAAOC,aAAa,CAACR,IAAD,EAAmCC,OAAnC,CAApB;;IACF,KAAKE,wBAAA,CAAWM,iBAAhB;MACE,OAAOC,iBAAiB,CAACV,IAAD,EAA+BC,OAA/B,CAAxB;;IACF,KAAKE,wBAAA,CAAWQ,cAAhB;MACE,OAAOC,cAAc,CAACZ,IAAD,EAAoCC,OAApC,CAArB;;IACF,KAAKE,wBAAA,CAAWU,WAAhB;MACE,OAAOC,WAAW,CAACd,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWY,WAAhB;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, SourceFile } from 'typescript';
2
2
  import { SchemaExtractor } from '@teambit/schema';
3
3
  import type { Workspace } from '@teambit/workspace';
4
4
  import { DependencyResolverMain } from '@teambit/dependency-resolver';
@@ -15,7 +15,7 @@ export declare class TypeScriptExtractor implements SchemaExtractor {
15
15
  private depResolver;
16
16
  private workspace;
17
17
  constructor(tsconfig: any, schemaTransformerSlot: SchemaTransformerSlot, tsMain: TypescriptMain, rootPath: string, depResolver: DependencyResolverMain, workspace: Workspace | undefined);
18
- parseSourceFile(file: AbstractVinyl): ts.SourceFile;
18
+ parseSourceFile(file: AbstractVinyl): SourceFile;
19
19
  /**
20
20
  * extract a component schema.
21
21
  */
@@ -93,7 +93,13 @@ class TypeScriptExtractor {
93
93
  }
94
94
 
95
95
  parseSourceFile(file) {
96
- return _typescript().default.createSourceFile(file.path, file.contents.toString('utf8'), _typescript().default.ScriptTarget.Latest, true, this.tsconfig.compilerOptions);
96
+ const sourceFile = _typescript().default.createSourceFile(file.path, file.contents.toString('utf8'), _typescript().default.ScriptTarget.Latest, true
97
+ /** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */
98
+ ); // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.
99
+ // console.log("sourceFile Errors", file.path, sourceFile.parseDiagnostics);
100
+
101
+
102
+ return sourceFile;
97
103
  }
98
104
  /**
99
105
  * extract a component schema.
@@ -1 +1 @@
1
- {"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","compilerOptions","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","id","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl) {\n return ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true,\n this.tsconfig.compilerOptions\n );\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as Module;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme, component.id);\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(tsserver: TsserverClient, component: Component): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAqD;EAC1DC,WAAW,CAC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gB,QAAZ;IACD;;IAED,OAAO,KAAKA,QAAZ;EACD;;EAEkB,MAAbW,aAAa,CAACO,IAAD,EAAad,OAAb,EAAmE;IACpF,MAAMe,WAAW,GAAG,KAAKC,cAAL,CAAoBF,IAApB,EAA0Bd,OAA1B,CAApB,CADoF,CAEpF;IACA;;IACA,OAAOe,WAAW,CAACY,SAAZ,CAAsBb,IAAtB,EAA4Bd,OAA5B,CAAP;EACD;;EAEyB,MAApB4B,oBAAoB,CAAC3C,IAAD,EAAe;IACvC,IAAI,CAAC,KAAKH,SAAV,EAAqB;MACnB,OAAO,IAAP;IACD;;IACD,OAAO,KAAKA,SAAL,CAAe+C,oBAAf,CAAoC5C,IAApC,CAAP;EACD;EAED;AACF;AACA;;;EACU+B,cAAc,CAACF,IAAD,EAAad,OAAb,EAA8C;IAClE,MAAM8B,YAAY,GAAG,IAAAC,iBAAA,EAAQ,KAAKrD,qBAAL,CAA2BsD,MAA3B,EAAR,CAArB;IACA,MAAMjB,WAAW,GAAGe,YAAY,CAACG,IAAb,CAAmBC,iBAAD,IAAuBA,iBAAiB,CAACC,SAAlB,CAA4BrB,IAA5B,CAAzC,CAApB;IAEA,IAAI,CAACC,WAAL,EAAkB,MAAM,KAAIG,iCAAJ,EAAwBJ,IAAxB,EAA8Bd,OAAO,CAACL,SAAtC,EAAiDK,OAAO,CAACW,WAAR,CAAoBG,IAApB,CAAjD,CAAN;IAElB,OAAOC,WAAP;EACD;;AAlGyD"}
1
+ {"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","sourceFile","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","extract","component","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","id","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl): SourceFile {\n const sourceFile = ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true\n /** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */\n );\n // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.\n // console.log(\"sourceFile Errors\", file.path, sourceFile.parseDiagnostics);\n return sourceFile;\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as Module;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme, component.id);\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(tsserver: TsserverClient, component: Component): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAKA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;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  "homepage": "https://bit.dev/teambit/typescript/typescript",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.typescript",
8
8
  "name": "typescript",
9
- "version": "0.0.748"
9
+ "version": "0.0.751"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -18,21 +18,21 @@
18
18
  "@babel/runtime": "7.12.18",
19
19
  "core-js": "^3.0.0",
20
20
  "@teambit/harmony": "0.3.3",
21
- "@teambit/compiler": "0.0.748",
21
+ "@teambit/compiler": "0.0.751",
22
22
  "@teambit/typescript.modules.ts-config-mutator": "0.0.68",
23
- "@teambit/component": "0.0.748",
24
- "@teambit/dependency-resolver": "0.0.748",
25
- "@teambit/semantics.entities.semantic-schema": "0.0.16",
23
+ "@teambit/component": "0.0.751",
24
+ "@teambit/dependency-resolver": "0.0.751",
25
+ "@teambit/semantics.entities.semantic-schema": "0.0.17",
26
26
  "@teambit/ts-server": "0.0.32",
27
- "@teambit/aspect-loader": "0.0.748",
27
+ "@teambit/aspect-loader": "0.0.751",
28
28
  "@teambit/bit-error": "0.0.394",
29
- "@teambit/builder": "0.0.748",
30
- "@teambit/isolator": "0.0.748",
31
- "@teambit/logger": "0.0.586",
32
- "@teambit/schema": "0.0.748",
33
- "@teambit/workspace": "0.0.748",
34
- "@teambit/cli": "0.0.493",
35
- "@teambit/pkg": "0.0.748"
29
+ "@teambit/builder": "0.0.751",
30
+ "@teambit/isolator": "0.0.751",
31
+ "@teambit/logger": "0.0.589",
32
+ "@teambit/schema": "0.0.751",
33
+ "@teambit/workspace": "0.0.751",
34
+ "@teambit/cli": "0.0.496",
35
+ "@teambit/pkg": "0.0.751"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash": "4.14.165",
@@ -48,7 +48,7 @@
48
48
  "@teambit/typescript.aspect-docs.typescript": "0.0.138"
49
49
  },
50
50
  "peerDependencies": {
51
- "@teambit/legacy": "1.0.273",
51
+ "@teambit/legacy": "1.0.276",
52
52
  "react-dom": "^16.8.0 || ^17.0.0",
53
53
  "react": "^16.8.0 || ^17.0.0"
54
54
  },
@@ -76,7 +76,7 @@
76
76
  "react": "-"
77
77
  },
78
78
  "peerDependencies": {
79
- "@teambit/legacy": "1.0.273",
79
+ "@teambit/legacy": "1.0.276",
80
80
  "react-dom": "^16.8.0 || ^17.0.0",
81
81
  "react": "^16.8.0 || ^17.0.0"
82
82
  }
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.748/dist/typescript.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.748/dist/typescript.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.751/dist/typescript.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.751/dist/typescript.docs.mdx')]
@@ -17,7 +17,17 @@ export async function toFunctionLikeSchema(
17
17
  const args = await getParams(node.parameters, context);
18
18
  const returnType = await context.resolveType(node, returnTypeStr, Boolean(info));
19
19
  const modifiers = node.modifiers?.map((modifier) => modifier.getText()) || [];
20
+ const typeParameters = node.typeParameters?.map((typeParam) => typeParam.name.getText());
20
21
  const location = context.getLocation(node);
21
22
  const doc = await jsDocToDocSchema(node, context);
22
- return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);
23
+ return new FunctionLikeSchema(
24
+ location,
25
+ name,
26
+ args,
27
+ returnType,
28
+ displaySig,
29
+ modifiers as Modifier[],
30
+ doc,
31
+ typeParameters
32
+ );
23
33
  }
@@ -7,6 +7,7 @@ import ts, {
7
7
  GetAccessorDeclaration,
8
8
  SetAccessorDeclaration,
9
9
  ConstructSignatureDeclaration,
10
+ CallSignatureDeclaration,
10
11
  } from 'typescript';
11
12
  import {
12
13
  GetAccessorSchema,
@@ -28,7 +29,7 @@ export async function typeElementToSchema(node: TypeElement, context: SchemaExtr
28
29
  case SyntaxKind.ConstructSignature:
29
30
  return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');
30
31
  case SyntaxKind.CallSignature:
31
- throw new Error(`CallSignature was not implemented yet`);
32
+ return callSignature(node as CallSignatureDeclaration, context);
32
33
  case SyntaxKind.PropertySignature:
33
34
  return propertySignature(node as ts.PropertySignature, context);
34
35
  case SyntaxKind.IndexSignature:
@@ -70,3 +71,7 @@ export async function setAccessor(node: SetAccessorDeclaration, context: SchemaE
70
71
  const displaySig = await context.getQuickInfoDisplayString(node.name);
71
72
  return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);
72
73
  }
74
+
75
+ async function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {
76
+ return toFunctionLikeSchema(node, context);
77
+ }
package/tsconfig.json CHANGED
@@ -30,7 +30,8 @@
30
30
  "preserveConstEnums": true
31
31
  },
32
32
  "exclude": [
33
- "dist"
33
+ "dist",
34
+ "package.json"
34
35
  ],
35
36
  "include": [
36
37
  "**/*",