@teambit/typescript 0.0.740 → 0.0.741

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.
@@ -2,7 +2,7 @@ import { TsserverClient } from '@teambit/ts-server';
2
2
  import ts, { ExportDeclaration, Node, TypeNode } from 'typescript';
3
3
  import type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';
4
4
  import { Component } from '@teambit/component';
5
- import { SchemaNode, Location } from '@teambit/semantics.entities.semantic-schema';
5
+ import { TypeRefSchema, SchemaNode, Location } from '@teambit/semantics.entities.semantic-schema';
6
6
  import { ComponentDependency } from '@teambit/dependency-resolver';
7
7
  import { TypeScriptExtractor } from './typescript.extractor';
8
8
  import { ExportList } from './export-list';
@@ -30,10 +30,6 @@ export declare class SchemaExtractorContext {
30
30
  * get the path for a source file.
31
31
  */
32
32
  getPath(node: Node): string;
33
- /**
34
- * create a reference to a type from a component.
35
- * think if we don't need this because of type ref
36
- */
37
33
  getQuickInfo(node: Node): Promise<import("typescript/lib/protocol").QuickInfoResponse | undefined>;
38
34
  getQuickInfoDisplayString(node: Node): Promise<string>;
39
35
  /**
@@ -47,8 +43,9 @@ export declare class SchemaExtractorContext {
47
43
  * return the file if part of the component.
48
44
  * otherwise, a reference to the target package and the type name.
49
45
  */
50
- private getSourceFile;
46
+ getSourceFileInsideComponent(filePath: string): ts.SourceFile | undefined;
51
47
  getSourceFileFromNode(node: Node): Promise<ts.SourceFile | undefined>;
48
+ getFilePathByNode(node: Node): Promise<string | undefined>;
52
49
  /**
53
50
  * get a definition for a given node.
54
51
  */
@@ -73,4 +70,5 @@ export declare class SchemaExtractorContext {
73
70
  type?: TypeNode;
74
71
  }, typeStr: string, isTypeStrFromQuickInfo?: boolean): Promise<SchemaNode>;
75
72
  private getCompIdByPkgName;
73
+ getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema>;
76
74
  }
@@ -161,23 +161,25 @@ class SchemaExtractorContext {
161
161
  const sourceFile = node.getSourceFile();
162
162
  return sourceFile.fileName;
163
163
  }
164
- /**
165
- * create a reference to a type from a component.
166
- * think if we don't need this because of type ref
167
- */
168
- // createRef() {
169
- // return {};
170
- // }
171
164
 
165
+ async getQuickInfo(node) {
166
+ const location = this.getLocation(node);
167
+
168
+ try {
169
+ return await this.tsserver.getQuickInfo(this.getPath(node), location);
170
+ } catch (err) {
171
+ if (err.message === 'No content available.') {
172
+ throw new Error(`unable to get quickinfo data from tsserver at ${location.file}, Ln ${location.line}, Col ${location.character}`);
173
+ }
172
174
 
173
- getQuickInfo(node) {
174
- return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
175
+ throw err;
176
+ }
175
177
  }
176
178
 
177
179
  async getQuickInfoDisplayString(node) {
178
180
  var _quickInfo$body;
179
181
 
180
- const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));
182
+ const quickInfo = await this.getQuickInfo(node);
181
183
  return (quickInfo === null || quickInfo === void 0 ? void 0 : (_quickInfo$body = quickInfo.body) === null || _quickInfo$body === void 0 ? void 0 : _quickInfo$body.displayString) || '';
182
184
  }
183
185
  /**
@@ -232,22 +234,26 @@ class SchemaExtractorContext {
232
234
  */
233
235
 
234
236
 
235
- getSourceFile(filePath) {
237
+ getSourceFileInsideComponent(filePath) {
236
238
  const file = this.findFileInComponent(filePath);
237
239
  if (!file) return undefined;
238
240
  return this.extractor.parseSourceFile(file);
239
241
  }
240
242
 
241
243
  async getSourceFileFromNode(node) {
242
- const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));
243
- const firstDef = (0, _lodash().head)(def.body);
244
+ const filePath = await this.getFilePathByNode(node);
244
245
 
245
- if (!firstDef) {
246
+ if (!filePath) {
246
247
  return undefined;
247
248
  }
248
249
 
249
- const sourceFile = this.getSourceFile(firstDef.file);
250
- return sourceFile;
250
+ return this.getSourceFileInsideComponent(filePath);
251
+ }
252
+
253
+ async getFilePathByNode(node) {
254
+ const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));
255
+ const firstDef = (0, _lodash().head)(def.body);
256
+ return firstDef === null || firstDef === void 0 ? void 0 : firstDef.file;
251
257
  }
252
258
  /**
253
259
  * get a definition for a given node.
@@ -263,7 +269,7 @@ class SchemaExtractorContext {
263
269
  }
264
270
 
265
271
  const startPosition = firstDef.start;
266
- const sourceFile = this.getSourceFile(firstDef.file);
272
+ const sourceFile = this.getSourceFileInsideComponent(firstDef.file);
267
273
 
268
274
  if (!sourceFile) {
269
275
  return undefined; // learn how to return a reference to a different component here.
@@ -305,7 +311,7 @@ class SchemaExtractorContext {
305
311
  const specifierPathStr = ((_exportDec$moduleSpec = exportDec.moduleSpecifier) === null || _exportDec$moduleSpec === void 0 ? void 0 : _exportDec$moduleSpec.getText()) || '';
306
312
  const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);
307
313
  const absPath = (0, _path().resolve)(file, '..', specifierPath);
308
- const sourceFile = this.getSourceFile(absPath);
314
+ const sourceFile = this.getSourceFileInsideComponent(absPath);
309
315
  if (!sourceFile) return [];
310
316
  return this.extractor.computeExportedIdentifiers(sourceFile, this);
311
317
  }
@@ -388,7 +394,7 @@ class SchemaExtractorContext {
388
394
 
389
395
  const unknownExactType = async () => {
390
396
  if (isTypeStrFromQuickInfo) {
391
- return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr);
397
+ return new (_semanticsEntities().InferenceTypeSchema)(location, typeStr || 'any');
392
398
  }
393
399
 
394
400
  const info = await this.getQuickInfo(node);
@@ -421,13 +427,23 @@ class SchemaExtractorContext {
421
427
  return schemaNode || unknownExactType();
422
428
  }
423
429
 
424
- const compIdByPath = await this.extractor.getComponentIDByPath(definition.file);
430
+ return this.getTypeRefForExternalPath(typeStr, definition.file, location);
431
+ }
432
+
433
+ getCompIdByPkgName(pkgName) {
434
+ var _this$componentDeps$f;
435
+
436
+ return (_this$componentDeps$f = this.componentDeps.find(dep => dep.packageName === pkgName)) === null || _this$componentDeps$f === void 0 ? void 0 : _this$componentDeps$f.componentId;
437
+ }
438
+
439
+ async getTypeRefForExternalPath(typeStr, filePath, location) {
440
+ const compIdByPath = await this.extractor.getComponentIDByPath(filePath);
425
441
 
426
442
  if (compIdByPath) {
427
443
  return new (_semanticsEntities().TypeRefSchema)(location, typeStr, compIdByPath);
428
444
  }
429
445
 
430
- const pkgName = this.parsePackageNameFromPath(definition.file);
446
+ const pkgName = this.parsePackageNameFromPath(filePath);
431
447
  const compIdByPkg = this.getCompIdByPkgName(pkgName);
432
448
 
433
449
  if (compIdByPkg) {
@@ -437,12 +453,6 @@ class SchemaExtractorContext {
437
453
  return new (_semanticsEntities().TypeRefSchema)(location, typeStr, undefined, pkgName);
438
454
  }
439
455
 
440
- getCompIdByPkgName(pkgName) {
441
- var _this$componentDeps$f;
442
-
443
- return (_this$componentDeps$f = this.componentDeps.find(dep => dep.packageName === pkgName)) === null || _this$componentDeps$f === void 0 ? void 0 : _this$componentDeps$f.componentId;
444
- }
445
-
446
456
  }
447
457
 
448
458
  exports.SchemaExtractorContext = SchemaExtractorContext;
@@ -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","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","parseSourceFile","getSourceFileFromNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","err","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","location","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","compIdByPath","getComponentIDByPath","compIdByPkg","getCompIdByPkgName","dep","packageName","componentId"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[]\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n /**\n * create a reference to a type from a component.\n * think if we don't need this because of type ref\n */\n // createRef() {\n // return {};\n // }\n\n getQuickInfo(node: Node) {\n return this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.tsserver.getQuickInfo(this.getPath(node), this.getLocation(node));\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n private getSourceFile(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const sourceFile = this.getSourceFile(firstDef.file);\n\n return sourceFile;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFile(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFile(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr);\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n const compIdByPath = await this.extractor.getComponentIDByPath(definition.file);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(definition.file);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\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;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aExtractorContext","constructor","tsserver","component","extractor","componentDeps","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getPathRelativeToComponent","filePath","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","location","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","getTypeRefForExternalPath","getCompIdByPkgName","dep","packageName","componentId","compIdByPath","getComponentIDByPath","compIdByPkg"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[]\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${location.file}, Ln ${location.line}, Col ${location.character}`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(node);\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n getSourceFileInsideComponent(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFileInsideComponent(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFileInsideComponent(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr || 'any');\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,sBAAN,CAA6B;EAClCC,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIAC,aAJA,EAKT;IAAA,KAJSH,QAIT,GAJSA,QAIT;IAAA,KAHSC,SAGT,GAHSA,SAGT;IAAA,KAFSC,SAET,GAFSA,SAET;IAAA,KADSC,aACT,GADSA,aACT;IAAA,kDA2LiCC,SA3LjC;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,QAA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4BmE,OAA5B,EAAqChG,SAArC,EAAgD0D,OAAhD,CAAP;EACD;;AAzTiC"}
@@ -95,10 +95,17 @@ class ExportDeclaration {
95
95
  if ((exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === _typescript().SyntaxKind.NamespaceExport) {
96
96
  exportClause;
97
97
  const namespace = exportClause.name.getText();
98
- const sourceFile = await context.getSourceFileFromNode(exportClause.name);
98
+ const filePath = await context.getFilePathByNode(exportClause.name);
99
+
100
+ if (!filePath) {
101
+ throw new Error(`unable to find the file-path for "${namespace}"`);
102
+ }
103
+
104
+ const sourceFile = context.getSourceFileInsideComponent(filePath);
99
105
 
100
106
  if (!sourceFile) {
101
- throw new Error(`unable to find the source-file for "${namespace}"`);
107
+ // it's a namespace from another component or an external package.
108
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));
102
109
  }
103
110
 
104
111
  const result = await context.computeSchema(sourceFile);
@@ -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","schemas","Promise","all","element","visitDefinition","Module","getLocation","compact","namespace","sourceFile","getSourceFileFromNode","Error","result","computeSchema","specifier"],"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(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportDec = node as ExportDeclarationNode;\n const exportClause = exportDec.exportClause;\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(node), 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 sourceFile = await context.getSourceFileFromNode(exportClause.name);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file for \"${namespace}\"`);\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 // 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 throw new Error('unrecognized export type');\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;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G,MAAMzB,OAAO,CAAC0B,qBAAR,CAA8BI,SAA9B,CAAzB;;MACA,IAAI,CAACL,UAAL,EAAiB;QACf,MAAM,IAAIE,KAAJ,CAAW,gCAAX,CAAN;MACD;;MACD,OAAO3B,OAAO,CAAC6B,aAAR,CAAsBJ,UAAtB,CAAP;IACD;;IAED,MAAM,IAAIE,KAAJ,CAAU,0BAAV,CAAN;EACD;;AAnEyD"}
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","schemas","Promise","all","element","visitDefinition","Module","getLocation","compact","namespace","filePath","getFilePathByNode","Error","sourceFile","getSourceFileInsideComponent","getTypeRefForExternalPath","result","computeSchema","specifier","getSourceFileFromNode"],"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(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportDec = node as ExportDeclarationNode;\n const exportClause = exportDec.exportClause;\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(node), 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(node));\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 // 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 throw new Error('unrecognized export type');\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,wBAAA,CAAWJ,iB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MAAM,IAAIN,KAAJ,CAAW,qBAAX,CAAN;MACD;;MACD,MAAMC,UAAU,GAAG,MAAM5B,OAAO,CAACkC,qBAAR,CAA8BD,SAA9B,CAAzB;;MACA,IAAI,CAACL,UAAL,EAAiB;QACf,MAAM,IAAID,KAAJ,CAAW,gCAAX,CAAN;MACD;;MACD,OAAO3B,OAAO,CAACgC,aAAR,CAAsBJ,UAAtB,CAAP;IACD;;IAED,MAAM,IAAID,KAAJ,CAAU,0BAAV,CAAN;EACD;;AAxEyD"}
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  require("core-js/modules/es.promise.js");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
@@ -20,7 +18,7 @@ function _semanticsEntities() {
20
18
  }
21
19
 
22
20
  function _typescript() {
23
- const data = _interopRequireDefault(require("typescript"));
21
+ const data = _interopRequireWildcard(require("typescript"));
24
22
 
25
23
  _typescript = function () {
26
24
  return data;
@@ -39,15 +37,9 @@ function _parseTypeFromQuickInfo() {
39
37
  return data;
40
38
  }
41
39
 
42
- function _typeNodeToSchema() {
43
- const data = require("./utils/type-node-to-schema");
44
-
45
- _typeNodeToSchema = function () {
46
- return data;
47
- };
40
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
48
41
 
49
- return data;
50
- }
42
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
51
43
 
52
44
  class PropertySignature {
53
45
  predicate(node) {
@@ -63,18 +55,11 @@ class PropertySignature {
63
55
  }
64
56
 
65
57
  async transform(prop, context) {
66
- var _info$body, _prop$type;
58
+ var _info$body;
67
59
 
68
60
  const name = this.getName(prop);
69
- const info = await context.getQuickInfo(prop.name);
61
+ const info = (0, _typescript().isComputedPropertyName)(prop.name) ? undefined : await context.getQuickInfo(prop.name);
70
62
  const displaySig = (info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString) || '';
71
-
72
- if (((_prop$type = prop.type) === null || _prop$type === void 0 ? void 0 : _prop$type.kind) === _typescript().default.SyntaxKind.FunctionType) {
73
- // e.g. `propertySig: () => void;` inside interface
74
- const propType = prop.type;
75
- return (0, _typeNodeToSchema().typeNodeToSchema)(propType, context);
76
- }
77
-
78
63
  const typeStr = (0, _parseTypeFromQuickInfo().parseTypeFromQuickInfo)(info);
79
64
  const type = await context.resolveType(prop, typeStr);
80
65
  return new (_semanticsEntities().VariableSchema)(context.getLocation(prop), name, displaySig, type);
@@ -1 +1 @@
1
- {"version":3,"names":["PropertySignature","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","transform","prop","context","info","getQuickInfo","displaySig","body","displayString","type","FunctionType","propType","typeNodeToSchema","typeStr","parseTypeFromQuickInfo","resolveType","VariableSchema","getLocation"],"sources":["property-signature.ts"],"sourcesContent":["import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { FunctionTypeNode, Node, PropertySignature as PropertySignatureNode } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class PropertySignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.PropertySignature;\n }\n\n getName(node: PropertySignatureNode) {\n return node.name.getText();\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(prop: PropertySignatureNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(prop);\n const info = await context.getQuickInfo(prop.name);\n const displaySig = info?.body?.displayString || '';\n if (prop.type?.kind === ts.SyntaxKind.FunctionType) {\n // e.g. `propertySig: () => void;` inside interface\n const propType = prop.type as FunctionTypeNode;\n return typeNodeToSchema(propType, context);\n }\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(prop, typeStr);\n return new VariableSchema(context.getLocation(prop), name, displaySig, type);\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;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,iBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAA8B;IACnC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,GAAG;IACrB,OAAO,EAAP;EACD;;EAEc,MAATC,SAAS,CAACC,IAAD,EAA8BC,OAA9B,EAAoF;IAAA;;IACjG,MAAML,IAAI,GAAG,KAAKD,OAAL,CAAaK,IAAb,CAAb;IACA,MAAME,IAAI,GAAG,MAAMD,OAAO,CAACE,YAAR,CAAqBH,IAAI,CAACJ,IAA1B,CAAnB;IACA,MAAMQ,UAAU,GAAG,CAAAF,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEG,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;;IACA,IAAI,eAAAN,IAAI,CAACO,IAAL,0DAAWf,IAAX,MAAoBC,qBAAA,CAAGC,UAAH,CAAcc,YAAtC,EAAoD;MAClD;MACA,MAAMC,QAAQ,GAAGT,IAAI,CAACO,IAAtB;MACA,OAAO,IAAAG,oCAAA,EAAiBD,QAAjB,EAA2BR,OAA3B,CAAP;IACD;;IACD,MAAMU,OAAO,GAAG,IAAAC,gDAAA,EAAuBV,IAAvB,CAAhB;IACA,MAAMK,IAAI,GAAG,MAAMN,OAAO,CAACY,WAAR,CAAoBb,IAApB,EAA0BW,OAA1B,CAAnB;IACA,OAAO,KAAIG,mCAAJ,EAAmBb,OAAO,CAACc,WAAR,CAAoBf,IAApB,CAAnB,EAA8CJ,IAA9C,EAAoDQ,UAApD,EAAgEG,IAAhE,CAAP;EACD;;AAzByD"}
1
+ {"version":3,"names":["PropertySignature","predicate","node","kind","ts","SyntaxKind","getName","name","getText","getIdentifiers","transform","prop","context","info","isComputedPropertyName","undefined","getQuickInfo","displaySig","body","displayString","typeStr","parseTypeFromQuickInfo","type","resolveType","VariableSchema","getLocation"],"sources":["property-signature.ts"],"sourcesContent":["import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, { isComputedPropertyName, Node, PropertySignature as PropertySignatureNode } from 'typescript';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';\n\nexport class PropertySignature implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.PropertySignature;\n }\n\n getName(node: PropertySignatureNode) {\n return node.name.getText();\n }\n\n async getIdentifiers() {\n return [];\n }\n\n async transform(prop: PropertySignatureNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = this.getName(prop);\n const info = isComputedPropertyName(prop.name) ? undefined : await context.getQuickInfo(prop.name);\n const displaySig = info?.body?.displayString || '';\n const typeStr = parseTypeFromQuickInfo(info);\n const type = await context.resolveType(prop, typeStr);\n return new VariableSchema(context.getLocation(prop), name, displaySig, type);\n }\n}\n"],"mappings":";;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcL,iBAAnC;EACD;;EAEDM,OAAO,CAACJ,IAAD,EAA8B;IACnC,OAAOA,IAAI,CAACK,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEmB,MAAdC,cAAc,GAAG;IACrB,OAAO,EAAP;EACD;;EAEc,MAATC,SAAS,CAACC,IAAD,EAA8BC,OAA9B,EAAoF;IAAA;;IACjG,MAAML,IAAI,GAAG,KAAKD,OAAL,CAAaK,IAAb,CAAb;IACA,MAAME,IAAI,GAAG,IAAAC,oCAAA,EAAuBH,IAAI,CAACJ,IAA5B,IAAoCQ,SAApC,GAAgD,MAAMH,OAAO,CAACI,YAAR,CAAqBL,IAAI,CAACJ,IAA1B,CAAnE;IACA,MAAMU,UAAU,GAAG,CAAAJ,IAAI,SAAJ,IAAAA,IAAI,WAAJ,0BAAAA,IAAI,CAAEK,IAAN,0DAAYC,aAAZ,KAA6B,EAAhD;IACA,MAAMC,OAAO,GAAG,IAAAC,gDAAA,EAAuBR,IAAvB,CAAhB;IACA,MAAMS,IAAI,GAAG,MAAMV,OAAO,CAACW,WAAR,CAAoBZ,IAApB,EAA0BS,OAA1B,CAAnB;IACA,OAAO,KAAII,mCAAJ,EAAmBZ,OAAO,CAACa,WAAR,CAAoBd,IAApB,CAAnB,EAA8CJ,IAA9C,EAAoDU,UAApD,EAAgEK,IAAhE,CAAP;EACD;;AApByD"}
@@ -63,12 +63,9 @@ class TypeAliasTransformer {
63
63
  }
64
64
 
65
65
  async transform(typeAlias, context) {
66
- var _info$body;
67
-
68
66
  const type = await (0, _typeNodeToSchema().typeNodeToSchema)(typeAlias.type, context);
69
- const info = await context.getQuickInfo(typeAlias.name);
70
- const displaySig = info === null || info === void 0 ? void 0 : (_info$body = info.body) === null || _info$body === void 0 ? void 0 : _info$body.displayString;
71
- return new (_semanticsEntities().TypeSchema)(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
67
+ const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
68
+ return new (_semanticsEntities().TypeSchema)(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig);
72
69
  }
73
70
 
74
71
  }
@@ -1 +1 @@
1
- {"version":3,"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","typeNodeToSchema","info","getQuickInfo","displaySig","body","displayString","TypeSchema","getLocation"],"sources":["type-alias.ts"],"sourcesContent":["import ts, { Node, TypeAliasDeclaration } from 'typescript';\nimport { TypeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class TypeAliasTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.TypeAliasDeclaration;\n }\n\n async getIdentifiers(node: TypeAliasDeclaration) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n private getName(node: TypeAliasDeclaration): string {\n return node.name.getText();\n }\n\n async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(typeAlias.type, context);\n const info = await context.getQuickInfo(typeAlias.name);\n const displaySig = info?.body?.displayString;\n return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');\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;;AAEO,MAAMA,oBAAN,CAAwD;EAC7DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,oBAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAA6B;IAC/C,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEOC,OAAO,CAACX,IAAD,EAAqC;IAClD,OAAOA,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEc,MAATI,SAAS,CAACC,SAAD,EAAkCC,OAAlC,EAAmE;IAAA;;IAChF,MAAMC,IAAI,GAAG,MAAM,IAAAC,oCAAA,EAAiBH,SAAS,CAACE,IAA3B,EAAiCD,OAAjC,CAAnB;IACA,MAAMG,IAAI,GAAG,MAAMH,OAAO,CAACI,YAAR,CAAqBL,SAAS,CAACN,IAA/B,CAAnB;IACA,MAAMY,UAAU,GAAGF,IAAH,aAAGA,IAAH,qCAAGA,IAAI,CAAEG,IAAT,+CAAG,WAAYC,aAA/B;IACA,OAAO,KAAIC,+BAAJ,EAAeR,OAAO,CAACS,WAAR,CAAoBV,SAApB,CAAf,EAA+C,KAAKF,OAAL,CAAaE,SAAb,CAA/C,EAAwEE,IAAxE,EAA8EI,UAAU,IAAI,EAA5F,CAAP;EACD;;AAlB4D"}
1
+ {"version":3,"names":["TypeAliasTransformer","predicate","node","kind","ts","SyntaxKind","TypeAliasDeclaration","getIdentifiers","ExportIdentifier","name","getText","getSourceFile","fileName","getName","transform","typeAlias","context","type","typeNodeToSchema","displaySig","getQuickInfoDisplayString","TypeSchema","getLocation"],"sources":["type-alias.ts"],"sourcesContent":["import ts, { Node, TypeAliasDeclaration } from 'typescript';\nimport { TypeSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { ExportIdentifier } from '../export-identifier';\nimport { typeNodeToSchema } from './utils/type-node-to-schema';\n\nexport class TypeAliasTransformer implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === ts.SyntaxKind.TypeAliasDeclaration;\n }\n\n async getIdentifiers(node: TypeAliasDeclaration) {\n return [new ExportIdentifier(node.name.getText(), node.getSourceFile().fileName)];\n }\n\n private getName(node: TypeAliasDeclaration): string {\n return node.name.getText();\n }\n\n async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(typeAlias.type, context);\n const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);\n return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig);\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;;AAEO,MAAMA,oBAAN,CAAwD;EAC7DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,qBAAA,CAAGC,UAAH,CAAcC,oBAAnC;EACD;;EAEmB,MAAdC,cAAc,CAACL,IAAD,EAA6B;IAC/C,OAAO,CAAC,KAAIM,oCAAJ,EAAqBN,IAAI,CAACO,IAAL,CAAUC,OAAV,EAArB,EAA0CR,IAAI,CAACS,aAAL,GAAqBC,QAA/D,CAAD,CAAP;EACD;;EAEOC,OAAO,CAACX,IAAD,EAAqC;IAClD,OAAOA,IAAI,CAACO,IAAL,CAAUC,OAAV,EAAP;EACD;;EAEc,MAATI,SAAS,CAACC,SAAD,EAAkCC,OAAlC,EAAmE;IAChF,MAAMC,IAAI,GAAG,MAAM,IAAAC,oCAAA,EAAiBH,SAAS,CAACE,IAA3B,EAAiCD,OAAjC,CAAnB;IACA,MAAMG,UAAU,GAAG,MAAMH,OAAO,CAACI,yBAAR,CAAkCL,SAAS,CAACN,IAA5C,CAAzB;IACA,OAAO,KAAIY,+BAAJ,EAAeL,OAAO,CAACM,WAAR,CAAoBP,SAApB,CAAf,EAA+C,KAAKF,OAAL,CAAaE,SAAb,CAA/C,EAAwEE,IAAxE,EAA8EE,UAA9E,CAAP;EACD;;AAjB4D"}
@@ -98,6 +98,12 @@ async function typeNodeToSchema(node, context) {
98
98
  case _typescript().SyntaxKind.IndexedAccessType:
99
99
  return indexedAccessType(node, context);
100
100
 
101
+ case _typescript().SyntaxKind.TemplateLiteralTypeSpan:
102
+ return templateLiteralTypeSpan(node, context);
103
+
104
+ case _typescript().SyntaxKind.TemplateLiteralType:
105
+ return templateLiteralType(node, context);
106
+
101
107
  case _typescript().SyntaxKind.ConstructorType:
102
108
  case _typescript().SyntaxKind.NamedTupleMember:
103
109
  case _typescript().SyntaxKind.OptionalType:
@@ -106,8 +112,6 @@ async function typeNodeToSchema(node, context) {
106
112
  case _typescript().SyntaxKind.InferType:
107
113
  case _typescript().SyntaxKind.ThisType:
108
114
  case _typescript().SyntaxKind.MappedType:
109
- case _typescript().SyntaxKind.TemplateLiteralType:
110
- case _typescript().SyntaxKind.TemplateLiteralTypeSpan:
111
115
  case _typescript().SyntaxKind.ImportType:
112
116
  case _typescript().SyntaxKind.ExpressionWithTypeArguments:
113
117
  case _typescript().SyntaxKind.JSDocTypeExpression:
@@ -286,4 +290,16 @@ async function indexedAccessType(node, context) {
286
290
  return new (_semanticsEntities().IndexedAccessSchema)(context.getLocation(node), objectType, indexType);
287
291
  }
288
292
 
293
+ async function templateLiteralType(node, context) {
294
+ const templateSpans = await (0, _pMapSeries().default)(node.templateSpans, span => templateLiteralTypeSpan(span, context));
295
+ const head = node.head.text;
296
+ return new (_semanticsEntities().TemplateLiteralTypeSchema)(context.getLocation(node), head, templateSpans);
297
+ }
298
+
299
+ async function templateLiteralTypeSpan(node, context) {
300
+ const type = await typeNodeToSchema(node.type, context);
301
+ const literal = node.literal.text;
302
+ return new (_semanticsEntities().TemplateLiteralTypeSpanSchema)(context.getLocation(node), literal, type);
303
+ }
304
+
289
305
  //# sourceMappingURL=type-node-to-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["typeNodeToSchema","node","context","location","getLocation","isKeywordType","KeywordTypeSchema","getText","kind","SyntaxKind","IntersectionType","intersectionType","UnionType","unionType","TypeReference","typeReference","TypeLiteral","typeLiteral","LiteralType","LiteralTypeSchema","FunctionType","functionType","TypeQuery","typeQuery","ArrayType","arrayType","TypeOperator","typeOperator","TupleType","tupleType","ParenthesizedType","parenthesizedType","TypePredicate","typePredicate","IndexedAccessType","indexedAccessType","ConstructorType","NamedTupleMember","OptionalType","RestType","ConditionalType","InferType","ThisType","MappedType","TemplateLiteralType","TemplateLiteralTypeSpan","ImportType","ExpressionWithTypeArguments","JSDocTypeExpression","JSDocAllType","JSDocUnknownType","JSDocNonNullableType","JSDocNullableType","JSDocOptionalType","JSDocFunctionType","JSDocVariadicType","JSDocNamepathType","JSDocSignature","JSDocTypeLiteral","Error","AnyKeyword","BigIntKeyword","BooleanKeyword","IntrinsicKeyword","NeverKeyword","NumberKeyword","ObjectKeyword","StringKeyword","SymbolKeyword","UndefinedKeyword","UnknownKeyword","VoidKeyword","types","pMapSeries","type","typeSchema","TypeIntersectionSchema","TypeUnionSchema","members","member","computeSchema","TypeLiteralSchema","name","typeName","resolveType","typeArguments","TypeRefSchema","args","arg","typeArgs","params","getParams","parameters","returnType","FunctionLikeSchema","displaySig","getQuickInfoDisplayString","exprName","TypeQuerySchema","elementType","TypeArraySchema","operatorName","getOperatorName","operator","TypeOperatorSchema","KeyOfKeyword","UniqueKeyword","ReadonlyKeyword","elements","elem","TupleTypeSchema","ParenthesizedTypeSchema","parameterName","isIdentifier","undefined","hasAssertsModifier","Boolean","assertsModifier","TypePredicateSchema","objectType","indexType","IndexedAccessSchema"],"sources":["type-node-to-schema.ts"],"sourcesContent":["import {\n TypeNode,\n SyntaxKind,\n KeywordTypeNode,\n FunctionTypeNode,\n TypeQueryNode,\n TypeReferenceNode,\n ArrayTypeNode,\n TypeOperatorNode,\n TupleTypeNode,\n IntersectionTypeNode,\n UnionTypeNode,\n TypeLiteralNode,\n ParenthesizedTypeNode,\n TypePredicateNode,\n isIdentifier,\n IndexedAccessTypeNode,\n} from 'typescript';\nimport {\n SchemaNode,\n TypeRefSchema,\n TypeIntersectionSchema,\n TypeUnionSchema,\n TypeLiteralSchema,\n TypeQuerySchema,\n LiteralTypeSchema,\n KeywordTypeSchema,\n TypeArraySchema,\n TypeOperatorSchema,\n TupleTypeSchema,\n FunctionLikeSchema,\n ParenthesizedTypeSchema,\n TypePredicateSchema,\n IndexedAccessSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\n\n// eslint-disable-next-line complexity\nexport async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const location = context.getLocation(node);\n if (isKeywordType(node)) {\n return new KeywordTypeSchema(location, node.getText());\n }\n switch (node.kind) {\n case SyntaxKind.IntersectionType:\n return intersectionType(node as IntersectionTypeNode, context);\n case SyntaxKind.UnionType:\n return unionType(node as UnionTypeNode, context);\n case SyntaxKind.TypeReference:\n return typeReference(node as TypeReferenceNode, context);\n case SyntaxKind.TypeLiteral:\n return typeLiteral(node as TypeLiteralNode, context);\n case SyntaxKind.LiteralType: // e.g. string/boolean\n return new LiteralTypeSchema(location, node.getText());\n case SyntaxKind.FunctionType:\n return functionType(node as FunctionTypeNode, context);\n case SyntaxKind.TypeQuery:\n return typeQuery(node as TypeQueryNode, context);\n case SyntaxKind.ArrayType:\n return arrayType(node as ArrayTypeNode, context);\n case SyntaxKind.TypeOperator:\n return typeOperator(node as TypeOperatorNode, context);\n case SyntaxKind.TupleType:\n return tupleType(node as TupleTypeNode, context);\n case SyntaxKind.ParenthesizedType:\n return parenthesizedType(node as ParenthesizedTypeNode, context);\n case SyntaxKind.TypePredicate:\n return typePredicate(node as TypePredicateNode, context);\n case SyntaxKind.IndexedAccessType:\n return indexedAccessType(node as IndexedAccessTypeNode, context);\n case SyntaxKind.ConstructorType:\n case SyntaxKind.NamedTupleMember:\n case SyntaxKind.OptionalType:\n case SyntaxKind.RestType:\n case SyntaxKind.ConditionalType:\n case SyntaxKind.InferType:\n case SyntaxKind.ThisType:\n case SyntaxKind.MappedType:\n case SyntaxKind.TemplateLiteralType:\n case SyntaxKind.TemplateLiteralTypeSpan:\n case SyntaxKind.ImportType:\n case SyntaxKind.ExpressionWithTypeArguments:\n case SyntaxKind.JSDocTypeExpression:\n case SyntaxKind.JSDocAllType:\n case SyntaxKind.JSDocUnknownType:\n case SyntaxKind.JSDocNonNullableType:\n case SyntaxKind.JSDocNullableType:\n case SyntaxKind.JSDocOptionalType:\n case SyntaxKind.JSDocFunctionType:\n case SyntaxKind.JSDocVariadicType:\n case SyntaxKind.JSDocNamepathType:\n case SyntaxKind.JSDocSignature:\n case SyntaxKind.JSDocTypeLiteral:\n throw new Error(`TypeNode ${node.kind} (probably ${SyntaxKind[node.kind]}) was not implemented yet.\ncontext: ${node.getText()}`);\n default:\n throw new Error(`Node ${node.kind} (probably ${SyntaxKind[node.kind]}) is not a TypeNode.\ncontext: ${node.getText()}`);\n }\n}\n\n/**\n * whether it's kind of `ts.KeywordTypeSyntaxKind`\n */\nfunction isKeywordType(node: TypeNode): node is KeywordTypeNode {\n switch (node.kind) {\n case SyntaxKind.AnyKeyword:\n case SyntaxKind.BigIntKeyword:\n case SyntaxKind.BooleanKeyword:\n case SyntaxKind.IntrinsicKeyword:\n case SyntaxKind.NeverKeyword:\n case SyntaxKind.NumberKeyword:\n case SyntaxKind.ObjectKeyword:\n case SyntaxKind.StringKeyword:\n case SyntaxKind.SymbolKeyword:\n case SyntaxKind.UndefinedKeyword:\n case SyntaxKind.UnknownKeyword:\n case SyntaxKind.VoidKeyword:\n return true;\n default:\n return false;\n }\n}\n\nasync function intersectionType(node: IntersectionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeIntersectionSchema(location, types);\n}\n\nasync function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeUnionSchema(location, types);\n}\n\n/**\n * not to be confused with \"LiteralType\", which is string/boolean/null.\n * this \"TypeLiteral\" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.\n */\nasync function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {\n const members = await pMapSeries(node.members, async (member) => {\n const typeSchema = await context.computeSchema(member);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeLiteralSchema(location, members);\n}\n\n/**\n * In the following example, `AriaButtonProps` is a type reference\n * ```ts\n * import type { AriaButtonProps } from '@react-types/button';\n * export type ButtonProps = AriaButtonProps & { a: string };\n * ```\n */\nasync function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {\n const name = node.typeName.getText();\n const type = await context.resolveType(node, name, false);\n if (node.typeArguments && type instanceof TypeRefSchema) {\n const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));\n type.typeArgs = args;\n }\n return type;\n}\n\nasync function functionType(node: FunctionTypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = node.name?.getText() || '';\n const params = await getParams(node.parameters, context);\n const returnType = await typeNodeToSchema(node.type, context);\n const location = context.getLocation(node);\n return new FunctionLikeSchema(location, name, params, returnType, '');\n}\n\n/**\n * e.g. `typeof Foo`\n */\nasync function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {\n const displaySig = await context.getQuickInfoDisplayString(node.exprName);\n const type = await context.resolveType(node.exprName, node.exprName.getText(), false);\n const location = context.getLocation(node);\n return new TypeQuerySchema(location, type, displaySig);\n}\n\nasync function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.elementType, context);\n const location = context.getLocation(node);\n return new TypeArraySchema(location, type);\n}\n\n/**\n * e.g. keyof typeof Foo\n */\nasync function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {\n const operatorName = getOperatorName(node.operator);\n const type = await typeNodeToSchema(node.type, context);\n return new TypeOperatorSchema(context.getLocation(node), operatorName, type);\n}\n\nfunction getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {\n switch (operator) {\n case SyntaxKind.KeyOfKeyword:\n return 'keyof';\n case SyntaxKind.UniqueKeyword:\n return 'unique';\n case SyntaxKind.ReadonlyKeyword:\n return 'readonly';\n default:\n throw new Error(`getOperatorName: unable to find operator name for ${operator}`);\n }\n}\n\nasync function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {\n const elements = await pMapSeries(node.elements, async (elem) => {\n const typeSchema = await typeNodeToSchema(elem, context);\n return typeSchema;\n });\n return new TupleTypeSchema(context.getLocation(node), elements);\n}\n\nasync function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n return new ParenthesizedTypeSchema(context.getLocation(node), type);\n}\n\nasync function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {\n const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';\n const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;\n const hasAssertsModifier = Boolean(node.assertsModifier);\n return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);\n}\n\nasync function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {\n const objectType = await typeNodeToSchema(node.objectType, context);\n const indexType = await typeNodeToSchema(node.indexType, context);\n return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAkBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAiBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACO,eAAeA,gBAAf,CAAgCC,IAAhC,EAAgDC,OAAhD,EAAsG;EAC3G,MAAMC,QAAQ,GAAGD,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAAjB;;EACA,IAAII,aAAa,CAACJ,IAAD,CAAjB,EAAyB;IACvB,OAAO,KAAIK,sCAAJ,EAAsBH,QAAtB,EAAgCF,IAAI,CAACM,OAAL,EAAhC,CAAP;EACD;;EACD,QAAQN,IAAI,CAACO,IAAb;IACE,KAAKC,wBAAA,CAAWC,gBAAhB;MACE,OAAOC,gBAAgB,CAACV,IAAD,EAA+BC,OAA/B,CAAvB;;IACF,KAAKO,wBAAA,CAAWG,SAAhB;MACE,OAAOC,SAAS,CAACZ,IAAD,EAAwBC,OAAxB,CAAhB;;IACF,KAAKO,wBAAA,CAAWK,aAAhB;MACE,OAAOC,aAAa,CAACd,IAAD,EAA4BC,OAA5B,CAApB;;IACF,KAAKO,wBAAA,CAAWO,WAAhB;MACE,OAAOC,WAAW,CAAChB,IAAD,EAA0BC,OAA1B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,MAAMC,kBAAkB,GAAGC,OAAO,CAACnH,IAAI,CAACoH,eAAN,CAAlC;EACA,OAAO,KAAIC,wCAAJ,EAAwBpH,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAAxB,EAAmD+G,aAAnD,EAAkEtC,IAAlE,EAAwEyC,kBAAxE,CAAP;AACD;;AAED,eAAehF,iBAAf,CAAiClC,IAAjC,EAA8DC,OAA9D,EAA+F;EAC7F,MAAMqH,UAAU,GAAG,MAAMvH,gBAAgB,CAACC,IAAI,CAACsH,UAAN,EAAkBrH,OAAlB,CAAzC;EACA,MAAMsH,SAAS,GAAG,MAAMxH,gBAAgB,CAACC,IAAI,CAACuH,SAAN,EAAiBtH,OAAjB,CAAxC;EACA,OAAO,KAAIuH,wCAAJ,EAAwBvH,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAAxB,EAAmDsH,UAAnD,EAA+DC,SAA/D,CAAP;AACD"}
1
+ {"version":3,"names":["typeNodeToSchema","node","context","location","getLocation","isKeywordType","KeywordTypeSchema","getText","kind","SyntaxKind","IntersectionType","intersectionType","UnionType","unionType","TypeReference","typeReference","TypeLiteral","typeLiteral","LiteralType","LiteralTypeSchema","FunctionType","functionType","TypeQuery","typeQuery","ArrayType","arrayType","TypeOperator","typeOperator","TupleType","tupleType","ParenthesizedType","parenthesizedType","TypePredicate","typePredicate","IndexedAccessType","indexedAccessType","TemplateLiteralTypeSpan","templateLiteralTypeSpan","TemplateLiteralType","templateLiteralType","ConstructorType","NamedTupleMember","OptionalType","RestType","ConditionalType","InferType","ThisType","MappedType","ImportType","ExpressionWithTypeArguments","JSDocTypeExpression","JSDocAllType","JSDocUnknownType","JSDocNonNullableType","JSDocNullableType","JSDocOptionalType","JSDocFunctionType","JSDocVariadicType","JSDocNamepathType","JSDocSignature","JSDocTypeLiteral","Error","AnyKeyword","BigIntKeyword","BooleanKeyword","IntrinsicKeyword","NeverKeyword","NumberKeyword","ObjectKeyword","StringKeyword","SymbolKeyword","UndefinedKeyword","UnknownKeyword","VoidKeyword","types","pMapSeries","type","typeSchema","TypeIntersectionSchema","TypeUnionSchema","members","member","computeSchema","TypeLiteralSchema","name","typeName","resolveType","typeArguments","TypeRefSchema","args","arg","typeArgs","params","getParams","parameters","returnType","FunctionLikeSchema","displaySig","getQuickInfoDisplayString","exprName","TypeQuerySchema","elementType","TypeArraySchema","operatorName","getOperatorName","operator","TypeOperatorSchema","KeyOfKeyword","UniqueKeyword","ReadonlyKeyword","elements","elem","TupleTypeSchema","ParenthesizedTypeSchema","parameterName","isIdentifier","undefined","hasAssertsModifier","Boolean","assertsModifier","TypePredicateSchema","objectType","indexType","IndexedAccessSchema","templateSpans","span","head","text","TemplateLiteralTypeSchema","literal","TemplateLiteralTypeSpanSchema"],"sources":["type-node-to-schema.ts"],"sourcesContent":["import {\n TypeNode,\n SyntaxKind,\n KeywordTypeNode,\n FunctionTypeNode,\n TypeQueryNode,\n TypeReferenceNode,\n ArrayTypeNode,\n TypeOperatorNode,\n TupleTypeNode,\n IntersectionTypeNode,\n UnionTypeNode,\n TypeLiteralNode,\n ParenthesizedTypeNode,\n TypePredicateNode,\n isIdentifier,\n IndexedAccessTypeNode,\n TemplateLiteralTypeNode,\n TemplateLiteralTypeSpan,\n} from 'typescript';\nimport {\n SchemaNode,\n TypeRefSchema,\n TypeIntersectionSchema,\n TypeUnionSchema,\n TypeLiteralSchema,\n TypeQuerySchema,\n LiteralTypeSchema,\n KeywordTypeSchema,\n TypeArraySchema,\n TypeOperatorSchema,\n TupleTypeSchema,\n FunctionLikeSchema,\n ParenthesizedTypeSchema,\n TypePredicateSchema,\n IndexedAccessSchema,\n TemplateLiteralTypeSpanSchema,\n TemplateLiteralTypeSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport pMapSeries from 'p-map-series';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { getParams } from './get-params';\n\n// eslint-disable-next-line complexity\nexport async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const location = context.getLocation(node);\n if (isKeywordType(node)) {\n return new KeywordTypeSchema(location, node.getText());\n }\n switch (node.kind) {\n case SyntaxKind.IntersectionType:\n return intersectionType(node as IntersectionTypeNode, context);\n case SyntaxKind.UnionType:\n return unionType(node as UnionTypeNode, context);\n case SyntaxKind.TypeReference:\n return typeReference(node as TypeReferenceNode, context);\n case SyntaxKind.TypeLiteral:\n return typeLiteral(node as TypeLiteralNode, context);\n case SyntaxKind.LiteralType: // e.g. string/boolean\n return new LiteralTypeSchema(location, node.getText());\n case SyntaxKind.FunctionType:\n return functionType(node as FunctionTypeNode, context);\n case SyntaxKind.TypeQuery:\n return typeQuery(node as TypeQueryNode, context);\n case SyntaxKind.ArrayType:\n return arrayType(node as ArrayTypeNode, context);\n case SyntaxKind.TypeOperator:\n return typeOperator(node as TypeOperatorNode, context);\n case SyntaxKind.TupleType:\n return tupleType(node as TupleTypeNode, context);\n case SyntaxKind.ParenthesizedType:\n return parenthesizedType(node as ParenthesizedTypeNode, context);\n case SyntaxKind.TypePredicate:\n return typePredicate(node as TypePredicateNode, context);\n case SyntaxKind.IndexedAccessType:\n return indexedAccessType(node as IndexedAccessTypeNode, context);\n case SyntaxKind.TemplateLiteralTypeSpan:\n return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);\n case SyntaxKind.TemplateLiteralType:\n return templateLiteralType(node as TemplateLiteralTypeNode, context);\n case SyntaxKind.ConstructorType:\n case SyntaxKind.NamedTupleMember:\n case SyntaxKind.OptionalType:\n case SyntaxKind.RestType:\n case SyntaxKind.ConditionalType:\n case SyntaxKind.InferType:\n case SyntaxKind.ThisType:\n case SyntaxKind.MappedType:\n case SyntaxKind.ImportType:\n case SyntaxKind.ExpressionWithTypeArguments:\n case SyntaxKind.JSDocTypeExpression:\n case SyntaxKind.JSDocAllType:\n case SyntaxKind.JSDocUnknownType:\n case SyntaxKind.JSDocNonNullableType:\n case SyntaxKind.JSDocNullableType:\n case SyntaxKind.JSDocOptionalType:\n case SyntaxKind.JSDocFunctionType:\n case SyntaxKind.JSDocVariadicType:\n case SyntaxKind.JSDocNamepathType:\n case SyntaxKind.JSDocSignature:\n case SyntaxKind.JSDocTypeLiteral:\n throw new Error(`TypeNode ${node.kind} (probably ${SyntaxKind[node.kind]}) was not implemented yet.\ncontext: ${node.getText()}`);\n default:\n throw new Error(`Node ${node.kind} (probably ${SyntaxKind[node.kind]}) is not a TypeNode.\ncontext: ${node.getText()}`);\n }\n}\n\n/**\n * whether it's kind of `ts.KeywordTypeSyntaxKind`\n */\nfunction isKeywordType(node: TypeNode): node is KeywordTypeNode {\n switch (node.kind) {\n case SyntaxKind.AnyKeyword:\n case SyntaxKind.BigIntKeyword:\n case SyntaxKind.BooleanKeyword:\n case SyntaxKind.IntrinsicKeyword:\n case SyntaxKind.NeverKeyword:\n case SyntaxKind.NumberKeyword:\n case SyntaxKind.ObjectKeyword:\n case SyntaxKind.StringKeyword:\n case SyntaxKind.SymbolKeyword:\n case SyntaxKind.UndefinedKeyword:\n case SyntaxKind.UnknownKeyword:\n case SyntaxKind.VoidKeyword:\n return true;\n default:\n return false;\n }\n}\n\nasync function intersectionType(node: IntersectionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeIntersectionSchema(location, types);\n}\n\nasync function unionType(node: UnionTypeNode, context: SchemaExtractorContext) {\n const types = await pMapSeries(node.types, async (type) => {\n const typeSchema = await typeNodeToSchema(type, context);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeUnionSchema(location, types);\n}\n\n/**\n * not to be confused with \"LiteralType\", which is string/boolean/null.\n * this \"TypeLiteral\" is an object with properties, such as: `{ a: string; b: number }`, similar to Interface.\n */\nasync function typeLiteral(node: TypeLiteralNode, context: SchemaExtractorContext) {\n const members = await pMapSeries(node.members, async (member) => {\n const typeSchema = await context.computeSchema(member);\n return typeSchema;\n });\n const location = context.getLocation(node);\n return new TypeLiteralSchema(location, members);\n}\n\n/**\n * In the following example, `AriaButtonProps` is a type reference\n * ```ts\n * import type { AriaButtonProps } from '@react-types/button';\n * export type ButtonProps = AriaButtonProps & { a: string };\n * ```\n */\nasync function typeReference(node: TypeReferenceNode, context: SchemaExtractorContext) {\n const name = node.typeName.getText();\n const type = await context.resolveType(node, name, false);\n if (node.typeArguments && type instanceof TypeRefSchema) {\n const args = await pMapSeries(node.typeArguments, (arg) => typeNodeToSchema(arg, context));\n type.typeArgs = args;\n }\n return type;\n}\n\nasync function functionType(node: FunctionTypeNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const name = node.name?.getText() || '';\n const params = await getParams(node.parameters, context);\n const returnType = await typeNodeToSchema(node.type, context);\n const location = context.getLocation(node);\n return new FunctionLikeSchema(location, name, params, returnType, '');\n}\n\n/**\n * e.g. `typeof Foo`\n */\nasync function typeQuery(node: TypeQueryNode, context: SchemaExtractorContext) {\n const displaySig = await context.getQuickInfoDisplayString(node.exprName);\n const type = await context.resolveType(node.exprName, node.exprName.getText(), false);\n const location = context.getLocation(node);\n return new TypeQuerySchema(location, type, displaySig);\n}\n\nasync function arrayType(node: ArrayTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.elementType, context);\n const location = context.getLocation(node);\n return new TypeArraySchema(location, type);\n}\n\n/**\n * e.g. keyof typeof Foo\n */\nasync function typeOperator(node: TypeOperatorNode, context: SchemaExtractorContext) {\n const operatorName = getOperatorName(node.operator);\n const type = await typeNodeToSchema(node.type, context);\n return new TypeOperatorSchema(context.getLocation(node), operatorName, type);\n}\n\nfunction getOperatorName(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.ReadonlyKeyword) {\n switch (operator) {\n case SyntaxKind.KeyOfKeyword:\n return 'keyof';\n case SyntaxKind.UniqueKeyword:\n return 'unique';\n case SyntaxKind.ReadonlyKeyword:\n return 'readonly';\n default:\n throw new Error(`getOperatorName: unable to find operator name for ${operator}`);\n }\n}\n\nasync function tupleType(node: TupleTypeNode, context: SchemaExtractorContext) {\n const elements = await pMapSeries(node.elements, async (elem) => {\n const typeSchema = await typeNodeToSchema(elem, context);\n return typeSchema;\n });\n return new TupleTypeSchema(context.getLocation(node), elements);\n}\n\nasync function parenthesizedType(node: ParenthesizedTypeNode, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n return new ParenthesizedTypeSchema(context.getLocation(node), type);\n}\n\nasync function typePredicate(node: TypePredicateNode, context: SchemaExtractorContext) {\n const parameterName = isIdentifier(node.parameterName) ? node.parameterName.getText() : 'this';\n const type = node.type ? await typeNodeToSchema(node.type, context) : undefined;\n const hasAssertsModifier = Boolean(node.assertsModifier);\n return new TypePredicateSchema(context.getLocation(node), parameterName, type, hasAssertsModifier);\n}\n\nasync function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExtractorContext) {\n const objectType = await typeNodeToSchema(node.objectType, context);\n const indexType = await typeNodeToSchema(node.indexType, context);\n return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);\n}\n\nasync function templateLiteralType(node: TemplateLiteralTypeNode, context: SchemaExtractorContext) {\n const templateSpans = await pMapSeries(node.templateSpans, (span) => templateLiteralTypeSpan(span, context));\n const head = node.head.text;\n return new TemplateLiteralTypeSchema(context.getLocation(node), head, templateSpans);\n}\n\nasync function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: SchemaExtractorContext) {\n const type = await typeNodeToSchema(node.type, context);\n const literal = node.literal.text;\n return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAoBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAmBA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;AACO,eAAeA,gBAAf,CAAgCC,IAAhC,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B,CAAxB,EAAmDwH,UAAnD,EAA+DC,SAA/D,CAAP;AACD;;AAED,eAAenF,mBAAf,CAAmCtC,IAAnC,EAAkEC,OAAlE,EAAmG;EACjG,MAAM0H,aAAa,GAAG,MAAM,IAAAjD,qBAAA,EAAW1E,IAAI,CAAC2H,aAAhB,EAAgCC,IAAD,IAAUxF,uBAAuB,CAACwF,IAAD,EAAO3H,OAAP,CAAhE,CAA5B;EACA,MAAM4H,IAAI,GAAG7H,IAAI,CAAC6H,IAAL,CAAUC,IAAvB;EACA,OAAO,KAAIC,8CAAJ,EAA8B9H,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAA9B,EAAyD6H,IAAzD,EAA+DF,aAA/D,CAAP;AACD;;AAED,eAAevF,uBAAf,CAAuCpC,IAAvC,EAAsEC,OAAtE,EAAuG;EACrG,MAAM0E,IAAI,GAAG,MAAM5E,gBAAgB,CAACC,IAAI,CAAC2E,IAAN,EAAY1E,OAAZ,CAAnC;EACA,MAAM+H,OAAO,GAAGhI,IAAI,CAACgI,OAAL,CAAaF,IAA7B;EACA,OAAO,KAAIG,kDAAJ,EAAkChI,OAAO,CAACE,WAAR,CAAoBH,IAApB,CAAlC,EAA6DgI,OAA7D,EAAsErD,IAAtE,CAAP;AACD"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.740",
3
+ "version": "0.0.741",
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.740"
9
+ "version": "0.0.741"
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.740",
21
+ "@teambit/compiler": "0.0.741",
22
22
  "@teambit/typescript.modules.ts-config-mutator": "0.0.68",
23
- "@teambit/component": "0.0.740",
24
- "@teambit/dependency-resolver": "0.0.740",
25
- "@teambit/semantics.entities.semantic-schema": "0.0.13",
23
+ "@teambit/component": "0.0.741",
24
+ "@teambit/dependency-resolver": "0.0.741",
25
+ "@teambit/semantics.entities.semantic-schema": "0.0.14",
26
26
  "@teambit/ts-server": "0.0.32",
27
- "@teambit/aspect-loader": "0.0.740",
27
+ "@teambit/aspect-loader": "0.0.741",
28
28
  "@teambit/bit-error": "0.0.394",
29
- "@teambit/builder": "0.0.740",
30
- "@teambit/isolator": "0.0.740",
29
+ "@teambit/builder": "0.0.741",
30
+ "@teambit/isolator": "0.0.741",
31
31
  "@teambit/logger": "0.0.584",
32
- "@teambit/schema": "0.0.740",
33
- "@teambit/workspace": "0.0.740",
32
+ "@teambit/schema": "0.0.741",
33
+ "@teambit/workspace": "0.0.741",
34
34
  "@teambit/cli": "0.0.492",
35
- "@teambit/pkg": "0.0.740"
35
+ "@teambit/pkg": "0.0.741"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/lodash": "4.14.165",
@@ -1,2 +1,2 @@
1
- export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.740/dist/typescript.composition.js')]
2
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.740/dist/typescript.docs.mdx')]
1
+ export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.741/dist/typescript.composition.js')]
2
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.741/dist/typescript.docs.mdx')]
@@ -53,9 +53,14 @@ export class ExportDeclaration implements SchemaTransformer {
53
53
  if (exportClause?.kind === SyntaxKind.NamespaceExport) {
54
54
  exportClause as NamespaceExport;
55
55
  const namespace = exportClause.name.getText();
56
- const sourceFile = await context.getSourceFileFromNode(exportClause.name);
56
+ const filePath = await context.getFilePathByNode(exportClause.name);
57
+ if (!filePath) {
58
+ throw new Error(`unable to find the file-path for "${namespace}"`);
59
+ }
60
+ const sourceFile = context.getSourceFileInsideComponent(filePath);
57
61
  if (!sourceFile) {
58
- throw new Error(`unable to find the source-file for "${namespace}"`);
62
+ // it's a namespace from another component or an external package.
63
+ return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(node));
59
64
  }
60
65
  const result = await context.computeSchema(sourceFile);
61
66
  if (!(result instanceof Module)) {
@@ -1,9 +1,8 @@
1
1
  import { SchemaNode, VariableSchema } from '@teambit/semantics.entities.semantic-schema';
2
- import ts, { FunctionTypeNode, Node, PropertySignature as PropertySignatureNode } from 'typescript';
2
+ import ts, { isComputedPropertyName, Node, PropertySignature as PropertySignatureNode } from 'typescript';
3
3
  import { SchemaTransformer } from '../schema-transformer';
4
4
  import { SchemaExtractorContext } from '../schema-extractor-context';
5
5
  import { parseTypeFromQuickInfo } from './utils/parse-type-from-quick-info';
6
- import { typeNodeToSchema } from './utils/type-node-to-schema';
7
6
 
8
7
  export class PropertySignature implements SchemaTransformer {
9
8
  predicate(node: Node) {
@@ -20,13 +19,8 @@ export class PropertySignature implements SchemaTransformer {
20
19
 
21
20
  async transform(prop: PropertySignatureNode, context: SchemaExtractorContext): Promise<SchemaNode> {
22
21
  const name = this.getName(prop);
23
- const info = await context.getQuickInfo(prop.name);
22
+ const info = isComputedPropertyName(prop.name) ? undefined : await context.getQuickInfo(prop.name);
24
23
  const displaySig = info?.body?.displayString || '';
25
- if (prop.type?.kind === ts.SyntaxKind.FunctionType) {
26
- // e.g. `propertySig: () => void;` inside interface
27
- const propType = prop.type as FunctionTypeNode;
28
- return typeNodeToSchema(propType, context);
29
- }
30
24
  const typeStr = parseTypeFromQuickInfo(info);
31
25
  const type = await context.resolveType(prop, typeStr);
32
26
  return new VariableSchema(context.getLocation(prop), name, displaySig, type);
@@ -20,8 +20,7 @@ export class TypeAliasTransformer implements SchemaTransformer {
20
20
 
21
21
  async transform(typeAlias: TypeAliasDeclaration, context: SchemaExtractorContext) {
22
22
  const type = await typeNodeToSchema(typeAlias.type, context);
23
- const info = await context.getQuickInfo(typeAlias.name);
24
- const displaySig = info?.body?.displayString;
25
- return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig || '');
23
+ const displaySig = await context.getQuickInfoDisplayString(typeAlias.name);
24
+ return new TypeSchema(context.getLocation(typeAlias), this.getName(typeAlias), type, displaySig);
26
25
  }
27
26
  }
@@ -15,6 +15,8 @@ import {
15
15
  TypePredicateNode,
16
16
  isIdentifier,
17
17
  IndexedAccessTypeNode,
18
+ TemplateLiteralTypeNode,
19
+ TemplateLiteralTypeSpan,
18
20
  } from 'typescript';
19
21
  import {
20
22
  SchemaNode,
@@ -32,6 +34,8 @@ import {
32
34
  ParenthesizedTypeSchema,
33
35
  TypePredicateSchema,
34
36
  IndexedAccessSchema,
37
+ TemplateLiteralTypeSpanSchema,
38
+ TemplateLiteralTypeSchema,
35
39
  } from '@teambit/semantics.entities.semantic-schema';
36
40
  import pMapSeries from 'p-map-series';
37
41
  import { SchemaExtractorContext } from '../../schema-extractor-context';
@@ -70,6 +74,10 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
70
74
  return typePredicate(node as TypePredicateNode, context);
71
75
  case SyntaxKind.IndexedAccessType:
72
76
  return indexedAccessType(node as IndexedAccessTypeNode, context);
77
+ case SyntaxKind.TemplateLiteralTypeSpan:
78
+ return templateLiteralTypeSpan(node as TemplateLiteralTypeSpan, context);
79
+ case SyntaxKind.TemplateLiteralType:
80
+ return templateLiteralType(node as TemplateLiteralTypeNode, context);
73
81
  case SyntaxKind.ConstructorType:
74
82
  case SyntaxKind.NamedTupleMember:
75
83
  case SyntaxKind.OptionalType:
@@ -78,8 +86,6 @@ export async function typeNodeToSchema(node: TypeNode, context: SchemaExtractorC
78
86
  case SyntaxKind.InferType:
79
87
  case SyntaxKind.ThisType:
80
88
  case SyntaxKind.MappedType:
81
- case SyntaxKind.TemplateLiteralType:
82
- case SyntaxKind.TemplateLiteralTypeSpan:
83
89
  case SyntaxKind.ImportType:
84
90
  case SyntaxKind.ExpressionWithTypeArguments:
85
91
  case SyntaxKind.JSDocTypeExpression:
@@ -243,3 +249,15 @@ async function indexedAccessType(node: IndexedAccessTypeNode, context: SchemaExt
243
249
  const indexType = await typeNodeToSchema(node.indexType, context);
244
250
  return new IndexedAccessSchema(context.getLocation(node), objectType, indexType);
245
251
  }
252
+
253
+ async function templateLiteralType(node: TemplateLiteralTypeNode, context: SchemaExtractorContext) {
254
+ const templateSpans = await pMapSeries(node.templateSpans, (span) => templateLiteralTypeSpan(span, context));
255
+ const head = node.head.text;
256
+ return new TemplateLiteralTypeSchema(context.getLocation(node), head, templateSpans);
257
+ }
258
+
259
+ async function templateLiteralTypeSpan(node: TemplateLiteralTypeSpan, context: SchemaExtractorContext) {
260
+ const type = await typeNodeToSchema(node.type, context);
261
+ const literal = node.literal.text;
262
+ return new TemplateLiteralTypeSpanSchema(context.getLocation(node), literal, type);
263
+ }