Merge pull request #19578 from amcasey/GH19395

Don't pass synthesized node to typeToTypeNode
This commit is contained in:
Andrew Casey 2017-10-30 16:35:20 -07:00 committed by GitHub
commit a89c055a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -2444,18 +2444,21 @@ namespace ts {
function createNodeBuilder() {
return {
typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags) => {
Debug.assert(enclosingDeclaration === undefined || (enclosingDeclaration.flags & NodeFlags.Synthesized) === 0);
const context = createNodeBuilderContext(enclosingDeclaration, flags);
const resultingNode = typeToTypeNodeHelper(type, context);
const result = context.encounteredError ? undefined : resultingNode;
return result;
},
indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags) => {
Debug.assert(enclosingDeclaration === undefined || (enclosingDeclaration.flags & NodeFlags.Synthesized) === 0);
const context = createNodeBuilderContext(enclosingDeclaration, flags);
const resultingNode = indexInfoToIndexSignatureDeclarationHelper(indexInfo, kind, context);
const result = context.encounteredError ? undefined : resultingNode;
return result;
},
signatureToSignatureDeclaration: (signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags) => {
Debug.assert(enclosingDeclaration === undefined || (enclosingDeclaration.flags & NodeFlags.Synthesized) === 0);
const context = createNodeBuilderContext(enclosingDeclaration, flags);
const resultingNode = signatureToSignatureDeclarationHelper(signature, kind, context);
const result = context.encounteredError ? undefined : resultingNode;

View File

@ -730,7 +730,7 @@ namespace ts.refactor.extractSymbol {
let type = checker.getTypeOfSymbolAtLocation(usage.symbol, usage.node);
// Widen the type so we don't emit nonsense annotations like "function fn(x: 3) {"
type = checker.getBaseTypeOfLiteralType(type);
typeNode = checker.typeToTypeNode(type, node, NodeBuilderFlags.NoTruncation);
typeNode = checker.typeToTypeNode(type, scope, NodeBuilderFlags.NoTruncation);
}
const paramDecl = createParameter(

View File

@ -0,0 +1,34 @@
/// <reference path='fourslash.ts' />
// Repro https://github.com/Microsoft/TypeScript/issues/19395
// @Filename: test.ts
//// export const b = 2;
//// interface Interface { }
////
//// async function handle(i: Interface) {
//// /*a*/const x = 3, y = i;/*b*/
//// }
// @Filename: library.d.ts
//// export as namespace NS;
//// export const a = 1;
goTo.select('a', 'b')
edit.applyRefactor({
refactorName: "Extract Symbol",
actionName: "function_scope_1",
actionDescription: "Extract to function in module scope",
newContent:
`export const b = 2;
interface Interface { }
async function handle(i: Interface) {
/*RENAME*/newFunction(i);
}
function newFunction(i: Interface) {
const x = 3, y = i;
}
`
});