@teambit/typescript 0.0.855 → 0.0.856

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.
@@ -1,5 +1,6 @@
1
1
  import { TsserverClient } from '@teambit/ts-server';
2
2
  import ts, { ExportDeclaration, Node, TypeNode } from 'typescript';
3
+ import protocol from 'typescript/lib/protocol';
3
4
  import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
4
5
  import { Component } from '@teambit/component';
5
6
  import { TypeRefSchema, SchemaNode, Location } from '@teambit/semantics.entities.semantic-schema';
@@ -22,7 +23,7 @@ export declare class SchemaExtractorContext {
22
23
  /**
23
24
  * returns a signature for a node.
24
25
  */
25
- getSignature(node: Node): Promise<import("typescript/lib/protocol").SignatureHelpResponse | undefined>;
26
+ getSignature(node: Node): Promise<protocol.SignatureHelpResponse | undefined>;
26
27
  /**
27
28
  * get the position for the tsserver.
28
29
  */
@@ -31,12 +32,12 @@ export declare class SchemaExtractorContext {
31
32
  * get the path for a source file.
32
33
  */
33
34
  getPath(node: Node): string;
34
- getQuickInfo(node: Node): Promise<import("typescript/lib/protocol").QuickInfoResponse | undefined>;
35
+ getQuickInfo(node: Node): Promise<protocol.QuickInfoResponse | undefined>;
35
36
  getQuickInfoDisplayString(node: Node): Promise<string>;
36
37
  /**
37
38
  * returns the type definition for a type.
38
39
  */
39
- typeDefinition(node: Node): Promise<import("typescript/lib/protocol").TypeDefinitionResponse | undefined>;
40
+ typeDefinition(node: Node): Promise<protocol.TypeDefinitionResponse | undefined>;
40
41
  visitTypeDefinition(): void;
41
42
  private findFileInComponent;
42
43
  private parsePackageNameFromPath;
@@ -47,10 +48,11 @@ export declare class SchemaExtractorContext {
47
48
  getSourceFileInsideComponent(filePath: string): ts.SourceFile | undefined;
48
49
  getSourceFileFromNode(node: Node): Promise<ts.SourceFile | undefined>;
49
50
  getFilePathByNode(node: Node): Promise<string | undefined>;
51
+ definitionInfo(node: Node): Promise<protocol.DefinitionInfo | undefined>;
50
52
  /**
51
53
  * get a definition for a given node.
52
54
  */
53
- definition(node: Node): Promise<Node | undefined>;
55
+ definition(definitonInfo: protocol.DefinitionInfo): Promise<Node | undefined>;
54
56
  /**
55
57
  * visit a definition for node - e.g. return it's schema.
56
58
  */
@@ -71,5 +73,6 @@ export declare class SchemaExtractorContext {
71
73
  type?: TypeNode;
72
74
  }, typeStr: string, isTypeStrFromQuickInfo?: boolean): Promise<SchemaNode>;
73
75
  private getCompIdByPkgName;
76
+ getTypeRefForExternalNode(node: Node): Promise<TypeRefSchema>;
74
77
  getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema>;
75
78
  }
@@ -271,24 +271,26 @@ class SchemaExtractorContext {
271
271
  const firstDef = (0, _lodash().head)(def.body);
272
272
  return firstDef === null || firstDef === void 0 ? void 0 : firstDef.file;
273
273
  }
274
+
275
+ async definitionInfo(node) {
276
+ const location = this.getLocation(node);
277
+ const filePath = this.getPath(node);
278
+ const def = await this.tsserver.getDefinition(filePath, location);
279
+ const firstDef = (0, _lodash().head)(def.body);
280
+ return firstDef;
281
+ }
274
282
  /**
275
283
  * get a definition for a given node.
276
284
  */
277
285
 
278
286
 
279
- async definition(node) {
280
- const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));
281
- const firstDef = (0, _lodash().head)(def.body);
282
-
283
- if (!firstDef) {
284
- return undefined;
285
- }
286
-
287
- const startPosition = firstDef.start;
288
- const sourceFile = this.getSourceFileInsideComponent(firstDef.file);
287
+ async definition(definitonInfo) {
288
+ const startPosition = definitonInfo.start;
289
+ const sourceFile = this.getSourceFileInsideComponent(definitonInfo.file);
289
290
 
290
291
  if (!sourceFile) {
291
- return undefined; // learn how to return a reference to a different component here.
292
+ // it might be an external reference, cant get the node
293
+ return undefined;
292
294
  }
293
295
 
294
296
  const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);
@@ -301,12 +303,18 @@ class SchemaExtractorContext {
301
303
 
302
304
 
303
305
  async visitDefinition(node) {
304
- const definition = await this.definition(node);
306
+ const definitionInfo = await this.definitionInfo(node);
305
307
 
306
- if (!definition) {
308
+ if (!definitionInfo) {
307
309
  return undefined;
308
310
  }
309
311
 
312
+ const definition = await this.definition(definitionInfo);
313
+
314
+ if (!definition) {
315
+ return this.getTypeRefForExternalNode(node);
316
+ }
317
+
310
318
  return this.visit(definition.parent);
311
319
  }
312
320
 
@@ -452,6 +460,14 @@ class SchemaExtractorContext {
452
460
  return (_this$componentDeps$f = this.componentDeps.find(dep => dep.packageName === pkgName)) === null || _this$componentDeps$f === void 0 ? void 0 : _this$componentDeps$f.componentId;
453
461
  }
454
462
 
463
+ async getTypeRefForExternalNode(node) {
464
+ const info = await this.getQuickInfo(node);
465
+ const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
466
+ const location = this.getLocation(node);
467
+ const filePath = this.getPath(node);
468
+ return this.getTypeRefForExternalPath(typeStr, filePath, location);
469
+ }
470
+
455
471
  async getTypeRefForExternalPath(typeStr, filePath, location) {
456
472
  const compIdByPath = await this.extractor.getComponentIDByPath(filePath);
457
473
 
@@ -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","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, typeStr);\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"],"mapp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D;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBlF,QAAlB,EAA4BgF,OAA5B,EAAqClG,SAArC,EAAgD4D,OAAhD,CAAP;EACD;;AAjUiC"}
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","definitionInfo","definition","definitonInfo","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","getTypeRefForExternalNode","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// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\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 async definitionInfo(node: Node): Promise<protocol.DefinitionInfo | undefined> {\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n\n const def = await this.tsserver.getDefinition(filePath, location);\n\n const firstDef = head(def.body);\n\n return firstDef;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(definitonInfo: protocol.DefinitionInfo): Promise<Node | undefined> {\n const startPosition = definitonInfo.start;\n const sourceFile = this.getSourceFileInsideComponent(definitonInfo.file);\n if (!sourceFile) {\n // it might be an external reference, cant get the node\n return undefined;\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 definitionInfo = await this.definitionInfo(node);\n if (!definitionInfo) {\n return undefined;\n }\n\n const definition = await this.definition(definitionInfo);\n if (!definition) {\n return this.getTypeRefForExternalNode(node);\n }\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, typeStr);\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 getTypeRefForExternalNode(node: Node): Promise<TypeRefSchema> {\n const info = await this.getQuickInfo(node);\n const typeStr = parseTypeFromQuickInfo(info);\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n return this.getTypeRefForExternalPath(typeStr, filePath, location);\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;;AAKA;EA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MAAMwG,YAAY,GAAG,MAAM,KAAK5H,SAAL,CAAe6H,oBAAf,CAAoC9G,QAApC,CAA3B;;IACA,IAAI6G,YAAJ,EAAkB;MAChB,OAAO,KAAInB,kCAAJ,EAAkBrF,QAAlB,EAA4BmF,OAA5B,EAAqCqB,YAArC,CAAP;IACD;;IACD,MAAM9D,OAAO,GAAG,KAAKT,wBAAL,CAA8BtC,QAA9B,CAAhB;IACA,MAAM+G,WAAW,GAAG,KAAKN,kBAAL,CAAwB1D,OAAxB,CAApB;;IACA,IAAIgE,WAAJ,EAAiB;MACf,OAAO,KAAIrB,kCAAJ,EAAkBrF,QAAlB,EAA4BmF,OAA5B,EAAqCuB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBrF,QAAlB,EAA4BmF,OAA5B,EAAqCrG,SAArC,EAAgD4D,OAAhD,CAAP;EACD;;AApViC"}
@@ -5,5 +5,5 @@ export declare class SchemaTransformerPlugin implements PluginDefinition {
5
5
  constructor(schemaTransformerSlot: SchemaTransformerSlot);
6
6
  pattern: string;
7
7
  runtimes: string[];
8
- register(object: any): Promise<void>;
8
+ register(object: any): void;
9
9
  }
@@ -2,8 +2,6 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- require("core-js/modules/es.promise.js");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
@@ -26,7 +24,7 @@ class SchemaTransformerPlugin {
26
24
  (0, _defineProperty2().default)(this, "runtimes", ['main']);
27
25
  }
28
26
 
29
- async register(object) {
27
+ register(object) {
30
28
  return this.schemaTransformerSlot.register([object]);
31
29
  }
32
30
 
@@ -1 +1 @@
1
- {"version":3,"names":["SchemaTransformerPlugin","constructor","schemaTransformerSlot","register","object"],"sources":["schema-transformer.plugin.ts"],"sourcesContent":["import { PluginDefinition } from '@teambit/aspect-loader';\nimport { SchemaTransformerSlot } from './typescript.main.runtime';\n\nexport class SchemaTransformerPlugin implements PluginDefinition {\n constructor(private schemaTransformerSlot: SchemaTransformerSlot) {}\n\n pattern = '*.schema-extractor.*';\n\n runtimes = ['main'];\n\n async register(object: any) {\n return this.schemaTransformerSlot.register([object]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAGO,MAAMA,uBAAN,CAA0D;EAC/DC,WAAW,CAASC,qBAAT,EAAuD;IAAA,KAA9CA,qBAA8C,GAA9CA,qBAA8C;IAAA,iDAExD,sBAFwD;IAAA,kDAIvD,CAAC,MAAD,CAJuD;EAAE;;EAMtD,MAARC,QAAQ,CAACC,MAAD,EAAc;IAC1B,OAAO,KAAKF,qBAAL,CAA2BC,QAA3B,CAAoC,CAACC,MAAD,CAApC,CAAP;EACD;;AAT8D"}
1
+ {"version":3,"names":["SchemaTransformerPlugin","constructor","schemaTransformerSlot","register","object"],"sources":["schema-transformer.plugin.ts"],"sourcesContent":["import { PluginDefinition } from '@teambit/aspect-loader';\nimport { SchemaTransformerSlot } from './typescript.main.runtime';\n\nexport class SchemaTransformerPlugin implements PluginDefinition {\n constructor(private schemaTransformerSlot: SchemaTransformerSlot) {}\n\n pattern = '*.schema-extractor.*';\n\n runtimes = ['main'];\n\n register(object: any) {\n return this.schemaTransformerSlot.register([object]);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAGO,MAAMA,uBAAN,CAA0D;EAC/DC,WAAW,CAASC,qBAAT,EAAuD;IAAA,KAA9CA,qBAA8C,GAA9CA,qBAA8C;IAAA,iDAExD,sBAFwD;IAAA,kDAIvD,CAAC,MAAD,CAJuD;EAAE;;EAMpEC,QAAQ,CAACC,MAAD,EAAc;IACpB,OAAO,KAAKF,qBAAL,CAA2BC,QAA3B,CAAoC,CAACC,MAAD,CAApC,CAAP;EACD;;AAT8D"}
@@ -109,14 +109,20 @@ exports.ExportDeclaration = ExportDeclaration;
109
109
 
110
110
  async function namedExport(exportClause, context) {
111
111
  const schemas = await Promise.all(exportClause.elements.map(async element => {
112
- const definitionNode = await context.definition(element.name);
112
+ const definitionInfo = await context.definitionInfo(element);
113
113
 
114
- if (!definitionNode) {
114
+ if (!definitionInfo) {
115
115
  // happens for example when the main index.ts file exports variable from an mdx file.
116
116
  // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
117
117
  return new (_semanticsEntities().UnresolvedSchema)(context.getLocation(element.name), element.name.getText());
118
118
  }
119
119
 
120
+ const definitionNode = await context.definition(definitionInfo);
121
+
122
+ if (!definitionNode) {
123
+ return context.getTypeRefForExternalNode(element);
124
+ }
125
+
120
126
  if (definitionNode.parent.kind === _typescript().SyntaxKind.ExportSpecifier) {
121
127
  // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
122
128
  // normally, "bit install" should fix it. another option is to open vscode and look for errors.
@@ -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","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,CA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,CAACqC,iBAAR,CAA0BpC,YAAY,CAACO,IAAvC,CAAvB;;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"}
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","definitionInfo","UnresolvedSchema","definitionNode","definition","getTypeRefForExternalNode","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 definitionInfo = await context.definitionInfo(element);\n if (!definitionInfo) {\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 const definitionNode = await context.definition(definitionInfo);\n if (!definitionNode) {\n return context.getTypeRefForExternalNode(element);\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,IAAx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B,IAAR,CAAaC,OAAb,EAAuB,QAAOT,OAAO,CAACoC,mBAAR,CACnGR,OAAO,CAACpB,IAD2F,CAEnG;AACV;AACA,6EAJc,CAAN;IAKD;;IACD,OAAOR,OAAO,CAACoB,aAAR,CAAsBW,cAAc,CAACG,MAArC,CAAP;EACD,CArBD,CADoB,CAAtB;EAyBA,OAAOb,OAAP;AACD;;AAED,eAAeI,eAAf,CACExB,YADF,EAEEF,SAFF,EAGEC,OAHF,EAIE;EACA,MAAMqC,SAAS,GAAGpC,YAAY,CAACO,IAAb,CAAkBC,OAAlB,EAAlB;EACA,MAAM6B,QAAQ,GAAG,MAAMtC,OAAO,CAACuC,iBAAR,CAA0BtC,YAAY,CAACO,IAAvC,CAAvB;;EACA,IAAI,CAAC8B,QAAL,EAAe;IACb,MAAM,IAAIrB,KAAJ,CAAW,qCAAoCoB,SAAU,GAAzD,CAAN;EACD;;EACD,MAAMnB,UAAU,GAAGlB,OAAO,CAACwC,4BAAR,CAAqCF,QAArC,CAAnB;;EACA,IAAI,CAACpB,UAAL,EAAiB;IACf;IACA,OAAOlB,OAAO,CAACyC,yBAAR,CAAkCJ,SAAlC,EAA6CC,QAA7C,EAAuDtC,OAAO,CAACwB,WAAR,CAAoBzB,SAApB,CAAvD,CAAP;EACD;;EACD,MAAM2C,MAAM,GAAG,MAAM1C,OAAO,CAACoB,aAAR,CAAsBF,UAAtB,CAArB;;EACA,IAAI,EAAEwB,MAAM,YAAYnB,2BAApB,CAAJ,EAAiC;IAC/B,MAAM,IAAIN,KAAJ,CAAW,wCAAX,CAAN;EACD;;EACDyB,MAAM,CAACL,SAAP,GAAmBA,SAAnB;EACA,OAAOK,MAAP;AACD"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.855",
3
+ "version": "0.0.856",
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.855"
9
+ "version": "0.0.856"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -17,22 +17,22 @@
17
17
  "chalk": "2.4.2",
18
18
  "@babel/runtime": "7.12.18",
19
19
  "core-js": "^3.0.0",
20
- "@teambit/compiler": "0.0.855",
20
+ "@teambit/compiler": "0.0.856",
21
21
  "@teambit/typescript.modules.ts-config-mutator": "0.0.74",
22
- "@teambit/component": "0.0.855",
23
- "@teambit/dependency-resolver": "0.0.855",
22
+ "@teambit/component": "0.0.856",
23
+ "@teambit/dependency-resolver": "0.0.856",
24
24
  "@teambit/semantics.entities.semantic-schema": "0.0.38",
25
25
  "@teambit/ts-server": "0.0.38",
26
- "@teambit/aspect-loader": "0.0.855",
26
+ "@teambit/aspect-loader": "0.0.856",
27
27
  "@teambit/harmony": "0.3.3",
28
28
  "@teambit/bit-error": "0.0.400",
29
- "@teambit/builder": "0.0.855",
30
- "@teambit/isolator": "0.0.855",
29
+ "@teambit/builder": "0.0.856",
30
+ "@teambit/isolator": "0.0.856",
31
31
  "@teambit/logger": "0.0.661",
32
- "@teambit/schema": "0.0.855",
33
- "@teambit/workspace": "0.0.855",
32
+ "@teambit/schema": "0.0.856",
33
+ "@teambit/workspace": "0.0.856",
34
34
  "@teambit/cli": "0.0.568",
35
- "@teambit/pkg": "0.0.855"
35
+ "@teambit/pkg": "0.0.856"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash": "4.14.165",
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.855/dist/typescript.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.855/dist/typescript.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.856/dist/typescript.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.856/dist/typescript.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -68,12 +68,16 @@ export class ExportDeclaration implements SchemaTransformer {
68
68
  async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {
69
69
  const schemas = await Promise.all(
70
70
  exportClause.elements.map(async (element) => {
71
- const definitionNode = await context.definition(element.name);
72
- if (!definitionNode) {
71
+ const definitionInfo = await context.definitionInfo(element);
72
+ if (!definitionInfo) {
73
73
  // happens for example when the main index.ts file exports variable from an mdx file.
74
74
  // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
75
75
  return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
76
76
  }
77
+ const definitionNode = await context.definition(definitionInfo);
78
+ if (!definitionNode) {
79
+ return context.getTypeRefForExternalNode(element);
80
+ }
77
81
  if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {
78
82
  // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
79
83
  // normally, "bit install" should fix it. another option is to open vscode and look for errors.