Skip to content

Commit

Permalink
feat: Move TypeScript to a peer dependency
Browse files Browse the repository at this point in the history
Closes #880
  • Loading branch information
Gerrit0 committed Mar 15, 2020
1 parent 3dadcde commit 49b1c4f
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 85 deletions.
38 changes: 0 additions & 38 deletions UPDATING.md

This file was deleted.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
"progress": "^2.0.3",
"shelljs": "^0.8.3",
"typedoc-default-themes": "^0.8.0",
"typescript": "3.7.x"
"typescript": "^3.8.3"
},
"peerDependencies": {
"typescript": ">=3.8.3"
},
"devDependencies": {
"@types/minimatch": "3.0.3",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/converter/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ export class Context {
return symbol;
}

expectSymbolAtLocation(node: ts.Node): ts.Symbol {
const symbol = this.getSymbolAtLocation(node);
if (!symbol) {
throw new Error(`Expected a symbol for node with kind ${ts.SyntaxKind[node.kind]}`);
}
return symbol;
}

resolveAliasedSymbol(symbol: ts.Symbol): ts.Symbol;
resolveAliasedSymbol(symbol: ts.Symbol | undefined): ts.Symbol | undefined;
resolveAliasedSymbol(symbol: ts.Symbol | undefined) {
Expand Down
32 changes: 19 additions & 13 deletions src/lib/converter/nodes/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,29 @@ export class ExportDeclarationConverter extends ConverterNodeComponent<ts.Export
throw new Error('Expected to be within a container');
}

if (node.exportClause) { // export { a, a as b }
if (node.exportClause && node.exportClause.kind === ts.SyntaxKind.NamedExports) { // export { a, a as b }
node.exportClause.elements.forEach(specifier => {
const source = context.getSymbolAtLocation(specifier.name);
const target = context.resolveAliasedSymbol(context.getSymbolAtLocation(specifier.propertyName ?? specifier.name));
if (source && target) {
// If the original declaration is in this file, export {} was used with something
// defined in this file and we don't need to create a reference unless the name is different.
if (!node.moduleSpecifier && !specifier.propertyName) {
return;
}

createReferenceReflection(context, source, target);
const source = context.expectSymbolAtLocation(specifier.name);
const target = context.resolveAliasedSymbol(context.expectSymbolAtLocation(specifier.propertyName ?? specifier.name));
// If the original declaration is in this file, export {} was used with something
// defined in this file and we don't need to create a reference unless the name is different.
if (!node.moduleSpecifier && !specifier.propertyName) {
return;
}

createReferenceReflection(context, source, target);
});
} else if (node.exportClause && node.exportClause.kind === ts.SyntaxKind.NamespaceExport) { // export * as ns
const source = context.expectSymbolAtLocation(node.exportClause.name);
if (!node.moduleSpecifier) {
throw new Error('Namespace export is missing a module specifier.');
}
const target = context.resolveAliasedSymbol(context.expectSymbolAtLocation(node.moduleSpecifier));
createReferenceReflection(context, source, target);

} else if (node.moduleSpecifier) { // export * from ...
const sourceFileSymbol = context.getSymbolAtLocation(node.moduleSpecifier);
for (const symbol of context.checker.getExportsOfModule(sourceFileSymbol!)) {
const sourceFileSymbol = context.expectSymbolAtLocation(node.moduleSpecifier);
for (const symbol of context.checker.getExportsOfModule(sourceFileSymbol)) {
if (symbol.name === 'default') { // Default exports are not re-exported with export *
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/converter/exports/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ export const hidden = true;
* No reference should be created.
*/
export { Node } from 'typescript';

// TS 3.8 namespace exports
export * as ThisModule from './mod';
48 changes: 35 additions & 13 deletions src/test/converter/exports/specs-without-exported.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"flags": {},
"children": [
{
"id": 14,
"id": 15,
"name": "\"export\"",
"kind": 1,
"kindString": "External module",
Expand All @@ -15,7 +15,17 @@
"originalName": "%BASE%/exports/export.ts",
"children": [
{
"id": 15,
"id": 20,
"name": "ThisModule",
"kind": 16777216,
"kindString": "Reference",
"flags": {
"isExported": true
},
"target": 9
},
{
"id": 16,
"name": "a",
"kind": 16777216,
"kindString": "Reference",
Expand All @@ -25,7 +35,7 @@
"target": 10
},
{
"id": 16,
"id": 17,
"name": "b",
"kind": 16777216,
"kindString": "Reference",
Expand All @@ -35,7 +45,7 @@
"target": 10
},
{
"id": 17,
"id": 18,
"name": "c",
"kind": 16777216,
"kindString": "Reference",
Expand All @@ -45,7 +55,7 @@
"target": 10
},
{
"id": 19,
"id": 21,
"name": "c",
"kind": 16777216,
"kindString": "Reference",
Expand All @@ -55,7 +65,7 @@
"target": 10
},
{
"id": 20,
"id": 22,
"name": "add",
"kind": 64,
"kindString": "Function",
Expand All @@ -64,7 +74,7 @@
},
"signatures": [
{
"id": 21,
"id": 23,
"name": "add",
"kind": 4096,
"kindString": "Call signature",
Expand All @@ -73,7 +83,7 @@
},
"parameters": [
{
"id": 22,
"id": 24,
"name": "x",
"kind": 32768,
"kindString": "Parameter",
Expand All @@ -86,7 +96,7 @@
}
},
{
"id": 23,
"id": 25,
"name": "y",
"kind": 32768,
"kindString": "Parameter",
Expand Down Expand Up @@ -119,17 +129,18 @@
"title": "References",
"kind": 16777216,
"children": [
15,
20,
16,
17,
19
18,
21
]
},
{
"title": "Functions",
"kind": 64,
"children": [
20
22
]
}
],
Expand Down Expand Up @@ -301,6 +312,16 @@
},
"originalName": "%BASE%/exports/mod.ts",
"children": [
{
"id": 14,
"name": "ThisModule",
"kind": 16777216,
"kindString": "Reference",
"flags": {
"isExported": true
},
"target": 9
},
{
"id": 11,
"name": "b",
Expand Down Expand Up @@ -352,6 +373,7 @@
"title": "References",
"kind": 16777216,
"children": [
14,
11,
12
]
Expand All @@ -378,7 +400,7 @@
"title": "External modules",
"kind": 1,
"children": [
14,
15,
1,
2,
3,
Expand Down
Loading

0 comments on commit 49b1c4f

Please sign in to comment.