@teambit/typescript 1.0.257 → 1.0.259

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.
@@ -3,6 +3,7 @@ import {
3
3
  ModuleSchema,
4
4
  UnresolvedSchema,
5
5
  UnImplementedSchema,
6
+ ExportSchema,
6
7
  } from '@teambit/semantics.entities.semantic-schema';
7
8
  import ts, {
8
9
  Node,
@@ -97,7 +98,7 @@ function isSameNode(nodeA: Node, nodeB: Node): boolean {
97
98
  return nodeA.kind === nodeB.kind && nodeA.pos === nodeB.pos && nodeA.end === nodeB.end;
98
99
  }
99
100
 
100
- async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<SchemaNode[]> {
101
+ async function namedExport(exportClause: NamedExports, context: SchemaExtractorContext): Promise<ExportSchema[]> {
101
102
  const schemas = await Promise.all(
102
103
  exportClause.elements.map(async (element) => {
103
104
  return exportSpecifierToSchemaNode(element, context);
@@ -107,19 +108,29 @@ async function namedExport(exportClause: NamedExports, context: SchemaExtractorC
107
108
  return schemas;
108
109
  }
109
110
 
110
- async function exportSpecifierToSchemaNode(element: ExportSpecifier, context: SchemaExtractorContext) {
111
+ async function exportSpecifierToSchemaNode(
112
+ element: ExportSpecifier,
113
+ context: SchemaExtractorContext
114
+ ): Promise<ExportSchema> {
111
115
  try {
112
116
  const definitionInfo = await context.definitionInfo(element);
117
+ const name = element.propertyName?.getText() || element.name.getText();
118
+ const alias = element.propertyName ? element.name.getText() : undefined;
119
+ const location = context.getLocation(element.name);
120
+
113
121
  if (!definitionInfo) {
122
+ const exportNode = new UnresolvedSchema(location, element.name.getText());
114
123
  // happens for example when the main index.ts file exports variable from an mdx file.
115
124
  // tsserver is unable to get the definition node because it doesn't know to parse mdx files.
116
- return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
125
+ // return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
126
+ return new ExportSchema(location, name, exportNode, alias);
117
127
  }
118
128
 
119
129
  const definitionNode = await context.definition(definitionInfo);
120
130
 
121
131
  if (!definitionNode) {
122
- return await context.resolveType(element, element.name.getText(), false);
132
+ const exportNode = await context.resolveType(element, name, false);
133
+ return new ExportSchema(location, name, exportNode, alias);
123
134
  }
124
135
 
125
136
  // if it is reexported from another export
@@ -133,12 +144,15 @@ make sure "bit status" is clean and there are no errors about missing packages/l
133
144
  also, make sure the tsconfig.json in the root has the "jsx" setting defined.`);
134
145
  }
135
146
 
136
- if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier)
147
+ if (definitionNode.parent.kind === SyntaxKind.ExportSpecifier) {
137
148
  return await exportSpecifierToSchemaNode(definitionNode.parent as ExportSpecifier, context);
149
+ }
138
150
 
139
- return await context.computeSchema(definitionNode.parent);
151
+ const exportNode = await context.computeSchema(definitionNode.parent);
152
+ return new ExportSchema(location, name, exportNode, alias);
140
153
  } catch (e) {
141
- return new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
154
+ const exportNode = new UnresolvedSchema(context.getLocation(element.name), element.name.getText());
155
+ return new ExportSchema(context.getLocation(element.name), element.name.getText(), exportNode);
142
156
  }
143
157
  }
144
158