@@ -4,21 +4,27 @@ import * as ts from 'typescript';
4
4
const securedKeys = [ 'value' , 'canRead' , 'canEdit' ] ;
5
5
6
6
export class ResourceVisitor {
7
- constructor ( readonly = false ) {
8
- this . readonly = readonly ;
7
+ key = '@cord/resources' ;
8
+ /** @type {Record<string, string> } */
9
+ typeImports = { } ;
10
+
11
+ collect ( ) {
12
+ return { } ;
9
13
}
10
14
11
15
/**
12
- * @param sf {ts.SourceFile}
13
- * @param ctx {ts.TransformationContext}
14
16
* @param program {ts.Program}
17
+ * @param sf {ts.SourceFile}
18
+ * @param [ctx] {ts.TransformationContext}
15
19
* @returns {ts.Node }
16
20
*/
17
- visit ( sf , ctx , program ) {
21
+ visit ( program , sf , ctx ) {
18
22
if ( ! sf . fileName . endsWith ( 'dto.ts' ) ) {
19
23
return sf ;
20
24
}
21
- const { factory } = ctx ;
25
+
26
+ const readonly = ! ctx ;
27
+ const factory = ctx ?. factory ?? ts . factory ;
22
28
/**
23
29
* @param node {ts.Node}
24
30
* @returns {ts.Node }
@@ -33,7 +39,7 @@ export class ResourceVisitor {
33
39
return this . enhanceDtoClass ( node , program , factory ) ;
34
40
}
35
41
36
- if ( this . readonly ) {
42
+ if ( readonly ) {
37
43
ts . forEachChild ( node , visitNode ) ;
38
44
} else {
39
45
return ts . visitEachChild ( node , visitNode , ctx ) ;
@@ -112,27 +118,3 @@ export class ResourceVisitor {
112
118
) ;
113
119
}
114
120
}
115
-
116
- export class ResourceReadonlyVisitor {
117
- key = '@cord/resources' ;
118
- visitor = new ResourceVisitor ( true ) ;
119
-
120
- get typeImports ( ) {
121
- return { } ;
122
- }
123
-
124
- /**
125
- * @param program {ts.Program}
126
- * @param sf {ts.SourceFile}
127
- * @returns {ts.Node }
128
- */
129
- visit ( program , sf ) {
130
- /** @type {* } */
131
- const factoryHost = { factory : ts . factory } ;
132
- return this . visitor . visit ( sf , factoryHost , program ) ;
133
- }
134
-
135
- collect ( ) {
136
- return { } ;
137
- }
138
- }
0 commit comments