Skip to content

Commit acfd670

Browse files
authored
Merge pull request #18617 from amcasey/NoModifiers25
JavaScript: handle lack of modifiers on extracted method
2 parents 7b5247f + 9630c46 commit acfd670

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
@@ -650,7 +650,7 @@ namespace ts.refactor.extractMethod {
650650
}
651651
newFunction = createMethod(
652652
/*decorators*/ undefined,
653-
modifiers,
653+
modifiers.length ? modifiers : undefined,
654654
range.facts & RangeFacts.IsGenerator ? createToken(SyntaxKind.AsteriskToken) : undefined,
655655
functionName,
656656
/*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 function into 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)