diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2455270330..dfc1c397eb 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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) { diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 0e8b1825d9..a086eff4fc 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -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) { diff --git a/tests/cases/fourslash/server/impliedNodeFormat.ts b/tests/cases/fourslash/server/impliedNodeFormat.ts new file mode 100644 index 0000000000..d7faa92d3b --- /dev/null +++ b/tests/cases/fourslash/server/impliedNodeFormat.ts @@ -0,0 +1,20 @@ +/// + +// @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();