@@ -3,10 +3,21 @@ var __extends = (this && this.__extends) || function (d, b) {
3
3
function __ ( ) { this . constructor = d ; }
4
4
d . prototype = b === null ? Object . create ( b ) : ( __ . prototype = b . prototype , new __ ( ) ) ;
5
5
} ;
6
+ var __decorate = ( this && this . __decorate ) || function ( decorators , target , key , desc ) {
7
+ if ( typeof Reflect === "object" && typeof Reflect . decorate === "function" ) return Reflect . decorate ( decorators , target , key , desc ) ;
8
+ switch ( arguments . length ) {
9
+ case 2 : return decorators . reduceRight ( function ( o , d ) { return ( d && d ( o ) ) || o ; } , target ) ;
10
+ case 3 : return decorators . reduceRight ( function ( o , d ) { return ( d && d ( target , key ) ) , void 0 ; } , void 0 ) ;
11
+ case 4 : return decorators . reduceRight ( function ( o , d ) { return ( d && d ( target , key , o ) ) || o ; } , desc ) ;
12
+ }
13
+ } ;
14
+ var __metadata = ( this && this . __metadata ) || function ( k , v ) {
15
+ if ( typeof Reflect === "object" && typeof Reflect . metadata === "function" ) return Reflect . metadata ( k , v ) ;
16
+ } ;
6
17
var ts = require ( "typescript" ) ;
7
18
var Options_1 = require ( "../Options" ) ;
8
19
var context_1 = require ( "./context" ) ;
9
- var convert_node_1 = require ( "./convert-node " ) ;
20
+ var components_1 = require ( "./components " ) ;
10
21
var compiler_host_1 = require ( "./utils/compiler-host" ) ;
11
22
var component_1 = require ( "../utils/component" ) ;
12
23
( function ( SourceFileMode ) {
@@ -21,6 +32,9 @@ var Converter = (function (_super) {
21
32
}
22
33
Converter . prototype . initialize = function ( ) {
23
34
this . compilerHost = new compiler_host_1 . CompilerHost ( this ) ;
35
+ this . nodeConverters = { } ;
36
+ this . typeTypeConverters = [ ] ;
37
+ this . typeNodeConverters = [ ] ;
24
38
} ;
25
39
Converter . prototype . getParameters = function ( ) {
26
40
return _super . prototype . getParameters . call ( this ) . concat ( [ {
@@ -52,6 +66,68 @@ var Converter = (function (_super) {
52
66
type : Options_1 . ParameterType . Boolean
53
67
} ] ) ;
54
68
} ;
69
+ Converter . prototype . addComponent = function ( name , componentClass ) {
70
+ var component = _super . prototype . addComponent . call ( this , name , componentClass ) ;
71
+ if ( component instanceof components_1 . ConverterNodeComponent ) {
72
+ this . addNodeConverter ( component ) ;
73
+ }
74
+ else if ( component instanceof components_1 . ConverterTypeComponent ) {
75
+ this . addTypeConverter ( component ) ;
76
+ }
77
+ return component ;
78
+ } ;
79
+ Converter . prototype . addNodeConverter = function ( converter ) {
80
+ for ( var _i = 0 , _a = converter . supports ; _i < _a . length ; _i ++ ) {
81
+ var supports = _a [ _i ] ;
82
+ this . nodeConverters [ supports ] = converter ;
83
+ }
84
+ } ;
85
+ Converter . prototype . addTypeConverter = function ( converter ) {
86
+ if ( "supportsNode" in converter && "convertNode" in converter ) {
87
+ this . typeNodeConverters . push ( converter ) ;
88
+ this . typeNodeConverters . sort ( function ( a , b ) { return ( b . priority || 0 ) - ( a . priority || 0 ) ; } ) ;
89
+ }
90
+ if ( "supportsType" in converter && "convertType" in converter ) {
91
+ this . typeTypeConverters . push ( converter ) ;
92
+ this . typeTypeConverters . sort ( function ( a , b ) { return ( b . priority || 0 ) - ( a . priority || 0 ) ; } ) ;
93
+ }
94
+ } ;
95
+ Converter . prototype . removeComponent = function ( name ) {
96
+ var component = _super . prototype . removeComponent . call ( this , name ) ;
97
+ if ( component instanceof components_1 . ConverterNodeComponent ) {
98
+ this . removeNodeConverter ( component ) ;
99
+ }
100
+ else if ( component instanceof components_1 . ConverterTypeComponent ) {
101
+ this . removeTypeConverter ( component ) ;
102
+ }
103
+ return component ;
104
+ } ;
105
+ Converter . prototype . removeNodeConverter = function ( converter ) {
106
+ var converters = this . nodeConverters ;
107
+ var keys = _ . keys ( this . nodeConverters ) ;
108
+ for ( var _i = 0 ; _i < keys . length ; _i ++ ) {
109
+ var key = keys [ _i ] ;
110
+ if ( converters [ key ] === converter ) {
111
+ delete converters [ key ] ;
112
+ }
113
+ }
114
+ } ;
115
+ Converter . prototype . removeTypeConverter = function ( converter ) {
116
+ var index = this . typeNodeConverters . indexOf ( converter ) ;
117
+ if ( index != - 1 ) {
118
+ this . typeTypeConverters . splice ( index , 1 ) ;
119
+ }
120
+ index = this . typeNodeConverters . indexOf ( converter ) ;
121
+ if ( index != - 1 ) {
122
+ this . typeNodeConverters . splice ( index , 1 ) ;
123
+ }
124
+ } ;
125
+ Converter . prototype . removeAllComponents = function ( ) {
126
+ _super . prototype . removeAllComponents . call ( this ) ;
127
+ this . nodeConverters = { } ;
128
+ this . typeTypeConverters = [ ] ;
129
+ this . typeNodeConverters = [ ] ;
130
+ } ;
55
131
Converter . prototype . convert = function ( fileNames ) {
56
132
if ( this . application . options . verbose ) {
57
133
this . application . logger . verbose ( '\n\x1b[32mStarting conversion\x1b[0m\n\nInput files:' ) ;
@@ -78,10 +154,54 @@ var Converter = (function (_super) {
78
154
project : project
79
155
} ;
80
156
} ;
157
+ Converter . prototype . convertNode = function ( context , node ) {
158
+ if ( context . visitStack . indexOf ( node ) != - 1 ) {
159
+ return null ;
160
+ }
161
+ var oldVisitStack = context . visitStack ;
162
+ context . visitStack = oldVisitStack . slice ( ) ;
163
+ context . visitStack . push ( node ) ;
164
+ if ( context . getOptions ( ) . verbose ) {
165
+ var file = ts . getSourceFileOfNode ( node ) ;
166
+ var pos = ts . getLineAndCharacterOfPosition ( file , node . pos ) ;
167
+ if ( node . symbol ) {
168
+ context . getLogger ( ) . verbose ( 'Visiting \x1b[34m%s\x1b[0m\n in %s (%s:%s)' , context . checker . getFullyQualifiedName ( node . symbol ) , file . fileName , pos . line . toString ( ) , pos . character . toString ( ) ) ;
169
+ }
170
+ else {
171
+ context . getLogger ( ) . verbose ( 'Visiting node of kind %s in %s (%s:%s)' , node . kind . toString ( ) , file . fileName , pos . line . toString ( ) , pos . character . toString ( ) ) ;
172
+ }
173
+ }
174
+ var result ;
175
+ if ( node . kind in this . nodeConverters ) {
176
+ result = this . nodeConverters [ node . kind ] . convert ( context , node ) ;
177
+ }
178
+ context . visitStack = oldVisitStack ;
179
+ return result ;
180
+ } ;
181
+ Converter . prototype . convertType = function ( context , node , type ) {
182
+ if ( node ) {
183
+ type = type || context . getTypeAtLocation ( node ) ;
184
+ for ( var _i = 0 , _a = this . typeNodeConverters ; _i < _a . length ; _i ++ ) {
185
+ var converter = _a [ _i ] ;
186
+ if ( converter . supportsNode ( context , node , type ) ) {
187
+ return converter . convertNode ( context , node , type ) ;
188
+ }
189
+ }
190
+ }
191
+ if ( type ) {
192
+ for ( var _b = 0 , _c = this . typeTypeConverters ; _b < _c . length ; _b ++ ) {
193
+ var converter = _c [ _b ] ;
194
+ if ( converter . supportsType ( context , type ) ) {
195
+ return converter . convertType ( context , type ) ;
196
+ }
197
+ }
198
+ }
199
+ } ;
81
200
Converter . prototype . compile = function ( context ) {
201
+ var _this = this ;
82
202
var program = context . program ;
83
203
program . getSourceFiles ( ) . forEach ( function ( sourceFile ) {
84
- convert_node_1 . convertNode ( context , sourceFile ) ;
204
+ _this . convertNode ( context , sourceFile ) ;
85
205
} ) ;
86
206
var diagnostics = program . getSyntacticDiagnostics ( ) ;
87
207
if ( diagnostics . length === 0 ) {
@@ -126,7 +246,10 @@ var Converter = (function (_super) {
126
246
Converter . EVENT_RESOLVE_BEGIN = 'resolveBegin' ;
127
247
Converter . EVENT_RESOLVE = 'resolveReflection' ;
128
248
Converter . EVENT_RESOLVE_END = 'resolveEnd' ;
249
+ Converter = __decorate ( [
250
+ component_1 . Component ( { childClass : components_1 . ConverterComponent } ) ,
251
+ __metadata ( 'design:paramtypes' , [ ] )
252
+ ] , Converter ) ;
129
253
return Converter ;
130
- } ) ( component_1 . ConverterHost ) ;
254
+ } ) ( component_1 . ChildableComponent ) ;
131
255
exports . Converter = Converter ;
132
- require ( "./plugins/index" ) ;
0 commit comments