9
9
*/
10
10
// Requires node >= 7.6
11
11
12
- import { Analyzer , Feature , Element , Package , FSUrlLoader , PackageUrlResolver , Property , ElementMixin , Method } from 'polymer-analyzer' ;
12
+ import { Analyzer , Feature , Element , Analysis , FSUrlLoader , PackageUrlResolver , Property , ElementMixin , Method } from 'polymer-analyzer' ;
13
13
import { Function as ResolvedFunction } from 'polymer-analyzer/lib/javascript/function' ;
14
14
import { generate } from 'escodegen' ;
15
15
@@ -24,16 +24,16 @@ const header = `declare namespace Polymer {
24
24
` ;
25
25
const footer = `}` ;
26
26
27
- export function generateDeclarations ( ) {
27
+ export function generateDeclarations ( ) : Promise < string > {
28
28
const analyzer = new Analyzer ( {
29
29
urlLoader : new FSUrlLoader ( ) ,
30
30
urlResolver : new PackageUrlResolver ( ) ,
31
31
} ) ;
32
32
33
- analyzer . analyzePackage ( ) . then ( generatePackage ) ;
33
+ return analyzer . analyzePackage ( ) . then ( generatePackage ) ;
34
34
}
35
35
36
- function generatePackage ( pkg : Package ) {
36
+ function generatePackage ( pkg : Analysis ) : Promise < string > {
37
37
const declarations = [ header ] ;
38
38
39
39
for ( const feature of pkg . getFeatures ( ) ) {
@@ -57,7 +57,7 @@ function generatePackage(pkg: Package) {
57
57
58
58
declarations . push ( footer ) ;
59
59
60
- process . stdout . write ( declarations . join ( '\n' ) ) ;
60
+ return Promise . resolve ( declarations . join ( '\n' ) ) ;
61
61
}
62
62
63
63
function genElementDeclaration ( element : Element , declarations : string [ ] , indent : number = 0 ) {
@@ -236,6 +236,7 @@ const typeMap = new Map([
236
236
[ 'String' , 'string' ] ,
237
237
[ 'Number' , 'number' ] ,
238
238
[ 'Boolean' , 'boolean' ] ,
239
+ [ '*' , 'any' ] ,
239
240
[ 'Array' , 'any[]' ] ,
240
241
] ) ;
241
242
@@ -247,7 +248,6 @@ interface TsType {
247
248
function getTsType ( type ?: string ) : TsType {
248
249
let optional = false ;
249
250
250
- // default to 'any'
251
251
type = type || 'any' ;
252
252
253
253
// handle Closure optionals
@@ -256,6 +256,11 @@ function getTsType(type?: string): TsType {
256
256
type = type . substring ( 0 , type . length - 1 ) ;
257
257
}
258
258
259
+ // handle Closure unknown type
260
+ if ( type . startsWith ( '?' ) ) {
261
+ type = type + '|null' ;
262
+ }
263
+
259
264
// convert from Closure
260
265
if ( typeMap . has ( type ) ) {
261
266
type = typeMap . get ( type ) ! ;
0 commit comments