Skip to content

Commit f00c78c

Browse files
authored
Merge pull request #18622 from amcasey/NoModifiers
JavaScript: handle lack of modifiers on extracted method
2 parents 4d2aa9b + a1dee45 commit f00c78c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/services/refactors/extractMethod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ namespace ts.refactor.extractMethod {
664664
}
665665
newFunction = createMethod(
666666
/*decorators*/ undefined,
667-
modifiers,
667+
modifiers.length ? modifiers : undefined,
668668
range.facts & RangeFacts.IsGenerator ? createToken(SyntaxKind.AsteriskToken) : undefined,
669669
functionName,
670670
/*questionToken*/ undefined,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Handle having zero modifiers on a method.
4+
5+
// @allowNonTsExtensions: true
6+
// @Filename: file1.js
7+
//// class C {
8+
//// M() {
9+
//// const q = /*a*/1 + 2/*b*/;
10+
//// q.toString();
11+
//// }
12+
//// }
13+
14+
goTo.select('a', 'b')
15+
edit.applyRefactor({
16+
refactorName: "Extract Method",
17+
actionName: "scope_0",
18+
actionDescription: "Extract to method in class 'C'",
19+
newContent:
20+
`class C {
21+
M() {
22+
const q = this./*RENAME*/newFunction();
23+
q.toString();
24+
}
25+
26+
newFunction() {
27+
return 1 + 2;
28+
}
29+
}`
30+
});

0 commit comments

Comments
 (0)