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

Reuse input type nodes when serializing signature parameter and return types #37444

Merged
merged 17 commits into from
Apr 2, 2020

Conversation

weswigham
Copy link
Member

Where possible (the conditions being that such an annotation exists, and the type of the annotation produces the same type as what we want to serialize). Fixes #37022.

This causes us to preserve input formatting, whitespace, comments, and aliasing choices.

@@ -3,7 +3,7 @@ class Foo{};
>Foo : Foo

function bar(x: {new(): Foo;}){}
>bar : (x: new () => Foo) => void
>bar : (x: { new (): Foo;}) => void
Copy link
Member

Choose a reason for hiding this comment

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

I see how the signature annotation changed but shouldnt it be { new (): Foo; } or {new(): Foo;} instead ? Why is there extra space before new

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure, it's because our default formatting for object literals which don't have any emit flags set is newline-separated with appropriate indentation. I could set some emit flags to try to make the objects single-line; but I imagine that default is actually better when we're not using the single line string writer that we use for .types baselines and error messages. (eg, quickinfo, declarations)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm even if its our default one wit wouldnt print it shouldnt start with these extra spaces no?

Copy link
Member Author

@weswigham weswigham Mar 20, 2020

Choose a reason for hiding this comment

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

If it actually emits as

{
    new (): Foo;
}

and the printer is simply eliding newlines (it is), it would be.

@@ -61,7 +61,7 @@ module m1 {
}

export function f4(arg1:
>f4 : (arg1: {}) => void
>f4 : (arg1: { [number]: C1;}) => void
Copy link
Member

Choose a reason for hiding this comment

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

same here

@@ -30,9 +30,9 @@ verify.quickInfoIs("var t: FooHandler");
goTo.marker("2");
verify.quickInfoIs("var t2: FooHandler2");
goTo.marker("3");
verify.quickInfoIs("type FooHandler2 = (eventName?: string, eventName2?: string) => any", "- What, another one?");
verify.quickInfoIs("type FooHandler2 = (eventName?: string | undefined, eventName2?: string) => any", "- What, another one?");
Copy link
Member

Choose a reason for hiding this comment

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

This seems like unwanted result of additional undefined given the parameter was written as {string=}

Copy link
Member Author

@weswigham weswigham Mar 20, 2020

Choose a reason for hiding this comment

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

{string=} can appear in not-ending positions, which still add | undefined to the parameter type, but don't add optionality to the parameter, so the existing node walker conservatively adds | undefined to the type nodes any time it sees the jsdoc optional type marker, since it's not semantically tracking if the = is actually implying a ? or not. In the real world, the extra | undefined won't do anything if the ? is present, so including it won't break anything, at least.

@weswigham
Copy link
Member Author

@typescript-bot user test this
@typescript-bot run dt
@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 1, 2020

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 1ccb136. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 1, 2020

Heya @weswigham, I've started to run the parallelized community code test suite on this PR at 1ccb136. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 1, 2020

Heya @weswigham, I've started to run the extended test suite on this PR at 1ccb136. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

cannot use unique symbol as object key when generating declarations from JS
5 participants