Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce reliance on internal TS apis #949

Merged
merged 4 commits into from Mar 22, 2019
Merged

Conversation

Gerrit0
Copy link
Collaborator

@Gerrit0 Gerrit0 commented Jan 13, 2019

Summary of changes:

  1. Removed the custom ts.CompilerHost implementation - it is not required when creating a program and we just passed the calls to ts.sys functions (and a few internal apis) anyways.
  2. Replaced internal calls with equivalent code.

I'll also make a few inline comments where code was just removed since it was no longer necessary.

}

return true;
return node.getChildren().some(ts.isModuleBlock);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toss namespace A.B.C {} into https://ts-ast-viewer.com/ and it's immediately obvious that a module declaration is "topmost" if it has a module block as an immediate child.

this.owner.convertNode(context, element);

if (_ts.isBindingPattern(element.name)) {
if (!ts.isBindingElement(element)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This additional check is required since the internal isBindingPattern check also ensures that node exists, while the is*BindingPattern do not

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to inline this with the if block below?

@@ -30,6 +30,7 @@ export class VariableConverter extends ConverterNodeComponent<ts.VariableDeclara

/**
* Analyze the given variable declaration node and create a suitable reflection.
* TODO: the type of `node` is incorrect, it should be a union of ts.PropertySignature | ts.PropertyDeclaration | ...
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving resolving this to a later PR since changing to the actual type caused quite a few type errors.

@@ -72,15 +72,6 @@ export class TypeScriptSource extends OptionsComponent {
}
}

switch (option.paramType) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer necessary since this is only used when printing help output, and TypeDoc hasn't printed TypeScript options in help since #569 was resolved months ago.

Copy link
Collaborator

@aciccarello aciccarello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I've left some comments but we can probably clean those up in a follow-up PR. I'd like to get this into the pre-release so it can be tested a little before being released fully

@@ -281,11 +274,12 @@ export class Converter extends ChildableComponent<Application, ConverterComponen
* @param fileNames Array of the file names that should be compiled.
*/
convert(fileNames: string[]): ConverterResult {
// TODO: This mutates the input array, is this side effect used anywhere? Can it be removed?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬 That seems unexpected and if it is intentional it shouldn't be done here. I wonder if we can use a map here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the side effects are used anywhere since this is passed into Application

@@ -65,6 +58,29 @@ function getRootModuleDeclaration(node: ts.ModuleDeclaration): ts.Node {
return node;
}

/**
* Derived from the internal ts utility
* https://github.com/Microsoft/TypeScript/blob/v3.2.2/src/compiler/utilities.ts#L954
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for including the source link

@@ -5,6 +5,13 @@ import { Component } from '../../component';
import { DiscoverEvent, OptionsComponent } from '../options';
import { ParameterType } from '../declaration';

enum CharacterCodes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a source link?

this.owner.convertNode(context, element);

if (_ts.isBindingPattern(element.name)) {
if (!ts.isBindingElement(element)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to inline this with the if block below?

@aciccarello aciccarello merged commit 26202da into master Mar 22, 2019
@aciccarello aciccarello deleted the reduce-ts-internal-use branch March 22, 2019 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants