diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index c34b2afe398..884f15164f5 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -650,7 +650,7 @@ namespace ts.refactor.extractMethod { } newFunction = createMethod( /*decorators*/ undefined, - modifiers, + modifiers.length ? modifiers : undefined, range.facts & RangeFacts.IsGenerator ? createToken(SyntaxKind.AsteriskToken) : undefined, functionName, /*questionToken*/ undefined, diff --git a/tests/cases/fourslash/extract-method26.ts b/tests/cases/fourslash/extract-method26.ts new file mode 100644 index 00000000000..8b517c6074f --- /dev/null +++ b/tests/cases/fourslash/extract-method26.ts @@ -0,0 +1,30 @@ +/// + +// Handle having zero modifiers on a method. + +// @allowNonTsExtensions: true +// @Filename: file1.js +//// class C { +//// M() { +//// const q = /*a*/1 + 2/*b*/; +//// q.toString(); +//// } +//// } + +goTo.select('a', 'b') +edit.applyRefactor({ + refactorName: "Extract Method", + actionName: "scope_0", + actionDescription: "Extract function into class 'C'", + newContent: +`class C { + M() { + const q = this./*RENAME*/newFunction(); + q.toString(); + } + + newFunction() { + return 1 + 2; + } +}` +});