Skip to content

Commit

Permalink
feat: Re-introduce support for TS 3.9
Browse files Browse the repository at this point in the history
Closes #1362.

Co-Authored-By: Constantine Dergachev <13132449+Dergash@users.noreply.github.com>
  • Loading branch information
Gerrit0 and Dergash committed Sep 5, 2020
1 parent 36aeac6 commit 833ebb8
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
19 changes: 15 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,11 +28,12 @@
"marked": "^1.1.1",
"minimatch": "^3.0.0",
"progress": "^2.0.3",
"semver": "^7.3.2",
"shelljs": "^0.8.4",
"typedoc-default-themes": "^0.11.1"
},
"peerDependencies": {
"typescript": ">=4.0.2"
"typescript": "3.9.x || 4.0.x"
},
"devDependencies": {
"@types/fs-extra": "^9.0.1",
Expand Down
31 changes: 22 additions & 9 deletions scripts/replace_application_version.js
@@ -1,16 +1,29 @@
// @ts-check

const fs = require('fs-extra');
const { join } = require('path');
const fs = require("fs-extra");
const { join } = require("path");

const file = join(__dirname, '../dist/lib/application.js');
const file = join(__dirname, "../dist/lib/application.js");

Promise.all([
fs.readJson(join(__dirname, '../package.json')).then(({ version }) => version),
fs.readFile(file, { encoding: 'utf-8' })
]).then(([version, text]) => {
return fs.writeFile(file, text.replace(/{{ VERSION }}/g, version));
}).catch(reason => {
async function main() {
const [package, text] = await Promise.all([
fs.readJson(join(__dirname, "../package.json")),
fs.readFile(file, { encoding: "utf-8" }),
]);

const replacements = {
VERSION: package.version,
SUPPORTED: package.peerDependencies.typescript,
};

const replaced = text.replace(/{{ (VERSION|SUPPORTED) }}/g, (_, match) => {
return replacements[match];
});

await fs.writeFile(file, replaced);
}

main().catch((reason) => {
console.error(reason);
process.exit(1);
});
10 changes: 10 additions & 0 deletions src/lib/application.ts
Expand Up @@ -9,6 +9,7 @@
import * as Path from 'path';
import * as FS from 'fs';
import * as typescript from 'typescript';
import * as semver from 'semver';

import { Converter } from './converter/index';
import { Renderer } from './output/renderer';
Expand Down Expand Up @@ -92,6 +93,11 @@ export class Application extends ChildableComponent<
*/
static VERSION = '{{ VERSION }}';

/**
* The supported TypeScript version.
*/
static SUPPORTED_TS_VERSION = '{{ SUPPORTED }}';

/**
* Create a new TypeDoc application instance.
*
Expand Down Expand Up @@ -184,6 +190,10 @@ export class Application extends ChildableComponent<
this.getTypeScriptPath()
);

if (!semver.satisfies(typescript.version, Application.SUPPORTED_TS_VERSION)) {
this.logger.warn(`You are running in an unsupported TypeScript version! TypeDoc supports ${Application.SUPPORTED_TS_VERSION}`);
}

const result = this.converter.convert(src);
if (result.errors && result.errors.length) {
this.logger.diagnostics(result.errors);
Expand Down
7 changes: 5 additions & 2 deletions src/lib/converter/types/tuple.ts
Expand Up @@ -47,7 +47,9 @@ export class TupleConverter extends ConverterTypeComponent implements TypeConver
* @returns The type reflection representing the given tuple type node.
*/
convertNode(context: Context, node: ts.TupleTypeNode): TupleType {
const elements: Type[] = this.owner.convertTypes(context, node.elements);
// TS 3.9 support
const elementTypes = node.elements ?? (node as any).elementTypes;
const elements: Type[] = this.owner.convertTypes(context, elementTypes);
return new TupleType(elements);
}

Expand All @@ -74,7 +76,8 @@ export class TupleConverter extends ConverterTypeComponent implements TypeConver
@Component({ name: 'type:named-tuple-member' })
export class NamedTupleMemberConverter extends ConverterTypeComponent implements TypeNodeConverter<ts.Type, ts.NamedTupleMember> {
supportsNode(_context: Context, node: ts.Node) {
return ts.isNamedTupleMember(node);
// TS 3.9 support
return ts.isNamedTupleMember && ts.isNamedTupleMember(node);
}

convertNode(context: Context, node: ts.NamedTupleMember): NamedTupleMember | undefined {
Expand Down

0 comments on commit 833ebb8

Please sign in to comment.