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:
parent
7dec4ae9d1
commit
a1dee452fa
|
@ -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,
|
||||
|
|
30
tests/cases/fourslash/extract-method26.ts
Normal file
30
tests/cases/fourslash/extract-method26.ts
Normal 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;
|
||||
}
|
||||
}`
|
||||
});
|
Loading…
Reference in a new issue