@teambit/typescript 0.0.756 → 0.0.759
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/schema-extractor-context.d.ts +1 -0
- package/dist/schema-extractor-context.js +17 -1
- package/dist/schema-extractor-context.js.map +1 -1
- package/dist/transformers/export-declaration.js +49 -36
- package/dist/transformers/export-declaration.js.map +1 -1
- package/package-tar/teambit-typescript-0.0.759.tgz +0 -0
- package/package.json +16 -16
- package/{preview-1654745302834.js → preview-1655090873683.js} +2 -2
- package/transformers/export-declaration.ts +52 -27
- package/package-tar/teambit-typescript-0.0.756.tgz +0 -0
|
@@ -17,6 +17,7 @@ export declare class SchemaExtractorContext {
|
|
|
17
17
|
* returns the location of a node in a source file.
|
|
18
18
|
*/
|
|
19
19
|
getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath?: boolean): Location;
|
|
20
|
+
getLocationAsString(node: Node): string;
|
|
20
21
|
getPathRelativeToComponent(filePath: string): string;
|
|
21
22
|
/**
|
|
22
23
|
* returns a signature for a node.
|
|
@@ -53,6 +53,16 @@ function _lodash() {
|
|
|
53
53
|
return data;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function _utils() {
|
|
57
|
+
const data = require("@teambit/legacy/dist/utils");
|
|
58
|
+
|
|
59
|
+
_utils = function () {
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
function _path() {
|
|
57
67
|
const data = require("path");
|
|
58
68
|
|
|
@@ -125,13 +135,19 @@ class SchemaExtractorContext {
|
|
|
125
135
|
const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
126
136
|
const line = position.line + 1;
|
|
127
137
|
const character = position.character + 1;
|
|
138
|
+
const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);
|
|
128
139
|
return {
|
|
129
|
-
|
|
140
|
+
filePath: (0, _utils().pathNormalizeToLinux)(filePath),
|
|
130
141
|
line,
|
|
131
142
|
character
|
|
132
143
|
};
|
|
133
144
|
}
|
|
134
145
|
|
|
146
|
+
getLocationAsString(node) {
|
|
147
|
+
const location = this.getLocation(node);
|
|
148
|
+
return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
135
151
|
getPathRelativeToComponent(filePath) {
|
|
136
152
|
const basePath = this.component.filesystem.files[0].base;
|
|
137
153
|
return (0, _path().relative)(basePath, filePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","componentDeps","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","file","fileName","getPathRelativeToComponent","filePath","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","location","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","getTypeRefForExternalPath","getCompIdByPkgName","dep","packageName","componentId","compIdByPath","getComponentIDByPath","compIdByPkg"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[]\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n\n return {\n file: absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName),\n line,\n character,\n };\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${\n location.character\n }`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(node);\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n getSourceFileInsideComponent(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFileInsideComponent(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFileInsideComponent(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr || 'any');\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAIA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEO,MAAMA,sBAAN,CAA6B;EAClCC,WAAW,CACAC,QADA,EAEAC,SAFA,EAGAC,SAHA,EAIAC,aAJA,EAKT;IAAA,KAJSH,QAIT,GAJSA,QAIT;I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AA3B;;IACA,IAAIqG,YAAJ,EAAkB;MAChB,OAAO,KAAInB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCqB,YAArC,CAAP;IACD;;IACD,MAAM3D,OAAO,GAAG,KAAKT,wBAAL,CAA8BjC,QAA9B,CAAhB;IACA,MAAMuG,WAAW,GAAG,KAAKN,kBAAL,CAAwBvD,OAAxB,CAApB;;IACA,IAAI6D,WAAJ,EAAiB;MACf,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqCuB,WAArC,CAAP;IACD;;IACD,OAAO,KAAIrB,kCAAJ,EAAkBrE,QAAlB,EAA4BmE,OAA5B,EAAqChG,SAArC,EAAgD0D,OAAhD,CAAP;EACD;;AA3TiC"}
|
|
1
|
+
{"version":3,"names":["SchemaExtractorContext","constructor","tsserver","component","extractor","componentDeps","undefined","computeSchema","node","getLocation","targetSourceFile","absolutePath","sourceFile","getSourceFile","position","getLineAndCharacterOfPosition","getStart","line","character","filePath","fileName","getPathRelativeToComponent","pathNormalizeToLinux","getLocationAsString","location","basePath","filesystem","files","base","relative","getSignature","getSignatureHelp","getPath","getPosition","offset","getPositionOfLineAndCharacter","getQuickInfo","err","message","Error","getQuickInfoDisplayString","quickInfo","body","displayString","typeDefinition","getTypeDefinition","visitTypeDefinition","findFileInComponent","find","file","path","includes","strings","map","format","endsWith","string","parsePackageNameFromPath","parts","split","length","lastPart","replace","sep","pkgParts","startsWith","pkgName","getSourceFileInsideComponent","parseSourceFile","getSourceFileFromNode","getFilePathByNode","def","getDefinition","firstDef","head","definition","startPosition","start","pos","nodeAtPos","getTokenAtPosition","visitDefinition","visit","parent","references","isExported","isFromComponent","getFileExports","exportDec","specifierPathStr","moduleSpecifier","getText","specifierPath","substring","absPath","resolve","computeExportedIdentifiers","setExports","exports","_exports","getExportedIdentifiers","jump","TransformerNotFound","resolveType","typeStr","isTypeStrFromQuickInfo","TypeRefSchema","type","ts","isTypeNode","typeNodeToSchema","getDef","headTypeDefinition","unknownExactType","InferenceTypeSchema","info","parseTypeFromQuickInfo","isDefInSameLocation","loc","schemaNode","getTypeRefForExternalPath","getCompIdByPkgName","dep","packageName","componentId","compIdByPath","getComponentIDByPath","compIdByPkg"],"sources":["schema-extractor-context.ts"],"sourcesContent":["import { TsserverClient } from '@teambit/ts-server';\nimport ts, { ExportDeclaration, Node, TypeNode } from 'typescript';\nimport { getTokenAtPosition } from 'tsutils';\nimport { head } from 'lodash';\n// @ts-ignore david we should figure fix this.\nimport type { AbstractVinyl } from '@teambit/legacy/dist/consumer/component/sources';\nimport { pathNormalizeToLinux } from '@teambit/legacy/dist/utils';\nimport { resolve, sep, relative } from 'path';\nimport { Component, ComponentID } from '@teambit/component';\nimport { TypeRefSchema, SchemaNode, InferenceTypeSchema, Location } from '@teambit/semantics.entities.semantic-schema';\nimport { ComponentDependency } from '@teambit/dependency-resolver';\nimport { TypeScriptExtractor } from './typescript.extractor';\nimport { ExportList } from './export-list';\nimport { typeNodeToSchema } from './transformers/utils/type-node-to-schema';\nimport { TransformerNotFound } from './exceptions';\nimport { parseTypeFromQuickInfo } from './transformers/utils/parse-type-from-quick-info';\n\nexport class SchemaExtractorContext {\n constructor(\n readonly tsserver: TsserverClient,\n readonly component: Component,\n readonly extractor: TypeScriptExtractor,\n readonly componentDeps: ComponentDependency[]\n ) {}\n\n computeSchema(node: Node) {\n return this.extractor.computeSchema(node, this);\n }\n\n /**\n * returns the location of a node in a source file.\n */\n getLocation(node: Node, targetSourceFile?: ts.SourceFile, absolutePath = false): Location {\n const sourceFile = targetSourceFile || node.getSourceFile();\n const position = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const line = position.line + 1;\n const character = position.character + 1;\n const filePath = absolutePath ? sourceFile.fileName : this.getPathRelativeToComponent(sourceFile.fileName);\n\n return {\n filePath: pathNormalizeToLinux(filePath),\n line,\n character,\n };\n }\n\n getLocationAsString(node: Node): string {\n const location = this.getLocation(node);\n return `${node.getSourceFile().fileName}, line: ${location.line}, character: ${location.character}`;\n }\n\n getPathRelativeToComponent(filePath: string): string {\n const basePath = this.component.filesystem.files[0].base;\n return relative(basePath, filePath);\n }\n\n /**\n * returns a signature for a node.\n */\n async getSignature(node: Node) {\n return this.tsserver.getSignatureHelp(this.getPath(node), this.getLocation(node));\n }\n\n /**\n * get the position for the tsserver.\n */\n getPosition(sourceFile: ts.SourceFile, line: number, offset: number): number {\n return sourceFile.getPositionOfLineAndCharacter(line - 1, offset - 1);\n }\n\n /**\n * get the path for a source file.\n */\n getPath(node: Node) {\n const sourceFile = node.getSourceFile();\n return sourceFile.fileName;\n }\n\n async getQuickInfo(node: Node) {\n const location = this.getLocation(node);\n try {\n return await this.tsserver.getQuickInfo(this.getPath(node), location);\n } catch (err: any) {\n if (err.message === 'No content available.') {\n throw new Error(\n `unable to get quickinfo data from tsserver at ${this.getPath(node)}, Ln ${location.line}, Col ${\n location.character\n }`\n );\n }\n throw err;\n }\n }\n\n async getQuickInfoDisplayString(node: Node): Promise<string> {\n const quickInfo = await this.getQuickInfo(node);\n return quickInfo?.body?.displayString || '';\n }\n\n /**\n * returns the type definition for a type.\n */\n typeDefinition(node: Node) {\n return this.tsserver.getTypeDefinition(this.getPath(node), this.getLocation(node));\n }\n\n visitTypeDefinition() {}\n\n private findFileInComponent(filePath: string) {\n return this.component.filesystem.files.find((file) => {\n // TODO: fix this line to support further extensions.\n if (file.path.includes(filePath)) {\n const strings = ['ts', 'tsx', 'js', 'jsx'].map((format) => {\n if (filePath.endsWith(format)) return filePath;\n return `${filePath}.${format}`;\n });\n\n return strings.find((string) => string === file.path);\n }\n\n return false;\n });\n }\n\n private parsePackageNameFromPath(path: string) {\n const parts = path.split('node_modules');\n if (parts.length === 1) return '';\n const lastPart = parts[parts.length - 1].replace(sep, '');\n const pkgParts = lastPart.split('/');\n if (lastPart.startsWith('@')) {\n // scoped package\n return `${pkgParts[0]}/${pkgParts[1]}`;\n }\n const pkgName = pkgParts[0];\n if (pkgName === 'typescript') {\n // it's a built-in type, such as \"string\".\n return '';\n }\n return pkgName;\n }\n\n /**\n * return the file if part of the component.\n * otherwise, a reference to the target package and the type name.\n */\n getSourceFileInsideComponent(filePath: string) {\n const file = this.findFileInComponent(filePath);\n if (!file) return undefined;\n return this.extractor.parseSourceFile(file);\n }\n\n async getSourceFileFromNode(node: Node) {\n const filePath = await this.getFilePathByNode(node);\n if (!filePath) {\n return undefined;\n }\n return this.getSourceFileInsideComponent(filePath);\n }\n\n async getFilePathByNode(node: Node) {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n return firstDef?.file;\n }\n\n /**\n * get a definition for a given node.\n */\n async definition(node: Node): Promise<Node | undefined> {\n const def = await this.tsserver.getDefinition(this.getPath(node), this.getLocation(node));\n\n const firstDef = head(def.body);\n if (!firstDef) {\n return undefined;\n }\n\n const startPosition = firstDef.start;\n const sourceFile = this.getSourceFileInsideComponent(firstDef.file);\n if (!sourceFile) {\n return undefined; // learn how to return a reference to a different component here.\n }\n const pos = this.getPosition(sourceFile, startPosition.line, startPosition.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n return nodeAtPos;\n }\n\n /**\n * visit a definition for node - e.g. return it's schema.\n */\n async visitDefinition(node: Node): Promise<SchemaNode | undefined> {\n const definition = await this.definition(node);\n if (!definition) {\n return undefined;\n }\n return this.visit(definition.parent);\n }\n\n async visit(node: Node): Promise<SchemaNode> {\n return this.extractor.computeSchema(node, this);\n }\n\n references() {}\n\n isExported() {}\n\n isFromComponent() {}\n\n async getFileExports(exportDec: ExportDeclaration) {\n const file = exportDec.getSourceFile().fileName;\n const specifierPathStr = exportDec.moduleSpecifier?.getText() || '';\n const specifierPath = specifierPathStr.substring(1, specifierPathStr.length - 1);\n const absPath = resolve(file, '..', specifierPath);\n const sourceFile = this.getSourceFileInsideComponent(absPath);\n if (!sourceFile) return [];\n return this.extractor.computeExportedIdentifiers(sourceFile, this);\n }\n\n _exports: ExportList | undefined = undefined;\n\n setExports(exports: ExportList) {\n this._exports = exports;\n return this;\n }\n\n getExportedIdentifiers(node: Node) {\n return this.extractor.computeExportedIdentifiers(node, this);\n }\n\n async jump(file: AbstractVinyl, start: any): Promise<SchemaNode | undefined> {\n const sourceFile = this.extractor.parseSourceFile(file);\n const pos = this.getPosition(sourceFile, start.line, start.offset);\n const nodeAtPos = getTokenAtPosition(sourceFile, pos);\n if (!nodeAtPos) return undefined;\n\n // this causes some infinite loops. it's helpful for getting more data from types that are not exported.\n // e.g.\n // ```ts\n // class Bar {}\n // export const getBar = () => new Bar();\n // ```\n // if (nodeAtPos.kind === ts.SyntaxKind.Identifier) {\n // // @todo: make sure with Ran that it's fine. Maybe it's better to do: `this.visit(nodeAtPos.parent);`\n // return this.visitDefinition(nodeAtPos);\n // }\n try {\n return await this.visit(nodeAtPos);\n } catch (err) {\n if (err instanceof TransformerNotFound) {\n return undefined;\n }\n throw err;\n }\n }\n\n /**\n * resolve a type by a node and its identifier.\n */\n async resolveType(\n node: Node & { type?: TypeNode },\n typeStr: string,\n isTypeStrFromQuickInfo = true\n ): Promise<SchemaNode> {\n const location = this.getLocation(node);\n if (this._exports?.includes(typeStr)) {\n return new TypeRefSchema(location, typeStr);\n }\n if (node.type && ts.isTypeNode(node.type)) {\n // if a node has \"type\" prop, it has the type data of the node. this normally happens when the code has the type\n // explicitly, e.g. `const str: string` vs implicitly `const str = 'some-string'`, which the node won't have \"type\"\n return typeNodeToSchema(node.type, this);\n }\n /**\n * tsserver has two different calls: \"definition\" and \"typeDefinition\".\n * normally, we need the \"typeDefinition\" to get the type data of a node.\n * sometimes, it has no data, for example when the node is of type TypeReference, and then using \"definition\" is\n * helpful. (couldn't find a rule when to use each one. e.g. \"VariableDeclaration\" sometimes has data only in\n * \"definition\" but it's not clear when/why).\n */\n const getDef = async () => {\n const typeDefinition = await this.typeDefinition(node);\n const headTypeDefinition = head(typeDefinition?.body);\n if (headTypeDefinition) {\n return headTypeDefinition;\n }\n const definition = await this.tsserver.getDefinition(node.getSourceFile().fileName, this.getLocation(node));\n return head(definition?.body);\n };\n const definition = await getDef();\n\n // when we can't figure out the component/package/type of this node, we'll use the typeStr as the type.\n const unknownExactType = async () => {\n if (isTypeStrFromQuickInfo) {\n return new InferenceTypeSchema(location, typeStr || 'any');\n }\n const info = await this.getQuickInfo(node);\n const type = parseTypeFromQuickInfo(info);\n return new InferenceTypeSchema(location, type);\n };\n if (!definition) {\n return unknownExactType();\n }\n\n // the reason for this check is to avoid infinite loop when calling `this.jump` with the same file+location\n const isDefInSameLocation = () => {\n if (definition.file !== node.getSourceFile().fileName) {\n return false;\n }\n const loc = this.getLocation(node);\n return loc.line === definition.start.line && loc.character === definition.start.offset;\n };\n\n const file = this.findFileInComponent(definition.file);\n if (file) {\n if (isDefInSameLocation()) {\n return unknownExactType();\n }\n const schemaNode = await this.jump(file, definition.start);\n return schemaNode || unknownExactType();\n }\n return this.getTypeRefForExternalPath(typeStr, definition.file, location);\n }\n\n private getCompIdByPkgName(pkgName: string): ComponentID | undefined {\n return this.componentDeps.find((dep) => dep.packageName === pkgName)?.componentId;\n }\n\n async getTypeRefForExternalPath(typeStr: string, filePath: string, location: Location): Promise<TypeRefSchema> {\n const compIdByPath = await this.extractor.getComponentIDByPath(filePath);\n if (compIdByPath) {\n return new TypeRefSchema(location, typeStr, compIdByPath);\n }\n const pkgName = this.parsePackageNameFromPath(filePath);\n const compIdByPkg = this.getCompIdByPkgName(pkgName);\n if (compIdByPkg) {\n return new TypeRefSchema(location, typeStr, compIdByPkg);\n }\n return new TypeRefSchema(location, typeStr, undefined, pkgName);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;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require("lodash");
|
|
24
|
-
|
|
25
|
-
_lodash = function () {
|
|
26
|
-
return data;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
22
|
function _typescript() {
|
|
33
23
|
const data = _interopRequireWildcard(require("typescript"));
|
|
34
24
|
|
|
@@ -100,46 +90,69 @@ class ExportDeclaration {
|
|
|
100
90
|
|
|
101
91
|
|
|
102
92
|
if (exportClause.kind === _typescript().SyntaxKind.NamedExports) {
|
|
103
|
-
exportClause;
|
|
104
|
-
|
|
105
|
-
return context.visitDefinition(element.name);
|
|
106
|
-
}));
|
|
107
|
-
return new (_semanticsEntities().Module)(context.getLocation(exportDec), (0, _lodash().compact)(schemas));
|
|
93
|
+
const schemas = await namedExport(exportClause, context);
|
|
94
|
+
return new (_semanticsEntities().Module)(context.getLocation(exportDec), schemas);
|
|
108
95
|
} // e.g. `export * as Composition from './button';
|
|
109
96
|
|
|
110
97
|
|
|
111
98
|
if (exportClause.kind === _typescript().SyntaxKind.NamespaceExport) {
|
|
112
|
-
exportClause;
|
|
113
|
-
|
|
114
|
-
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
99
|
+
return namespaceExport(exportClause, exportDec, context);
|
|
100
|
+
} // should never reach here. exportClause can be either NamespaceExport or NamedExports
|
|
115
101
|
|
|
116
|
-
if (!filePath) {
|
|
117
|
-
throw new Error(`unable to find the file-path for "${namespace}"`);
|
|
118
|
-
}
|
|
119
102
|
|
|
120
|
-
|
|
103
|
+
throw new Error(`unrecognized exportClause type`);
|
|
104
|
+
}
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
// it's a namespace from another component or an external package.
|
|
124
|
-
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
|
|
125
|
-
}
|
|
106
|
+
}
|
|
126
107
|
|
|
127
|
-
|
|
108
|
+
exports.ExportDeclaration = ExportDeclaration;
|
|
128
109
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
110
|
+
async function namedExport(exportClause, context) {
|
|
111
|
+
const schemas = await Promise.all(exportClause.elements.map(async element => {
|
|
112
|
+
const definitionNode = await context.definition(element.name);
|
|
132
113
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
if (!definitionNode) {
|
|
115
|
+
// happens for example when the main index.ts file exports variable from an mdx file.
|
|
116
|
+
// tsserver is unable to get the definition node because it doesn't know to parse mdx files.
|
|
117
|
+
return new (_semanticsEntities().UnresolvedSchema)(context.getLocation(element.name), element.name.getText());
|
|
118
|
+
}
|
|
136
119
|
|
|
120
|
+
if (definitionNode.parent.kind === _typescript().SyntaxKind.ExportSpecifier) {
|
|
121
|
+
// the definition node is the same node as element.name. tsserver wasn't able to find the source for it
|
|
122
|
+
// normally, "bit install" should fix it. another option is to open vscode and look for errors.
|
|
123
|
+
throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(element.name)}.
|
|
124
|
+
make sure "bit status" is clean and there are no errors about missing packages/links.
|
|
125
|
+
also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
|
|
126
|
+
}
|
|
137
127
|
|
|
138
|
-
|
|
128
|
+
return context.computeSchema(definitionNode.parent);
|
|
129
|
+
}));
|
|
130
|
+
return schemas;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function namespaceExport(exportClause, exportDec, context) {
|
|
134
|
+
const namespace = exportClause.name.getText();
|
|
135
|
+
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
136
|
+
|
|
137
|
+
if (!filePath) {
|
|
138
|
+
throw new Error(`unable to find the file-path for "${namespace}"`);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
141
|
+
const sourceFile = context.getSourceFileInsideComponent(filePath);
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
if (!sourceFile) {
|
|
144
|
+
// it's a namespace from another component or an external package.
|
|
145
|
+
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const result = await context.computeSchema(sourceFile);
|
|
149
|
+
|
|
150
|
+
if (!(result instanceof _semanticsEntities().Module)) {
|
|
151
|
+
throw new Error(`expect result to be instance of Module`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
result.namespace = namespace;
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
144
157
|
|
|
145
158
|
//# sourceMappingURL=export-declaration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","Promise","all","element","
|
|
1
|
+
{"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","namedExport","Module","getLocation","namespaceExport","Promise","all","element","definitionNode","definition","UnresolvedSchema","parent","ExportSpecifier","getLocationAsString","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import { SchemaNode, Module, UnresolvedSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n const schemas = await namedExport(exportClause, context);\n return new Module(context.getLocation(exportDec), schemas);\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n return namespaceExport(exportClause, exportDec, context);\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n const definitionNode = await context.definition(element.name);\n if (!definitionNode) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {\n // the definition node is the same node as element.name. tsserver wasn't able to find the source for it\n // normally, \"bit install\" should fix it. another option is to open vscode and look for errors.\n throw new Error(`error: tsserver is unable to locate the identifier \"${element.name.getText()}\" at ${context.getLocationAsString(\n element.name\n )}.\nmake sure \"bit status\" is clean and there are no errors about missing packages/links.\nalso, make sure the tsconfig.json in the root has the \"jsx\" setting defined.`);\n }\n return context.computeSchema(definitionNode.parent);\n })\n );\n\n return schemas;\n}\n\nasync function namespaceExport(\n exportClause: NamespaceExport,\n exportDec: ExportDeclarationNode,\n context: SchemaExtractorContext\n) {\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n}\n"],"mappings":";;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AASA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAEO,MAAMA,iBAAN,CAAqD;EAC1DC,SAAS,CAACC,IAAD,EAAa;IACpB,OAAOA,IAAI,CAACC,IAAL,KAAcC,wBAAA,CAAWJ,iBAAhC;EACD;;EAEmB,MAAdK,cAAc,CAACC,SAAD,EAAmCC,OAAnC,EAAoE;IAAA;;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAV,gFAAwBL,IAAxB,MAAiCM,qBAAA,CAAGL,UAAH,CAAcM,YAAnD,EAAiE;MAC/DJ,SAAS,CAACE,YAAV;MACA,OAAOF,SAAS,CAACE,YAAV,CAAuBG,QAAvB,CAAgCC,GAAhC,CAAqCC,GAAD,IAAS;QAClD,OAAO,KAAIC,oCAAJ,EAAqBD,GAAG,CAACE,IAA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ACA,MAAM2B,QAAQ,GAAG,MAAMpC,OAAO,CAACqC,iBAAR,CAA0BpC,YAAY,CAACO,IAAvC,CAAvB;;EACA,IAAI,CAAC4B,QAAL,EAAe;IACb,MAAM,IAAInB,KAAJ,CAAW,qCAAoCkB,SAAU,GAAzD,CAAN;EACD;;EACD,MAAMjB,UAAU,GAAGlB,OAAO,CAACsC,4BAAR,CAAqCF,QAArC,CAAnB;;EACA,IAAI,CAAClB,UAAL,EAAiB;IACf;IACA,OAAOlB,OAAO,CAACuC,yBAAR,CAAkCJ,SAAlC,EAA6CC,QAA7C,EAAuDpC,OAAO,CAACwB,WAAR,CAAoBzB,SAApB,CAAvD,CAAP;EACD;;EACD,MAAMyC,MAAM,GAAG,MAAMxC,OAAO,CAACoB,aAAR,CAAsBF,UAAtB,CAArB;;EACA,IAAI,EAAEsB,MAAM,YAAYjB,2BAApB,CAAJ,EAAiC;IAC/B,MAAM,IAAIN,KAAJ,CAAW,wCAAX,CAAN;EACD;;EACDuB,MAAM,CAACL,SAAP,GAAmBA,SAAnB;EACA,OAAOK,MAAP;AACD"}
|
|
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.759",
|
|
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.759"
|
|
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.
|
|
21
|
+
"@teambit/compiler": "0.0.759",
|
|
22
22
|
"@teambit/typescript.modules.ts-config-mutator": "0.0.68",
|
|
23
|
-
"@teambit/component": "0.0.
|
|
24
|
-
"@teambit/dependency-resolver": "0.0.
|
|
25
|
-
"@teambit/semantics.entities.semantic-schema": "0.0.
|
|
23
|
+
"@teambit/component": "0.0.759",
|
|
24
|
+
"@teambit/dependency-resolver": "0.0.759",
|
|
25
|
+
"@teambit/semantics.entities.semantic-schema": "0.0.20",
|
|
26
26
|
"@teambit/ts-server": "0.0.32",
|
|
27
|
-
"@teambit/aspect-loader": "0.0.
|
|
27
|
+
"@teambit/aspect-loader": "0.0.759",
|
|
28
28
|
"@teambit/bit-error": "0.0.394",
|
|
29
|
-
"@teambit/builder": "0.0.
|
|
30
|
-
"@teambit/isolator": "0.0.
|
|
31
|
-
"@teambit/logger": "0.0.
|
|
32
|
-
"@teambit/schema": "0.0.
|
|
33
|
-
"@teambit/workspace": "0.0.
|
|
34
|
-
"@teambit/cli": "0.0.
|
|
35
|
-
"@teambit/pkg": "0.0.
|
|
29
|
+
"@teambit/builder": "0.0.759",
|
|
30
|
+
"@teambit/isolator": "0.0.759",
|
|
31
|
+
"@teambit/logger": "0.0.594",
|
|
32
|
+
"@teambit/schema": "0.0.759",
|
|
33
|
+
"@teambit/workspace": "0.0.759",
|
|
34
|
+
"@teambit/cli": "0.0.501",
|
|
35
|
+
"@teambit/pkg": "0.0.759"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash": "4.14.165",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@teambit/typescript.aspect-docs.typescript": "0.0.138"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@teambit/legacy": "1.0.
|
|
51
|
+
"@teambit/legacy": "1.0.281",
|
|
52
52
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
53
53
|
"react": "^16.8.0 || ^17.0.0"
|
|
54
54
|
},
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"react": "-"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@teambit/legacy": "1.0.
|
|
79
|
+
"@teambit/legacy": "1.0.281",
|
|
80
80
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
81
81
|
"react": "^16.8.0 || ^17.0.0"
|
|
82
82
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
2
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.
|
|
1
|
+
export const compositions = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.759/dist/typescript.composition.js')]
|
|
2
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.759/dist/typescript.docs.mdx')]
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { SchemaNode, Module } from '@teambit/semantics.entities.semantic-schema';
|
|
2
|
-
import { compact } from 'lodash';
|
|
1
|
+
import { SchemaNode, Module, UnresolvedSchema } from '@teambit/semantics.entities.semantic-schema';
|
|
3
2
|
import ts, {
|
|
4
3
|
Node,
|
|
5
4
|
SyntaxKind,
|
|
@@ -53,37 +52,63 @@ export class ExportDeclaration implements SchemaTransformer {
|
|
|
53
52
|
|
|
54
53
|
// e.g. `export { button1, button2 } as Composition from './button';
|
|
55
54
|
if (exportClause.kind === SyntaxKind.NamedExports) {
|
|
56
|
-
exportClause
|
|
57
|
-
|
|
58
|
-
exportClause.elements.map(async (element) => {
|
|
59
|
-
return context.visitDefinition(element.name);
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return new Module(context.getLocation(exportDec), compact(schemas));
|
|
55
|
+
const schemas = await namedExport(exportClause, context);
|
|
56
|
+
return new Module(context.getLocation(exportDec), schemas);
|
|
64
57
|
}
|
|
65
58
|
// e.g. `export * as Composition from './button';
|
|
66
59
|
if (exportClause.kind === SyntaxKind.NamespaceExport) {
|
|
67
|
-
exportClause
|
|
68
|
-
const namespace = exportClause.name.getText();
|
|
69
|
-
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
70
|
-
if (!filePath) {
|
|
71
|
-
throw new Error(`unable to find the file-path for "${namespace}"`);
|
|
72
|
-
}
|
|
73
|
-
const sourceFile = context.getSourceFileInsideComponent(filePath);
|
|
74
|
-
if (!sourceFile) {
|
|
75
|
-
// it's a namespace from another component or an external package.
|
|
76
|
-
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
|
|
77
|
-
}
|
|
78
|
-
const result = await context.computeSchema(sourceFile);
|
|
79
|
-
if (!(result instanceof Module)) {
|
|
80
|
-
throw new Error(`expect result to be instance of Module`);
|
|
81
|
-
}
|
|
82
|
-
result.namespace = namespace;
|
|
83
|
-
return result;
|
|
60
|
+
return namespaceExport(exportClause, exportDec, context);
|
|
84
61
|
}
|
|
85
62
|
|
|
86
63
|
// should never reach here. exportClause can be either NamespaceExport or NamedExports
|
|
87
64
|
throw new Error(`unrecognized exportClause type`);
|
|
88
65
|
}
|
|
89
66
|
}
|
|
67
|
+
|
|
68
|
+
async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {
|
|
69
|
+
const schemas = await Promise.all(
|
|
70
|
+
exportClause.elements.map(async (element) => {
|
|
71
|
+
const definitionNode = await context.definition(element.name);
|
|
72
|
+
if (!definitionNode) {
|
|
73
|
+
// happens for example when the main index.ts file exports variable from an mdx file.
|
|
74
|
+
// tsserver is unable to get the definition node because it doesn't know to parse mdx files.
|
|
75
|
+
return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
|
|
76
|
+
}
|
|
77
|
+
if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {
|
|
78
|
+
// the definition node is the same node as element.name. tsserver wasn't able to find the source for it
|
|
79
|
+
// normally, "bit install" should fix it. another option is to open vscode and look for errors.
|
|
80
|
+
throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(
|
|
81
|
+
element.name
|
|
82
|
+
)}.
|
|
83
|
+
make sure "bit status" is clean and there are no errors about missing packages/links.
|
|
84
|
+
also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
|
|
85
|
+
}
|
|
86
|
+
return context.computeSchema(definitionNode.parent);
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return schemas;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function namespaceExport(
|
|
94
|
+
exportClause: NamespaceExport,
|
|
95
|
+
exportDec: ExportDeclarationNode,
|
|
96
|
+
context: SchemaExtractorContext
|
|
97
|
+
) {
|
|
98
|
+
const namespace = exportClause.name.getText();
|
|
99
|
+
const filePath = await context.getFilePathByNode(exportClause.name);
|
|
100
|
+
if (!filePath) {
|
|
101
|
+
throw new Error(`unable to find the file-path for "${namespace}"`);
|
|
102
|
+
}
|
|
103
|
+
const sourceFile = context.getSourceFileInsideComponent(filePath);
|
|
104
|
+
if (!sourceFile) {
|
|
105
|
+
// it's a namespace from another component or an external package.
|
|
106
|
+
return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));
|
|
107
|
+
}
|
|
108
|
+
const result = await context.computeSchema(sourceFile);
|
|
109
|
+
if (!(result instanceof Module)) {
|
|
110
|
+
throw new Error(`expect result to be instance of Module`);
|
|
111
|
+
}
|
|
112
|
+
result.namespace = namespace;
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
Binary file
|