Skip to content

Conversation

Andarist
Copy link
Contributor

fixes #55391

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 16, 2023
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 16, 2023
@Andarist Andarist requested a review from jakebailey August 16, 2023 22:46
get x(): number;
}
export class G {
set x(args: number);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this could be generated as args_0 (or smth like that) - but I don't think it's worth the added code complexity

@Andarist Andarist requested a review from jakebailey August 18, 2023 09:58
const isRest = parameterDeclaration && isRestParameter(parameterDeclaration) || getCheckFlags(parameterSymbol) & CheckFlags.RestParameter;
const dotDotDotToken = isRest ? factory.createToken(SyntaxKind.DotDotDotToken) : undefined;
const name = parameterDeclaration ? parameterDeclaration.name ?
function parameterToParameterDeclarationName(parameterSymbol: Symbol, parameterDeclaration: ParameterDeclaration | JSDocParameterTag | undefined, context: NodeBuilderContext) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to extract some useful bits to separate helpers instead of reusing symbolToParameterDeclaration. To reuse symbolToParameterDeclaration in full I'd have to introduce some extra parameters there (like preserveType, preserveQuestionToken and I don't think it's worth it. And even with that, I'd have to check if it would for bizarre setters declared using rest params and potentially put even more work into supporting that.

});

Debug.assert(setter && isFunctionLikeDeclaration(setter));
const paramSymbol: Symbol | undefined = getSignatureFromDeclaration(setter).parameters[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This annotation isn't enforced, it acts as a documentation hint~. The problem is that indexed access here won't return | undefined and TypeScript prefers the expression type here over the declared type (it's a known design decision). In practice, this array might be empty and I handle it in the implementation to make the truthiness check less weird I decided to annotate this here.

/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
"arg",
paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to use "value" as a new fallback here to make it more consistent with:

if (!newValueParameter) {
newValueParameter = factory.createParameterDeclaration(
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
"value",
);
}

/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
"arg",
paramSymbol ? parameterToParameterDeclarationName(paramSymbol, getEffectiveParameterDeclaration(paramSymbol), context) : "value",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to use "value" as a new fallback here to make it more consistent with:

if (!newValueParameter) {
newValueParameter = factory.createParameterDeclaration(
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
"value",
);
}

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Seems okay to me so far, but the diff definitely becomes 10x more reviewable when the functions are reordered (and I did that when reading it on github.dev for that reason)

@Andarist
Copy link
Contributor Author

@jakebailey reordered this, let me know how it feels now

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

LGTM; https://github.dev/microsoft/TypeScript/pull/55393/files shows the diff a lot better still even than github at this point. Wish github could use that algorithm somehow :(

@jakebailey jakebailey merged commit 97d8c83 into microsoft:main Aug 22, 2023
@Andarist
Copy link
Contributor Author

pleasure doing business with you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep argument name of setter in declaration from JavaScript
4 participants