Skip to content

Commit bc1e772

Browse files
ajafffsheetalkamat
authored andcommitted
experimentalDecorators and emitDecoratorMetadata affect builder state (microsoft#36297)
* experimentalDecorators and emitDecoratorMetadata affect builder state * better test
1 parent 2dd21a0 commit bc1e772

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,12 +743,15 @@ namespace ts {
743743
{
744744
name: "experimentalDecorators",
745745
type: "boolean",
746+
affectsSemanticDiagnostics: true,
746747
category: Diagnostics.Experimental_Options,
747748
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
748749
},
749750
{
750751
name: "emitDecoratorMetadata",
751752
type: "boolean",
753+
affectsSemanticDiagnostics: true,
754+
affectsEmit: true,
752755
category: Diagnostics.Experimental_Options,
753756
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
754757
},

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,49 @@ namespace ts.tscWatch {
243243
]
244244
});
245245

246+
verifyTscWatch({
247+
scenario,
248+
subScenario: "updates diagnostics and emit for decorators",
249+
commandLineArgs: ["-w"],
250+
sys: () => {
251+
const aTs: File = {
252+
path: "/a.ts",
253+
content: `import {B} from './b'
254+
@((_) => {})
255+
export class A {
256+
constructor(p: B) {}
257+
}`,
258+
};
259+
const bTs: File = {
260+
path: "/b.ts",
261+
content: `export class B {}`,
262+
};
263+
const tsconfig: File = {
264+
path: "/tsconfig.json",
265+
content: JSON.stringify({
266+
compilerOptions: { target: "es6", importsNotUsedAsValues: "error" }
267+
})
268+
};
269+
return createWatchedSystem([libFile, aTs, bTs, tsconfig]);
270+
},
271+
changes: [
272+
sys => {
273+
sys.modifyFile("/tsconfig.json", JSON.stringify({
274+
compilerOptions: { target: "es6", importsNotUsedAsValues: "error", experimentalDecorators: true }
275+
}));
276+
sys.checkTimeoutQueueLengthAndRun(1);
277+
return "Enable experimentalDecorators";
278+
},
279+
sys => {
280+
sys.modifyFile("/tsconfig.json", JSON.stringify({
281+
compilerOptions: { target: "es6", importsNotUsedAsValues: "error", experimentalDecorators: true, emitDecoratorMetadata: true }
282+
}));
283+
sys.checkTimeoutQueueLengthAndRun(1);
284+
return "Enable emitDecoratorMetadata";
285+
}
286+
]
287+
});
288+
246289
verifyTscWatch({
247290
scenario,
248291
subScenario: "files explicitly excluded in config file",
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/a/lib/tsc.js -w
2+
//// [/a/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
15+
//// [/a.ts]
16+
import {B} from './b'
17+
@((_) => {})
18+
export class A {
19+
constructor(p: B) {}
20+
}
21+
22+
//// [/b.ts]
23+
export class B {}
24+
25+
//// [/tsconfig.json]
26+
{"compilerOptions":{"target":"es6","importsNotUsedAsValues":"error"}}
27+
28+
//// [/b.js]
29+
export class B {
30+
}
31+
32+
33+
//// [/a.js]
34+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
35+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
36+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
37+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
38+
return c > 3 && r && Object.defineProperty(target, key, r), r;
39+
};
40+
import './b';
41+
let A = class A {
42+
constructor(p) { }
43+
};
44+
A = __decorate([
45+
((_) => { })
46+
], A);
47+
export { A };
48+
49+
50+
51+
Output::
52+
>> Screen clear
53+
12:00:15 AM - Starting compilation in watch mode...
54+
55+
56+
a.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
57+
58+
a.ts(3,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
59+
60+
61+
12:00:20 AM - Found 2 errors. Watching for file changes.
62+
63+
64+
Program root files: ["/a.ts","/b.ts","/a/lib/lib.d.ts"]
65+
Program options: {"target":2,"importsNotUsedAsValues":2,"watch":true,"configFilePath":"/tsconfig.json"}
66+
Program files::
67+
/b.ts
68+
/a.ts
69+
/a/lib/lib.d.ts
70+
71+
Semantic diagnostics in builder refreshed for::
72+
/b.ts
73+
/a.ts
74+
/a/lib/lib.d.ts
75+
76+
WatchedFiles::
77+
/tsconfig.json:
78+
{"pollingInterval":250}
79+
/a.ts:
80+
{"pollingInterval":250}
81+
/b.ts:
82+
{"pollingInterval":250}
83+
/a/lib/lib.d.ts:
84+
{"pollingInterval":250}
85+
86+
FsWatches::
87+
88+
FsWatchesRecursive::
89+
/:
90+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
91+
92+
exitCode:: ExitStatus.undefined
93+
94+
Change:: Enable experimentalDecorators
95+
96+
//// [/tsconfig.json]
97+
{"compilerOptions":{"target":"es6","importsNotUsedAsValues":"error","experimentalDecorators":true}}
98+
99+
100+
Output::
101+
>> Screen clear
102+
12:00:23 AM - File change detected. Starting incremental compilation...
103+
104+
105+
a.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
106+
107+
108+
12:00:24 AM - Found 1 error. Watching for file changes.
109+
110+
111+
Program root files: ["/a.ts","/b.ts","/a/lib/lib.d.ts"]
112+
Program options: {"target":2,"importsNotUsedAsValues":2,"experimentalDecorators":true,"watch":true,"configFilePath":"/tsconfig.json"}
113+
Program files::
114+
/b.ts
115+
/a.ts
116+
/a/lib/lib.d.ts
117+
118+
Semantic diagnostics in builder refreshed for::
119+
/b.ts
120+
/a.ts
121+
/a/lib/lib.d.ts
122+
123+
WatchedFiles::
124+
/tsconfig.json:
125+
{"pollingInterval":250}
126+
/a.ts:
127+
{"pollingInterval":250}
128+
/b.ts:
129+
{"pollingInterval":250}
130+
/a/lib/lib.d.ts:
131+
{"pollingInterval":250}
132+
133+
FsWatches::
134+
135+
FsWatchesRecursive::
136+
/:
137+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
138+
139+
exitCode:: ExitStatus.undefined
140+
141+
Change:: Enable emitDecoratorMetadata
142+
143+
//// [/tsconfig.json]
144+
{"compilerOptions":{"target":"es6","importsNotUsedAsValues":"error","experimentalDecorators":true,"emitDecoratorMetadata":true}}
145+
146+
//// [/b.js] file written with same contents
147+
//// [/a.js]
148+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
149+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
150+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
151+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
152+
return c > 3 && r && Object.defineProperty(target, key, r), r;
153+
};
154+
var __metadata = (this && this.__metadata) || function (k, v) {
155+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
156+
};
157+
import { B } from './b';
158+
let A = class A {
159+
constructor(p) { }
160+
};
161+
A = __decorate([
162+
((_) => { }),
163+
__metadata("design:paramtypes", [B])
164+
], A);
165+
export { A };
166+
167+
168+
169+
Output::
170+
>> Screen clear
171+
12:00:27 AM - File change detected. Starting incremental compilation...
172+
173+
174+
175+
12:00:34 AM - Found 0 errors. Watching for file changes.
176+
177+
178+
Program root files: ["/a.ts","/b.ts","/a/lib/lib.d.ts"]
179+
Program options: {"target":2,"importsNotUsedAsValues":2,"experimentalDecorators":true,"emitDecoratorMetadata":true,"watch":true,"configFilePath":"/tsconfig.json"}
180+
Program files::
181+
/b.ts
182+
/a.ts
183+
/a/lib/lib.d.ts
184+
185+
Semantic diagnostics in builder refreshed for::
186+
/b.ts
187+
/a.ts
188+
/a/lib/lib.d.ts
189+
190+
WatchedFiles::
191+
/tsconfig.json:
192+
{"pollingInterval":250}
193+
/a.ts:
194+
{"pollingInterval":250}
195+
/b.ts:
196+
{"pollingInterval":250}
197+
/a/lib/lib.d.ts:
198+
{"pollingInterval":250}
199+
200+
FsWatches::
201+
202+
FsWatchesRecursive::
203+
/:
204+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
205+
206+
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)