mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
parent
611e0f7b4a
commit
249c2cbaf7
@ -243,7 +243,8 @@ namespace ts.refactor.convertFunctionToES6Class {
|
||||
memberElements.unshift(createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, initializer.parameters, initializer.body));
|
||||
}
|
||||
|
||||
const cls = createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, node.name,
|
||||
const modifiers = getExportModifierFromSource(precedingNode);
|
||||
const cls = createClassDeclaration(/*decorators*/ undefined, modifiers, node.name,
|
||||
/*typeParameters*/ undefined, /*heritageClauses*/ undefined, memberElements);
|
||||
// Don't call copyComments here because we'll already leave them in place
|
||||
return cls;
|
||||
@ -255,10 +256,15 @@ namespace ts.refactor.convertFunctionToES6Class {
|
||||
memberElements.unshift(createConstructor(/*decorators*/ undefined, /*modifiers*/ undefined, node.parameters, node.body));
|
||||
}
|
||||
|
||||
const cls = createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, node.name,
|
||||
const modifiers = getExportModifierFromSource(node);
|
||||
const cls = createClassDeclaration(/*decorators*/ undefined, modifiers, node.name,
|
||||
/*typeParameters*/ undefined, /*heritageClauses*/ undefined, memberElements);
|
||||
// Don't call copyComments here because we'll already leave them in place
|
||||
return cls;
|
||||
}
|
||||
|
||||
function getExportModifierFromSource(source: Node) {
|
||||
return filter(source.modifiers, modifier => modifier.kind === SyntaxKind.ExportKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: test123.js
|
||||
////export function /**/MyClass() {
|
||||
////}
|
||||
////MyClass.prototype.foo = function() {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker("");
|
||||
verify.fileAfterApplyingRefactorAtMarker("",
|
||||
`export class MyClass {
|
||||
constructor() {
|
||||
}
|
||||
foo() {
|
||||
}
|
||||
}
|
||||
`,
|
||||
'Convert to ES2015 class', 'convert');
|
||||
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: test123.js
|
||||
////export const /**/foo = function() {
|
||||
////};
|
||||
////foo.prototype.instanceMethod = function() {
|
||||
////};
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker("");
|
||||
verify.fileAfterApplyingRefactorAtMarker("",
|
||||
`export class foo {
|
||||
constructor() {
|
||||
}
|
||||
instanceMethod() {
|
||||
}
|
||||
}
|
||||
`,
|
||||
'Convert to ES2015 class', 'convert');
|
||||
Loading…
x
Reference in New Issue
Block a user