-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixed declaration emit of object literals withs divergent accessors #55442
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
Fixed declaration emit of object literals withs divergent accessors #55442
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
export namespace obj1 { | ||
let x: string; | ||
} | ||
export const obj2: { | ||
/** | ||
* my awesome getter | ||
* @returns {string} | ||
*/ | ||
get x(): string; | ||
/** | ||
* my awesome setter | ||
* @param {number} a | ||
*/ | ||
set x(a: number); | ||
}; | ||
export namespace obj3 { | ||
let x_1: string; | ||
export { x_1 as x }; | ||
} | ||
export namespace obj4 { | ||
let x_2: number; | ||
export { x_2 as x }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might notice that comments are only preserved here in obj2
. There is probably a complication related to this here since JSDoc comments here will always refer to @param
and @returns
and those don't make sense for variable declarations - so should the comment be reconstructed/trimmed in such a case?
Either way, I think that's a separate issue and I would prefer not to work on it here.
const getterDeclaration = getDeclarationOfKind<GetAccessorDeclaration>(propertySymbol, SyntaxKind.GetAccessor)!; | ||
const getterSignature = getSignatureFromDeclaration(getterDeclaration); | ||
typeElements.push( | ||
setCommentRange( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two are using direct calls to setCommentRange
instead of the existing preserveCommentsOn
helper. The only added benefit of preserveCommentsOn
is that it handles JSDocPropertyTag
s. However, those only matter when serializing typedefs, as far as I can tell. We are serializing an "inferred" type of the object literal here - its property declarations can't be sourced from @property
, right?
@typescript-bot pack this |
Heya @andrewbranch, I've started to run the tarball bundle task on this PR at 6bc2a84. You can monitor the build here. |
Heya @andrewbranch, I've started to run the diff-based user code test suite on this PR at 6bc2a84. You can monitor the build here. Update: The results are in! |
Heya @andrewbranch, I've started to run the regular perf test suite on this PR at 6bc2a84. You can monitor the build here. Update: The results are in! |
Hey @andrewbranch, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
src/compiler/checker.ts
Outdated
every(getPropertiesOfType(typeToSerialize), p => { | ||
if (!isIdentifierText(symbolName(p), languageVersion)) { | ||
return false; | ||
} | ||
if (!(p.flags & SymbolFlags.Accessor)) { | ||
return true; | ||
} | ||
return getNonMissingTypeOfSymbol(p) === getWriteTypeOfSymbol(p); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s a test that exercises this new code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this is executed by the JS-related test case: https://github.com/microsoft/TypeScript/pull/55442/files#diff-1624f807bc31e4fbb911a4979b0f28a8c7a415c3f743d047af32cecf23b58ffa
@andrewbranch Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
StartupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@andrewbranch Here are the results of running the user test suite comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Details
|
Uhh, I guess I broke perf. |
@typescript-bot perf test this |
Heya @jakebailey, I've started to run the regular perf test suite on this PR at 6bc2a84. You can monitor the build here. Update: The results are in! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good as long as perf comes back clean
@jakebailey Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
StartupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
set x(a: number); | ||
}; | ||
export namespace obj3 { | ||
let x_1: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to change because I merged your other jsdoc declaration emit PR, right? I think this is ready to go once it's sync'd, though - perf did come back clean, after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this was impacted by that other PR. I just synced with main
so this should now be mergeable.
…divergent-accessors
cc @andrewbranch as divergent setters became allowed since #53417