Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/services/suggestionDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ts {
const diags: Diagnostic[] = [];

if (sourceFile.commonJsModuleIndicator) {
diags.push(createDiagnosticForNode(sourceFile.commonJsModuleIndicator, Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module));
}

const isJsFile = isSourceFileJavaScript(sourceFile);
Expand Down Expand Up @@ -61,4 +61,8 @@ namespace ts {
return undefined;
}
}

function getErrorNodeFromCommonJsIndicator(commonJsModuleIndicator: Node): Node {
return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @allowJs: true

// @Filename: /a.js
////[|exports.f = function() {}|];
////[|exports.f|] = function() {};
////exports.C = class {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only offer the fix on the first one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, only at the single location that comes from commonJsModuleIndicator.

////exports.x = 0;

Expand Down