Skip to content

Commit 2dd21a0

Browse files
ajafffsheetalkamat
authored andcommitted
useDefineForClassFields affects emit (microsoft#36308)
* useDefineForClassFields affects emit * fix lint
1 parent 4445e11 commit 2dd21a0

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ namespace ts {
968968
name: "useDefineForClassFields",
969969
type: "boolean",
970970
affectsSemanticDiagnostics: true,
971+
affectsEmit: true,
971972
category: Diagnostics.Advanced_Options,
972973
description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set,
973974
},

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,31 @@ foo().hello`
11211121
]
11221122
});
11231123

1124+
verifyTscWatch({
1125+
scenario,
1126+
subScenario: "updates diagnostics and emit when useDefineForClassFields changes",
1127+
commandLineArgs: ["-w"],
1128+
sys: () => {
1129+
const aFile: File = {
1130+
path: `/a.ts`,
1131+
content: `class C { get prop() { return 1; } }
1132+
class D extends C { prop = 1; }`
1133+
};
1134+
const config: File = {
1135+
path: `/tsconfig.json`,
1136+
content: JSON.stringify({ compilerOptions: { target: "es6" } })
1137+
};
1138+
return createWatchedSystem([aFile, config, libFile]);
1139+
},
1140+
changes: [
1141+
sys => {
1142+
sys.writeFile(`/tsconfig.json`, JSON.stringify({ compilerOptions: { target: "es6", useDefineForClassFields: true } }));
1143+
sys.runQueuedTimeoutCallbacks();
1144+
return "Enable useDefineForClassFields";
1145+
},
1146+
]
1147+
});
1148+
11241149
verifyTscWatch({
11251150
scenario,
11261151
subScenario: "updates errors and emit when importsNotUsedAsValues changes",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/a/lib/tsc.js -w
2+
//// [/a.ts]
3+
class C { get prop() { return 1; } }
4+
class D extends C { prop = 1; }
5+
6+
//// [/tsconfig.json]
7+
{"compilerOptions":{"target":"es6"}}
8+
9+
//// [/a/lib/lib.d.ts]
10+
/// <reference no-default-lib="true"/>
11+
interface Boolean {}
12+
interface Function {}
13+
interface CallableFunction {}
14+
interface NewableFunction {}
15+
interface IArguments {}
16+
interface Number { toExponential: any; }
17+
interface Object {}
18+
interface RegExp {}
19+
interface String { charAt: any; }
20+
interface Array<T> { length: number; [n: number]: T; }
21+
22+
//// [/a.js]
23+
class C {
24+
get prop() { return 1; }
25+
}
26+
class D extends C {
27+
constructor() {
28+
super(...arguments);
29+
this.prop = 1;
30+
}
31+
}
32+
33+
34+
35+
Output::
36+
>> Screen clear
37+
12:00:13 AM - Starting compilation in watch mode...
38+
39+
40+
41+
12:00:16 AM - Found 0 errors. Watching for file changes.
42+
43+
44+
Program root files: ["/a.ts","/a/lib/lib.d.ts"]
45+
Program options: {"target":2,"watch":true,"configFilePath":"/tsconfig.json"}
46+
Program files::
47+
/a.ts
48+
/a/lib/lib.d.ts
49+
50+
Semantic diagnostics in builder refreshed for::
51+
/a.ts
52+
/a/lib/lib.d.ts
53+
54+
WatchedFiles::
55+
/tsconfig.json:
56+
{"pollingInterval":250}
57+
/a.ts:
58+
{"pollingInterval":250}
59+
/a/lib/lib.d.ts:
60+
{"pollingInterval":250}
61+
62+
FsWatches::
63+
64+
FsWatchesRecursive::
65+
/:
66+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
67+
68+
exitCode:: ExitStatus.undefined
69+
70+
Change:: Enable useDefineForClassFields
71+
72+
//// [/tsconfig.json]
73+
{"compilerOptions":{"target":"es6","useDefineForClassFields":true}}
74+
75+
//// [/a.js]
76+
class C {
77+
get prop() { return 1; }
78+
}
79+
class D extends C {
80+
constructor() {
81+
super(...arguments);
82+
Object.defineProperty(this, "prop", {
83+
enumerable: true,
84+
configurable: true,
85+
writable: true,
86+
value: 1
87+
});
88+
}
89+
}
90+
91+
92+
93+
Output::
94+
>> Screen clear
95+
12:00:20 AM - File change detected. Starting incremental compilation...
96+
97+
98+
a.ts(2,21): error TS2610: 'prop' is defined as an accessor in class 'C', but is overridden here in 'D' as an instance property.
99+
100+
101+
12:00:24 AM - Found 1 error. Watching for file changes.
102+
103+
104+
Program root files: ["/a.ts","/a/lib/lib.d.ts"]
105+
Program options: {"target":2,"useDefineForClassFields":true,"watch":true,"configFilePath":"/tsconfig.json"}
106+
Program files::
107+
/a.ts
108+
/a/lib/lib.d.ts
109+
110+
Semantic diagnostics in builder refreshed for::
111+
/a.ts
112+
/a/lib/lib.d.ts
113+
114+
WatchedFiles::
115+
/tsconfig.json:
116+
{"pollingInterval":250}
117+
/a.ts:
118+
{"pollingInterval":250}
119+
/a/lib/lib.d.ts:
120+
{"pollingInterval":250}
121+
122+
FsWatches::
123+
124+
FsWatchesRecursive::
125+
/:
126+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
127+
128+
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)