diff --git a/UPDATING.md b/UPDATING.md deleted file mode 100644 index 22a275bc9..000000000 --- a/UPDATING.md +++ /dev/null @@ -1,38 +0,0 @@ - -## Updating -TypeDoc uses internal TypeScript compiler APIs. Since internal APIs can be changed by a minor -release, TypeDoc must target exact TypeScript compiler versions. If your project is using a newer -version of TypeScript than TypeDoc, but does not rely on features from the latest version, you -may be able to get away with using a version of TypeDoc that targets a lower TypeScript version. - -If you need the latest version and one hasn't yet been published then these are the steps -you should follow to build your own. - -```bash -# Checkout a copy of TypeDoc if you don't have one already -git clone https://github.com/TypeStrong/typedoc -cd typedoc - -# Change the version of TypeScript used by the project -editor package.json - -npm install # install TypeDoc's dependencies - -# Build and run the automated TypeDoc tests -npm run build_and_test -``` - -Once this has been done, you should have a functional version of TypeDoc for -your version of TypeScript. Please open a Pull Request with your updated project -so that others may benefit from the update. - -To use your version of TypeDoc in a project, point your `package.json` -file at it using your GitHub project path. - -```json -{ - "dependencies": { - "typedoc": "mygithubuser/typedoc#v1.8.10" - } -} -``` diff --git a/package-lock.json b/package-lock.json index 9d6446811..faa9d8231 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2072,9 +2072,9 @@ } }, "typescript": { - "version": "3.7.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", - "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==" + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", + "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==" }, "uglify-js": { "version": "3.7.5", diff --git a/package.json b/package.json index 3a1d5a929..41a09b284 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/converter/context.ts b/src/lib/converter/context.ts index be6a747f3..0d11576d1 100644 --- a/src/lib/converter/context.ts +++ b/src/lib/converter/context.ts @@ -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) { diff --git a/src/lib/converter/nodes/export.ts b/src/lib/converter/nodes/export.ts index 3742e8a13..3d6388a9a 100644 --- a/src/lib/converter/nodes/export.ts +++ b/src/lib/converter/nodes/export.ts @@ -69,23 +69,29 @@ export class ExportDeclarationConverter extends ConverterNodeComponent { - 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; } diff --git a/src/test/converter/exports/mod.ts b/src/test/converter/exports/mod.ts index b7e32bb6c..a6cb72d5b 100644 --- a/src/test/converter/exports/mod.ts +++ b/src/test/converter/exports/mod.ts @@ -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'; diff --git a/src/test/converter/exports/specs-without-exported.json b/src/test/converter/exports/specs-without-exported.json index 74f6ecb0b..59c9b76f7 100644 --- a/src/test/converter/exports/specs-without-exported.json +++ b/src/test/converter/exports/specs-without-exported.json @@ -5,7 +5,7 @@ "flags": {}, "children": [ { - "id": 14, + "id": 15, "name": "\"export\"", "kind": 1, "kindString": "External module", @@ -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", @@ -25,7 +35,7 @@ "target": 10 }, { - "id": 16, + "id": 17, "name": "b", "kind": 16777216, "kindString": "Reference", @@ -35,7 +45,7 @@ "target": 10 }, { - "id": 17, + "id": 18, "name": "c", "kind": 16777216, "kindString": "Reference", @@ -45,7 +55,7 @@ "target": 10 }, { - "id": 19, + "id": 21, "name": "c", "kind": 16777216, "kindString": "Reference", @@ -55,7 +65,7 @@ "target": 10 }, { - "id": 20, + "id": 22, "name": "add", "kind": 64, "kindString": "Function", @@ -64,7 +74,7 @@ }, "signatures": [ { - "id": 21, + "id": 23, "name": "add", "kind": 4096, "kindString": "Call signature", @@ -73,7 +83,7 @@ }, "parameters": [ { - "id": 22, + "id": 24, "name": "x", "kind": 32768, "kindString": "Parameter", @@ -86,7 +96,7 @@ } }, { - "id": 23, + "id": 25, "name": "y", "kind": 32768, "kindString": "Parameter", @@ -119,17 +129,18 @@ "title": "References", "kind": 16777216, "children": [ - 15, + 20, 16, 17, - 19 + 18, + 21 ] }, { "title": "Functions", "kind": 64, "children": [ - 20 + 22 ] } ], @@ -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", @@ -352,6 +373,7 @@ "title": "References", "kind": 16777216, "children": [ + 14, 11, 12 ] @@ -378,7 +400,7 @@ "title": "External modules", "kind": 1, "children": [ - 14, + 15, 1, 2, 3, diff --git a/src/test/converter/exports/specs.json b/src/test/converter/exports/specs.json index 32586c974..6620e4fba 100644 --- a/src/test/converter/exports/specs.json +++ b/src/test/converter/exports/specs.json @@ -5,7 +5,7 @@ "flags": {}, "children": [ { - "id": 26, + "id": 27, "name": "\"export\"", "kind": 1, "kindString": "External module", @@ -15,7 +15,17 @@ "originalName": "%BASE%/exports/export.ts", "children": [ { - "id": 27, + "id": 32, + "name": "ThisModule", + "kind": 16777216, + "kindString": "Reference", + "flags": { + "isExported": true + }, + "target": 19 + }, + { + "id": 28, "name": "a", "kind": 16777216, "kindString": "Reference", @@ -25,7 +35,7 @@ "target": 20 }, { - "id": 28, + "id": 29, "name": "b", "kind": 16777216, "kindString": "Reference", @@ -35,7 +45,7 @@ "target": 20 }, { - "id": 29, + "id": 30, "name": "c", "kind": 16777216, "kindString": "Reference", @@ -45,7 +55,7 @@ "target": 20 }, { - "id": 31, + "id": 33, "name": "c", "kind": 16777216, "kindString": "Reference", @@ -55,7 +65,7 @@ "target": 20 }, { - "id": 32, + "id": 34, "name": "add", "kind": 64, "kindString": "Function", @@ -64,7 +74,7 @@ }, "signatures": [ { - "id": 33, + "id": 35, "name": "add", "kind": 4096, "kindString": "Call signature", @@ -73,7 +83,7 @@ }, "parameters": [ { - "id": 34, + "id": 36, "name": "x", "kind": 32768, "kindString": "Parameter", @@ -86,7 +96,7 @@ } }, { - "id": 35, + "id": 37, "name": "y", "kind": 32768, "kindString": "Parameter", @@ -114,21 +124,21 @@ ] }, { - "id": 36, + "id": 38, "name": "default", "kind": 64, "kindString": "Function", "flags": {}, "signatures": [ { - "id": 37, + "id": 39, "name": "default", "kind": 4096, "kindString": "Call signature", "flags": {}, "parameters": [ { - "id": 38, + "id": 40, "name": "a", "kind": 32768, "kindString": "Parameter", @@ -159,18 +169,19 @@ "title": "References", "kind": 16777216, "children": [ - 27, + 32, 28, 29, - 31 + 30, + 33 ] }, { "title": "Functions", "kind": 64, "children": [ - 32, - 36 + 34, + 38 ] } ], @@ -514,6 +525,16 @@ }, "originalName": "%BASE%/exports/mod.ts", "children": [ + { + "id": 26, + "name": "ThisModule", + "kind": 16777216, + "kindString": "Reference", + "flags": { + "isExported": true + }, + "target": 19 + }, { "id": 21, "name": "b", @@ -595,6 +616,7 @@ "title": "References", "kind": 16777216, "children": [ + 26, 21, 22 ] @@ -628,7 +650,7 @@ "title": "External modules", "kind": 1, "children": [ - 26, + 27, 1, 6, 8,