-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 accidentally reused comments between files in the emitter #61261
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse1.ts] //// | ||
|
||
//// [a.ts] | ||
import { object } from "./obj"; | ||
|
||
export const _ = object; | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
//// [obj.d.ts] | ||
export declare const object: import("./id").Id<{ | ||
foo: import("./id" ).Id<{}>; | ||
}>; | ||
|
||
//// [id.d.ts] | ||
export type Id<T> = T; | ||
|
||
|
||
|
||
|
||
//// [a.d.ts] | ||
export declare const _: { | ||
foo: import("./id").Id<{}>; | ||
}; | ||
/** | ||
* huh | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse1.ts] //// | ||
|
||
=== a.ts === | ||
import { object } from "./obj"; | ||
>object : Symbol(object, Decl(a.ts, 0, 8)) | ||
|
||
export const _ = object; | ||
>_ : Symbol(_, Decl(a.ts, 2, 12)) | ||
>object : Symbol(object, Decl(a.ts, 0, 8)) | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
=== obj.d.ts === | ||
export declare const object: import("./id").Id<{ | ||
>object : Symbol(object, Decl(obj.d.ts, 0, 20)) | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
|
||
foo: import("./id" ).Id<{}>; | ||
>foo : Symbol(foo, Decl(obj.d.ts, 0, 48)) | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
|
||
}>; | ||
|
||
=== id.d.ts === | ||
export type Id<T> = T; | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
>T : Symbol(T, Decl(id.d.ts, 0, 15)) | ||
>T : Symbol(T, Decl(id.d.ts, 0, 15)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse1.ts] //// | ||
|
||
=== a.ts === | ||
import { object } from "./obj"; | ||
>object : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
export const _ = object; | ||
>_ : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
>object : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
=== obj.d.ts === | ||
export declare const object: import("./id").Id<{ | ||
>object : { foo: import("./id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
foo: import("./id" ).Id<{}>; | ||
>foo : {} | ||
> : ^^ | ||
|
||
}>; | ||
|
||
=== id.d.ts === | ||
export type Id<T> = T; | ||
>Id : T | ||
> : ^ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse2.ts] //// | ||
|
||
//// [a.ts] | ||
import { object } from "./obj.ts"; | ||
|
||
export const _ = object; | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
//// [obj.d.ts] | ||
export declare const object: import("./id.ts").Id<{ | ||
foo: import("./id.ts" ).Id<{}>; | ||
}>; | ||
|
||
//// [id.d.ts] | ||
export type Id<T> = T; | ||
|
||
|
||
|
||
|
||
//// [a.d.ts] | ||
export declare const _: { | ||
foo: import("./id").Id<{}>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm slightly surprised this one gets rewritten to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: #61037 |
||
}; | ||
/** | ||
* huh | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse2.ts] //// | ||
|
||
=== a.ts === | ||
import { object } from "./obj.ts"; | ||
>object : Symbol(object, Decl(a.ts, 0, 8)) | ||
|
||
export const _ = object; | ||
>_ : Symbol(_, Decl(a.ts, 2, 12)) | ||
>object : Symbol(object, Decl(a.ts, 0, 8)) | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
=== obj.d.ts === | ||
export declare const object: import("./id.ts").Id<{ | ||
>object : Symbol(object, Decl(obj.d.ts, 0, 20)) | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
|
||
foo: import("./id.ts" ).Id<{}>; | ||
>foo : Symbol(foo, Decl(obj.d.ts, 0, 51)) | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
|
||
}>; | ||
|
||
=== id.d.ts === | ||
export type Id<T> = T; | ||
>Id : Symbol(Id, Decl(id.d.ts, 0, 0)) | ||
>T : Symbol(T, Decl(id.d.ts, 0, 15)) | ||
>T : Symbol(T, Decl(id.d.ts, 0, 15)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//// [tests/cases/compiler/declarationEmitNoInvalidCommentReuse2.ts] //// | ||
|
||
=== a.ts === | ||
import { object } from "./obj.ts"; | ||
>object : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
export const _ = object; | ||
>_ : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
>object : { foo: import("id").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
=== obj.d.ts === | ||
export declare const object: import("./id.ts").Id<{ | ||
>object : { foo: import("./id.ts").Id<{}>; } | ||
> : ^^^^^^^ ^^^ | ||
|
||
foo: import("./id.ts" ).Id<{}>; | ||
>foo : {} | ||
> : ^^ | ||
|
||
}>; | ||
|
||
=== id.d.ts === | ||
export type Id<T> = T; | ||
>Id : T | ||
> : ^ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @strict: true | ||
// @declaration: true | ||
// @emitDeclarationOnly: true | ||
|
||
// https://github.com/microsoft/TypeScript/issues/61239 | ||
|
||
// @filename: a.ts | ||
import { object } from "./obj"; | ||
|
||
export const _ = object; | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
// @filename: obj.d.ts | ||
export declare const object: import("./id").Id<{ | ||
foo: import("./id" ).Id<{}>; | ||
}>; | ||
|
||
// @filename: id.d.ts | ||
export type Id<T> = T; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @strict: true | ||
// @declaration: true | ||
// @emitDeclarationOnly: true | ||
// @rewriteRelativeImportExtensions: true | ||
|
||
// @filename: a.ts | ||
import { object } from "./obj.ts"; | ||
|
||
export const _ = object; | ||
|
||
/////////// | ||
/** | ||
* huh | ||
*/ | ||
// @filename: obj.d.ts | ||
export declare const object: import("./id.ts").Id<{ | ||
foo: import("./id.ts" ).Id<{}>; | ||
}>; | ||
|
||
// @filename: id.d.ts | ||
export type Id<T> = T; |
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.
The issue was caused by
factory.updateLiteralTypeNode
calling itssetTextRange
. This one is specifically different fromsetTextRange
used byreuseNode
(check the comment abovesetTextRange
in thechecker.ts
).But it also means that likely all
factory.update*
methods used in this file here are susceptible for similar bugs. At least some of them are using the internalupdate
function that callssetTextRange
. There is a chance though this bug was extra tricky becauseLiteralType
andStringLiteral
here have the very same positions and onlyStringLiteral
was correctly stripped from its positions before. So maybe the other update methods are safe-ish.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.
The factories doing anything with locations sounds very very cursed; but I can very much see
update
being used all over the place inside of the factory. So, not sure what to think there. I'd personally prefer if we didn't set ranges on nodes that didn't come out of real parsed source.