Skip to content

Commit 40fd6ae

Browse files
author
Andy
authored
Shrink span for convert-to-es6-module suggestion (microsoft#23441)
1 parent 221ac50 commit 40fd6ae

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/services/suggestionDiagnostics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ts {
66
const diags: Diagnostic[] = [];
77

88
if (sourceFile.commonJsModuleIndicator) {
9-
diags.push(createDiagnosticForNode(sourceFile.commonJsModuleIndicator, Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
9+
diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
1010
}
1111

1212
const isJsFile = isSourceFileJavaScript(sourceFile);
@@ -61,4 +61,8 @@ namespace ts {
6161
return undefined;
6262
}
6363
}
64+
65+
function getErrorNodeFromCommonJsIndicator(commonJsModuleIndicator: Node): Node {
66+
return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator;
67+
}
6468
}

tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @allowJs: true
44

55
// @Filename: /a.js
6-
////[|exports.f = function() {}|];
6+
////[|exports.f|] = function() {};
77
////exports.C = class {};
88
////exports.x = 0;
99
////exports.a1 = () => {};

0 commit comments

Comments
 (0)