diff --git a/src/services/refactors/convertFunctionToEs6Class.ts b/src/services/refactors/convertFunctionToEs6Class.ts
index e4cd1a42083..110f64d1220 100644
--- a/src/services/refactors/convertFunctionToEs6Class.ts
+++ b/src/services/refactors/convertFunctionToEs6Class.ts
@@ -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);
+ }
}
}
\ No newline at end of file
diff --git a/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts
new file mode 100644
index 00000000000..940a68a05b6
--- /dev/null
+++ b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier1.ts
@@ -0,0 +1,19 @@
+///
+
+// @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');
diff --git a/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts
new file mode 100644
index 00000000000..fb1276d4f03
--- /dev/null
+++ b/tests/cases/fourslash/convertFunctionToEs6Class_exportModifier2.ts
@@ -0,0 +1,19 @@
+///
+
+// @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');