Add refactoring to convert CommonJS module to ES6 module (#19916)

* Add refactoring to convert CommonJS module to ES6 module

* Code review

* includeGlobals -> excludeGlobals

* Improve handling of `module.exports = require("...")`

* Allow NoSubstitutionTemplateLiteral as argument to createLiteral
This commit is contained in:
Andy
2018-01-09 13:15:47 -08:00
committed by GitHub
parent 9aa99b90c7
commit 8bce69e6bd
41 changed files with 1170 additions and 71 deletions
+2 -2
View File
@@ -746,7 +746,7 @@ namespace ts.codefix {
}
else if (isJsxOpeningLikeElement(symbolToken.parent) && symbolToken.parent.tagName === symbolToken) {
// The error wasn't for the symbolAtLocation, it was for the JSX tag itself, which needs access to e.g. `React`.
symbol = checker.getAliasedSymbol(checker.resolveName(checker.getJsxNamespace(), symbolToken.parent.tagName, SymbolFlags.Value));
symbol = checker.getAliasedSymbol(checker.resolveName(checker.getJsxNamespace(), symbolToken.parent.tagName, SymbolFlags.Value, /*excludeGlobals*/ false));
symbolName = symbol.name;
}
else {
@@ -867,7 +867,7 @@ namespace ts.codefix {
return moduleSpecifierToValidIdentifier(removeFileExtension(getBaseFileName(moduleSymbol.name)), target);
}
function moduleSpecifierToValidIdentifier(moduleSpecifier: string, target: ScriptTarget): string {
export function moduleSpecifierToValidIdentifier(moduleSpecifier: string, target: ScriptTarget): string {
let res = "";
let lastCharWasValid = true;
const firstCharCode = moduleSpecifier.charCodeAt(0);