Skip to content

Commit

Permalink
JavaScript: handle lack of modifiers on extracted method
Browse files Browse the repository at this point in the history
The emitter expects undefined, rather than empty.  This only affects JS,
because TS applies `private` to all extracted methods.
  • Loading branch information
amcasey committed Sep 20, 2017
1 parent 7b5247f commit 9630c46
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 9630c46

Please sign in to comment.