Skip to content

Commit

Permalink
Merge pull request #18617 from amcasey/NoModifiers25
Browse files Browse the repository at this point in the history
JavaScript: handle lack of modifiers on extracted method
  • Loading branch information
amcasey committed Sep 20, 2017
2 parents 7b5247f + 9630c46 commit acfd670
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/refactors/extractMethod.ts
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions tests/cases/fourslash/extract-method26.ts
@@ -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;
}
}`
});

0 comments on commit acfd670

Please sign in to comment.