@@ -24,11 +24,7 @@ function jsDocComment(property) {
2424 if ( ! lines . length ) {
2525 return undefined ;
2626 }
27- return [
28- '/**' ,
29- ...lines . map ( line => ` * ${ line } ` ) ,
30- ' */' ,
31- ] . join ( '\n' ) ;
27+ return [ '/**' , ...lines . map ( ( line ) => ` * ${ line } ` ) , ' */' ] . join ( '\n' ) ;
3228}
3329
3430function jsDocBlock ( tag , value ) {
@@ -40,9 +36,11 @@ ${formatJSON(value)}
4036
4137function unionType ( values ) {
4238 if ( Array . isArray ( values ) ) {
43- return values . map ( v => JSON . stringify ( v ) ) . join ( ' | ' ) ;
39+ return values . map ( ( v ) => JSON . stringify ( v ) ) . join ( ' | ' ) ;
4440 } else {
45- return Object . keys ( values ) . map ( v => JSON . stringify ( v ) ) . join ( ' | ' ) ;
41+ return Object . keys ( values )
42+ . map ( ( v ) => JSON . stringify ( v ) )
43+ . join ( ' | ' ) ;
4644 }
4745}
4846
@@ -60,7 +58,11 @@ function propertyType(property) {
6058 case 'enum' :
6159 return unionType ( property . values ) ;
6260 case 'array' : {
63- const elementType = propertyType ( typeof property . value === 'string' ? { type : property . value , values : property . values } : property . value ) ;
61+ const elementType = propertyType (
62+ typeof property . value === 'string'
63+ ? { type : property . value , values : property . values }
64+ : property . value
65+ ) ;
6466 if ( property . length ) {
6567 return `[${ Array ( property . length ) . fill ( elementType ) . join ( ', ' ) } ]` ;
6668 } else {
@@ -104,32 +106,37 @@ function objectDeclaration(key, properties) {
104106function objectType ( properties , indent ) {
105107 return `{
106108${ Object . keys ( properties )
107- . filter ( k => k !== '*' )
108- . flatMap ( k => {
109+ . filter ( ( k ) => k !== '*' )
110+ . flatMap ( ( k ) => {
109111 const declarations = [ propertyDeclaration ( k , properties [ k ] ) ] ;
110112 if ( properties [ k ] . transition ) {
111113 declarations . push ( transitionPropertyDeclaration ( k ) ) ;
112114 }
113115 return declarations ;
114116 } )
115- . map ( declaration => {
117+ . map ( ( declaration ) => {
116118 return declaration
117119 . split ( '\n' )
118- . map ( line => ` ${ indent } ${ line } ` )
120+ . map ( ( line ) => ` ${ indent } ${ line } ` )
119121 . join ( '\n' ) ;
120122 } )
121123 . join ( ',\n' ) }
122124${ indent } }`;
123125}
124126
125127function sourceTypeName ( key ) {
126- return key . replace ( / s o u r c e _ ( .) ( .* ) / , ( _ , _1 , _2 ) => `${ _1 . toUpperCase ( ) } ${ _2 } SourceSpecification` )
128+ return key
129+ . replace ( / s o u r c e _ ( .) ( .* ) / , ( _ , _1 , _2 ) => `${ _1 . toUpperCase ( ) } ${ _2 } SourceSpecification` )
127130 . replace ( / _ d e m / , 'DEM' )
128131 . replace ( / G e o j s o n / , 'GeoJSON' ) ;
129132}
130133
131134function layerTypeName ( key ) {
132- return key . split ( '-' ) . map ( k => k . replace ( / ( .) ( .* ) / , ( _ , _1 , _2 ) => `${ _1 . toUpperCase ( ) } ${ _2 } ` ) ) . concat ( 'LayerSpecification' ) . join ( '' ) ;
135+ return key
136+ . split ( '-' )
137+ . map ( ( k ) => k . replace ( / ( .) ( .* ) / , ( _ , _1 , _2 ) => `${ _1 . toUpperCase ( ) } ${ _2 } ` ) )
138+ . concat ( 'LayerSpecification' )
139+ . join ( '' ) ;
133140}
134141
135142function layerType ( key ) {
@@ -165,9 +172,9 @@ function layerType(key) {
165172
166173const layerTypes = Object . keys ( spec . layer . type . values ) ;
167174
168- writeFileSync ( 'src/types.g.ts' ,
175+ writeFileSync (
176+ 'src/types.g.ts' ,
169177 `// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
170- /* eslint-disable */
171178
172179export type ColorSpecification = string;
173180
@@ -394,21 +401,24 @@ ${objectDeclaration('ProjectionSpecification', spec.projection)}
394401
395402${ objectDeclaration ( 'TerrainSpecification' , spec . terrain ) }
396403
397- ${ spec . source . map ( key => {
398- let str = objectDeclaration ( sourceTypeName ( key ) , spec [ key ] ) ;
399- if ( sourceTypeName ( key ) === 'GeoJSONSourceSpecification' ) {
400- // This is done in order to overcome the type system's inability to express this type:
401- str = str . replace ( / u n k n o w n / , 'GeoJSON.GeoJSON | string' ) ;
402- }
403- return str ;
404- } ) . join ( '\n\n' ) }
404+ ${ spec . source
405+ . map ( ( key ) => {
406+ let str = objectDeclaration ( sourceTypeName ( key ) , spec [ key ] ) ;
407+ if ( sourceTypeName ( key ) === 'GeoJSONSourceSpecification' ) {
408+ // This is done in order to overcome the type system's inability to express this type:
409+ str = str . replace ( / u n k n o w n / , 'GeoJSON.GeoJSON | string' ) ;
410+ }
411+ return str ;
412+ } )
413+ . join ( '\n\n' ) }
405414
406415export type SourceSpecification =
407- ${ spec . source . map ( key => ` | ${ sourceTypeName ( key ) } ` ) . join ( '\n' ) }
416+ ${ spec . source . map ( ( key ) => ` | ${ sourceTypeName ( key ) } ` ) . join ( '\n' ) }
408417
409- ${ layerTypes . map ( key => layerType ( key ) ) . join ( '\n\n' ) }
418+ ${ layerTypes . map ( ( key ) => layerType ( key ) ) . join ( '\n\n' ) }
410419
411420export type LayerSpecification =
412- ${ layerTypes . map ( key => ` | ${ layerTypeName ( key ) } ` ) . join ( '\n' ) } ;
421+ ${ layerTypes . map ( ( key ) => ` | ${ layerTypeName ( key ) } ` ) . join ( '\n' ) } ;
413422
414- ` ) ;
423+ `
424+ ) ;
0 commit comments