@teambit/typescript 0.0.755 → 0.0.758

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.
@@ -17,6 +17,7 @@ export declare class SchemaExtractorContext {
17
17
  * returns the location of a node in a source file.
18
18
  */
19
19
  getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath?: boolean): Location;
20
+ getLocationAsString(node: Node): string;
20
21
  getPathRelativeToComponent(filePath: string): string;
21
22
  /**
22
23
  * returns a signature for a node.
@@ -53,6 +53,16 @@ function _lodash() {
53
53
  return data;
54
54
  }
55
55
 
56
+ function _utils() {
57
+ const data = require("@teambit/legacy/dist/utils");
58
+
59
+ _utils = function () {
60
+ return data;
61
+ };
62
+
63
+ return data;
64
+ }
65
+
56
66
  function _path() {
57
67
  const data = require("path");
58
68
 
@@ -125,13 +135,19 @@ class SchemaExtractorContext {
125
135
  const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
126
136
  const line = position.line + 1;
127
137
  const character = position.character + 1;
138
+ const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);
128
139
  return {
129
- file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),
140
+ filePath: (0, _utils().pathNormalizeToLinux)(filePath),
130
141
  line,
131
142
  character
132
143
  };
133
144
  }
134
145
 
146
+ getLocationAsString(node) {
147
+ const location = this.getLocation(node);
148
+ return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;
149
+ }
150
+
135
151
  getPathRelativeToComponent(filePath) {
136
152
  const basePath = this.component.filesystem.files[0].base;
137
153
  return (0, _path().relative)(basePath, filePath);
@@ -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 ${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,sBAAN,CAA6B;EAClCC,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIAC,aAJA,EAKT;IAAA,KAJSH,QAIT,GAJSA,QAIT;IAAA,KAHSC,SAGT,GAHSA,SAGT;IAAA,KAFSC,SAET,GAFSA,SAET;IAAA,KADSC,aACT,GADSA,aACT;IAAA,kDA6LiCC,SA7LjC;EAAE;;EAEJC,aAAa,CAACC,IAAD,EAAa;IACxB,OAAO,KAAKJ,SAAL,CAAeG,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,GA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IAAIA,IAAJ,EAAU;MACR,IAAIgG,mBAAmB,EAAvB,EAA2B;QACzB,OAAOJ,gBAAgB,EAAvB;MACD;;MACD,MAAMM,UAAU,GAAG,MAAM,KAAKlB,IAAL,CAAUhF,IAAV,EAAgBsD,UAAU,CAACE,KAA3B,CAAzB;MACA,OAAO0C,UAAU,IAAIN,gBAAgB,EAArC;IACD;;IACD,OAAO,KAAKO,yBAAL,CAA+BhB,OAA/B,EAAwC7B,UAAU,CAACtD,IAAnD,EAAyDgB,QAAzD,CAAP;EACD;;EAEOoF,kBAAkB,CAACvD,OAAD,EAA2C;IAAA;;IACnE,gCAAO,KAAK3D,aAAL,CAAmB0C,IAAnB,CAAyByE,GAAD,IAASA,GAAG,CAACC,WAAJ,KAAoBzD,OAArD,CAAP,0DAAO,sBAA+D0D,WAAtE;EACD;;EAE8B,MAAzBJ,yBAAyB,CAAChB,OAAD,EAAkBhF,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"}
1
+ {"version":3,"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","componentDeps","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","filePath","fileName","getPathRelativeToComponent","pathNormalizeToLinux","getLocationAsString","location","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","file","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 { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\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 const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);\n\n return {\n filePath: pathNormalizeToLinux(filePath),\n line,\n character,\n };\n }\n\n getLocationAsString(node: Node): string {\n const location = this.getLocation(node);\n return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;\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;;AACA;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,QAIT,GAJSA,QAIT;IAAA,KAHSC,SAGT,GAHSA,SAGT;IAAA,KAFSC,SAET,GAFSA,SAET;IAAA,KADSC,aACT,GADSA,aACT;IAAA,kDAmMiCC,SAnMjC;EAAE;;EAEJC,aAAa,CAACC,IAAD,EAAa;IACxB,OAAO,KAAKJ,SAAL,CAAeG,aAAf,CAA6BC,IAA7B,EAAmC,IAAnC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Y,GAAG,MAAM,KAAKzH,SAAL,CAAe0H,oBAAf,CAAoC3G,QAApC,CAA3B;;IACA,IAAI0G,YAAJ,EAAkB;MAChB,OAAO,KAAInB,kCAAJ,EAAkBlF,QAAlB,EAA4BgF,OAA5B,EAAqCqB,YAArC,CAAP;IACD;;IACD,MAAM3D,OAAO,GAAG,KAAKT,wBAAL,CAA8BtC,QAA9B,CAAhB;IACA,MAAM4G,WAAW,GAAG,KAAKN,kBAAL,CAAwBvD,OAAxB,CAApB;;IACA,IAAI6D,WAAJ,EAAiB;MACf,OAAO,KAAIrB,kCAAJ,EAAkBlF,QAAlB,EAA4BgF,OAA5B,EAAqCuB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBlF,QAAlB,EAA4BgF,OAA5B,EAAqClG,SAArC,EAAgD4D,OAAhD,CAAP;EACD;;AAjUiC"}
@@ -1,5 +1,5 @@
1
1
  import { BindingElement, Node } from 'typescript';
2
- import { VariableSchema } from '@teambit/semantics.entities.semantic-schema';
2
+ import { VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';
3
3
  import { SchemaTransformer } from '../schema-transformer';
4
4
  import { SchemaExtractorContext } from '../schema-extractor-context';
5
5
  import { ExportIdentifier } from '../export-identifier';
@@ -13,5 +13,5 @@ import { ExportIdentifier } from '../export-identifier';
13
13
  export declare class BindingElementTransformer implements SchemaTransformer {
14
14
  predicate(node: Node): boolean;
15
15
  getIdentifiers(node: BindingElement): Promise<ExportIdentifier[]>;
16
- transform(node: BindingElement, context: SchemaExtractorContext): Promise<VariableSchema>;
16
+ transform(node: BindingElement, context: SchemaExtractorContext): Promise<VariableLikeSchema>;
17
17
  }
@@ -73,7 +73,7 @@ class BindingElementTransformer {
73
73
  const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
74
74
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
75
75
  const type = await context.resolveType(node, typeStr);
76
- return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type, false);
76
+ return new (_semanticsEntities().VariableLikeSchema)(context.getLocation(node), name, displaySig, type, false);
77
77
  }
78
78
 
79
79
  }
@@ -1 +1 @@
1
- {"version":3,"names":["BindingElementTransformer","predicate","node","kind","ts","SyntaxKind","BindingElement","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","context","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation"],"sources":["binding-element.ts"],"sourcesContent":["import ts, { BindingElement, Node } from 'typescript';\nimport { VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\n/**\n * for example:\n *\n * const objBindingElem = { elem1: 1, elem2: 2 };\n * const { elem1 } = objBindingElem;\n * export { elem1 };\n */\nexport class BindingElementTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.BindingElement;\n }\n\n async getIdentifiers(node: BindingElement) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(node: BindingElement, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableSchema(context.getLocation(node), name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,yBAAN,CAA6D;EAClEC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,cAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAAuB;IACzC,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACX,IAAD,EAAuBY,OAAvB,EAAwD;IAAA;;IACrE,MAAML,IAAI,GAAGP,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAb;IACA,MAAMK,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBd,IAAI,CAACO,IAA1B,CAAnB;IACA,MAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBN,IAAvB,CAAhB;IACA,MAAMO,IAAI,GAAG,MAAMR,OAAO,CAACS,WAAR,CAAoBrB,IAApB,EAA0BkB,OAA1B,CAAnB;IACA,OAAO,KAAII,mCAAJ,EAAmBV,OAAO,CAACW,WAAR,CAAoBvB,IAApB,CAAnB,EAA8CO,IAA9C,EAAoDQ,UAApD,EAAgEK,IAAhE,EAAsE,KAAtE,CAAP;EACD;;AAhBiE"}
1
+ {"version":3,"names":["BindingElementTransformer","predicate","node","kind","ts","SyntaxKind","BindingElement","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","transform","context","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableLikeSchema","getLocation"],"sources":["binding-element.ts"],"sourcesContent":["import ts, { BindingElement, Node } from 'typescript';\nimport { VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\n/**\n * for example:\n *\n * const objBindingElem = { elem1: 1, elem2: 2 };\n * const { elem1 } = objBindingElem;\n * export { elem1 };\n */\nexport class BindingElementTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.BindingElement;\n }\n\n async getIdentifiers(node: BindingElement) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(node: BindingElement, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,yBAAN,CAA6D;EAClEC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,cAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAAuB;IACzC,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEc,MAATC,SAAS,CAACX,IAAD,EAAuBY,OAAvB,EAAwD;IAAA;;IACrE,MAAML,IAAI,GAAGP,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAb;IACA,MAAMK,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBd,IAAI,CAACO,IAA1B,CAAnB;IACA,MAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBN,IAAvB,CAAhB;IACA,MAAMO,IAAI,GAAG,MAAMR,OAAO,CAACS,WAAR,CAAoBrB,IAApB,EAA0BkB,OAA1B,CAAnB;IACA,OAAO,KAAII,uCAAJ,EAAuBV,OAAO,CAACW,WAAR,CAAoBvB,IAApB,CAAvB,EAAkDO,IAAlD,EAAwDQ,UAAxD,EAAoEK,IAApE,EAA0E,KAA1E,CAAP;EACD;;AAhBiE"}
@@ -19,16 +19,6 @@ function _semanticsEntities() {
19
19
  return data;
20
20
  }
21
21
 
22
- function _lodash() {
23
- const data = require("lodash");
24
-
25
- _lodash = function () {
26
- return data;
27
- };
28
-
29
- return data;
30
- }
31
-
32
22
  function _typescript() {
33
23
  const data = _interopRequireWildcard(require("typescript"));
34
24
 
@@ -100,46 +90,69 @@ class ExportDeclaration {
100
90
 
101
91
 
102
92
  if (exportClause.kind === _typescript().SyntaxKind.NamedExports) {
103
- exportClause;
104
- const schemas = await Promise.all(exportClause.elements.map(async element => {
105
- return context.visitDefinition(element.name);
106
- }));
107
- return new (_semanticsEntities().Module)(context.getLocation(exportDec), (0, _lodash().compact)(schemas));
93
+ const schemas = await namedExport(exportClause, context);
94
+ return new (_semanticsEntities().Module)(context.getLocation(exportDec), schemas);
108
95
  } // e.g. `export * as Composition from './button';
109
96
 
110
97
 
111
98
  if (exportClause.kind === _typescript().SyntaxKind.NamespaceExport) {
112
- exportClause;
113
- const namespace = exportClause.name.getText();
114
- const filePath = await context.getFilePathByNode(exportClause.name);
99
+ return namespaceExport(exportClause, exportDec, context);
100
+ } // should never reach here. exportClause can be either NamespaceExport or NamedExports
115
101
 
116
- if (!filePath) {
117
- throw new Error(`unable to find the file-path for "${namespace}"`);
118
- }
119
102
 
120
- const sourceFile = context.getSourceFileInsideComponent(filePath);
103
+ throw new Error(`unrecognized exportClause type`);
104
+ }
121
105
 
122
- if (!sourceFile) {
123
- // it's a namespace from another component or an external package.
124
- return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
125
- }
106
+ }
126
107
 
127
- const result = await context.computeSchema(sourceFile);
108
+ exports.ExportDeclaration = ExportDeclaration;
128
109
 
129
- if (!(result instanceof _semanticsEntities().Module)) {
130
- throw new Error(`expect result to be instance of Module`);
131
- }
110
+ async function namedExport(exportClause, context) {
111
+ const schemas = await Promise.all(exportClause.elements.map(async element => {
112
+ const definitionNode = await context.definition(element.name);
132
113
 
133
- result.namespace = namespace;
134
- return result;
135
- } // should never reach here. exportClause can be either NamespaceExport or NamedExports
114
+ if (!definitionNode) {
115
+ // happens for example when the main index.ts file exports variable from an mdx file.
116
+ // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
117
+ return new (_semanticsEntities().UnresolvedSchema)(context.getLocation(element.name), element.name.getText());
118
+ }
136
119
 
120
+ if (definitionNode.parent.kind === _typescript().SyntaxKind.ExportSpecifier) {
121
+ // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
122
+ // normally, "bit install" should fix it. another option is to open vscode and look for errors.
123
+ throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(element.name)}.
124
+ make sure "bit status" is clean and there are no errors about missing packages/links.
125
+ also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
126
+ }
137
127
 
138
- throw new Error(`unrecognized exportClause type`);
128
+ return context.computeSchema(definitionNode.parent);
129
+ }));
130
+ return schemas;
131
+ }
132
+
133
+ async function namespaceExport(exportClause, exportDec, context) {
134
+ const namespace = exportClause.name.getText();
135
+ const filePath = await context.getFilePathByNode(exportClause.name);
136
+
137
+ if (!filePath) {
138
+ throw new Error(`unable to find the file-path for "${namespace}"`);
139
139
  }
140
140
 
141
- }
141
+ const sourceFile = context.getSourceFileInsideComponent(filePath);
142
142
 
143
- exports.ExportDeclaration = ExportDeclaration;
143
+ if (!sourceFile) {
144
+ // it's a namespace from another component or an external package.
145
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
146
+ }
147
+
148
+ const result = await context.computeSchema(sourceFile);
149
+
150
+ if (!(result instanceof _semanticsEntities().Module)) {
151
+ throw new Error(`expect result to be instance of Module`);
152
+ }
153
+
154
+ result.namespace = namespace;
155
+ return result;
156
+ }
144
157
 
145
158
  //# sourceMappingURL=export-declaration.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","Promise","all","element","visitDefinition","Module","getLocation","compact","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import { SchemaNode, Module } from '@teambit/semantics.entities.semantic-schema';\nimport { compact } from 'lodash';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n exportClause as NamedExports;\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return context.visitDefinition(element.name);\n })\n );\n\n return new Module(context.getLocation(exportDec), compact(schemas));\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n exportClause as NamespaceExport;\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;A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iC,yBAAR,CAAkCJ,SAAlC,EAA6CC,QAA7C,EAAuD9B,OAAO,CAAC2B,WAAR,CAAoB5B,SAApB,CAAvD,CAAP;MACD;;MACD,MAAMmC,MAAM,GAAG,MAAMlC,OAAO,CAACoB,aAAR,CAAsBF,UAAtB,CAArB;;MACA,IAAI,EAAEgB,MAAM,YAAYR,2BAApB,CAAJ,EAAiC;QAC/B,MAAM,IAAIT,KAAJ,CAAW,wCAAX,CAAN;MACD;;MACDiB,MAAM,CAACL,SAAP,GAAmBA,SAAnB;MACA,OAAOK,MAAP;IACD,CA9CqG,CAgDtG;;;IACA,MAAM,IAAIjB,KAAJ,CAAW,gCAAX,CAAN;EACD;;AA1EyD"}
1
+ {"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","namedExport","Module","getLocation","namespaceExport","Promise","all","element","definitionNode","definition","UnresolvedSchema","parent","ExportSpecifier","getLocationAsString","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import { SchemaNode, Module, UnresolvedSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n const schemas = await namedExport(exportClause, context);\n return new Module(context.getLocation(exportDec), schemas);\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n return namespaceExport(exportClause, exportDec, context);\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n const definitionNode = await context.definition(element.name);\n if (!definitionNode) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {\n // the definition node is the same node as element.name. tsserver wasn't able to find the source for it\n // normally, \"bit install\" should fix it. another option is to open vscode and look for errors.\n throw new Error(`error: tsserver is unable to locate the identifier \"${element.name.getText()}\" at ${context.getLocationAsString(\n element.name\n )}.\nmake sure \"bit status\" is clean and there are no errors about missing packages/links.\nalso, make sure the tsconfig.json in the root has the \"jsx\" setting defined.`);\n }\n return context.computeSchema(definitionNode.parent);\n })\n );\n\n return schemas;\n}\n\nasync function namespaceExport(\n exportClause: NamespaceExport,\n exportDec: ExportDeclarationNode,\n context: SchemaExtractorContext\n) {\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,wBAAA,CAAWJ,iBAAhC;EACD;;EAEmB,MAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;IAAA;;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,qBAAA,CAAGL,UAAH,CAAcM,YAAnD,EAAiE;MAC/DJ,SAAS,CAACE,YAAV;MACA,OAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;QAClD,OAAO,KAAIC,oCAAJ,EAAqBD,GAAG,CAACE,IAAJ,CAASC,OAAT,EAArB,EAAyCH,GAAG,CAACI,aAAJ,GAAoBC,QAA7D,CAAP;MACD,CAFM,CAA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AvB;;EACA,IAAI,CAAC4B,QAAL,EAAe;IACb,MAAM,IAAInB,KAAJ,CAAW,qCAAoCkB,SAAU,GAAzD,CAAN;EACD;;EACD,MAAMjB,UAAU,GAAGlB,OAAO,CAACsC,4BAAR,CAAqCF,QAArC,CAAnB;;EACA,IAAI,CAAClB,UAAL,EAAiB;IACf;IACA,OAAOlB,OAAO,CAACuC,yBAAR,CAAkCJ,SAAlC,EAA6CC,QAA7C,EAAuDpC,OAAO,CAACwB,WAAR,CAAoBzB,SAApB,CAAvD,CAAP;EACD;;EACD,MAAMyC,MAAM,GAAG,MAAMxC,OAAO,CAACoB,aAAR,CAAsBF,UAAtB,CAArB;;EACA,IAAI,EAAEsB,MAAM,YAAYjB,2BAApB,CAAJ,EAAiC;IAC/B,MAAM,IAAIN,KAAJ,CAAW,wCAAX,CAAN;EACD;;EACDuB,MAAM,CAACL,SAAP,GAAmBA,SAAnB;EACA,OAAOK,MAAP;AACD"}
@@ -113,7 +113,7 @@ async function propertyDeclaration(node, context) {
113
113
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
114
114
  const type = await context.resolveType(node, typeStr);
115
115
  const isOptional = Boolean(node.questionToken);
116
- return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig || '', type, isOptional);
116
+ return new (_semanticsEntities().VariableLikeSchema)(context.getLocation(node), name, displaySig || '', type, isOptional);
117
117
  }
118
118
 
119
119
  async function methodDeclaration(node, context) {
@@ -1 +1 @@
1
- {"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","ConstructorSchema","getLocation","name","getText","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableSchema","toFunctionLikeSchema"],"sources":["class-element-to-schema.ts"],"sourcesContent":["import {\n ClassElement,\n ConstructorDeclaration,\n GetAccessorDeclaration,\n IndexSignatureDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n SetAccessorDeclaration,\n SyntaxKind,\n} from 'typescript';\nimport { ConstructorSchema, SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\n\nexport async function classElementToSchema(\n node: ClassElement,\n context: SchemaExtractorContext\n): Promise<SchemaNode | null> {\n switch (node.kind) {\n case SyntaxKind.Constructor:\n return constructor(node as ConstructorDeclaration, context);\n case SyntaxKind.PropertyDeclaration:\n return propertyDeclaration(node as PropertyDeclaration, context);\n case SyntaxKind.MethodDeclaration:\n return methodDeclaration(node as MethodDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need\n case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon\n return null;\n default:\n // should never be here unless typescript added new class elements\n throw new Error(`unrecognized ClassElement type. got ${node.kind}`);\n }\n}\n\nasync function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await getParams(node.parameters, context);\n return new ConstructorSchema(context.getLocation(node), args);\n}\n\nasync function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString;\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n\n return new VariableSchema(context.getLocation(node), name, displaySig || '', type, isOptional);\n}\n\nasync function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,oBAAf,CACLC,IADK,EAELC,OAFK,EAGuB;EAC5B,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,WAAhB;MACE,OAAOC,WAAW,CAACL,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWG,mBAAhB;MACE,OAAOC,mBAAmB,CAACP,IAAD,EAA8BC,OAA9B,CAA1B;;IACF,KAAKE,wBAAA,CAAWK,iBAAhB;MACE,OAAOC,iBAAiB,CAACT,IAAD,EAA4BC,OAA5B,CAAxB;;IACF,KAAKE,wBAAA,CAAWO,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYX,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWS,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYb,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWW,cAAhB;MACE,OAAO,IAAAC,qCAAA,EAAef,IAAf,EAAkDC,OAAlD,CAAP;;IACF,KAAKE,wBAAA,CAAWa,2BAAhB,CAbF,CAa+C;;IAC7C,KAAKb,wBAAA,CAAWc,qBAAhB;MAAuC;MACrC,OAAO,IAAP;;IACF;MACE;MACA,MAAM,IAAIC,KAAJ,CAAW,uCAAsClB,IAAI,CAACE,IAAK,EAA3D,CAAN;EAlBJ;AAoBD;;AAED,eAAeG,WAAf,CAA2BL,IAA3B,EAAyDC,OAAzD,EAA0F;EACxF,MAAMkB,IAAI,GAAG,MAAM,IAAAC,sBAAA,EAAUpB,IAAI,CAACqB,UAAf,EAA2BpB,OAA3B,CAAnB;EACA,OAAO,KAAIqB,sCAAJ,EAAsBrB,OAAO,CAACsB,WAAR,CAAoBvB,IAApB,CAAtB,EAAiDmB,IAAjD,CAAP;AACD;;AAED,eAAeZ,mBAAf,CAAmCP,IAAnC,EAA8DC,OAA9D,EAA+F;EAAA;;EAC7F,MAAMuB,IAAI,GAAGxB,IAAI,CAACwB,IAAL,CAAUC,OAAV,EAAb;EACA,MAAMC,IAAI,GAAG,MAAMzB,OAAO,CAAC0B,YAAR,CAAqB3B,IAAI,CAACwB,IAA1B,CAAnB;EACA,MAAMI,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;EACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBN,IAAvB,CAAhB;EACA,MAAMO,IAAI,GAAG,MAAMhC,OAAO,CAACiC,WAAR,CAAoBlC,IAApB,EAA0B+B,OAA1B,CAAnB;EACA,MAAMI,UAAU,GAAGC,OAAO,CAACpC,IAAI,CAACqC,aAAN,CAA1B;EAEA,OAAO,KAAIC,mCAAJ,EAAmBrC,OAAO,CAACsB,WAAR,CAAoBvB,IAApB,CAAnB,EAA8CwB,IAA9C,EAAoDI,UAAU,IAAI,EAAlE,EAAsEK,IAAtE,EAA4EE,UAA5E,CAAP;AACD;;AAED,eAAe1B,iBAAf,CAAiCT,IAAjC,EAA0DC,OAA1D,EAA2F;EACzF,OAAO,IAAAsC,4CAAA,EAAqBvC,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
1
+ {"version":3,"names":["classElementToSchema","node","context","kind","SyntaxKind","Constructor","constructor","PropertyDeclaration","propertyDeclaration","MethodDeclaration","methodDeclaration","GetAccessor","getAccessor","SetAccessor","setAccessor","IndexSignature","indexSignature","ClassStaticBlockDeclaration","SemicolonClassElement","Error","args","getParams","parameters","ConstructorSchema","getLocation","name","getText","info","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableLikeSchema","toFunctionLikeSchema"],"sources":["class-element-to-schema.ts"],"sourcesContent":["import {\n ClassElement,\n ConstructorDeclaration,\n GetAccessorDeclaration,\n IndexSignatureDeclaration,\n MethodDeclaration,\n PropertyDeclaration,\n SetAccessorDeclaration,\n SyntaxKind,\n} from 'typescript';\nimport { ConstructorSchema, SchemaNode, VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\nimport { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\n\nexport async function classElementToSchema(\n node: ClassElement,\n context: SchemaExtractorContext\n): Promise<SchemaNode | null> {\n switch (node.kind) {\n case SyntaxKind.Constructor:\n return constructor(node as ConstructorDeclaration, context);\n case SyntaxKind.PropertyDeclaration:\n return propertyDeclaration(node as PropertyDeclaration, context);\n case SyntaxKind.MethodDeclaration:\n return methodDeclaration(node as MethodDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.ClassStaticBlockDeclaration: // not sure what is it, but the name sounds like not something we need\n case SyntaxKind.SemicolonClassElement: // seems to be just a semicolon\n return null;\n default:\n // should never be here unless typescript added new class elements\n throw new Error(`unrecognized ClassElement type. got ${node.kind}`);\n }\n}\n\nasync function constructor(node: ConstructorDeclaration, context: SchemaExtractorContext) {\n const args = await getParams(node.parameters, context);\n return new ConstructorSchema(context.getLocation(node), args);\n}\n\nasync function propertyDeclaration(node: PropertyDeclaration, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString;\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n\n return new VariableLikeSchema(context.getLocation(node), name, displaySig || '', type, isOptional);\n}\n\nasync function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAUA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,oBAAf,CACLC,IADK,EAELC,OAFK,EAGuB;EAC5B,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,WAAhB;MACE,OAAOC,WAAW,CAACL,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWG,mBAAhB;MACE,OAAOC,mBAAmB,CAACP,IAAD,EAA8BC,OAA9B,CAA1B;;IACF,KAAKE,wBAAA,CAAWK,iBAAhB;MACE,OAAOC,iBAAiB,CAACT,IAAD,EAA4BC,OAA5B,CAAxB;;IACF,KAAKE,wBAAA,CAAWO,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYX,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWS,WAAhB;MACE,OAAO,IAAAC,kCAAA,EAAYb,IAAZ,EAA4CC,OAA5C,CAAP;;IACF,KAAKE,wBAAA,CAAWW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hF,CAAP;AACD;;AAED,eAAe1B,iBAAf,CAAiCT,IAAjC,EAA0DC,OAA1D,EAA2F;EACzF,OAAO,IAAAsC,4CAAA,EAAqBvC,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
@@ -107,7 +107,7 @@ async function propertySignature(node, context) {
107
107
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
108
108
  const type = await context.resolveType(node, typeStr);
109
109
  const isOptional = Boolean(node.questionToken);
110
- return new (_semanticsEntities().VariableSchema)(context.getLocation(node), name, displaySig, type, isOptional);
110
+ return new (_semanticsEntities().VariableLikeSchema)(context.getLocation(node), name, displaySig, type, isOptional);
111
111
  }
112
112
 
113
113
  async function indexSignature(node, context) {
@@ -1 +1 @@
1
- {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableSchema","getLocation","params","getParams","parameters","typeNodeToSchema","IndexSignatureSchema","GetAccessorSchema","getQuickInfoDisplayString","SetAccessorSchema"],"sources":["type-element-to-schema.ts"],"sourcesContent":["import ts, {\n SyntaxKind,\n TypeElement,\n MethodSignature,\n isComputedPropertyName,\n IndexSignatureDeclaration,\n GetAccessorDeclaration,\n SetAccessorDeclaration,\n ConstructSignatureDeclaration,\n CallSignatureDeclaration,\n} from 'typescript';\nimport {\n GetAccessorSchema,\n IndexSignatureSchema,\n SchemaNode,\n SetAccessorSchema,\n VariableSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n return new VariableSchema(context.getLocation(node), name, displaySig, type, isOptional);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,mBAAf,CAAmCC,IAAnC,EAAsDC,OAAtD,EAA4G;EACjH,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,eAAhB;MACE,OAAO,IAAAC,4CAAA,EAAqBL,IAArB,EAA8CC,OAA9C,CAAP;;IACF,KAAKE,wBAAA,CAAWG,kBAAhB;MACE,OAAO,IAAAD,4CAAA,EAAqBL,IAArB,EAA4DC,OAA5D,EAAqE,KAArE,CAAP;;IACF,KAAKE,wBAAA,CAAWI,aAAhB;MACE,OAAOC,aAAa,CAACR,IAAD,EAAmCC,OAAnC,CAApB;;IACF,KAAKE,wBAAA,CAAWM,iBAAhB;MACE,OAAOC,iBAAiB,CAACV,IAAD,EAA+BC,OAA/B,CAAxB;;IACF,KAAKE,wBAAA,CAAWQ,cAAhB;MACE,OAAOC,cAAc,CAACZ,IAAD,EAAoCC,OAApC,CAArB;;IACF,KAAKE,wBAAA,CAAWU,WAAhB;MACE,OAAOC,WAAW,CAACd,IAAD,EAAiCC,OAAjC,CAAlB;;IACF,KAAKE,wBAAA,CAAWY,WAAhB;MACE,OAAOC,WAAW,CAAChB,IAAD,EAAiCC,OAAjC,CAAlB;;IACF;MACE,MAAM,IAAIgB,KAAJ,CAAW,qDAAoDjB,IAAI,CAACE,IAAK,EAAzE,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OAAzD,EAA0F;EAAA;;EAC/F,MAAMmB,IAAI,GAAG,MAAMnB,OAAO,CAACsB,YAAR,CAAqBvB,IAAI,CAACkB,IAA1B,CAAnB;EACA,MAAMM,UAAU,GAAG,CAAAJ,IAAI,SAAJ,IAAAA,IAAI,WAAJ,2BAAAA,IAAI,CAAEK,IAAN,4DAAYC,aAAZ,KAA6B,EAAhD;EACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBR,IAAvB,CAAhB;EACA,MAAMS,IAAI,GAAG,MAAM5B,OAAO,CAAC6B,WAAR,CAAoB9B,IAApB,EAA0B2B,OAA1B,CAAnB;EACA,OAAO,KAAIc,sCAAJ,EAAsBxC,OAAO,CAACkC,WAAR,CAAoBnC,IAApB,CAAtB,EAAiDA,IAAI,CAACkB,IAAL,CAAUC,OAAV,EAAjD,EAAsEU,IAAtE,EAA4EL,UAA5E,CAAP;AACD;;AAEM,eAAeR,WAAf,CAA2BhB,IAA3B,EAAyDC,OAAzD,EAA0F;EAC/F,MAAMmC,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUrC,IAAI,CAACsC,UAAf,EAA2BrC,OAA3B,CAArB;EACA,MAAMuB,UAAU,GAAG,MAAMvB,OAAO,CAACyC,yBAAR,CAAkC1C,IAAI,CAACkB,IAAvC,CAAzB;EACA,OAAO,KAAIyB,sCAAJ,EAAsB1C,OAAO,CAACkC,WAAR,CAAoBnC,IAApB,CAAtB,EAAiDA,IAAI,CAACkB,IAAL,CAAUC,OAAV,EAAjD,EAAsEiB,MAAM,CAAC,CAAD,CAA5E,EAAiFZ,UAAjF,CAAP;AACD;;AAED,eAAehB,aAAf,CAA6BR,IAA7B,EAA6DC,OAA7D,EAA8F;EAC5F,OAAO,IAAAI,4CAAA,EAAqBL,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
1
+ {"version":3,"names":["typeElementToSchema","node","context","kind","SyntaxKind","MethodSignature","toFunctionLikeSchema","ConstructSignature","CallSignature","callSignature","PropertySignature","propertySignature","IndexSignature","indexSignature","GetAccessor","getAccessor","SetAccessor","setAccessor","Error","name","getText","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","isOptional","Boolean","questionToken","VariableLikeSchema","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 VariableLikeSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { toFunctionLikeSchema } from './to-function-like-schema';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './parse-type-from-quick-info';\nimport { typeNodeToSchema } from './type-node-to-schema';\nimport { getParams } from './get-params';\n\nexport async function typeElementToSchema(node: TypeElement, context: SchemaExtractorContext): Promise<SchemaNode> {\n switch (node.kind) {\n case SyntaxKind.MethodSignature:\n return toFunctionLikeSchema(node as MethodSignature, context);\n case SyntaxKind.ConstructSignature:\n return toFunctionLikeSchema(node as ConstructSignatureDeclaration, context, 'new');\n case SyntaxKind.CallSignature:\n return callSignature(node as CallSignatureDeclaration, context);\n case SyntaxKind.PropertySignature:\n return propertySignature(node as ts.PropertySignature, context);\n case SyntaxKind.IndexSignature:\n return indexSignature(node as IndexSignatureDeclaration, context);\n case SyntaxKind.GetAccessor:\n return getAccessor(node as GetAccessorDeclaration, context);\n case SyntaxKind.SetAccessor:\n return setAccessor(node as SetAccessorDeclaration, context);\n default:\n throw new Error(`typeElementToSchema expect type-element node. got ${node.kind}`);\n }\n}\n\nasync function propertySignature(node: ts.PropertySignature, context: SchemaExtractorContext) {\n const name = node.name.getText();\n const info = isComputedPropertyName(node.name) ? undefined : await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n const isOptional = Boolean(node.questionToken);\n return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, isOptional);\n}\n\nexport async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const type = await typeNodeToSchema(node.type, context);\n return new IndexSignatureSchema(context.getLocation(node), params, type);\n}\n\nexport async function getAccessor(node: GetAccessorDeclaration, context: SchemaExtractorContext) {\n const info = await context.getQuickInfo(node.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(node, typeStr);\n return new GetAccessorSchema(context.getLocation(node), node.name.getText(), type, displaySig);\n}\n\nexport async function setAccessor(node: SetAccessorDeclaration, context: SchemaExtractorContext) {\n const params = await getParams(node.parameters, context);\n const displaySig = await context.getQuickInfoDisplayString(node.name);\n return new SetAccessorSchema(context.getLocation(node), node.name.getText(), params[0], displaySig);\n}\n\nasync function callSignature(node: CallSignatureDeclaration, context: SchemaExtractorContext) {\n return toFunctionLikeSchema(node, context);\n}\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAWA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAOA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,eAAeA,mBAAf,CAAmCC,IAAnC,EAAsDC,OAAtD,EAA4G;EACjH,QAAQD,IAAI,CAACE,IAAb;IACE,KAAKC,wBAAA,CAAWC,eAAhB;MACE,OAAO,IAAA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D;;AAEM,eAAeR,WAAf,CAA2BhB,IAA3B,EAAyDC,OAAzD,EAA0F;EAC/F,MAAMmC,MAAM,GAAG,MAAM,IAAAC,sBAAA,EAAUrC,IAAI,CAACsC,UAAf,EAA2BrC,OAA3B,CAArB;EACA,MAAMuB,UAAU,GAAG,MAAMvB,OAAO,CAACyC,yBAAR,CAAkC1C,IAAI,CAACkB,IAAvC,CAAzB;EACA,OAAO,KAAIyB,sCAAJ,EAAsB1C,OAAO,CAACkC,WAAR,CAAoBnC,IAApB,CAAtB,EAAiDA,IAAI,CAACkB,IAAL,CAAUC,OAAV,EAAjD,EAAsEiB,MAAM,CAAC,CAAD,CAA5E,EAAiFZ,UAAjF,CAAP;AACD;;AAED,eAAehB,aAAf,CAA6BR,IAA7B,EAA6DC,OAA7D,EAA8F;EAC5F,OAAO,IAAAI,4CAAA,EAAqBL,IAArB,EAA2BC,OAA3B,CAAP;AACD"}
@@ -103,7 +103,7 @@ class VariableDeclaration {
103
103
 
104
104
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
105
105
  const type = await context.resolveType(varDec, typeStr);
106
- return new (_semanticsEntities().VariableSchema)(location, name, displaySig, type, false);
106
+ return new (_semanticsEntities().VariableLikeSchema)(location, name, displaySig, type, false);
107
107
  }
108
108
 
109
109
  }
@@ -1 +1 @@
1
- {"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableSchema(location, name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;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AM,CAACkB,SAAP,wEAAkBC,GAAlB,CAAuBC,QAAD,IAAcA,QAAQ,CAAC1B,OAAT,EAApC,MAA2D,EAA7E;MACA,MAAM2B,GAAG,GAAG,MAAM,IAAAC,oCAAA,EAAiBtB,MAAjB,EAAyBC,OAAzB,CAAlB;MACA,OAAO,KAAIsB,uCAAJ,EAAuBhB,QAAvB,EAAiCd,IAAjC,EAAuCkB,IAAvC,EAA6CK,UAA7C,EAAyDZ,UAAzD,EAAqEc,SAArE,EAA8FG,GAA9F,CAAP;IACD;;IACD,MAAMP,OAAO,GAAG,IAAAU,gDAAA,EAAuBtB,IAAvB,CAAhB;IACA,MAAMuB,IAAI,GAAG,MAAMxB,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAnB;IACA,OAAO,KAAIY,mCAAJ,EAAmBnB,QAAnB,EAA6Bd,IAA7B,EAAmCW,UAAnC,EAA+CqB,IAA/C,EAAqD,KAArD,CAAP;EACD;;AA7B2D"}
1
+ {"version":3,"names":["VariableDeclaration","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","ExportIdentifier","getSourceFile","fileName","transform","varDec","context","info","getQuickInfo","displaySig","body","displayString","location","getLocation","initializer","ArrowFunction","args","getParams","parameters","typeStr","parseReturnTypeFromQuickInfo","returnType","resolveType","modifiers","map","modifier","doc","jsDocToDocSchema","FunctionLikeSchema","parseTypeFromQuickInfo","type","VariableLikeSchema"],"sources":["variable-declaration.ts"],"sourcesContent":["import {\n SchemaNode,\n VariableLikeSchema,\n FunctionLikeSchema,\n Modifier,\n} from '@teambit/semantics.entities.semantic-schema';\nimport ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { getParams } from './utils/get-params';\nimport { parseReturnTypeFromQuickInfo, parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { jsDocToDocSchema } from './utils/jsdoc-to-doc-schema';\n\nexport class VariableDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.VariableDeclaration;\n }\n\n getName(node: VariableDeclarationNode) {\n return node.name.getText();\n }\n\n async getIdentifiers(node: VariableDeclarationNode) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n async transform(varDec: VariableDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(varDec);\n const info = await context.getQuickInfo(varDec.name);\n const displaySig = info?.body?.displayString || '';\n const location = context.getLocation(varDec);\n if (varDec.initializer?.kind === ts.SyntaxKind.ArrowFunction) {\n const args = await getParams((varDec.initializer as ArrowFunction).parameters, context);\n const typeStr = parseReturnTypeFromQuickInfo(info);\n const returnType = await context.resolveType(varDec, typeStr);\n const modifiers = varDec.modifiers?.map((modifier) => modifier.getText()) || [];\n const doc = await jsDocToDocSchema(varDec, context);\n return new FunctionLikeSchema(location, name, args, returnType, displaySig, modifiers as Modifier[], doc);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(varDec, typeStr);\n return new VariableLikeSchema(location, name, displaySig, type, false);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAMA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,mBAAN,CAAuD;EAC5DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,mBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAAgC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,OAAO,KAAIsB,uCAAJ,EAAuBhB,QAAvB,EAAiCd,IAAjC,EAAuCkB,IAAvC,EAA6CK,UAA7C,EAAyDZ,UAAzD,EAAqEc,SAArE,EAA8FG,GAA9F,CAAP;IACD;;IACD,MAAMP,OAAO,GAAG,IAAAU,gDAAA,EAAuBtB,IAAvB,CAAhB;IACA,MAAMuB,IAAI,GAAG,MAAMxB,OAAO,CAACgB,WAAR,CAAoBjB,MAApB,EAA4Bc,OAA5B,CAAnB;IACA,OAAO,KAAIY,uCAAJ,EAAuBnB,QAAvB,EAAiCd,IAAjC,EAAuCW,UAAvC,EAAmDqB,IAAnD,EAAyD,KAAzD,CAAP;EACD;;AA7B2D"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.755",
3
+ "version": "0.0.758",
4
4
  "homepage": "https://bit.dev/teambit/typescript/typescript",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.typescript",
8
8
  "name": "typescript",
9
- "version": "0.0.755"
9
+ "version": "0.0.758"
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.755",
21
+ "@teambit/compiler": "0.0.758",
22
22
  "@teambit/typescript.modules.ts-config-mutator": "0.0.68",
23
- "@teambit/component": "0.0.755",
24
- "@teambit/dependency-resolver": "0.0.755",
25
- "@teambit/semantics.entities.semantic-schema": "0.0.18",
23
+ "@teambit/component": "0.0.758",
24
+ "@teambit/dependency-resolver": "0.0.758",
25
+ "@teambit/semantics.entities.semantic-schema": "0.0.20",
26
26
  "@teambit/ts-server": "0.0.32",
27
- "@teambit/aspect-loader": "0.0.755",
27
+ "@teambit/aspect-loader": "0.0.758",
28
28
  "@teambit/bit-error": "0.0.394",
29
- "@teambit/builder": "0.0.755",
30
- "@teambit/isolator": "0.0.755",
31
- "@teambit/logger": "0.0.591",
32
- "@teambit/schema": "0.0.755",
33
- "@teambit/workspace": "0.0.755",
34
- "@teambit/cli": "0.0.498",
35
- "@teambit/pkg": "0.0.755"
29
+ "@teambit/builder": "0.0.758",
30
+ "@teambit/isolator": "0.0.758",
31
+ "@teambit/logger": "0.0.594",
32
+ "@teambit/schema": "0.0.758",
33
+ "@teambit/workspace": "0.0.758",
34
+ "@teambit/cli": "0.0.501",
35
+ "@teambit/pkg": "0.0.758"
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.278",
51
+ "@teambit/legacy": "1.0.281",
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.278",
79
+ "@teambit/legacy": "1.0.281",
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.755/dist/typescript.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.755/dist/typescript.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.758/dist/typescript.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.758/dist/typescript.docs.mdx')]
@@ -1,5 +1,5 @@
1
1
  import ts, { BindingElement, Node } from 'typescript';
2
- import { VariableSchema } from '@teambit/semantics.entities.semantic-schema';
2
+ import { VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';
3
3
  import { SchemaTransformer } from '../schema-transformer';
4
4
  import { SchemaExtractorContext } from '../schema-extractor-context';
5
5
  import { ExportIdentifier } from '../export-identifier';
@@ -27,6 +27,6 @@ export class BindingElementTransformer implements SchemaTransformer {
27
27
  const displaySig = info?.body?.displayString || '';
28
28
  const typeStr = parseTypeFromQuickInfo(info);
29
29
  const type = await context.resolveType(node, typeStr);
30
- return new VariableSchema(context.getLocation(node), name, displaySig, type, false);
30
+ return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, false);
31
31
  }
32
32
  }
@@ -1,5 +1,4 @@
1
- import { SchemaNode, Module } from '@teambit/semantics.entities.semantic-schema';
2
- import { compact } from 'lodash';
1
+ import { SchemaNode, Module, UnresolvedSchema } from '@teambit/semantics.entities.semantic-schema';
3
2
  import ts, {
4
3
  Node,
5
4
  SyntaxKind,
@@ -53,37 +52,63 @@ export class ExportDeclaration implements SchemaTransformer {
53
52
 
54
53
  // e.g. `export { button1, button2 } as Composition from './button';
55
54
  if (exportClause.kind === SyntaxKind.NamedExports) {
56
- exportClause as NamedExports;
57
- const schemas = await Promise.all(
58
- exportClause.elements.map(async (element) => {
59
- return context.visitDefinition(element.name);
60
- })
61
- );
62
-
63
- return new Module(context.getLocation(exportDec), compact(schemas));
55
+ const schemas = await namedExport(exportClause, context);
56
+ return new Module(context.getLocation(exportDec), schemas);
64
57
  }
65
58
  // e.g. `export * as Composition from './button';
66
59
  if (exportClause.kind === SyntaxKind.NamespaceExport) {
67
- exportClause as NamespaceExport;
68
- const namespace = exportClause.name.getText();
69
- const filePath = await context.getFilePathByNode(exportClause.name);
70
- if (!filePath) {
71
- throw new Error(`unable to find the file-path for "${namespace}"`);
72
- }
73
- const sourceFile = context.getSourceFileInsideComponent(filePath);
74
- if (!sourceFile) {
75
- // it's a namespace from another component or an external package.
76
- return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
77
- }
78
- const result = await context.computeSchema(sourceFile);
79
- if (!(result instanceof Module)) {
80
- throw new Error(`expect result to be instance of Module`);
81
- }
82
- result.namespace = namespace;
83
- return result;
60
+ return namespaceExport(exportClause, exportDec, context);
84
61
  }
85
62
 
86
63
  // should never reach here. exportClause can be either NamespaceExport or NamedExports
87
64
  throw new Error(`unrecognized exportClause type`);
88
65
  }
89
66
  }
67
+
68
+ async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {
69
+ const schemas = await Promise.all(
70
+ exportClause.elements.map(async (element) => {
71
+ const definitionNode = await context.definition(element.name);
72
+ if (!definitionNode) {
73
+ // happens for example when the main index.ts file exports variable from an mdx file.
74
+ // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
75
+ return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
76
+ }
77
+ if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {
78
+ // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
79
+ // normally, "bit install" should fix it. another option is to open vscode and look for errors.
80
+ throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(
81
+ element.name
82
+ )}.
83
+ make sure "bit status" is clean and there are no errors about missing packages/links.
84
+ also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
85
+ }
86
+ return context.computeSchema(definitionNode.parent);
87
+ })
88
+ );
89
+
90
+ return schemas;
91
+ }
92
+
93
+ async function namespaceExport(
94
+ exportClause: NamespaceExport,
95
+ exportDec: ExportDeclarationNode,
96
+ context: SchemaExtractorContext
97
+ ) {
98
+ const namespace = exportClause.name.getText();
99
+ const filePath = await context.getFilePathByNode(exportClause.name);
100
+ if (!filePath) {
101
+ throw new Error(`unable to find the file-path for "${namespace}"`);
102
+ }
103
+ const sourceFile = context.getSourceFileInsideComponent(filePath);
104
+ if (!sourceFile) {
105
+ // it's a namespace from another component or an external package.
106
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
107
+ }
108
+ const result = await context.computeSchema(sourceFile);
109
+ if (!(result instanceof Module)) {
110
+ throw new Error(`expect result to be instance of Module`);
111
+ }
112
+ result.namespace = namespace;
113
+ return result;
114
+ }
@@ -8,7 +8,7 @@ import {
8
8
  SetAccessorDeclaration,
9
9
  SyntaxKind,
10
10
  } from 'typescript';
11
- import { ConstructorSchema, SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';
11
+ import { ConstructorSchema, SchemaNode, VariableLikeSchema } from '@teambit/semantics.entities.semantic-schema';
12
12
  import { SchemaExtractorContext } from '../../schema-extractor-context';
13
13
  import { getParams } from './get-params';
14
14
  import { getAccessor, indexSignature, setAccessor } from './type-element-to-schema';
@@ -54,7 +54,7 @@ async function propertyDeclaration(node: PropertyDeclaration, context: SchemaExt
54
54
  const type = await context.resolveType(node, typeStr);
55
55
  const isOptional = Boolean(node.questionToken);
56
56
 
57
- return new VariableSchema(context.getLocation(node), name, displaySig || '', type, isOptional);
57
+ return new VariableLikeSchema(context.getLocation(node), name, displaySig || '', type, isOptional);
58
58
  }
59
59
 
60
60
  async function methodDeclaration(node: MethodDeclaration, context: SchemaExtractorContext) {
@@ -14,7 +14,7 @@ import {
14
14
  IndexSignatureSchema,
15
15
  SchemaNode,
16
16
  SetAccessorSchema,
17
- VariableSchema,
17
+ VariableLikeSchema,
18
18
  } from '@teambit/semantics.entities.semantic-schema';
19
19
  import { toFunctionLikeSchema } from './to-function-like-schema';
20
20
  import { SchemaExtractorContext } from '../../schema-extractor-context';
@@ -50,7 +50,7 @@ async function propertySignature(node: ts.PropertySignature, context: SchemaExtr
50
50
  const typeStr = parseTypeFromQuickInfo(info);
51
51
  const type = await context.resolveType(node, typeStr);
52
52
  const isOptional = Boolean(node.questionToken);
53
- return new VariableSchema(context.getLocation(node), name, displaySig, type, isOptional);
53
+ return new VariableLikeSchema(context.getLocation(node), name, displaySig, type, isOptional);
54
54
  }
55
55
 
56
56
  export async function indexSignature(node: IndexSignatureDeclaration, context: SchemaExtractorContext) {
@@ -1,4 +1,9 @@
1
- import { SchemaNode, VariableSchema, FunctionLikeSchema, Modifier } from '@teambit/semantics.entities.semantic-schema';
1
+ import {
2
+ SchemaNode,
3
+ VariableLikeSchema,
4
+ FunctionLikeSchema,
5
+ Modifier,
6
+ } from '@teambit/semantics.entities.semantic-schema';
2
7
  import ts, { Node, VariableDeclaration as VariableDeclarationNode, ArrowFunction } from 'typescript';
3
8
  import { SchemaTransformer } from '../schema-transformer';
4
9
  import { SchemaExtractorContext } from '../schema-extractor-context';
@@ -35,6 +40,6 @@ export class VariableDeclaration implements SchemaTransformer {
35
40
  }
36
41
  const typeStr = parseTypeFromQuickInfo(info);
37
42
  const type = await context.resolveType(varDec, typeStr);
38
- return new VariableSchema(location, name, displaySig, type, false);
43
+ return new VariableLikeSchema(location, name, displaySig, type, false);
39
44
  }
40
45
  }