Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

Conversation

@devversion
Copy link
Member

@devversion devversion commented Aug 19, 2018

Introduces a new option that allows developers to configure the tsHost to not concatenate multiple leading comments for a TypeScript node content.

The tsHost is a newly created service that delegates (for now) to the tsParser package for retrieving the content of a given node. The advantage of the tsHost is that people can inject the tsHost in Dgeni .config() and specify options or overwrite methods.

Related angular/components#12736.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this @devversion.
I feel a little awkward about hard coding the license tag requirement in here. It would also be a breaking change (even if for the better for most projects).

How about we simplify the approach and just add an option for not concatenating leading comments? In practice, I don't think that we should be collecting up multiple documentation comments before the current AST node anyway. (At least I don't remember the motivation for doing this).

@devversion devversion force-pushed the fix/typescript-license-header-comment branch 2 times, most recently from fa27863 to 74cf6dd Compare August 20, 2018 10:04

// Search for classes with a constructor marked as `@internal`
if (exportDoc.docType === 'class' && exportDoc.constructorDoc && exportDoc.constructorDoc.internal) {
const classDoc = exportDoc as ClassExportDoc;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should rather use a type constraint function here:

function isPrivateClassExportDoc(doc as any): doc is ClassExportDoc {
  return exportDoc.docType === 'class' && exportDoc.constructorDoc && exportDoc.constructorDoc.internal;
}

This would be called as:

if (isPrivateClassExportDoc(exportDoc)) {
  ...
}

Then inside the if statement the exportDoc will already be typed as ClassExportDoc

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Done!

export class Host {

/** Whether multiple leading comments for a TypeScript node should be concatenated. */
concatMultipleLeadingComments: boolean = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

A minor suggestion around using a type constraint, but otherwise looks good!

@devversion
Copy link
Member Author

@petebacondarwin Done. Thanks for your review. Please have another look.

@devversion
Copy link
Member Author

I just realize that the commit description and title are outdated. Do you want me to update them? Otherwise you can just change the title when merging? (should be easy when using squash&merge from GitHub).

@devversion devversion force-pushed the fix/typescript-license-header-comment branch from 6f4415b to 613a12e Compare August 27, 2018 10:21
@devversion devversion changed the title fix(typescript): do not add license header comments to jsdoc content. feat(typescript): add option to disable leading comment concatenation Aug 27, 2018
@devversion
Copy link
Member Author

@petebacondarwin I've squashed all commits and tried to create an appropriate description & title. Please have another look. Thanks!

// Register the services and file readers
.factory(modules)
.factory(exportSymbolsToDocsMap)
.factory('tsHost', () => new Host())
Copy link
Contributor

Choose a reason for hiding this comment

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

You can get away with a fat arrow function here, because it has no dependencies. But this would not work if you added a dependency as a parameter. Therefore I think it is safer to avoid using these when doing DI.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually you only get away with it because you are compiling the TS down to ES5, which downgrades the fat arrow to a normal JS function: () => new Host() becomes function() { return new Host(); }).

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Probably safer to avoid fat arrow functions in DI injectable factories but fine otherwise.

Introduces a new option that allows developers to configure the `tsHost` to not concatenate multiple leading comments for a `TypeScript` node content.

The `tsHost` is a newly created service that delegates (for now) to the `tsParser` package for retrieving the content of a given node. The advantage of the `tsHost` is that people can inject the `tsHost` in Dgeni `.config()` and specify options or overwrite methods.

Related angular/components#12736.
@devversion devversion force-pushed the fix/typescript-license-header-comment branch from 613a12e to 64ad97e Compare August 28, 2018 14:16
@petebacondarwin petebacondarwin merged commit bd748bb into angular:master Aug 28, 2018
@petebacondarwin
Copy link
Contributor

Released as 0.26.6

@devversion
Copy link
Member Author

@petebacondarwin Awesome. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants