Merge pull request #18617 from amcasey/NoModifiers25

JavaScript: handle lack of modifiers on extracted method
This commit is contained in:
Andrew Casey 2017-09-20 16:23:39 -07:00 committed by GitHub
commit acfd67022f
2 changed files with 31 additions and 1 deletions

View File

@ -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,

View File

@ -0,0 +1,30 @@
/// <reference path='fourslash.ts' />
// 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;
}
}`
});