Skip to content

Commit 9157e28

Browse files
committed
feat: decorators
1 parent 270e9b4 commit 9157e28

File tree

6 files changed

+125
-18
lines changed

6 files changed

+125
-18
lines changed

fixtures/jsii-calc/lib/decorators.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function classDecorator(x: typeof SomeDecoratedClass, _context: ClassDecoratorContext): typeof SomeDecoratedClass {
2+
const ret = class extends x {
3+
constructor() {
4+
super();
5+
this.state = this.state + this.state;
6+
}
7+
};
8+
9+
// This adds a field to the class, but we can't reflect that in the type because of the limitations
10+
// of decorators. That's we advertise it through interface merging below.
11+
ret.prototype['field'] = 'some_added_field';
12+
13+
return ret;
14+
}
15+
16+
function methodDecorator<A extends Function>(x: A, _context: ClassMethodDecoratorContext): A {
17+
return x;
18+
}
19+
20+
@classDecorator
21+
export class SomeDecoratedClass {
22+
protected state = 'state';
23+
24+
@methodDecorator
25+
public accessState() {
26+
return this.state;
27+
}
28+
}
29+
30+
export interface SomeDecoratedClass {
31+
field: string;
32+
}
33+
34+
/**
35+
* Exercise the above code
36+
*/
37+
function tryDecoratedClass() {
38+
const instance = new SomeDecoratedClass();
39+
return instance.field;
40+
}
41+
// Suppress unused locals warnings
42+
void tryDecoratedClass;

fixtures/jsii-calc/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './stability';
99
export * from './submodules';
1010
export * from './container-types';
1111
export * from './indirect-implementation';
12+
export * from './decorators';
1213

1314
export * as submodule from './submodule';
1415
export * as onlystatic from './only-static';

src/tsconfig/compiler-options.ts

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as Case from '../case';
44
export const BASE_COMPILER_OPTIONS: ts.CompilerOptions = {
55
alwaysStrict: true,
66
declaration: true,
7-
experimentalDecorators: true,
87
incremental: true,
98
lib: ['lib.es2020.d.ts'],
109
module: ts.ModuleKind.CommonJS,

test/__snapshots__/integration.test.ts.snap

+81-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/compiler.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ function expectedTypeScriptConfig() {
484484
alwaysStrict: true,
485485
composite: false,
486486
declaration: true,
487-
experimentalDecorators: true,
488487
incremental: true,
489488
inlineSourceMap: true,
490489
inlineSources: true,

test/tsconfig/validator.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@ describe('Object Validator', () => {
235235
function anythingExceptUndefined() {
236236
return fc.anything().filter((x) => x !== undefined);
237237
}
238+

0 commit comments

Comments
 (0)