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

@typedef: Improve error spans from declaration emit #42501

Merged
merged 5 commits into from
Jan 28, 2021

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Jan 26, 2021

This is a proof-of-concept fix. I think it could be expanded for all of jsdoc, but I only set it up for jsdoc type aliases.

It could use a lot of polish too.
(The silly prefix on trueErrorNode should remind me of that.)

Fixes rest of #41672 for jsdoc type aliases: @typedef, @callback, @enum. But not for commonplace tags like @param, @return, @type, etc.

This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.
@sandersn sandersn requested a review from weswigham January 26, 2021 19:40
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 26, 2021
@@ -4699,7 +4700,7 @@ namespace ts {

function createMappedTypeNodeFromType(type: MappedType) {
Debug.assert(!!(type.flags & TypeFlags.Object));
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined;
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyKeyword | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined;
Copy link
Member Author

Choose a reason for hiding this comment

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

drive-by deprecation fix

@@ -6183,7 +6184,7 @@ namespace ts {
tracker: {
...oldcontext.tracker,
trackSymbol: (sym, decl, meaning) => {
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false);
const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false);
Copy link
Member Author

Choose a reason for hiding this comment

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

drive-by case fix

/** @typedef {import('./base')} BaseFactory */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'.
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we should add a Exported type alias 'BaseFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". formatted error?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the general case, yes -- in this case, with the import('./base') sitting right there, it's not so valuable.

!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'.
/** @enum {import('./base')} BaseFactoryFactoryRegistry */
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'.
Copy link
Member

Choose a reason for hiding this comment

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

This one seems less like the other two.

Copy link
Member Author

Choose a reason for hiding this comment

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

uhhhhhhhh yeah, I didn't notice that. It should be ${0}=BaseFactoryFactoryRegistry, ${1}='Base'.

Copy link
Member Author

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I'll take a look at these two issues.

/** @typedef {import('./base')} BaseFactory */
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'.
Copy link
Member Author

Choose a reason for hiding this comment

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

In the general case, yes -- in this case, with the import('./base') sitting right there, it's not so valuable.

!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'.
/** @enum {import('./base')} BaseFactoryFactoryRegistry */
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'.
Copy link
Member Author

Choose a reason for hiding this comment

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

uhhhhhhhh yeah, I didn't notice that. It should be ${0}=BaseFactoryFactoryRegistry, ${1}='Base'.

Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
@sandersn
Copy link
Member Author

Done. Improving the error forced me to fix the @enum one, and the fix was in the same place.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

👍

@sandersn sandersn merged commit d2443a5 into master Jan 28, 2021
@sandersn sandersn deleted the better-typedef-error-spans-in-declaration-emit branch January 28, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants