Fix broken module resolution after large/rapid edits in nodenext (#46818)

* Fix broken module resolution after edits in nodenext

* Move field copying to a better place I guess
This commit is contained in:
Andrew Branch 2021-11-17 13:04:43 -08:00 committed by GitHub
parent 009dd487a6
commit f11f14baba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -1577,6 +1577,7 @@ namespace ts {
newSourceFile.originalFileName = oldSourceFile.originalFileName;
newSourceFile.resolvedPath = oldSourceFile.resolvedPath;
newSourceFile.fileName = oldSourceFile.fileName;
newSourceFile.impliedNodeFormat = oldSourceFile.impliedNodeFormat;
const packageName = oldProgram.sourceFileToPackageName.get(oldSourceFile.path);
if (packageName !== undefined) {

View file

@ -637,7 +637,8 @@ namespace FourSlash {
ts.forEachKey(this.inputFiles, fileName => {
if (!ts.isAnySupportedFileExtension(fileName)
|| Harness.getConfigNameFromFileName(fileName)
|| !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))
// Can't get a Program in Server tests
|| this.testType !== FourSlashTestType.Server && !ts.getAllowJSCompilerOption(this.getProgram().getCompilerOptions()) && !ts.resolutionExtensionIsTSOrJson(ts.extensionFromPath(fileName))
|| ts.getBaseFileName(fileName) === "package.json") return;
const errors = this.getDiagnostics(fileName).filter(e => e.category !== ts.DiagnosticCategory.Suggestion);
if (errors.length) {

View file

@ -0,0 +1,20 @@
/// <reference path="../fourslash.ts" />
// @Filename: /tsconfig.json
//// { "compilerOptions": { "module": "nodenext" } }
// @Filename: /package.json
//// { "name": "foo", "type": "module", "exports": { ".": "./main.js" } }
// @Filename: /main.ts
//// export {};
// @Filename: /index.ts
//// import {} from "foo";
goTo.file("/index.ts");
verify.noErrors();
edit.paste(`\n"${"a".repeat(256)}";`);
verify.noErrors();