-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed declaration emit issue related to a qualifier being reused cross-file #58810
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
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 |
---|---|---|
|
@@ -8726,7 +8726,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
} | ||
if (isJSDocTypeLiteral(node)) { | ||
return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, t => { | ||
const name = isIdentifier(t.name) ? t.name : t.name.right; | ||
const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier)!; | ||
const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode(context, node), name.escapedText); | ||
const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : undefined; | ||
|
||
|
@@ -8765,7 +8765,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
/*modifiers*/ undefined, | ||
getEffectiveDotDotDotForParameter(p), | ||
setTextRange(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), | ||
p.questionToken, | ||
factory.cloneNode(p.questionToken), | ||
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. Some other code paths in this function do a similar "cloning" of the 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. Those 2 call sites related to |
||
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), | ||
/*initializer*/ undefined, | ||
)), | ||
|
@@ -8780,7 +8780,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
/*modifiers*/ undefined, | ||
getEffectiveDotDotDotForParameter(p), | ||
setTextRange(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), | ||
p.questionToken, | ||
factory.cloneNode(p.questionToken), | ||
visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), | ||
/*initializer*/ undefined, | ||
)), | ||
|
@@ -8798,7 +8798,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
if (isTypeParameterDeclaration(node)) { | ||
return factory.updateTypeParameterDeclaration( | ||
node, | ||
node.modifiers, | ||
visitNodes(node.modifiers, visitExistingNodeTreeSymbols, isModifier), | ||
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. those modifiers are just tokens so i guess i could just map over them and clone them? |
||
setTextRange(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node), | ||
visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode), | ||
visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode), | ||
|
@@ -8839,8 +8839,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
return factory.updateImportTypeNode( | ||
node, | ||
factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)), | ||
node.attributes, | ||
node.qualifier, | ||
visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes), | ||
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. those are not jus flat tokens so I wasn't quite sure what to do about those, it seemed like maybe i should deep clone them? |
||
visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName), | ||
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 definitely don't have enough context on the workings of the checker to give any informed feedback, but I can at least ask at a high level do we have some confidence whether anything more could be done to the structure of the code to avoid this general class of problem? 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. Tbh, I don't know this part of TS too well either so we need to wait for @weswigham or @dragomirtitian to give some feedback on this. I'd expect that other things in this function (like 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 would definitely suspect a lot of this needs this same fix. 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. 100% - any child node we copy should have its' children visited - any missing visitor calls on manually remapped nodes are an oversight, presumably. |
||
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode), | ||
node.isTypeOf, | ||
); | ||
|
@@ -8904,9 +8904,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
parameterName = result; | ||
} | ||
else { | ||
parameterName = node.parameterName; | ||
parameterName = factory.cloneNode(node.parameterName); | ||
} | ||
return factory.updateTypePredicateNode(node, node.assertsModifier, parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); | ||
return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); | ||
} | ||
|
||
if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) { | ||
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. there are also places in this function that do smth like: if (visited === node) {
visited = factory.cloneNode(node)
} this pattern is not applied consistently across the whole function, should it be? 🤔 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 suspect yes.... Sure seems like though that we should make some sort of wrapper for the visitor func that would check that. Though I feel like I've seen that exact code in some visitor transformer code already (maybe we're not going through that) 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 think this might be a bigger change so I'd leave it out of this PR. I just want to flag this as a potential problem. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//// [tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts] //// | ||
|
||
//// [a.ts] | ||
import { boxedBox } from "./boxedBox"; | ||
|
||
export const _ = boxedBox; | ||
|
||
// At index 83 | ||
/** | ||
* wat | ||
*/ | ||
|
||
//// [boxedBox.d.ts] | ||
export declare const boxedBox: import("./box").Box<{ | ||
boxed: import("./box").Box<number>; | ||
}>; // ^This is index 83 in this file | ||
|
||
//// [box.d.ts] | ||
export declare class Box<T> { | ||
value: T; | ||
constructor(value: T); | ||
} | ||
export declare function box<T>(value: T): Box<T>; | ||
|
||
//// [a.js] | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._ = void 0; | ||
var boxedBox_1 = require("./boxedBox"); | ||
exports._ = boxedBox_1.boxedBox; | ||
// At index 83 | ||
/** | ||
* wat | ||
*/ | ||
|
||
|
||
//// [a.d.ts] | ||
export declare const _: import("./box").Box<{ | ||
boxed: import("./box").Box<number>; | ||
}>; | ||
/** | ||
* wat | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//// [tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts] //// | ||
|
||
=== a.ts === | ||
import { boxedBox } from "./boxedBox"; | ||
>boxedBox : Symbol(boxedBox, Decl(a.ts, 0, 8)) | ||
|
||
export const _ = boxedBox; | ||
>_ : Symbol(_, Decl(a.ts, 2, 12)) | ||
>boxedBox : Symbol(boxedBox, Decl(a.ts, 0, 8)) | ||
|
||
// At index 83 | ||
/** | ||
* wat | ||
*/ | ||
|
||
=== boxedBox.d.ts === | ||
export declare const boxedBox: import("./box").Box<{ | ||
>boxedBox : Symbol(boxedBox, Decl(boxedBox.d.ts, 0, 20)) | ||
>Box : Symbol(Box, Decl(box.d.ts, 0, 0)) | ||
|
||
boxed: import("./box").Box<number>; | ||
>boxed : Symbol(boxed, Decl(boxedBox.d.ts, 0, 52)) | ||
>Box : Symbol(Box, Decl(box.d.ts, 0, 0)) | ||
|
||
}>; // ^This is index 83 in this file | ||
|
||
=== box.d.ts === | ||
export declare class Box<T> { | ||
>Box : Symbol(Box, Decl(box.d.ts, 0, 0)) | ||
>T : Symbol(T, Decl(box.d.ts, 0, 25)) | ||
|
||
value: T; | ||
>value : Symbol(Box.value, Decl(box.d.ts, 0, 29)) | ||
>T : Symbol(T, Decl(box.d.ts, 0, 25)) | ||
|
||
constructor(value: T); | ||
>value : Symbol(value, Decl(box.d.ts, 2, 16)) | ||
>T : Symbol(T, Decl(box.d.ts, 0, 25)) | ||
} | ||
export declare function box<T>(value: T): Box<T>; | ||
>box : Symbol(box, Decl(box.d.ts, 3, 1)) | ||
>T : Symbol(T, Decl(box.d.ts, 4, 28)) | ||
>value : Symbol(value, Decl(box.d.ts, 4, 31)) | ||
>T : Symbol(T, Decl(box.d.ts, 4, 28)) | ||
>Box : Symbol(Box, Decl(box.d.ts, 0, 0)) | ||
>T : Symbol(T, Decl(box.d.ts, 4, 28)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//// [tests/cases/compiler/declarationEmitTopLevelNodeFromCrossFile2.ts] //// | ||
|
||
=== a.ts === | ||
import { boxedBox } from "./boxedBox"; | ||
>boxedBox : import("box").Box<{ boxed: import("box").Box<number>; }> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ | ||
|
||
export const _ = boxedBox; | ||
>_ : import("box").Box<{ boxed: import("box").Box<number>; }> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ | ||
>boxedBox : import("box").Box<{ boxed: import("box").Box<number>; }> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ | ||
|
||
// At index 83 | ||
/** | ||
* wat | ||
*/ | ||
|
||
=== boxedBox.d.ts === | ||
export declare const boxedBox: import("./box").Box<{ | ||
>boxedBox : import("box").Box<{ boxed: import("./box").Box<number>; }> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ | ||
|
||
boxed: import("./box").Box<number>; | ||
>boxed : import("box").Box<number> | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
}>; // ^This is index 83 in this file | ||
|
||
=== box.d.ts === | ||
export declare class Box<T> { | ||
>Box : Box<T> | ||
> : ^^^^^^ | ||
|
||
value: T; | ||
>value : T | ||
> : ^ | ||
|
||
constructor(value: T); | ||
>value : T | ||
> : ^ | ||
} | ||
export declare function box<T>(value: T): Box<T>; | ||
>box : <T>(value: T) => Box<T> | ||
> : ^ ^^ ^^ ^^^^^ | ||
>value : T | ||
> : ^ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// @strict: true | ||
// @declaration: true | ||
|
||
// @filename: a.ts | ||
import { boxedBox } from "./boxedBox"; | ||
|
||
export const _ = boxedBox; | ||
|
||
// At index 83 | ||
/** | ||
* wat | ||
*/ | ||
|
||
// @filename: boxedBox.d.ts | ||
export declare const boxedBox: import("./box").Box<{ | ||
boxed: import("./box").Box<number>; | ||
}>; // ^This is index 83 in this file | ||
|
||
// @filename: box.d.ts | ||
export declare class Box<T> { | ||
value: T; | ||
constructor(value: T); | ||
} | ||
export declare function box<T>(value: T): Box<T>; |
Uh oh!
There was an error while loading. Please reload this page.