@teambit/typescript 0.0.884 → 0.0.885

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.
@@ -80,29 +80,38 @@ class ExportDeclaration {
80
80
  }
81
81
  }
82
82
  exports.ExportDeclaration = ExportDeclaration;
83
+ function isSameNode(nodeA, nodeB) {
84
+ return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;
85
+ }
83
86
  async function namedExport(exportClause, context) {
84
87
  const schemas = await Promise.all(exportClause.elements.map(async element => {
85
- const definitionInfo = await context.definitionInfo(element);
86
- if (!definitionInfo) {
87
- // happens for example when the main index.ts file exports variable from an mdx file.
88
- // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
89
- return new (_semanticsEntities().UnresolvedSchema)(context.getLocation(element.name), element.name.getText());
90
- }
91
- const definitionNode = await context.definition(definitionInfo);
92
- if (!definitionNode) {
93
- return context.getTypeRefForExternalNode(element);
94
- }
95
- if (definitionNode.parent.kind === _typescript().SyntaxKind.ExportSpecifier) {
96
- // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
97
- // normally, "bit install" should fix it. another option is to open vscode and look for errors.
98
- throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(element.name)}.
99
- make sure "bit status" is clean and there are no errors about missing packages/links.
100
- also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
101
- }
102
- return context.computeSchema(definitionNode.parent);
88
+ return exportSpecifierToSchemaNode(element, context);
103
89
  }));
104
90
  return schemas;
105
91
  }
92
+ async function exportSpecifierToSchemaNode(element, context) {
93
+ const definitionInfo = await context.definitionInfo(element);
94
+ if (!definitionInfo) {
95
+ // happens for example when the main index.ts file exports variable from an mdx file.
96
+ // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
97
+ return new (_semanticsEntities().UnresolvedSchema)(context.getLocation(element.name), element.name.getText());
98
+ }
99
+ const definitionNode = await context.definition(definitionInfo);
100
+ if (!definitionNode) {
101
+ return context.getTypeRefForExternalNode(element);
102
+ }
103
+
104
+ // if it is reexported from another export
105
+ if (isSameNode(element, definitionNode.parent)) {
106
+ // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
107
+ // normally, "bit install" should fix it. another option is to open vscode and look for errors.
108
+ throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(element.name)}.
109
+ make sure "bit status" is clean and there are no errors about missing packages/links.
110
+ also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
111
+ }
112
+ if (definitionNode.parent.kind === _typescript().SyntaxKind.ExportSpecifier) return exportSpecifierToSchemaNode(definitionNode.parent, context);
113
+ return context.computeSchema(definitionNode.parent);
114
+ }
106
115
  async function namespaceExport(exportClause, exportDec, context) {
107
116
  const namespace = exportClause.name.getText();
108
117
  const filePath = await context.getFilePathByNode(exportClause.name);
@@ -1 +1 @@
1
- {"version":3,"names":["ExportDeclaration","predicate","node","kind","SyntaxKind","getIdentifiers","exportDec","context","exportClause","ts","NamedExports","elements","map","elm","ExportIdentifier","name","getText","getSourceFile","fileName","NamespaceExport","moduleSpecifier","getFileExports","transform","specifier","Error","sourceFile","getSourceFileFromNode","computeSchema","schemas","namedExport","Module","getLocation","namespaceExport","Promise","all","element","definitionInfo","UnresolvedSchema","definitionNode","definition","getTypeRefForExternalNode","parent","ExportSpecifier","getLocationAsString","namespace","filePath","getFilePathByNode","getSourceFileInsideComponent","getTypeRefForExternalPath","result"],"sources":["export-declaration.ts"],"sourcesContent":["import { SchemaNode, Module, UnresolvedSchema } from '@teambit/semantics.entities.semantic-schema';\nimport ts, {\n Node,\n SyntaxKind,\n ExportDeclaration as ExportDeclarationNode,\n NamedExports,\n NamespaceExport,\n} from 'typescript';\nimport { SchemaExtractorContext } from '../schema-extractor-context';\nimport { SchemaTransformer } from '../schema-transformer';\nimport { ExportIdentifier } from '../export-identifier';\n\nexport class ExportDeclaration implements SchemaTransformer {\n predicate(node: Node) {\n return node.kind === SyntaxKind.ExportDeclaration;\n }\n\n async getIdentifiers(exportDec: ExportDeclarationNode, context: SchemaExtractorContext) {\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamedExports) {\n exportDec.exportClause as NamedExports;\n return exportDec.exportClause.elements.map((elm) => {\n return new ExportIdentifier(elm.name.getText(), elm.getSourceFile().fileName);\n });\n }\n\n if (exportDec.exportClause?.kind === ts.SyntaxKind.NamespaceExport) {\n return [new ExportIdentifier(exportDec.exportClause.name.getText(), exportDec.getSourceFile().fileName)];\n }\n\n if (exportDec.moduleSpecifier) {\n return context.getFileExports(exportDec);\n }\n\n return [];\n }\n\n async transform(exportDec: ExportDeclarationNode, context: SchemaExtractorContext): Promise<SchemaNode> {\n const exportClause = exportDec.exportClause;\n\n // it's export-all, e.g. `export * from './button'`;\n if (!exportClause) {\n const specifier = exportDec.moduleSpecifier;\n if (!specifier) {\n throw new Error(`fatal: no specifier`);\n }\n const sourceFile = await context.getSourceFileFromNode(specifier);\n if (!sourceFile) {\n throw new Error(`unable to find the source-file`);\n }\n return context.computeSchema(sourceFile);\n }\n\n // e.g. `export { button1, button2 } as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamedExports) {\n const schemas = await namedExport(exportClause, context);\n return new Module(context.getLocation(exportDec), schemas);\n }\n // e.g. `export * as Composition from './button';\n if (exportClause.kind === SyntaxKind.NamespaceExport) {\n return namespaceExport(exportClause, exportDec, context);\n }\n\n // should never reach here. exportClause can be either NamespaceExport or NamedExports\n throw new Error(`unrecognized exportClause type`);\n }\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n const definitionInfo = await context.definitionInfo(element);\n if (!definitionInfo) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n const definitionNode = await context.definition(definitionInfo);\n if (!definitionNode) {\n return context.getTypeRefForExternalNode(element);\n }\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {\n // the definition node is the same node as element.name. tsserver wasn't able to find the source for it\n // normally, \"bit install\" should fix it. another option is to open vscode and look for errors.\n throw new Error(`error: tsserver is unable to locate the identifier \"${element.name.getText()}\" at ${context.getLocationAsString(\n element.name\n )}.\nmake sure \"bit status\" is clean and there are no errors about missing packages/links.\nalso, make sure the tsconfig.json in the root has the \"jsx\" setting defined.`);\n }\n return context.computeSchema(definitionNode.parent);\n })\n );\n\n return schemas;\n}\n\nasync function namespaceExport(\n exportClause: NamespaceExport,\n exportDec: ExportDeclarationNode,\n context: SchemaExtractorContext\n) {\n const namespace = exportClause.name.getText();\n const filePath = await context.getFilePathByNode(exportClause.name);\n if (!filePath) {\n throw new Error(`unable to find the file-path for \"${namespace}\"`);\n }\n const sourceFile = context.getSourceFileInsideComponent(filePath);\n if (!sourceFile) {\n // it's a namespace from another component or an external package.\n return context.getTypeRefForExternalPath(namespace, filePath, context.getLocation(exportDec));\n }\n const result = await context.computeSchema(sourceFile);\n if (!(result instanceof Module)) {\n throw new Error(`expect result to be instance of Module`);\n }\n result.namespace = namespace;\n return result;\n}\n"],"mappings":";;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AASA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAwD;AAAA;AAEjD,MAAMA,iBAAiB,CAA8B;EAC1DC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,wBAAU,CAACJ,iBAAiB;EACnD;EAEA,MAAMK,cAAc,CAACC,SAAgC,EAAEC,OAA+B,EAAE;IAAA;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAY,0DAAtB,sBAAwBL,IAAI,MAAKM,qBAAE,CAACL,UAAU,CAACM,YAAY,EAAE;MAC/DJ,SAAS,CAACE,YAAY;M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H;EAED,OAAOb,OAAO;AAChB;AAEA,eAAeI,eAAe,CAC5BxB,YAA6B,EAC7BF,SAAgC,EAChCC,OAA+B,EAC/B;EACA,MAAMqC,SAAS,GAAGpC,YAAY,CAACO,IAAI,CAACC,OAAO,EAAE;EAC7C,MAAM6B,QAAQ,GAAG,MAAMtC,OAAO,CAACuC,iBAAiB,CAACtC,YAAY,CAACO,IAAI,CAAC;EACnE,IAAI,CAAC8B,QAAQ,EAAE;IACb,MAAM,IAAIrB,KAAK,CAAE,qCAAoCoB,SAAU,GAAE,CAAC;EACpE;EACA,MAAMnB,UAAU,GAAGlB,OAAO,CAACwC,4BAA4B,CAACF,QAAQ,CAAC;EACjE,IAAI,CAACpB,UAAU,EAAE;IACf;IACA,OAAOlB,OAAO,CAACyC,yBAAyB,CAACJ,SAAS,EAAEC,QAAQ,EAAEtC,OAAO,CAACwB,WAAW,CAACzB,SAAS,CAAC,CAAC;EAC/F;EACA,MAAM2C,MAAM,GAAG,MAAM1C,OAAO,CAACoB,aAAa,CAACF,UAAU,CAAC;EACtD,IAAI,EAAEwB,MAAM,YAAYnB,2BAAM,CAAC,EAAE;IAC/B,MAAM,IAAIN,KAAK,CAAE,wCAAuC,CAAC;EAC3D;EACAyB,MAAM,CAACL,SAAS,GAAGA,SAAS;EAC5B,OAAOK,MAAM;AACf"}
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","isSameNode","nodeA","nodeB","pos","end","Promise","all","element","exportSpecifierToSchemaNode","definitionInfo","UnresolvedSchema","definitionNode","definition","getTypeRefForExternalNode","parent","getLocationAsString","ExportSpecifier","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 ExportSpecifier,\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\nfunction isSameNode(nodeA: Node, nodeB: Node): boolean {\n return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;\n}\n\nasync function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {\n const schemas = await Promise.all(\n exportClause.elements.map(async (element) => {\n return exportSpecifierToSchemaNode(element, context);\n })\n );\n\n return schemas;\n}\n\nasync function exportSpecifierToSchemaNode(element: ExportSpecifier, context: SchemaExtractorContext) {\n const definitionInfo = await context.definitionInfo(element);\n\n if (!definitionInfo) {\n // happens for example when the main index.ts file exports variable from an mdx file.\n // tsserver is unable to get the definition node because it doesn't know to parse mdx files.\n return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());\n }\n\n const definitionNode = await context.definition(definitionInfo);\n\n if (!definitionNode) {\n return context.getTypeRefForExternalNode(element);\n }\n\n // if it is reexported from another export\n if (isSameNode(element, definitionNode.parent)) {\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\n if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier)\n return exportSpecifierToSchemaNode(definitionNode.parent as ExportSpecifier, context);\n\n return context.computeSchema(definitionNode.parent);\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;AAUA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAAwD;AAAA;AAEjD,MAAMA,iBAAiB,CAA8B;EAC1DC,SAAS,CAACC,IAAU,EAAE;IACpB,OAAOA,IAAI,CAACC,IAAI,KAAKC,wBAAU,CAACJ,iBAAiB;EACnD;EAEA,MAAMK,cAAc,CAACC,SAAgC,EAAEC,OAA+B,EAAE;IAAA;IACtF,IAAI,0BAAAD,SAAS,CAACE,YAAY,0DAAtB,sBAAwBL,IAAI,MAAKM,qBAAE,CAACL,UAAU,CAACM,YAAY,EAAE;MAC/DJ,SAAS,CAACE,YAAY;MACtB,OAAOF,SAAS,CAACE,YAAY,CAACG,QAAQ,CAACC,GAAG,CAAEC,GAAG,IAAK;QAClD,OAAO,KAAIC,oCAAgB,EAACD,GAAG,CAACE,IAAI,CAACC,OAAO,EAAE,EAAEH,GAAG,CAACI,aAAa,EAAE,CAACC,QAAQ,CAAC;MAC/E,CAAC,CAAC;IACJ;IAEA,IAAI,2BAAAZ,SAAS,CAACE,YAAY,2DAAtB,uBAAwBL,IAAI,MAAKM,qBAAE,CAACL,UAAU,CAACe,eAAe,EAAE;MAClE,OAAO,CAAC,KAAIL,oCAAgB,EAACR,SAAS,CAACE,YAAY,CAACO,IAAI,CAACC,OAAO,EAAE,EAAEV,SAAS,CAACW,aAAa,EAAE,CAACC,QAAQ,CAAC,CAAC;IAC1G;IAEA,IAAIZ,SAAS,CAACc,eAAe,EAAE;MAC7B,OAAOb,OAAO,CAACc,cAAc,CAACf,SAAS,CAAC;IAC1C;IAEA,OAAO,EAAE;EACX;EAEA,MAAMgB,SAAS,CA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IAAI,CAACC,OAAO,EAAE;EAC7C,MAAMmC,QAAQ,GAAG,MAAM5C,OAAO,CAAC6C,iBAAiB,CAAC5C,YAAY,CAACO,IAAI,CAAC;EACnE,IAAI,CAACoC,QAAQ,EAAE;IACb,MAAM,IAAI3B,KAAK,CAAE,qCAAoC0B,SAAU,GAAE,CAAC;EACpE;EACA,MAAMzB,UAAU,GAAGlB,OAAO,CAAC8C,4BAA4B,CAACF,QAAQ,CAAC;EACjE,IAAI,CAAC1B,UAAU,EAAE;IACf;IACA,OAAOlB,OAAO,CAAC+C,yBAAyB,CAACJ,SAAS,EAAEC,QAAQ,EAAE5C,OAAO,CAACwB,WAAW,CAACzB,SAAS,CAAC,CAAC;EAC/F;EACA,MAAMiD,MAAM,GAAG,MAAMhD,OAAO,CAACoB,aAAa,CAACF,UAAU,CAAC;EACtD,IAAI,EAAE8B,MAAM,YAAYzB,2BAAM,CAAC,EAAE;IAC/B,MAAM,IAAIN,KAAK,CAAE,wCAAuC,CAAC;EAC3D;EACA+B,MAAM,CAACL,SAAS,GAAGA,SAAS;EAC5B,OAAOK,MAAM;AACf"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@teambit/typescript",
3
- "version": "0.0.884",
3
+ "version": "0.0.885",
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.884"
9
+ "version": "0.0.885"
10
10
  },
11
11
  "dependencies": {
12
12
  "lodash": "4.17.21",
@@ -19,22 +19,22 @@
19
19
  "@babel/runtime": "7.12.18",
20
20
  "core-js": "^3.0.0",
21
21
  "@teambit/harmony": "0.3.3",
22
- "@teambit/compiler": "0.0.884",
22
+ "@teambit/compiler": "0.0.885",
23
23
  "@teambit/typescript.modules.ts-config-mutator": "0.0.75",
24
- "@teambit/component": "0.0.884",
25
- "@teambit/dependency-resolver": "0.0.884",
24
+ "@teambit/component": "0.0.885",
25
+ "@teambit/dependency-resolver": "0.0.885",
26
26
  "@teambit/semantics.entities.semantic-schema": "0.0.39",
27
27
  "@teambit/ts-server": "0.0.38",
28
- "@teambit/aspect-loader": "0.0.884",
29
- "@teambit/envs": "0.0.884",
30
- "@teambit/logger": "0.0.685",
31
- "@teambit/workspace": "0.0.884",
28
+ "@teambit/aspect-loader": "0.0.885",
29
+ "@teambit/envs": "0.0.885",
30
+ "@teambit/logger": "0.0.686",
31
+ "@teambit/workspace": "0.0.885",
32
32
  "@teambit/bit-error": "0.0.400",
33
- "@teambit/builder": "0.0.884",
34
- "@teambit/isolator": "0.0.884",
35
- "@teambit/schema": "0.0.884",
36
- "@teambit/cli": "0.0.592",
37
- "@teambit/pkg": "0.0.884"
33
+ "@teambit/builder": "0.0.885",
34
+ "@teambit/isolator": "0.0.885",
35
+ "@teambit/schema": "0.0.885",
36
+ "@teambit/cli": "0.0.593",
37
+ "@teambit/pkg": "0.0.885"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/lodash": "4.14.165",
@@ -50,7 +50,7 @@
50
50
  "@teambit/typescript.aspect-docs.typescript": "0.0.146"
51
51
  },
52
52
  "peerDependencies": {
53
- "@teambit/legacy": "1.0.375",
53
+ "@teambit/legacy": "1.0.376",
54
54
  "react-dom": "^16.8.0 || ^17.0.0",
55
55
  "react": "^16.8.0 || ^17.0.0"
56
56
  },
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.884/dist/typescript.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.884/dist/typescript.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.885/dist/typescript.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.typescript_typescript@0.0.885/dist/typescript.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
@@ -5,6 +5,7 @@ import ts, {
5
5
  ExportDeclaration as ExportDeclarationNode,
6
6
  NamedExports,
7
7
  NamespaceExport,
8
+ ExportSpecifier,
8
9
  } from 'typescript';
9
10
  import { SchemaExtractorContext } from '../schema-extractor-context';
10
11
  import { SchemaTransformer } from '../schema-transformer';
@@ -65,35 +66,52 @@ export class ExportDeclaration implements SchemaTransformer {
65
66
  }
66
67
  }
67
68
 
69
+ function isSameNode(nodeA: Node, nodeB: Node): boolean {
70
+ return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;
71
+ }
72
+
68
73
  async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {
69
74
  const schemas = await Promise.all(
70
75
  exportClause.elements.map(async (element) => {
71
- const definitionInfo = await context.definitionInfo(element);
72
- if (!definitionInfo) {
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
- const definitionNode = await context.definition(definitionInfo);
78
- if (!definitionNode) {
79
- return context.getTypeRefForExternalNode(element);
80
- }
81
- if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {
82
- // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
83
- // normally, "bit install" should fix it. another option is to open vscode and look for errors.
84
- throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(
85
- element.name
86
- )}.
87
- make sure "bit status" is clean and there are no errors about missing packages/links.
88
- also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
89
- }
90
- return context.computeSchema(definitionNode.parent);
76
+ return exportSpecifierToSchemaNode(element, context);
91
77
  })
92
78
  );
93
79
 
94
80
  return schemas;
95
81
  }
96
82
 
83
+ async function exportSpecifierToSchemaNode(element: ExportSpecifier, context: SchemaExtractorContext) {
84
+ const definitionInfo = await context.definitionInfo(element);
85
+
86
+ if (!definitionInfo) {
87
+ // happens for example when the main index.ts file exports variable from an mdx file.
88
+ // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
89
+ return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
90
+ }
91
+
92
+ const definitionNode = await context.definition(definitionInfo);
93
+
94
+ if (!definitionNode) {
95
+ return context.getTypeRefForExternalNode(element);
96
+ }
97
+
98
+ // if it is reexported from another export
99
+ if (isSameNode(element, definitionNode.parent)) {
100
+ // the definition node is the same node as element.name. tsserver wasn't able to find the source for it
101
+ // normally, "bit install" should fix it. another option is to open vscode and look for errors.
102
+ throw new Error(`error: tsserver is unable to locate the identifier "${element.name.getText()}" at ${context.getLocationAsString(
103
+ element.name
104
+ )}.
105
+ make sure "bit status" is clean and there are no errors about missing packages/links.
106
+ also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
107
+ }
108
+
109
+ if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier)
110
+ return exportSpecifierToSchemaNode(definitionNode.parent as ExportSpecifier, context);
111
+
112
+ return context.computeSchema(definitionNode.parent);
113
+ }
114
+
97
115
  async function namespaceExport(
98
116
  exportClause: NamespaceExport,
99
117
  exportDec: ExportDeclarationNode,