diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c17cc4ef9ca01..c0dd121d3c825 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -859,6 +859,9 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ { name: "isolatedModules", type: "boolean", + affectsSemanticDiagnostics: true, + affectsEmit: true, + affectsBuildInfo: true, category: Diagnostics.Interop_Constraints, description: Diagnostics.Ensure_that_each_file_can_be_safely_transpiled_without_relying_on_other_imports, transpileOptionValue: true, diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index fed193fbe900c..0d13642b58db7 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -2488,4 +2488,51 @@ import { x } from "../b";`, }, ], }); + + verifyTscWatch({ + scenario, + subScenario: "toggling isolatedModules re-emits const enums", + commandLineArgs: ["-w"], + sys: () => { + const enumFile: File = { + path: `/user/username/projects/myproject/a.ts`, + content: `const enum TestEnum { a = 1, b = 3, c = 5 } +const x = TestEnum.b;`, + }; + const configFile: File = { + path: `/user/username/projects/myproject/tsconfig.json`, + content: jsonToReadableText({ + compilerOptions: {}, + }), + }; + return TestServerHost.createWatchedSystem( + [enumFile, configFile], + { currentDirectory: "/user/username/projects/myproject" }, + ); + }, + edits: [ + { + caption: "Enable isolatedModules — const enum should no longer be inlined", + edit: sys => + sys.writeFile( + `/user/username/projects/myproject/tsconfig.json`, + jsonToReadableText({ + compilerOptions: { isolatedModules: true }, + }), + ), + timeouts: sys => sys.runQueuedTimeoutCallbacks(), + }, + { + caption: "Disable isolatedModules — const enum should be inlined again", + edit: sys => + sys.writeFile( + `/user/username/projects/myproject/tsconfig.json`, + jsonToReadableText({ + compilerOptions: { isolatedModules: false }, + }), + ), + timeouts: sys => sys.runQueuedTimeoutCallbacks(), + }, + ], + }); }); diff --git a/tests/baselines/reference/tscWatch/programUpdates/toggling-isolatedModules-re-emits-const-enums.js b/tests/baselines/reference/tscWatch/programUpdates/toggling-isolatedModules-re-emits-const-enums.js new file mode 100644 index 0000000000000..c0384ecf096c2 --- /dev/null +++ b/tests/baselines/reference/tscWatch/programUpdates/toggling-isolatedModules-re-emits-const-enums.js @@ -0,0 +1,192 @@ +currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames:: false +Input:: +//// [/user/username/projects/myproject/a.ts] +const enum TestEnum { a = 1, b = 3, c = 5 } +const x = TestEnum.b; + +//// [/user/username/projects/myproject/tsconfig.json] +{ + "compilerOptions": {} +} + +//// [/home/src/tslibs/TS/Lib/lib.d.ts] +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + + +/home/src/tslibs/TS/Lib/tsc.js -w +Output:: +>> Screen clear +[HH:MM:SS AM] Starting compilation in watch mode... + +[HH:MM:SS AM] Found 0 errors. Watching for file changes. + + + +//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib* + +//// [/user/username/projects/myproject/a.js] +"use strict"; +const x = 3 /* TestEnum.b */; + + + +FsWatches:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts: *new* + {} +/user/username/projects/myproject/a.ts: *new* + {} +/user/username/projects/myproject/tsconfig.json: *new* + {} + +FsWatchesRecursive:: +/user/username/projects/myproject: *new* + {} + +Program root files: [ + "/user/username/projects/myproject/a.ts" +] +Program options: { + "watch": true, + "configFilePath": "/user/username/projects/myproject/tsconfig.json" +} +Program structureReused: Not +Program files:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +Semantic diagnostics in builder refreshed for:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +Shape signatures in builder refreshed for:: +/home/src/tslibs/ts/lib/lib.es2025.full.d.ts (used version) +/user/username/projects/myproject/a.ts (used version) + +exitCode:: ExitStatus.undefined + +Change:: Enable isolatedModules — const enum should no longer be inlined + +Input:: +//// [/user/username/projects/myproject/tsconfig.json] +{ + "compilerOptions": { + "isolatedModules": true + } +} + + +Timeout callback:: count: 1 +1: timerToUpdateProgram *new* + +Before running Timeout callback:: count: 1 +1: timerToUpdateProgram + +Host is moving to new time +After running Timeout callback:: count: 0 +Output:: +>> Screen clear +[HH:MM:SS AM] File change detected. Starting incremental compilation... + +[HH:MM:SS AM] Found 0 errors. Watching for file changes. + + + +//// [/user/username/projects/myproject/a.js] +"use strict"; +var TestEnum; +(function (TestEnum) { + TestEnum[TestEnum["a"] = 1] = "a"; + TestEnum[TestEnum["b"] = 3] = "b"; + TestEnum[TestEnum["c"] = 5] = "c"; +})(TestEnum || (TestEnum = {})); +const x = TestEnum.b; + + + + +Program root files: [ + "/user/username/projects/myproject/a.ts" +] +Program options: { + "isolatedModules": true, + "watch": true, + "configFilePath": "/user/username/projects/myproject/tsconfig.json" +} +Program structureReused: Completely +Program files:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +Semantic diagnostics in builder refreshed for:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +No shapes updated in the builder:: + +exitCode:: ExitStatus.undefined + +Change:: Disable isolatedModules — const enum should be inlined again + +Input:: +//// [/user/username/projects/myproject/tsconfig.json] +{ + "compilerOptions": { + "isolatedModules": false + } +} + + +Timeout callback:: count: 1 +2: timerToUpdateProgram *new* + +Before running Timeout callback:: count: 1 +2: timerToUpdateProgram + +Host is moving to new time +After running Timeout callback:: count: 0 +Output:: +>> Screen clear +[HH:MM:SS AM] File change detected. Starting incremental compilation... + +[HH:MM:SS AM] Found 0 errors. Watching for file changes. + + + +//// [/user/username/projects/myproject/a.js] +"use strict"; +const x = 3 /* TestEnum.b */; + + + + +Program root files: [ + "/user/username/projects/myproject/a.ts" +] +Program options: { + "isolatedModules": false, + "watch": true, + "configFilePath": "/user/username/projects/myproject/tsconfig.json" +} +Program structureReused: Completely +Program files:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +Semantic diagnostics in builder refreshed for:: +/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts +/user/username/projects/myproject/a.ts + +No shapes updated in the builder:: + +exitCode:: ExitStatus.undefined