JavaScript: handle lack of modifiers on extracted method

The emitter expects undefined, rather than empty.  This only affects JS,
because TS applies `private` to all extracted methods.

(cherry picked from commit 9630c46ea7)
This commit is contained in:
Andrew Casey 2017-09-20 14:48:11 -07:00
parent 7dec4ae9d1
commit a1dee452fa
2 changed files with 31 additions and 1 deletions

View file

@ -664,7 +664,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 to method in class 'C'",
newContent:
`class C {
M() {
const q = this./*RENAME*/newFunction();
q.toString();
}
newFunction() {
return 1 + 2;
}
}`
});