Shrink span for convert-to-es6-module suggestion (#23441)

This commit is contained in:
Andy 2018-04-16 16:46:27 -07:00 committed by GitHub
parent 221ac50c4c
commit 40fd6aebdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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);
@ -61,4 +61,8 @@ namespace ts {
return undefined;
}
}
function getErrorNodeFromCommonJsIndicator(commonJsModuleIndicator: Node): Node {
return isBinaryExpression(commonJsModuleIndicator) ? commonJsModuleIndicator.left : commonJsModuleIndicator;
}
}

View File

@ -3,7 +3,7 @@
// @allowJs: true
// @Filename: /a.js
////[|exports.f = function() {}|];
////[|exports.f|] = function() {};
////exports.C = class {};
////exports.x = 0;
////exports.a1 = () => {};