Skip to content

Commit 49b1c4f

Browse files
committed
feat: Move TypeScript to a peer dependency
Closes #880
1 parent 3dadcde commit 49b1c4f

File tree

8 files changed

+111
-85
lines changed

8 files changed

+111
-85
lines changed

UPDATING.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
"progress": "^2.0.3",
3030
"shelljs": "^0.8.3",
3131
"typedoc-default-themes": "^0.8.0",
32-
"typescript": "3.7.x"
32+
"typescript": "^3.8.3"
33+
},
34+
"peerDependencies": {
35+
"typescript": ">=3.8.3"
3336
},
3437
"devDependencies": {
3538
"@types/minimatch": "3.0.3",

src/lib/converter/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export class Context {
154154
return symbol;
155155
}
156156

157+
expectSymbolAtLocation(node: ts.Node): ts.Symbol {
158+
const symbol = this.getSymbolAtLocation(node);
159+
if (!symbol) {
160+
throw new Error(`Expected a symbol for node with kind ${ts.SyntaxKind[node.kind]}`);
161+
}
162+
return symbol;
163+
}
164+
157165
resolveAliasedSymbol(symbol: ts.Symbol): ts.Symbol;
158166
resolveAliasedSymbol(symbol: ts.Symbol | undefined): ts.Symbol | undefined;
159167
resolveAliasedSymbol(symbol: ts.Symbol | undefined) {

src/lib/converter/nodes/export.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,29 @@ export class ExportDeclarationConverter extends ConverterNodeComponent<ts.Export
6969
throw new Error('Expected to be within a container');
7070
}
7171

72-
if (node.exportClause) { // export { a, a as b }
72+
if (node.exportClause && node.exportClause.kind === ts.SyntaxKind.NamedExports) { // export { a, a as b }
7373
node.exportClause.elements.forEach(specifier => {
74-
const source = context.getSymbolAtLocation(specifier.name);
75-
const target = context.resolveAliasedSymbol(context.getSymbolAtLocation(specifier.propertyName ?? specifier.name));
76-
if (source && target) {
77-
// If the original declaration is in this file, export {} was used with something
78-
// defined in this file and we don't need to create a reference unless the name is different.
79-
if (!node.moduleSpecifier && !specifier.propertyName) {
80-
return;
81-
}
82-
83-
createReferenceReflection(context, source, target);
74+
const source = context.expectSymbolAtLocation(specifier.name);
75+
const target = context.resolveAliasedSymbol(context.expectSymbolAtLocation(specifier.propertyName ?? specifier.name));
76+
// If the original declaration is in this file, export {} was used with something
77+
// defined in this file and we don't need to create a reference unless the name is different.
78+
if (!node.moduleSpecifier && !specifier.propertyName) {
79+
return;
8480
}
81+
82+
createReferenceReflection(context, source, target);
8583
});
84+
} else if (node.exportClause && node.exportClause.kind === ts.SyntaxKind.NamespaceExport) { // export * as ns
85+
const source = context.expectSymbolAtLocation(node.exportClause.name);
86+
if (!node.moduleSpecifier) {
87+
throw new Error('Namespace export is missing a module specifier.');
88+
}
89+
const target = context.resolveAliasedSymbol(context.expectSymbolAtLocation(node.moduleSpecifier));
90+
createReferenceReflection(context, source, target);
91+
8692
} else if (node.moduleSpecifier) { // export * from ...
87-
const sourceFileSymbol = context.getSymbolAtLocation(node.moduleSpecifier);
88-
for (const symbol of context.checker.getExportsOfModule(sourceFileSymbol!)) {
93+
const sourceFileSymbol = context.expectSymbolAtLocation(node.moduleSpecifier);
94+
for (const symbol of context.checker.getExportsOfModule(sourceFileSymbol)) {
8995
if (symbol.name === 'default') { // Default exports are not re-exported with export *
9096
continue;
9197
}

src/test/converter/exports/mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ export const hidden = true;
3333
* No reference should be created.
3434
*/
3535
export { Node } from 'typescript';
36+
37+
// TS 3.8 namespace exports
38+
export * as ThisModule from './mod';

src/test/converter/exports/specs-without-exported.json

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"flags": {},
66
"children": [
77
{
8-
"id": 14,
8+
"id": 15,
99
"name": "\"export\"",
1010
"kind": 1,
1111
"kindString": "External module",
@@ -15,7 +15,17 @@
1515
"originalName": "%BASE%/exports/export.ts",
1616
"children": [
1717
{
18-
"id": 15,
18+
"id": 20,
19+
"name": "ThisModule",
20+
"kind": 16777216,
21+
"kindString": "Reference",
22+
"flags": {
23+
"isExported": true
24+
},
25+
"target": 9
26+
},
27+
{
28+
"id": 16,
1929
"name": "a",
2030
"kind": 16777216,
2131
"kindString": "Reference",
@@ -25,7 +35,7 @@
2535
"target": 10
2636
},
2737
{
28-
"id": 16,
38+
"id": 17,
2939
"name": "b",
3040
"kind": 16777216,
3141
"kindString": "Reference",
@@ -35,7 +45,7 @@
3545
"target": 10
3646
},
3747
{
38-
"id": 17,
48+
"id": 18,
3949
"name": "c",
4050
"kind": 16777216,
4151
"kindString": "Reference",
@@ -45,7 +55,7 @@
4555
"target": 10
4656
},
4757
{
48-
"id": 19,
58+
"id": 21,
4959
"name": "c",
5060
"kind": 16777216,
5161
"kindString": "Reference",
@@ -55,7 +65,7 @@
5565
"target": 10
5666
},
5767
{
58-
"id": 20,
68+
"id": 22,
5969
"name": "add",
6070
"kind": 64,
6171
"kindString": "Function",
@@ -64,7 +74,7 @@
6474
},
6575
"signatures": [
6676
{
67-
"id": 21,
77+
"id": 23,
6878
"name": "add",
6979
"kind": 4096,
7080
"kindString": "Call signature",
@@ -73,7 +83,7 @@
7383
},
7484
"parameters": [
7585
{
76-
"id": 22,
86+
"id": 24,
7787
"name": "x",
7888
"kind": 32768,
7989
"kindString": "Parameter",
@@ -86,7 +96,7 @@
8696
}
8797
},
8898
{
89-
"id": 23,
99+
"id": 25,
90100
"name": "y",
91101
"kind": 32768,
92102
"kindString": "Parameter",
@@ -119,17 +129,18 @@
119129
"title": "References",
120130
"kind": 16777216,
121131
"children": [
122-
15,
132+
20,
123133
16,
124134
17,
125-
19
135+
18,
136+
21
126137
]
127138
},
128139
{
129140
"title": "Functions",
130141
"kind": 64,
131142
"children": [
132-
20
143+
22
133144
]
134145
}
135146
],
@@ -301,6 +312,16 @@
301312
},
302313
"originalName": "%BASE%/exports/mod.ts",
303314
"children": [
315+
{
316+
"id": 14,
317+
"name": "ThisModule",
318+
"kind": 16777216,
319+
"kindString": "Reference",
320+
"flags": {
321+
"isExported": true
322+
},
323+
"target": 9
324+
},
304325
{
305326
"id": 11,
306327
"name": "b",
@@ -352,6 +373,7 @@
352373
"title": "References",
353374
"kind": 16777216,
354375
"children": [
376+
14,
355377
11,
356378
12
357379
]
@@ -378,7 +400,7 @@
378400
"title": "External modules",
379401
"kind": 1,
380402
"children": [
381-
14,
403+
15,
382404
1,
383405
2,
384406
3,

0 commit comments

Comments
 (0)