mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Ensure that we copy empty NodeArrays during transform (#48490)
This commit is contained in:
parent
41aca7c337
commit
3c6c2799b6
@ -5262,7 +5262,18 @@ namespace ts {
|
||||
if (!nodeIsSynthesized(node) && getParseTreeNode(node) === node) {
|
||||
return node;
|
||||
}
|
||||
return setTextRange(factory.cloneNode(visitEachChild(node, deepCloneOrReuseNode, nullTransformationContext)), node);
|
||||
return setTextRange(factory.cloneNode(visitEachChild(node, deepCloneOrReuseNode, nullTransformationContext, deepCloneOrReuseNodes)), node);
|
||||
}
|
||||
|
||||
function deepCloneOrReuseNodes<T extends Node>(nodes: NodeArray<T>, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T>;
|
||||
function deepCloneOrReuseNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined;
|
||||
function deepCloneOrReuseNodes<T extends Node>(nodes: NodeArray<T> | undefined, visitor: Visitor | undefined, test?: (node: Node) => boolean, start?: number, count?: number): NodeArray<T> | undefined {
|
||||
if (nodes && nodes.length === 0) {
|
||||
// Ensure we explicitly make a copy of an empty array; visitNodes will not do this unless the array has elements,
|
||||
// which can lead to us reusing the same empty NodeArray more than once within the same AST during type noding.
|
||||
return setTextRange(factory.createNodeArray<T>(/*nodes*/ undefined, nodes.hasTrailingComma), nodes);
|
||||
}
|
||||
return visitNodes(nodes, visitor, test, start, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
tests/cases/fourslash/completionsOverridingMethodCrash1.ts
Normal file
28
tests/cases/fourslash/completionsOverridingMethodCrash1.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @newline: LF
|
||||
// @Filename: a.ts
|
||||
////declare class Component<T> {
|
||||
//// setState(stateHandler: ((oldState: T, newState: T) => void)): void;
|
||||
////}
|
||||
////
|
||||
////class SubComponent extends Component<{}> {
|
||||
//// /*$*/
|
||||
////}
|
||||
|
||||
verify.completions({
|
||||
marker: "$",
|
||||
isNewIdentifierLocation: true,
|
||||
preferences: {
|
||||
includeCompletionsWithInsertText: true,
|
||||
includeCompletionsWithSnippetText: false,
|
||||
includeCompletionsWithClassMemberSnippets: true,
|
||||
},
|
||||
includes: [
|
||||
{
|
||||
name: "setState",
|
||||
sortText: completion.SortText.ClassMemberSnippets,
|
||||
insertText: "setState(stateHandler: (oldState: {}, newState: {}) => void): void {\n}",
|
||||
}
|
||||
]
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user