@@ -24,46 +24,50 @@ export class PluginMetadataPrinter {
24
24
metadata : ComposedPluginMeta ,
25
25
typeImports : Record < string , string > ,
26
26
options : PluginMetadataPrintOptions ,
27
+ tsBinary : typeof ts ,
27
28
) {
28
- const objectLiteralExpr = ts . factory . createObjectLiteralExpression (
29
+ const objectLiteralExpr = tsBinary . factory . createObjectLiteralExpression (
29
30
Object . keys ( metadata ) . map ( ( key ) =>
30
31
this . recursivelyCreatePropertyAssignment (
31
32
key ,
32
33
metadata [ key ] as unknown as Array <
33
34
[ ts . CallExpression , DeepPluginMeta ]
34
35
> ,
36
+ tsBinary ,
35
37
) ,
36
38
) ,
37
39
) ;
38
40
39
- const exportAssignment = ts . factory . createExportAssignment (
41
+ const exportAssignment = tsBinary . factory . createExportAssignment (
40
42
undefined ,
41
43
undefined ,
42
- ts . factory . createArrowFunction (
43
- [ ts . factory . createToken ( ts . SyntaxKind . AsyncKeyword ) ] ,
44
+ tsBinary . factory . createArrowFunction (
45
+ [ tsBinary . factory . createToken ( tsBinary . SyntaxKind . AsyncKeyword ) ] ,
44
46
undefined ,
45
47
[ ] ,
46
48
undefined ,
47
- ts . factory . createToken ( ts . SyntaxKind . EqualsGreaterThanToken ) ,
48
- ts . factory . createBlock (
49
+ tsBinary . factory . createToken (
50
+ tsBinary . SyntaxKind . EqualsGreaterThanToken ,
51
+ ) ,
52
+ tsBinary . factory . createBlock (
49
53
[
50
- this . createTypeImportVariableStatement ( typeImports ) ,
51
- ts . factory . createReturnStatement ( objectLiteralExpr ) ,
54
+ this . createTypeImportVariableStatement ( typeImports , tsBinary ) ,
55
+ tsBinary . factory . createReturnStatement ( objectLiteralExpr ) ,
52
56
] ,
53
57
true ,
54
58
) ,
55
59
) ,
56
60
) ;
57
61
58
- const printer = ts . createPrinter ( {
59
- newLine : ts . NewLineKind . LineFeed ,
62
+ const printer = tsBinary . createPrinter ( {
63
+ newLine : tsBinary . NewLineKind . LineFeed ,
60
64
} ) ;
61
- const resultFile = ts . createSourceFile (
65
+ const resultFile = tsBinary . createSourceFile (
62
66
'file.ts' ,
63
67
'' ,
64
- ts . ScriptTarget . Latest ,
68
+ tsBinary . ScriptTarget . Latest ,
65
69
/*setParentNodes*/ false ,
66
- ts . ScriptKind . TS ,
70
+ tsBinary . ScriptKind . TS ,
67
71
) ;
68
72
69
73
const filename = join (
@@ -75,7 +79,7 @@ export class PluginMetadataPrinter {
75
79
filename ,
76
80
eslintPrefix +
77
81
printer . printNode (
78
- ts . EmitHint . Unspecified ,
82
+ tsBinary . EmitHint . Unspecified ,
79
83
exportAssignment ,
80
84
resultFile ,
81
85
) ,
@@ -85,15 +89,16 @@ export class PluginMetadataPrinter {
85
89
private recursivelyCreatePropertyAssignment (
86
90
identifier : string ,
87
91
meta : DeepPluginMeta | Array < [ ts . CallExpression , DeepPluginMeta ] > ,
92
+ tsBinary : typeof ts ,
88
93
) : ts . PropertyAssignment {
89
94
if ( Array . isArray ( meta ) ) {
90
- return ts . factory . createPropertyAssignment (
91
- ts . factory . createStringLiteral ( identifier ) ,
92
- ts . factory . createArrayLiteralExpression (
95
+ return tsBinary . factory . createPropertyAssignment (
96
+ tsBinary . factory . createStringLiteral ( identifier ) ,
97
+ tsBinary . factory . createArrayLiteralExpression (
93
98
meta . map ( ( [ importExpr , meta ] ) =>
94
- ts . factory . createArrayLiteralExpression ( [
99
+ tsBinary . factory . createArrayLiteralExpression ( [
95
100
importExpr ,
96
- ts . factory . createObjectLiteralExpression (
101
+ tsBinary . factory . createObjectLiteralExpression (
97
102
Object . keys ( meta ) . map ( ( key ) =>
98
103
this . recursivelyCreatePropertyAssignment (
99
104
key ,
@@ -102,6 +107,7 @@ export class PluginMetadataPrinter {
102
107
[ key : string ] : DeepPluginMeta ;
103
108
}
104
109
) [ key ] ,
110
+ tsBinary ,
105
111
) ,
106
112
) ,
107
113
) ,
@@ -110,11 +116,11 @@ export class PluginMetadataPrinter {
110
116
) ,
111
117
) ;
112
118
}
113
- return ts . factory . createPropertyAssignment (
114
- ts . factory . createStringLiteral ( identifier ) ,
115
- ts . isObjectLiteralExpression ( meta as unknown as ts . Node )
119
+ return tsBinary . factory . createPropertyAssignment (
120
+ tsBinary . factory . createStringLiteral ( identifier ) ,
121
+ tsBinary . isObjectLiteralExpression ( meta as unknown as ts . Node )
116
122
? ( meta as ts . ObjectLiteralExpression )
117
- : ts . factory . createObjectLiteralExpression (
123
+ : tsBinary . factory . createObjectLiteralExpression (
118
124
Object . keys ( meta ) . map ( ( key ) =>
119
125
this . recursivelyCreatePropertyAssignment (
120
126
key ,
@@ -123,6 +129,7 @@ export class PluginMetadataPrinter {
123
129
[ key : string ] : DeepPluginMeta ;
124
130
}
125
131
) [ key ] ,
132
+ tsBinary ,
126
133
) ,
127
134
) ,
128
135
) ,
@@ -131,37 +138,42 @@ export class PluginMetadataPrinter {
131
138
132
139
private createTypeImportVariableStatement (
133
140
typeImports : Record < string , string > ,
141
+ tsBinary : typeof ts ,
134
142
) : ts . Statement {
135
- return ts . factory . createVariableStatement (
143
+ return tsBinary . factory . createVariableStatement (
136
144
undefined ,
137
- ts . factory . createVariableDeclarationList (
145
+ tsBinary . factory . createVariableDeclarationList (
138
146
[
139
- ts . factory . createVariableDeclaration (
140
- ts . factory . createIdentifier ( TYPE_IMPORT_VARIABLE_NAME ) ,
147
+ tsBinary . factory . createVariableDeclaration (
148
+ tsBinary . factory . createIdentifier ( TYPE_IMPORT_VARIABLE_NAME ) ,
141
149
undefined ,
142
150
undefined ,
143
- ts . factory . createObjectLiteralExpression (
151
+ tsBinary . factory . createObjectLiteralExpression (
144
152
Object . keys ( typeImports ) . map ( ( ti ) =>
145
- this . createPropertyAssignment ( ti , typeImports [ ti ] ) ,
153
+ this . createPropertyAssignment ( ti , typeImports [ ti ] , tsBinary ) ,
146
154
) ,
147
155
true ,
148
156
) ,
149
157
) ,
150
158
] ,
151
- ts . NodeFlags . Const |
152
- ts . NodeFlags . AwaitContext |
153
- ts . NodeFlags . ContextFlags |
154
- ts . NodeFlags . TypeExcludesFlags ,
159
+ tsBinary . NodeFlags . Const |
160
+ tsBinary . NodeFlags . AwaitContext |
161
+ tsBinary . NodeFlags . ContextFlags |
162
+ tsBinary . NodeFlags . TypeExcludesFlags ,
155
163
) ,
156
164
) ;
157
165
}
158
166
159
- private createPropertyAssignment ( identifier : string , target : string ) {
160
- return ts . factory . createPropertyAssignment (
161
- ts . factory . createComputedPropertyName (
162
- ts . factory . createStringLiteral ( identifier ) ,
167
+ private createPropertyAssignment (
168
+ identifier : string ,
169
+ target : string ,
170
+ tsBinary : typeof ts ,
171
+ ) {
172
+ return tsBinary . factory . createPropertyAssignment (
173
+ tsBinary . factory . createComputedPropertyName (
174
+ tsBinary . factory . createStringLiteral ( identifier ) ,
163
175
) ,
164
- ts . factory . createIdentifier ( target ) ,
176
+ tsBinary . factory . createIdentifier ( target ) ,
165
177
) ;
166
178
}
167
179
}
0 commit comments