-
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
Merged
andrewbranch
merged 5 commits into
microsoft:main
from
Andarist:fix/declaration-emit-divergent-accessors
Oct 5, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fda81ae
Fixed declaration emit of object literals withs divergent accessors
Andarist 5919ec9
fixed declaration emit of divergent accessors with jsdoc
Andarist 6bc2a84
Avoid double iteration in `preserveCommentsOn`
Andarist 23dc530
Merge remote-tracking branch 'origin/main' into fix/declaration-emit-…
Andarist a05a1ff
Merge remote-tracking branch 'origin/main' into fix/declaration-emit-…
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/declarationEmitObjectLiteralAccessors1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//// [tests/cases/compiler/declarationEmitObjectLiteralAccessors1.ts] //// | ||
|
||
//// [declarationEmitObjectLiteralAccessors1.ts] | ||
// same type accessors | ||
export const obj1 = { | ||
/** my awesome getter (first in source order) */ | ||
get x(): string { | ||
return ""; | ||
}, | ||
/** my awesome setter (second in source order) */ | ||
set x(a: string) {}, | ||
}; | ||
|
||
// divergent accessors | ||
export const obj2 = { | ||
/** my awesome getter */ | ||
get x(): string { | ||
return ""; | ||
}, | ||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
}; | ||
|
||
export const obj3 = { | ||
/** my awesome getter */ | ||
get x(): string { | ||
return ""; | ||
}, | ||
}; | ||
|
||
export const obj4 = { | ||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
}; | ||
|
||
|
||
|
||
|
||
//// [declarationEmitObjectLiteralAccessors1.d.ts] | ||
export declare const obj1: { | ||
/** my awesome getter (first in source order) */ | ||
x: string; | ||
}; | ||
export declare const obj2: { | ||
/** my awesome getter */ | ||
get x(): string; | ||
/** my awesome setter */ | ||
set x(a: number); | ||
}; | ||
export declare const obj3: { | ||
/** my awesome getter */ | ||
readonly x: string; | ||
}; | ||
export declare const obj4: { | ||
/** my awesome setter */ | ||
x: number; | ||
}; |
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/declarationEmitObjectLiteralAccessors1.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//// [tests/cases/compiler/declarationEmitObjectLiteralAccessors1.ts] //// | ||
|
||
=== declarationEmitObjectLiteralAccessors1.ts === | ||
// same type accessors | ||
export const obj1 = { | ||
>obj1 : Symbol(obj1, Decl(declarationEmitObjectLiteralAccessors1.ts, 1, 12)) | ||
|
||
/** my awesome getter (first in source order) */ | ||
get x(): string { | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 1, 21), Decl(declarationEmitObjectLiteralAccessors1.ts, 5, 4)) | ||
|
||
return ""; | ||
}, | ||
/** my awesome setter (second in source order) */ | ||
set x(a: string) {}, | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 1, 21), Decl(declarationEmitObjectLiteralAccessors1.ts, 5, 4)) | ||
>a : Symbol(a, Decl(declarationEmitObjectLiteralAccessors1.ts, 7, 8)) | ||
|
||
}; | ||
|
||
// divergent accessors | ||
export const obj2 = { | ||
>obj2 : Symbol(obj2, Decl(declarationEmitObjectLiteralAccessors1.ts, 11, 12)) | ||
|
||
/** my awesome getter */ | ||
get x(): string { | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 11, 21), Decl(declarationEmitObjectLiteralAccessors1.ts, 15, 4)) | ||
|
||
return ""; | ||
}, | ||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 11, 21), Decl(declarationEmitObjectLiteralAccessors1.ts, 15, 4)) | ||
>a : Symbol(a, Decl(declarationEmitObjectLiteralAccessors1.ts, 17, 8)) | ||
|
||
}; | ||
|
||
export const obj3 = { | ||
>obj3 : Symbol(obj3, Decl(declarationEmitObjectLiteralAccessors1.ts, 20, 12)) | ||
|
||
/** my awesome getter */ | ||
get x(): string { | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 20, 21)) | ||
|
||
return ""; | ||
}, | ||
}; | ||
|
||
export const obj4 = { | ||
>obj4 : Symbol(obj4, Decl(declarationEmitObjectLiteralAccessors1.ts, 27, 12)) | ||
|
||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
>x : Symbol(x, Decl(declarationEmitObjectLiteralAccessors1.ts, 27, 21)) | ||
>a : Symbol(a, Decl(declarationEmitObjectLiteralAccessors1.ts, 29, 8)) | ||
|
||
}; | ||
|
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/declarationEmitObjectLiteralAccessors1.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//// [tests/cases/compiler/declarationEmitObjectLiteralAccessors1.ts] //// | ||
|
||
=== declarationEmitObjectLiteralAccessors1.ts === | ||
// same type accessors | ||
export const obj1 = { | ||
>obj1 : { x: string; } | ||
>{ /** my awesome getter (first in source order) */ get x(): string { return ""; }, /** my awesome setter (second in source order) */ set x(a: string) {},} : { x: string; } | ||
|
||
/** my awesome getter (first in source order) */ | ||
get x(): string { | ||
>x : string | ||
|
||
return ""; | ||
>"" : "" | ||
|
||
}, | ||
/** my awesome setter (second in source order) */ | ||
set x(a: string) {}, | ||
>x : string | ||
>a : string | ||
|
||
}; | ||
|
||
// divergent accessors | ||
export const obj2 = { | ||
>obj2 : { get x(): string; set x(a: number); } | ||
>{ /** my awesome getter */ get x(): string { return ""; }, /** my awesome setter */ set x(a: number) {},} : { get x(): string; set x(a: number); } | ||
|
||
/** my awesome getter */ | ||
get x(): string { | ||
>x : string | ||
|
||
return ""; | ||
>"" : "" | ||
|
||
}, | ||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
>x : string | ||
>a : number | ||
|
||
}; | ||
|
||
export const obj3 = { | ||
>obj3 : { readonly x: string; } | ||
>{ /** my awesome getter */ get x(): string { return ""; },} : { readonly x: string; } | ||
|
||
/** my awesome getter */ | ||
get x(): string { | ||
>x : string | ||
|
||
return ""; | ||
>"" : "" | ||
|
||
}, | ||
}; | ||
|
||
export const obj4 = { | ||
>obj4 : { x: number; } | ||
>{ /** my awesome setter */ set x(a: number) {},} : { x: number; } | ||
|
||
/** my awesome setter */ | ||
set x(a: number) {}, | ||
>x : number | ||
>a : number | ||
|
||
}; | ||
|
80 changes: 80 additions & 0 deletions
80
tests/baselines/reference/declarationEmitObjectLiteralAccessorsJs1.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//// [tests/cases/compiler/declarationEmitObjectLiteralAccessorsJs1.ts] //// | ||
|
||
//// [index.js] | ||
// same type accessors | ||
export const obj1 = { | ||
/** | ||
* my awesome getter (first in source order) | ||
* @returns {string} | ||
*/ | ||
get x() { | ||
return ""; | ||
}, | ||
/** | ||
* my awesome setter (second in source order) | ||
* @param {string} a | ||
*/ | ||
set x(a) {}, | ||
}; | ||
|
||
// divergent accessors | ||
export const obj2 = { | ||
/** | ||
* my awesome getter | ||
* @returns {string} | ||
*/ | ||
get x() { | ||
return ""; | ||
}, | ||
/** | ||
* my awesome setter | ||
* @param {number} a | ||
*/ | ||
set x(a) {}, | ||
}; | ||
|
||
export const obj3 = { | ||
/** | ||
* my awesome getter | ||
* @returns {string} | ||
*/ | ||
get x() { | ||
return ""; | ||
}, | ||
}; | ||
|
||
export const obj4 = { | ||
/** | ||
* my awesome setter | ||
* @param {number} a | ||
*/ | ||
set x(a) {}, | ||
}; | ||
|
||
|
||
|
||
|
||
//// [index.d.ts] | ||
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 { | ||
const x_1: string; | ||
export { x_1 as x }; | ||
} | ||
export namespace obj4 { | ||
let x_2: number; | ||
export { x_2 as x }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 existingpreserveCommentsOn
helper. The only added benefit ofpreserveCommentsOn
is that it handlesJSDocPropertyTag
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?