diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 619348685efbc..372eb47c50307 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -616,7 +616,7 @@ namespace ts { nodeVisitor(node.argument, visitor, isTypeNode), nodeVisitor(node.assertions, visitor, isNode), nodeVisitor(node.qualifier, visitor, isEntityName), - visitNodes(node.typeArguments, visitor, isTypeNode), + nodesVisitor(node.typeArguments, visitor, isTypeNode), node.isTypeOf ); @@ -630,10 +630,10 @@ namespace ts { case SyntaxKind.NamedTupleMember: Debug.type(node); return factory.updateNamedTupleMember(node, - visitNode(node.dotDotDotToken, visitor, isDotDotDotToken), - visitNode(node.name, visitor, isIdentifier), - visitNode(node.questionToken, visitor, isQuestionToken), - visitNode(node.type, visitor, isTypeNode), + nodeVisitor(node.dotDotDotToken, visitor, isDotDotDotToken), + nodeVisitor(node.name, visitor, isIdentifier), + nodeVisitor(node.questionToken, visitor, isQuestionToken), + nodeVisitor(node.type, visitor, isTypeNode), ); case SyntaxKind.ParenthesizedType: @@ -761,7 +761,7 @@ namespace ts { Debug.type(node); return factory.updateTaggedTemplateExpression(node, nodeVisitor(node.tag, visitor, isExpression), - visitNodes(node.typeArguments, visitor, isTypeNode), + nodesVisitor(node.typeArguments, visitor, isTypeNode), nodeVisitor(node.template, visitor, isTemplateLiteral)); case SyntaxKind.TypeAssertionExpression: diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 609246d0d7253..3f81d4d374da8 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -691,6 +691,7 @@ namespace ts.formatting { undecoratedParentStartLine: number, isListItem: boolean, isFirstListItem?: boolean): number { + Debug.assert(!nodeIsSynthesized(child)); if (nodeIsMissing(child)) { return inheritedIndentation; @@ -778,6 +779,7 @@ namespace ts.formatting { parentStartLine: number, parentDynamicIndentation: DynamicIndentation): void { Debug.assert(isNodeArray(nodes)); + Debug.assert(!nodeIsSynthesized(nodes)); const listStartToken = getOpenTokenForList(parent, nodes); diff --git a/tests/cases/fourslash/extractFunctionWithSyntheticNodes.ts b/tests/cases/fourslash/extractFunctionWithSyntheticNodes.ts new file mode 100644 index 0000000000000..ef3081d375998 --- /dev/null +++ b/tests/cases/fourslash/extractFunctionWithSyntheticNodes.ts @@ -0,0 +1,62 @@ +/// + +// @filename: /project/tsconfig.json +//// {} + +// @filename: /project/index.esm.d.ts +//// export declare class Chart { +//// constructor(config: ChartConfiguration); +//// } +//// +//// export interface ChartConfiguration { +//// options?: Partial; +//// } +//// +//// export interface TickOptions { +//// callback: (this: Scale, tickValue: number | string) => string | string[] | number | number[] | null | undefined; +//// } +//// +//// export interface CoreScaleOptions { +//// opt: boolean; +//// } +//// +//// export interface Scale { +//// opts: O; +//// getLabelForValue(value: number): string; +//// } + +// @filename: /project/options.ts +//// import { Chart } from './index.esm'; +//// +//// const chart = new Chart({ +//// options: { +//// callback(tickValue) { +//// /*a*/const value = this.getLabelForValue(tickValue as number);/*b*/ +//// return '$' + value; +//// } +//// } +//// }); + +goTo.file("/project/options.ts"); +verify.noErrors(); +goTo.select("a", "b"); +edit.applyRefactor({ + refactorName: "Extract Symbol", + actionName: "function_scope_0", + actionDescription: "Extract to inner function in method 'callback'", + newContent: +`import { Chart } from './index.esm'; + +const chart = new Chart({ + options: { + callback(tickValue) { + const value = /*RENAME*/newFunction.call(this); + return '$' + value; + + function newFunction(this: import("/project/index.esm").Scale) { + return this.getLabelForValue(tickValue as number); + } + } + } +});` +});