@teambit/typescript 0.0.955 → 0.0.957
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.
- package/dist/{preview-1673347296243.js → preview-1673494106850.js} +2 -2
- package/dist/schema-extractor-context.d.ts +2 -2
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/utils/jsdoc-to-doc-schema.d.ts +1 -1
- package/dist/transformers/utils/jsdoc-to-doc-schema.js +1 -0
- package/dist/transformers/utils/jsdoc-to-doc-schema.js.map +1 -1
- package/dist/typescript.extractor.d.ts +1 -1
- package/dist/typescript.extractor.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.957.tgz +0 -0
- package/package.json +16 -16
- package/transformers/utils/jsdoc-to-doc-schema.ts +2 -1
- package/package-tar/teambit-typescript-0.0.955.tgz +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.957/dist/typescript.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.957/dist/typescript.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -13,8 +13,8 @@ export declare class SchemaExtractorContext {
|
|
|
13
13
|
readonly component: Component;
|
|
14
14
|
readonly extractor: TypeScriptExtractor;
|
|
15
15
|
readonly componentDeps: ComponentDependency[];
|
|
16
|
-
readonly formatter
|
|
17
|
-
constructor(tsserver: TsserverClient, component: Component, extractor: TypeScriptExtractor, componentDeps: ComponentDependency[], formatter
|
|
16
|
+
readonly formatter?: Formatter | undefined;
|
|
17
|
+
constructor(tsserver: TsserverClient, component: Component, extractor: TypeScriptExtractor, componentDeps: ComponentDependency[], formatter?: Formatter | undefined);
|
|
18
18
|
computeSchema(node: Node): Promise<SchemaNode>;
|
|
19
19
|
/**
|
|
20
20
|
* returns the location of a node in a source file.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","componentDeps","formatter","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","filePath","fileName","getPathRelativeToComponent","pathNormalizeToLinux","getLocationAsString","location","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","def","getDefinition","firstDef","head","definitionInfo","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","getTypeRefForExternalNode","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","kind","SyntaxKind","ExportDeclaration","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","jsDocToDocSchema","canHaveJsDoc","jsDocs","getJsDoc","jsDoc","comment","getTextOfJSDocComment","tags","pMapSeries","tag","tagParser","DocSchema"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport { getTokenAtPosition, canHaveJsDoc, getJsDoc } from 'tsutils';\nimport ts, { ExportAssignment, getTextOfJSDocComment, ExportDeclaration, Node, SyntaxKind, TypeNode } from 'typescript';\nimport { head } from 'lodash';\n// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport {\n TypeRefSchema,\n SchemaNode,\n InferenceTypeSchema,\n Location,\n DocSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { Formatter } from '@teambit/formatter';\nimport pMapSeries from 'p-map-series';\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';\nimport { tagParser } from './transformers/utils/jsdoc-to-doc-schema';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[],\n readonly formatter: Formatter\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);\n\n return {\n filePath: pathNormalizeToLinux(filePath),\n line,\n character,\n };\n }\n\n getLocationAsString(node: Node): string {\n const location = this.getLocation(node);\n return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${\n location.character\n }`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(node);\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n getSourceFileInsideComponent(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\n }\n\n async definitionInfo(node: Node): Promise<protocol.DefinitionInfo | undefined> {\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n\n const def = await this.tsserver.getDefinition(filePath, location);\n\n const firstDef = head(def.body);\n\n return firstDef;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(definition: protocol.DefinitionInfo): Promise<Node | undefined> {\n const startPosition = definition.start;\n const sourceFile = this.getSourceFileInsideComponent(definition.file);\n if (!sourceFile) {\n // it might be an external reference, cant get the node\n return undefined;\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definitionInfo = await this.definitionInfo(node);\n if (!definitionInfo) {\n return undefined;\n }\n\n const definition = await this.definition(definitionInfo);\n if (!definition) {\n return this.getTypeRefForExternalNode(node);\n }\n\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration | ExportAssignment) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr =\n (exportDec.kind === SyntaxKind.ExportDeclaration && exportDec.moduleSpecifier?.getText()) || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFileInsideComponent(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr || 'any');\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type, typeStr);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalNode(node: Node): Promise<TypeRefSchema> {\n const info = await this.getQuickInfo(node);\n const typeStr = parseTypeFromQuickInfo(info);\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n return this.getTypeRefForExternalPath(typeStr, filePath, location);\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n\n async jsDocToDocSchema(node: Node): Promise<DocSchema | undefined> {\n if (!canHaveJsDoc(node)) {\n return undefined;\n }\n const jsDocs = getJsDoc(node);\n if (!jsDocs.length) {\n return undefined;\n }\n // not sure how common it is to have multiple JSDocs. never seen it before.\n // regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)\n const jsDoc = jsDocs[0];\n const location = this.getLocation(jsDoc);\n const comment = getTextOfJSDocComment(jsDoc.comment);\n const tags = jsDoc.tags ? await pMapSeries(jsDoc.tags, (tag) => tagParser(tag, this, this.formatter)) : undefined;\n return new DocSchema(location, jsDoc.getText(), comment, tags);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;E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or","componentDeps","formatter","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","filePath","fileName","getPathRelativeToComponent","pathNormalizeToLinux","getLocationAsString","location","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","def","getDefinition","firstDef","head","definitionInfo","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","getTypeRefForExternalNode","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","kind","SyntaxKind","ExportDeclaration","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","jsDocToDocSchema","canHaveJsDoc","jsDocs","getJsDoc","jsDoc","comment","getTextOfJSDocComment","tags","pMapSeries","tag","tagParser","DocSchema"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport { getTokenAtPosition, canHaveJsDoc, getJsDoc } from 'tsutils';\nimport ts, { ExportAssignment, getTextOfJSDocComment, ExportDeclaration, Node, SyntaxKind, TypeNode } from 'typescript';\nimport { head } from 'lodash';\n// eslint-disable-next-line import/no-unresolved\nimport protocol from 'typescript/lib/protocol';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport {\n TypeRefSchema,\n SchemaNode,\n InferenceTypeSchema,\n Location,\n DocSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { Formatter } from '@teambit/formatter';\nimport pMapSeries from 'p-map-series';\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';\nimport { tagParser } from './transformers/utils/jsdoc-to-doc-schema';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[],\n readonly formatter?: Formatter\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);\n\n return {\n filePath: pathNormalizeToLinux(filePath),\n line,\n character,\n };\n }\n\n getLocationAsString(node: Node): string {\n const location = this.getLocation(node);\n return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${\n location.character\n }`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(node);\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n getSourceFileInsideComponent(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\n }\n\n async definitionInfo(node: Node): Promise<protocol.DefinitionInfo | undefined> {\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n\n const def = await this.tsserver.getDefinition(filePath, location);\n\n const firstDef = head(def.body);\n\n return firstDef;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(definition: protocol.DefinitionInfo): Promise<Node | undefined> {\n const startPosition = definition.start;\n const sourceFile = this.getSourceFileInsideComponent(definition.file);\n if (!sourceFile) {\n // it might be an external reference, cant get the node\n return undefined;\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definitionInfo = await this.definitionInfo(node);\n if (!definitionInfo) {\n return undefined;\n }\n\n const definition = await this.definition(definitionInfo);\n if (!definition) {\n return this.getTypeRefForExternalNode(node);\n }\n\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration | ExportAssignment) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr =\n (exportDec.kind === SyntaxKind.ExportDeclaration && exportDec.moduleSpecifier?.getText()) || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFileInsideComponent(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr || 'any');\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type, typeStr);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalNode(node: Node): Promise<TypeRefSchema> {\n const info = await this.getQuickInfo(node);\n const typeStr = parseTypeFromQuickInfo(info);\n const location = this.getLocation(node);\n const filePath = this.getPath(node);\n return this.getTypeRefForExternalPath(typeStr, filePath, location);\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n\n async jsDocToDocSchema(node: Node): Promise<DocSchema | undefined> {\n if (!canHaveJsDoc(node)) {\n return undefined;\n }\n const jsDocs = getJsDoc(node);\n if (!jsDocs.length) {\n return undefined;\n }\n // not sure how common it is to have multiple JSDocs. never seen it before.\n // regardless, in typescript implementation of methods like `getJSDocDeprecatedTag()`, they use the first one. (`getFirstJSDocTag()`)\n const jsDoc = jsDocs[0];\n const location = this.getLocation(jsDoc);\n const comment = getTextOfJSDocComment(jsDoc.comment);\n const tags = jsDoc.tags ? await pMapSeries(jsDoc.tags, (tag) => tagParser(tag, this, this.formatter)) : undefined;\n return new DocSchema(location, jsDoc.getText(), comment, tags);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAqE;AAAA;AAE9D,MAAMA,sBAAsB,CAAC;EAClCC,WAAW,CACAC,QAAwB,EACxBC,SAAoB,EACpBC,SAA8B,EAC9BC,aAAoC,EACpCC,SAAqB,EAC9B;IAAA,KALSJ,QAAwB,GAAxBA,QAAwB;IAAA,KACxBC,SAAoB,GAApBA,SAAoB;IAAA,KACpBC,SAA8B,GAA9BA,SAA8B;IAAA,KAC9BC,aAAoC,GAApCA,aAAoC;IAAA,KACpCC,SAAqB,GAArBA,SAAqB;IAAA,kDAgNGC,SAAS;EA/MzC;EAEHC,aAAa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O,CAAC;EACjE;EAEA,MAAMmE,gBAAgB,CAAC7H,IAAU,EAAkC;IACjE,IAAI,CAAC,IAAA8H,uBAAY,EAAC9H,IAAI,CAAC,EAAE;MACvB,OAAOF,SAAS;IAClB;IACA,MAAMiI,MAAM,GAAG,IAAAC,mBAAQ,EAAChI,IAAI,CAAC;IAC7B,IAAI,CAAC+H,MAAM,CAAC3E,MAAM,EAAE;MAClB,OAAOtD,SAAS;IAClB;IACA;IACA;IACA,MAAMmI,KAAK,GAAGF,MAAM,CAAC,CAAC,CAAC;IACvB,MAAM/G,QAAQ,GAAG,IAAI,CAACf,WAAW,CAACgI,KAAK,CAAC;IACxC,MAAMC,OAAO,GAAG,IAAAC,mCAAqB,EAACF,KAAK,CAACC,OAAO,CAAC;IACpD,MAAME,IAAI,GAAGH,KAAK,CAACG,IAAI,GAAG,MAAM,IAAAC,qBAAU,EAACJ,KAAK,CAACG,IAAI,EAAGE,GAAG,IAAK,IAAAC,6BAAS,EAACD,GAAG,EAAE,IAAI,EAAE,IAAI,CAACzI,SAAS,CAAC,CAAC,GAAGC,SAAS;IACjH,OAAO,KAAI0I,8BAAS,EAACxH,QAAQ,EAAEiH,KAAK,CAACzC,OAAO,EAAE,EAAE0C,OAAO,EAAEE,IAAI,CAAC;EAChE;AACF;AAAC"}
|
|
@@ -2,4 +2,4 @@ import { JSDocTag } from 'typescript';
|
|
|
2
2
|
import { TagSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
3
|
import { Formatter } from '@teambit/formatter';
|
|
4
4
|
import { SchemaExtractorContext } from '../../schema-extractor-context';
|
|
5
|
-
export declare function tagParser(tag: JSDocTag, context: SchemaExtractorContext, formatter
|
|
5
|
+
export declare function tagParser(tag: JSDocTag, context: SchemaExtractorContext, formatter?: Formatter): Promise<TagSchema>;
|
|
@@ -77,6 +77,7 @@ async function tagParser(tag, context, formatter) {
|
|
|
77
77
|
const tagName = tag.tagName.getText(tag.getSourceFile());
|
|
78
78
|
if (tagName === 'example') {
|
|
79
79
|
const comment = (0, _typescript().getTextOfJSDocComment)(tag.comment);
|
|
80
|
+
if (!formatter) return simpleTag(tag, tagName, context);
|
|
80
81
|
try {
|
|
81
82
|
const formattedComment = comment && (await formatter.formatSnippet(comment));
|
|
82
83
|
return new (_semanticsEntities().TagSchema)(context.getLocation(tag), tagName, formattedComment);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["tagParser","tag","context","formatter","kind","SyntaxKind","JSDocReturnTag","returnTag","JSDocPropertyTag","propertyLikeTag","JSDocParameterTag","JSDocAugmentsTag","simpleTag","TagName","augments","JSDocAuthorTag","author","JSDocClassTag","class","JSDocCallbackTag","callback","JSDocPublicTag","public","JSDocPrivateTag","private","JSDocProtectedTag","protected","JSDocReadonlyTag","readonly","JSDocOverrideTag","override","JSDocDeprecatedTag","deprecated","JSDocSeeTag","see","JSDocEnumTag","enum","JSDocThisTag","this","JSDocTypeTag","type","JSDocTemplateTag","template","JSDocTypedefTag","typedef","JSDocImplementsTag","implements","tagName","getText","getSourceFile","comment","getTextOfJSDocComment","formattedComment","formatSnippet","TagSchema","getLocation","e","typeExpression","typeNodeToSchema","undefined","ReturnTagSchema","PropertyLikeTagSchema","name"],"sources":["jsdoc-to-doc-schema.ts"],"sourcesContent":["/* eslint-disable no-fallthrough */\nimport {\n getTextOfJSDocComment,\n JSDocParameterTag,\n JSDocPropertyLikeTag,\n JSDocPropertyTag,\n JSDocReturnTag,\n JSDocTag,\n SyntaxKind,\n} from 'typescript';\nimport {\n PropertyLikeTagSchema,\n ReturnTagSchema,\n TagName,\n TagSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { Formatter } from '@teambit/formatter';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function tagParser(\n tag: JSDocTag,\n context: SchemaExtractorContext,\n formatter
|
|
1
|
+
{"version":3,"names":["tagParser","tag","context","formatter","kind","SyntaxKind","JSDocReturnTag","returnTag","JSDocPropertyTag","propertyLikeTag","JSDocParameterTag","JSDocAugmentsTag","simpleTag","TagName","augments","JSDocAuthorTag","author","JSDocClassTag","class","JSDocCallbackTag","callback","JSDocPublicTag","public","JSDocPrivateTag","private","JSDocProtectedTag","protected","JSDocReadonlyTag","readonly","JSDocOverrideTag","override","JSDocDeprecatedTag","deprecated","JSDocSeeTag","see","JSDocEnumTag","enum","JSDocThisTag","this","JSDocTypeTag","type","JSDocTemplateTag","template","JSDocTypedefTag","typedef","JSDocImplementsTag","implements","tagName","getText","getSourceFile","comment","getTextOfJSDocComment","formattedComment","formatSnippet","TagSchema","getLocation","e","typeExpression","typeNodeToSchema","undefined","ReturnTagSchema","PropertyLikeTagSchema","name"],"sources":["jsdoc-to-doc-schema.ts"],"sourcesContent":["/* eslint-disable no-fallthrough */\nimport {\n getTextOfJSDocComment,\n JSDocParameterTag,\n JSDocPropertyLikeTag,\n JSDocPropertyTag,\n JSDocReturnTag,\n JSDocTag,\n SyntaxKind,\n} from 'typescript';\nimport {\n PropertyLikeTagSchema,\n ReturnTagSchema,\n TagName,\n TagSchema,\n} from '@teambit/semantics.entities.semantic-schema';\nimport { Formatter } from '@teambit/formatter';\nimport { SchemaExtractorContext } from '../../schema-extractor-context';\nimport { typeNodeToSchema } from './type-node-to-schema';\n\nexport async function tagParser(\n tag: JSDocTag,\n context: SchemaExtractorContext,\n formatter?: Formatter\n): Promise<TagSchema> {\n // for some reason, in some cases, if `tag.getSourceFile()` is not provided to the `getText()`, it throws \"Cannot read property 'text' of undefined\"\n\n switch (tag.kind) {\n case SyntaxKind.JSDocReturnTag:\n return returnTag(tag as JSDocReturnTag, context);\n case SyntaxKind.JSDocPropertyTag:\n return propertyLikeTag(tag as JSDocPropertyTag, context);\n case SyntaxKind.JSDocParameterTag:\n return propertyLikeTag(tag as JSDocParameterTag, context);\n case SyntaxKind.JSDocAugmentsTag:\n return simpleTag(tag, TagName.augments, context);\n case SyntaxKind.JSDocAuthorTag:\n return simpleTag(tag, TagName.author, context);\n case SyntaxKind.JSDocClassTag:\n return simpleTag(tag, TagName.class, context);\n case SyntaxKind.JSDocCallbackTag:\n return simpleTag(tag, TagName.callback, context);\n case SyntaxKind.JSDocPublicTag:\n return simpleTag(tag, TagName.public, context);\n case SyntaxKind.JSDocPrivateTag:\n return simpleTag(tag, TagName.private, context);\n case SyntaxKind.JSDocProtectedTag:\n return simpleTag(tag, TagName.protected, context);\n case SyntaxKind.JSDocReadonlyTag:\n return simpleTag(tag, TagName.readonly, context);\n case SyntaxKind.JSDocOverrideTag:\n return simpleTag(tag, TagName.override, context);\n case SyntaxKind.JSDocDeprecatedTag:\n return simpleTag(tag, TagName.deprecated, context);\n case SyntaxKind.JSDocSeeTag:\n return simpleTag(tag, TagName.see, context);\n case SyntaxKind.JSDocEnumTag:\n return simpleTag(tag, TagName.enum, context);\n case SyntaxKind.JSDocThisTag:\n return simpleTag(tag, TagName.this, context);\n case SyntaxKind.JSDocTypeTag:\n return simpleTag(tag, TagName.type, context);\n case SyntaxKind.JSDocTemplateTag:\n return simpleTag(tag, TagName.template, context);\n case SyntaxKind.JSDocTypedefTag:\n return simpleTag(tag, TagName.typedef, context);\n case SyntaxKind.JSDocImplementsTag:\n return simpleTag(tag, TagName.implements, context);\n default: {\n const tagName: TagName | string = tag.tagName.getText(tag.getSourceFile());\n if (tagName === 'example') {\n const comment = getTextOfJSDocComment(tag.comment);\n if (!formatter) return simpleTag(tag, tagName, context);\n try {\n const formattedComment = comment && (await formatter.formatSnippet(comment));\n return new TagSchema(context.getLocation(tag), tagName, formattedComment);\n } catch (e) {\n return simpleTag(tag, tagName, context);\n }\n }\n return simpleTag(tag, tagName, context);\n }\n }\n}\n\nfunction simpleTag(tag: JSDocTag, tagName: TagName | string, context: SchemaExtractorContext): TagSchema {\n return new TagSchema(context.getLocation(tag), tagName, getTextOfJSDocComment(tag.comment));\n}\n\nasync function returnTag(tag: JSDocReturnTag, context: SchemaExtractorContext) {\n const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;\n return new ReturnTagSchema(context.getLocation(tag), getTextOfJSDocComment(tag.comment), type);\n}\n\nasync function propertyLikeTag(tag: JSDocPropertyLikeTag, context: SchemaExtractorContext) {\n const type = tag.typeExpression?.type ? await typeNodeToSchema(tag.typeExpression?.type, context) : undefined;\n return new PropertyLikeTagSchema(\n context.getLocation(tag),\n tag.name.getText(),\n getTextOfJSDocComment(tag.comment),\n type\n );\n}\n"],"mappings":";;;;;;;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAQA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAlBA;;AAoBO,eAAeA,SAAS,CAC7BC,GAAa,EACbC,OAA+B,EAC/BC,SAAqB,EACD;EACpB;;EAEA,QAAQF,GAAG,CAACG,IAAI;IACd,KAAKC,wBAAU,CAACC,cAAc;MAC5B,OAAOC,SAAS,CAACN,GAAG,EAAoBC,OAAO,CAAC;IAClD,KAAKG,wBAAU,CAACG,gBAAgB;MAC9B,OAAOC,eAAe,CAACR,GAAG,EAAsBC,OAAO,CAAC;IAC1D,KAAKG,wBAAU,CAACK,iBAAiB;MAC/B,OAAOD,eAAe,CAACR,GAAG,EAAuBC,OAAO,CAAC;IAC3D,KAAKG,wBAAU,CAACM,gBAAgB;MAC9B,OAAOC,SAAS,CAACX,GAAG,EAAEY,4BAAO,CAACC,QAAQ,EAAEZ,OAAO,CAAC;IAClD,KAAKG,wBAAU,CAACU,cAAc;MAC5B,OAAOH,SAAS,CAACX,GAAG,EAAEY,4BAAO,CAACG,MAAM,EAAEd,OAAO,CAAC;IAChD,KAAKG,wBAAU,CAACY,aAAa;MAC3B,OAAOL,SAAS,CAACX,GAAG,EAAEY,4BAAO,CAACK,KAAK,EAAEhB,OAAO,CAAC;IAC/C,KAAKG,wBAAU,CAACc,gBAAgB;MAC9B,OAAOP,SAAS,CAACX,GAAG,EAAEY,4BAAO,CAACO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ACiD,OAAO,CAAC,CAAC;AAC7F;AAEA,eAAe3C,SAAS,CAACN,GAAmB,EAAEC,OAA+B,EAAE;EAAA;EAC7E,MAAMsC,IAAI,GAAG,uBAAAvC,GAAG,CAACwD,cAAc,gDAAlB,oBAAoBjB,IAAI,GAAG,MAAM,IAAAkB,oCAAgB,0BAACzD,GAAG,CAACwD,cAAc,yDAAlB,qBAAoBjB,IAAI,EAAEtC,OAAO,CAAC,GAAGyD,SAAS;EAC7G,OAAO,KAAIC,oCAAe,EAAC1D,OAAO,CAACqD,WAAW,CAACtD,GAAG,CAAC,EAAE,IAAAkD,mCAAqB,EAAClD,GAAG,CAACiD,OAAO,CAAC,EAAEV,IAAI,CAAC;AAChG;AAEA,eAAe/B,eAAe,CAACR,GAAyB,EAAEC,OAA+B,EAAE;EAAA;EACzF,MAAMsC,IAAI,GAAG,wBAAAvC,GAAG,CAACwD,cAAc,iDAAlB,qBAAoBjB,IAAI,GAAG,MAAM,IAAAkB,oCAAgB,0BAACzD,GAAG,CAACwD,cAAc,yDAAlB,qBAAoBjB,IAAI,EAAEtC,OAAO,CAAC,GAAGyD,SAAS;EAC7G,OAAO,KAAIE,0CAAqB,EAC9B3D,OAAO,CAACqD,WAAW,CAACtD,GAAG,CAAC,EACxBA,GAAG,CAAC6D,IAAI,CAACd,OAAO,EAAE,EAClB,IAAAG,mCAAqB,EAAClD,GAAG,CAACiD,OAAO,CAAC,EAClCV,IAAI,CACL;AACH"}
|
|
@@ -22,7 +22,7 @@ export declare class TypeScriptExtractor implements SchemaExtractor {
|
|
|
22
22
|
/**
|
|
23
23
|
* extract a component schema.
|
|
24
24
|
*/
|
|
25
|
-
extract(component: Component, formatter
|
|
25
|
+
extract(component: Component, formatter?: Formatter): Promise<APISchema>;
|
|
26
26
|
dispose(): void;
|
|
27
27
|
computeExportedIdentifiers(node: Node, context: SchemaExtractorContext): Promise<import("./export-identifier").ExportIdentifier[]>;
|
|
28
28
|
private createContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","sourceFile","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","extract","component","formatter","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","id","dispose","killTsServer","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate","from","options","getTsconfig","config","compilerOptions","getAspect","TypescriptAspect","wsPath"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { getTsconfig } from 'get-tsconfig';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, ModuleSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { EnvContext } from '@teambit/envs';\nimport { Formatter } from '@teambit/formatter';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\nimport { ExtractorOptions } from './extractor-options';\nimport { TypescriptAspect } from './typescript.aspect';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl): SourceFile {\n const sourceFile = ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true\n /** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */\n );\n // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.\n // console.log(\"sourceFile Errors\", file.path, sourceFile.parseDiagnostics);\n return sourceFile;\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component, formatter: Formatter): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component, formatter);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as ModuleSchema;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme, component.id);\n }\n\n dispose() {\n if (!this.tsserver) return;\n this.tsserver.killTsServer();\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(\n tsserver: TsserverClient,\n component: Component,\n formatter: Formatter\n ): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps, formatter);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n\n static from(options: ExtractorOptions) {\n return (context: EnvContext) => {\n const tsconfig = getTsconfig(options.tsconfig)?.config || { compilerOptions: options.compilerOptions };\n const tsMain = context.getAspect<TypescriptMain>(TypescriptAspect.id);\n // When loading the env from a scope you don't have a workspace\n const wsPath = tsMain.workspace?.path || '';\n return new TypeScriptExtractor(\n tsconfig,\n tsMain.schemaTransformerSlot,\n tsMain,\n wsPath,\n tsMain.depResolver,\n tsMain.workspace,\n );\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAKA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,mBAAmB,CAA4B;EAC1DC,WAAW,CACDC,QAAa,EACbC,qBAA4C,EAC5CC,MAAsB,EACtBC,QAAgB,EAChBC,WAAmC,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AA+BiE,MAAM,KAAI;QAAEC,eAAe,EAAEH,OAAO,CAACG;MAAgB,CAAC;MACtG,MAAMhE,MAAM,GAAGsB,OAAO,CAAC2C,SAAS,CAAiBC,+BAAgB,CAAC/B,EAAE,CAAC;MACrE;MACA,MAAMgC,MAAM,GAAG,sBAAAnE,MAAM,CAACG,SAAS,sDAAhB,kBAAkBO,IAAI,KAAI,EAAE;MAC3C,OAAO,IAAId,mBAAmB,CAC5BE,QAAQ,EACRE,MAAM,CAACD,qBAAqB,EAC5BC,MAAM,EACNmE,MAAM,EACNnE,MAAM,CAACE,WAAW,EAClBF,MAAM,CAACG,SAAS,CACjB;IACH,CAAC;EACH;AACF;AAAC"}
|
|
1
|
+
{"version":3,"names":["TypeScriptExtractor","constructor","tsconfig","schemaTransformerSlot","tsMain","rootPath","depResolver","workspace","undefined","parseSourceFile","file","sourceFile","ts","createSourceFile","path","contents","toString","ScriptTarget","Latest","extract","component","formatter","tsserver","getTsServer","mainFile","mainAst","context","createContext","exportNames","computeExportedIdentifiers","setExports","ExportList","moduleSchema","computeSchema","flatExportsRecursively","apiScheme","location","getLocation","APISchema","id","dispose","killTsServer","node","transformer","getTransformer","getIdentifiers","TransformerNotFound","componentDeps","getComponentDeps","SchemaExtractorContext","deps","getDependencies","getComponentDependencies","getTsserverClient","initTsserverClient","transform","getComponentIDByPath","getComponentIdByPath","transformers","flatten","values","find","singleTransformer","predicate","from","options","getTsconfig","config","compilerOptions","getAspect","TypescriptAspect","wsPath"],"sources":["typescript.extractor.ts"],"sourcesContent":["import ts, { Node, SourceFile } from 'typescript';\nimport { getTsconfig } from 'get-tsconfig';\nimport { SchemaExtractor } from '@teambit/schema';\nimport { TsserverClient } from '@teambit/ts-server';\nimport type { Workspace } from '@teambit/workspace';\nimport { ComponentDependency, DependencyResolverMain } from '@teambit/dependency-resolver';\nimport { SchemaNode, APISchema, ModuleSchema } from '@teambit/semantics.entities.semantic-schema';\nimport { Component } from '@teambit/component';\nimport { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { EnvContext } from '@teambit/envs';\nimport { Formatter } from '@teambit/formatter';\nimport { flatten } from 'lodash';\nimport { TypescriptMain, SchemaTransformerSlot } from './typescript.main.runtime';\nimport { TransformerNotFound } from './exceptions';\nimport { SchemaExtractorContext } from './schema-extractor-context';\nimport { ExportList } from './export-list';\nimport { ExtractorOptions } from './extractor-options';\nimport { TypescriptAspect } from './typescript.aspect';\n\nexport class TypeScriptExtractor implements SchemaExtractor {\n constructor(\n private tsconfig: any,\n private schemaTransformerSlot: SchemaTransformerSlot,\n private tsMain: TypescriptMain,\n private rootPath: string,\n private depResolver: DependencyResolverMain,\n private workspace: Workspace | undefined\n ) {}\n\n parseSourceFile(file: AbstractVinyl): SourceFile {\n const sourceFile = ts.createSourceFile(\n file.path,\n file.contents.toString('utf8'),\n ts.ScriptTarget.Latest,\n true\n /** don't pass the scriptKind, it'll be determined automatically by typescript by the filepath */\n );\n // leave this commented out, it's helpful when there are issues with ASTs. consider throwing in this case.\n // console.log(\"sourceFile Errors\", file.path, sourceFile.parseDiagnostics);\n return sourceFile;\n }\n\n /**\n * extract a component schema.\n */\n async extract(component: Component, formatter?: Formatter): Promise<APISchema> {\n const tsserver = await this.getTsServer();\n const mainFile = component.mainFile;\n const mainAst = this.parseSourceFile(mainFile);\n const context = await this.createContext(tsserver, component, formatter);\n const exportNames = await this.computeExportedIdentifiers(mainAst, context);\n context.setExports(new ExportList(exportNames));\n const moduleSchema = (await this.computeSchema(mainAst, context)) as ModuleSchema;\n moduleSchema.flatExportsRecursively();\n const apiScheme = moduleSchema;\n const location = context.getLocation(mainAst);\n\n return new APISchema(location, apiScheme, component.id);\n }\n\n dispose() {\n if (!this.tsserver) return;\n this.tsserver.killTsServer();\n }\n\n async computeExportedIdentifiers(node: Node, context: SchemaExtractorContext) {\n const transformer = this.getTransformer(node, context);\n if (!transformer || !transformer.getIdentifiers) {\n throw new TransformerNotFound(node, context.component, context.getLocation(node));\n }\n return transformer.getIdentifiers(node, context);\n }\n\n private async createContext(\n tsserver: TsserverClient,\n component: Component,\n formatter?: Formatter\n ): Promise<SchemaExtractorContext> {\n const componentDeps = await this.getComponentDeps(component);\n return new SchemaExtractorContext(tsserver, component, this, componentDeps, formatter);\n }\n\n private async getComponentDeps(component: Component): Promise<ComponentDependency[]> {\n const deps = await this.depResolver.getDependencies(component);\n const componentDeps = deps.getComponentDependencies();\n return componentDeps;\n }\n\n private tsserver: TsserverClient | undefined = undefined;\n\n private async getTsServer() {\n if (!this.tsserver) {\n const tsserver = this.tsMain.getTsserverClient();\n if (tsserver) {\n this.tsserver = tsserver;\n return tsserver;\n }\n\n this.tsserver = await this.tsMain.initTsserverClient(this.rootPath);\n return this.tsserver;\n }\n\n return this.tsserver;\n }\n\n async computeSchema(node: Node, context: SchemaExtractorContext): Promise<SchemaNode> {\n const transformer = this.getTransformer(node, context);\n // leave the next line commented out, it is used for debugging\n // console.log('transformer', transformer.constructor.name, node.getText());\n return transformer.transform(node, context);\n }\n\n async getComponentIDByPath(file: string) {\n if (!this.workspace) {\n return null;\n }\n return this.workspace.getComponentIdByPath(file);\n }\n\n /**\n * select the correct transformer for a node.\n */\n private getTransformer(node: Node, context: SchemaExtractorContext) {\n const transformers = flatten(this.schemaTransformerSlot.values());\n const transformer = transformers.find((singleTransformer) => singleTransformer.predicate(node));\n\n if (!transformer) throw new TransformerNotFound(node, context.component, context.getLocation(node));\n\n return transformer;\n }\n\n static from(options: ExtractorOptions) {\n return (context: EnvContext) => {\n const tsconfig = getTsconfig(options.tsconfig)?.config || { compilerOptions: options.compilerOptions };\n const tsMain = context.getAspect<TypescriptMain>(TypescriptAspect.id);\n // When loading the env from a scope you don't have a workspace\n const wsPath = tsMain.workspace?.path || '';\n return new TypeScriptExtractor(\n tsconfig,\n tsMain.schemaTransformerSlot,\n tsMain,\n wsPath,\n tsMain.depResolver,\n tsMain.workspace\n );\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;EAAA;EA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B,WAAW,GAAGe,YAAY,CAACG,IAAI,CAAEC,iBAAiB,IAAKA,iBAAiB,CAACC,SAAS,CAACrB,IAAI,CAAC,CAAC;IAE/F,IAAI,CAACC,WAAW,EAAE,MAAM,KAAIG,iCAAmB,EAACJ,IAAI,EAAEhB,OAAO,CAACN,SAAS,EAAEM,OAAO,CAACW,WAAW,CAACK,IAAI,CAAC,CAAC;IAEnG,OAAOC,WAAW;EACpB;EAEA,OAAOqB,IAAI,CAACC,OAAyB,EAAE;IACrC,OAAQvC,OAAmB,IAAK;MAAA;MAC9B,MAAMxB,QAAQ,GAAG,qBAAAgE,2BAAW,EAACD,OAAO,CAAC/D,QAAQ,CAAC,iDAA7B,aAA+BiE,MAAM,KAAI;QAAEC,eAAe,EAAEH,OAAO,CAACG;MAAgB,CAAC;MACtG,MAAMhE,MAAM,GAAGsB,OAAO,CAAC2C,SAAS,CAAiBC,+BAAgB,CAAC/B,EAAE,CAAC;MACrE;MACA,MAAMgC,MAAM,GAAG,sBAAAnE,MAAM,CAACG,SAAS,sDAAhB,kBAAkBO,IAAI,KAAI,EAAE;MAC3C,OAAO,IAAId,mBAAmB,CAC5BE,QAAQ,EACRE,MAAM,CAACD,qBAAqB,EAC5BC,MAAM,EACNmE,MAAM,EACNnE,MAAM,CAACE,WAAW,EAClBF,MAAM,CAACG,SAAS,CACjB;IACH,CAAC;EACH;AACF;AAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.957",
|
|
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.
|
|
9
|
+
"version": "0.0.957"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -20,23 +20,23 @@
|
|
|
20
20
|
"core-js": "^3.0.0",
|
|
21
21
|
"@babel/runtime": "7.20.0",
|
|
22
22
|
"@teambit/harmony": "0.4.6",
|
|
23
|
-
"@teambit/compiler": "0.0.
|
|
23
|
+
"@teambit/compiler": "0.0.957",
|
|
24
24
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.76",
|
|
25
|
-
"@teambit/component": "0.0.
|
|
26
|
-
"@teambit/dependency-resolver": "0.0.
|
|
27
|
-
"@teambit/formatter": "0.0.
|
|
25
|
+
"@teambit/component": "0.0.957",
|
|
26
|
+
"@teambit/dependency-resolver": "0.0.957",
|
|
27
|
+
"@teambit/formatter": "0.0.508",
|
|
28
28
|
"@teambit/semantics.entities.semantic-schema": "0.0.48",
|
|
29
29
|
"@teambit/ts-server": "0.0.39",
|
|
30
|
-
"@teambit/aspect-loader": "0.0.
|
|
31
|
-
"@teambit/envs": "0.0.
|
|
32
|
-
"@teambit/logger": "0.0.
|
|
33
|
-
"@teambit/workspace": "0.0.
|
|
30
|
+
"@teambit/aspect-loader": "0.0.957",
|
|
31
|
+
"@teambit/envs": "0.0.957",
|
|
32
|
+
"@teambit/logger": "0.0.734",
|
|
33
|
+
"@teambit/workspace": "0.0.957",
|
|
34
34
|
"@teambit/bit-error": "0.0.402",
|
|
35
|
-
"@teambit/builder": "0.0.
|
|
36
|
-
"@teambit/isolator": "0.0.
|
|
37
|
-
"@teambit/schema": "0.0.
|
|
38
|
-
"@teambit/cli": "0.0.
|
|
39
|
-
"@teambit/pkg": "0.0.
|
|
35
|
+
"@teambit/builder": "0.0.957",
|
|
36
|
+
"@teambit/isolator": "0.0.957",
|
|
37
|
+
"@teambit/schema": "0.0.957",
|
|
38
|
+
"@teambit/cli": "0.0.641",
|
|
39
|
+
"@teambit/pkg": "0.0.957"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/lodash": "4.14.165",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@teambit/typescript.aspect-docs.typescript": "0.0.150"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@teambit/legacy": "1.0.
|
|
55
|
+
"@teambit/legacy": "1.0.423",
|
|
56
56
|
"react": "^16.8.0 || ^17.0.0",
|
|
57
57
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
58
58
|
},
|
|
@@ -21,7 +21,7 @@ import { typeNodeToSchema } from './type-node-to-schema';
|
|
|
21
21
|
export async function tagParser(
|
|
22
22
|
tag: JSDocTag,
|
|
23
23
|
context: SchemaExtractorContext,
|
|
24
|
-
formatter
|
|
24
|
+
formatter?: Formatter
|
|
25
25
|
): Promise<TagSchema> {
|
|
26
26
|
// for some reason, in some cases, if `tag.getSourceFile()` is not provided to the `getText()`, it throws "Cannot read property 'text' of undefined"
|
|
27
27
|
|
|
@@ -70,6 +70,7 @@ export async function tagParser(
|
|
|
70
70
|
const tagName: TagName | string = tag.tagName.getText(tag.getSourceFile());
|
|
71
71
|
if (tagName === 'example') {
|
|
72
72
|
const comment = getTextOfJSDocComment(tag.comment);
|
|
73
|
+
if (!formatter) return simpleTag(tag, tagName, context);
|
|
73
74
|
try {
|
|
74
75
|
const formattedComment = comment && (await formatter.formatSnippet(comment));
|
|
75
76
|
return new TagSchema(context.getLocation(tag), tagName, formattedComment);
|
|
Binary file
|