Skip to content

Commit 18269c0

Browse files
authored
Add assumeChangesOnlyAffectDirectDependencies as a option to skip checking and generating .d.ts files for files indirectly importing affected file (microsoft#35711)
* Baselining tsc --watch output * Add noIndirectImports as a option to skip checking and generating .d.ts files for files indirectly importing affected file Fixes microsoft#33329 * Rename option to assumeChangesOnlyAffectDirectDependencies * Description change as per feedback
1 parent 5a34274 commit 18269c0

File tree

21 files changed

+2515
-1
lines changed

21 files changed

+2515
-1
lines changed

src/compiler/builder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ namespace ts {
433433
return;
434434
}
435435

436-
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
436+
if (!state.compilerOptions.assumeChangesOnlyAffectDirectDependencies) {
437+
forEachReferencingModulesOfExportOfAffectedFile(state, affectedFile, (state, path) => handleDtsMayChangeOf(state, path, cancellationToken, computeHash));
438+
}
437439
}
438440

439441
/**

src/compiler/commandLineParser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ namespace ts {
202202
description: Diagnostics.Enable_incremental_compilation,
203203
transpileOptionValue: undefined
204204
},
205+
{
206+
name: "assumeChangesOnlyAffectDirectDependencies",
207+
type: "boolean",
208+
affectsSemanticDiagnostics: true,
209+
affectsEmit: true,
210+
category: Diagnostics.Advanced_Options,
211+
description: Diagnostics.Have_recompiles_in_incremental_and_watch_assume_that_changes_within_a_file_will_only_affect_files_directly_depending_on_it
212+
},
205213
{
206214
name: "locale",
207215
type: "string",

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,6 +4366,10 @@
43664366
"category": "Message",
43674367
"code": 6383
43684368
},
4369+
"Have recompiles in '--incremental' and '--watch' assume that changes within a file will only affect files directly depending on it.": {
4370+
"category": "Message",
4371+
"code": 6384
4372+
},
43694373

43704374
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
43714375
"category": "Message",

src/compiler/tsbuildPublic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ts {
1616
/*@internal*/ listFiles?: boolean;
1717
/*@internal*/ pretty?: boolean;
1818
incremental?: boolean;
19+
assumeChangesOnlyAffectDirectDependencies?: boolean;
1920

2021
traceResolution?: boolean;
2122
/* @internal */ diagnostics?: boolean;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5070,6 +5070,7 @@ namespace ts {
50705070
noUnusedLocals?: boolean;
50715071
noUnusedParameters?: boolean;
50725072
noImplicitUseStrict?: boolean;
5073+
assumeChangesOnlyAffectDirectDependencies?: boolean;
50735074
noLib?: boolean;
50745075
noResolve?: boolean;
50755076
out?: string;

src/testRunner/unittests/tscWatch/emitAndErrorUpdates.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ namespace ts.tscWatch {
6666
subScenario: `config with --isolatedModules and --declaration/${input.subScenario}`,
6767
configFile: () => changeCompilerOptions(input, { isolatedModules: true, declaration: true })
6868
});
69+
70+
verifyEmitAndErrorUpdatesWorker({
71+
...input,
72+
subScenario: `config with --assumeChangesOnlyAffectDirectDependencies/${input.subScenario}`,
73+
configFile: () => changeCompilerOptions(input, { assumeChangesOnlyAffectDirectDependencies: true })
74+
});
75+
76+
verifyEmitAndErrorUpdatesWorker({
77+
...input,
78+
subScenario: `config with --assumeChangesOnlyAffectDirectDependencies and --declaration/${input.subScenario}`,
79+
configFile: () => changeCompilerOptions(input, { assumeChangesOnlyAffectDirectDependencies: true, declaration: true })
80+
});
6981
}
7082

7183
describe("deep import changes", () => {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,7 @@ declare namespace ts {
26732673
noUnusedLocals?: boolean;
26742674
noUnusedParameters?: boolean;
26752675
noImplicitUseStrict?: boolean;
2676+
assumeChangesOnlyAffectDirectDependencies?: boolean;
26762677
noLib?: boolean;
26772678
noResolve?: boolean;
26782679
out?: string;
@@ -4779,6 +4780,7 @@ declare namespace ts {
47794780
force?: boolean;
47804781
verbose?: boolean;
47814782
incremental?: boolean;
4783+
assumeChangesOnlyAffectDirectDependencies?: boolean;
47824784
traceResolution?: boolean;
47834785
[option: string]: CompilerOptionsValue | undefined;
47844786
}

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,7 @@ declare namespace ts {
26732673
noUnusedLocals?: boolean;
26742674
noUnusedParameters?: boolean;
26752675
noImplicitUseStrict?: boolean;
2676+
assumeChangesOnlyAffectDirectDependencies?: boolean;
26762677
noLib?: boolean;
26772678
noResolve?: boolean;
26782679
out?: string;
@@ -4779,6 +4780,7 @@ declare namespace ts {
47794780
force?: boolean;
47804781
verbose?: boolean;
47814782
incremental?: boolean;
4783+
assumeChangesOnlyAffectDirectDependencies?: boolean;
47824784
traceResolution?: boolean;
47834785
[option: string]: CompilerOptionsValue | undefined;
47844786
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"assumeChangesOnlyAffectDirectDependencies": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/a/lib/tsc.js --w
2+
//// [/user/username/projects/myproject/a.ts]
3+
import {B} from './b';
4+
declare var console: any;
5+
let b = new B();
6+
console.log(b.c.d);
7+
8+
//// [/user/username/projects/myproject/b.ts]
9+
import {C} from './c';
10+
export class B
11+
{
12+
c = new C();
13+
}
14+
15+
//// [/user/username/projects/myproject/c.ts]
16+
export class C
17+
{
18+
d = 1;
19+
}
20+
21+
//// [/user/username/projects/myproject/tsconfig.json]
22+
{"compilerOptions":{"assumeChangesOnlyAffectDirectDependencies":true,"declaration":true}}
23+
24+
//// [/a/lib/lib.d.ts]
25+
/// <reference no-default-lib="true"/>
26+
interface Boolean {}
27+
interface Function {}
28+
interface CallableFunction {}
29+
interface NewableFunction {}
30+
interface IArguments {}
31+
interface Number { toExponential: any; }
32+
interface Object {}
33+
interface RegExp {}
34+
interface String { charAt: any; }
35+
interface Array<T> { length: number; [n: number]: T; }
36+
37+
//// [/user/username/projects/myproject/c.js]
38+
"use strict";
39+
exports.__esModule = true;
40+
var C = /** @class */ (function () {
41+
function C() {
42+
this.d = 1;
43+
}
44+
return C;
45+
}());
46+
exports.C = C;
47+
48+
49+
//// [/user/username/projects/myproject/c.d.ts]
50+
export declare class C {
51+
d: number;
52+
}
53+
54+
55+
//// [/user/username/projects/myproject/b.js]
56+
"use strict";
57+
exports.__esModule = true;
58+
var c_1 = require("./c");
59+
var B = /** @class */ (function () {
60+
function B() {
61+
this.c = new c_1.C();
62+
}
63+
return B;
64+
}());
65+
exports.B = B;
66+
67+
68+
//// [/user/username/projects/myproject/b.d.ts]
69+
import { C } from './c';
70+
export declare class B {
71+
c: C;
72+
}
73+
74+
75+
//// [/user/username/projects/myproject/a.js]
76+
"use strict";
77+
exports.__esModule = true;
78+
var b_1 = require("./b");
79+
var b = new b_1.B();
80+
console.log(b.c.d);
81+
82+
83+
//// [/user/username/projects/myproject/a.d.ts]
84+
export {};
85+
86+
87+
88+
Output::
89+
>> Screen clear
90+
12:00:25 AM - Starting compilation in watch mode...
91+
92+
93+
94+
12:00:38 AM - Found 0 errors. Watching for file changes.
95+
96+
97+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
98+
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"declaration":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
99+
Program files::
100+
/a/lib/lib.d.ts
101+
/user/username/projects/myproject/c.ts
102+
/user/username/projects/myproject/b.ts
103+
/user/username/projects/myproject/a.ts
104+
105+
Semantic diagnostics in builder refreshed for::
106+
/a/lib/lib.d.ts
107+
/user/username/projects/myproject/c.ts
108+
/user/username/projects/myproject/b.ts
109+
/user/username/projects/myproject/a.ts
110+
111+
WatchedFiles::
112+
/user/username/projects/myproject/tsconfig.json:
113+
{"pollingInterval":250}
114+
/user/username/projects/myproject/a.ts:
115+
{"pollingInterval":250}
116+
/user/username/projects/myproject/b.ts:
117+
{"pollingInterval":250}
118+
/user/username/projects/myproject/c.ts:
119+
{"pollingInterval":250}
120+
/a/lib/lib.d.ts:
121+
{"pollingInterval":250}
122+
123+
FsWatches::
124+
125+
FsWatchesRecursive::
126+
/user/username/projects/myproject/node_modules/@types:
127+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
128+
/user/username/projects/myproject:
129+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
130+
131+
exitCode:: ExitStatus.undefined
132+
133+
Change:: Rename property d to d2 of class C
134+
135+
//// [/user/username/projects/myproject/c.ts]
136+
export class C
137+
{
138+
d2 = 1;
139+
}
140+
141+
//// [/user/username/projects/myproject/c.js]
142+
"use strict";
143+
exports.__esModule = true;
144+
var C = /** @class */ (function () {
145+
function C() {
146+
this.d2 = 1;
147+
}
148+
return C;
149+
}());
150+
exports.C = C;
151+
152+
153+
//// [/user/username/projects/myproject/c.d.ts]
154+
export declare class C {
155+
d2: number;
156+
}
157+
158+
159+
//// [/user/username/projects/myproject/b.js] file written with same contents
160+
//// [/user/username/projects/myproject/b.d.ts] file written with same contents
161+
162+
Output::
163+
>> Screen clear
164+
12:00:42 AM - File change detected. Starting incremental compilation...
165+
166+
167+
168+
12:00:55 AM - Found 0 errors. Watching for file changes.
169+
170+
171+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
172+
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"declaration":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
173+
Program files::
174+
/a/lib/lib.d.ts
175+
/user/username/projects/myproject/c.ts
176+
/user/username/projects/myproject/b.ts
177+
/user/username/projects/myproject/a.ts
178+
179+
Semantic diagnostics in builder refreshed for::
180+
/user/username/projects/myproject/c.ts
181+
/user/username/projects/myproject/b.ts
182+
183+
WatchedFiles::
184+
/user/username/projects/myproject/tsconfig.json:
185+
{"pollingInterval":250}
186+
/user/username/projects/myproject/a.ts:
187+
{"pollingInterval":250}
188+
/user/username/projects/myproject/b.ts:
189+
{"pollingInterval":250}
190+
/user/username/projects/myproject/c.ts:
191+
{"pollingInterval":250}
192+
/a/lib/lib.d.ts:
193+
{"pollingInterval":250}
194+
195+
FsWatches::
196+
197+
FsWatchesRecursive::
198+
/user/username/projects/myproject/node_modules/@types:
199+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
200+
/user/username/projects/myproject:
201+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
202+
203+
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)