@@ -22,18 +22,19 @@ class Generator {
2222 * @return {string } the template
2323*/
2424function makeInitial ( srcData , generator ) {
25- let definitions = generator . data . definitions [ generator . data . modelName ] ;
26- let properties = definitions . properties ;
25+ let definitions = generator . data . definitions [ generator . data . modelName ]
26+ let properties = definitions . properties
2727 var data = {
28- imports : getImports ( properties ) ,
28+ imports : genImports ( properties ) ,
2929 ...generator . data
3030 }
31- var template = srcData . replace ( / { { .* ?} } / g, function ( str , p1 , offset , s ) {
31+
32+ var template = srcData . replace ( / { { .* ?} } / g, function ( str , _ , _ , _ ) {
3233 var key = str . trim ( ) . slice ( 2 , str . trim ( ) . length - 2 ) . trim ( )
3334 var ret = data [ key ]
3435 if ( ret === null || ret === undefined ) {
3536 console . log ( 'missing property:' , key )
36- ret = ' !!!' + key + '!!'
37+ ret = ` !!!${ key } !!`
3738 }
3839
3940 return ret
@@ -42,7 +43,7 @@ function makeInitial(srcData, generator) {
4243 return template
4344}
4445
45- function getImports ( properties ) {
46+ function genImports ( properties ) {
4647 var result = new Set ( )
4748 for ( var propName in properties ) {
4849 var props = properties [ propName ]
@@ -74,16 +75,20 @@ function genNames(properties) {
7475 for ( var propName in properties ) {
7576 if ( propName !== 'children' ) {
7677 var props = properties [ propName ]
77- if ( props [ 'x-source' ] == 'inject' ) {
78- inject += ' \t/* ' + JSON . stringify ( props ) + ' */\n'
78+ if ( props [ 'x-source' ] === 'inject' ) {
79+ inject += ` \t/* ${ JSON . stringify ( props ) } */\n`
7980 inject += '\t@Inject\n'
80- if ( props [ 'x-sourceName' ] ) {
81- inject += '\t@Named(value ="' + props [ 'x-sourceName' ] + '")\n'
81+
82+ var sourceName = props [ 'x-sourceName' ] ;
83+ if ( sourceName ) {
84+ inject += `\t@Named(value ="${ sourceName } ")\n`
8285 }
83- if ( props [ 'x-default' ] === "" || props [ 'x-default' ] ) {
84- inject += '\t@Default(values ="' + props [ 'x-default' ] + '")\n'
86+
87+ var x_default = props [ 'x-default' ] ;
88+ if ( x_default === "" || x_default ) {
89+ inject += `\t@Default(values ="${ x_default } ")\n`
8590 }
86- if ( props [ 'x-form-type' ] === ( 'collection' ) ) {
91+ if ( props [ 'x-form-type' ] === 'collection' ) {
8792 if ( Object . keys ( props [ 'properties' ] ) . length > 1 || props [ 'x-form-multifield' ] === "true" || props [ 'x-form-multifield' ] === true ) {
8893 inject += '\tprivate List<IComponent> '
8994 } else {
@@ -92,15 +97,12 @@ function genNames(properties) {
9297 } else {
9398 inject += '\tprivate String '
9499 }
95- inject += propName
96- inject += ';'
97- inject += '\n'
98- inject += '\n'
100+ inject += `${ propName } ;\n\n`
99101 var annotate = props [ 'x-annotate' ]
100102 if ( annotate ) {
101103 inject += genNamesAnnotates ( propName , annotate )
102104 }
103- } else if ( props [ 'x-form-type' ] === ( 'reference' ) ) {
105+ } else if ( props [ 'x-form-type' ] === 'reference' ) {
104106 inject += genNames ( props . properties )
105107 }
106108 }
@@ -129,11 +131,11 @@ function genGetters(properties, customGetters) {
129131 inject = ''
130132 for ( var propName in properties ) {
131133 var getterName = propName . charAt ( 0 ) . toUpperCase ( ) + propName . slice ( 1 )
132- if ( propName !== 'children' && ( customGetters === null || ! customGetters . includes ( ' public String get' + getterName + '()' ) ) ) {
134+ if ( propName !== 'children' && ( customGetters === null || ! customGetters . includes ( ` public String get${ getterName } ()` ) ) ) {
133135 var props = properties [ propName ]
134136 if ( props [ 'x-source' ] == 'inject' ) {
135- inject += ' \t/* ' + JSON . stringify ( props ) + ' */\n'
136- if ( props [ 'x-form-type' ] === ( 'collection' ) ) {
137+ inject += ` \t/* ${ JSON . stringify ( props ) } */\n`
138+ if ( props [ 'x-form-type' ] === 'collection' ) {
137139 if ( Object . keys ( props [ 'properties' ] ) . length > 1 || props [ 'x-form-multifield' ] === "true" || props [ 'x-form-multifield' ] === true ) {
138140 inject += '\tpublic List<IComponent> get'
139141 } else {
@@ -142,11 +144,9 @@ function genGetters(properties, customGetters) {
142144 } else {
143145 inject += '\tpublic String get'
144146 }
145- inject += getterName + '() {\n'
146- inject += '\t\treturn ' + propName + ';\n'
147- inject += '\t}'
148- inject += '\n'
149- inject += '\n'
147+ inject += `${ getterName } () {\n`
148+ inject += `\t\treturn ${ propName } ;\n`
149+ inject += '\t}\n\n'
150150 var annotate = props [ 'x-annotate' ]
151151 if ( annotate ) {
152152 inject += genGettersAnnotates ( propName , annotate )
0 commit comments