@@ -94,7 +94,9 @@ module.exports.cli = function(opts) {
9494 if ( opts . simple && opts . min ) {
9595 throw new Handlebars . Exception ( 'Unable to minimize simple output' ) ;
9696 }
97- if ( opts . simple && ( opts . templates . length !== 1 || opts . hasDirectory ) ) {
97+
98+ const multiple = opts . templates . length !== 1 || opts . hasDirectory ;
99+ if ( opts . simple && multiple ) {
98100 throw new Handlebars . Exception ( 'Unable to output multiple templates in simple mode' ) ;
99101 }
100102
@@ -109,6 +111,8 @@ module.exports.cli = function(opts) {
109111 }
110112 }
111113
114+ const objectName = opts . partial ? 'Handlebars.partials' : 'templates' ;
115+
112116 let output = new SourceNode ( ) ;
113117 if ( ! opts . simple ) {
114118 if ( opts . amd ) {
@@ -151,28 +155,19 @@ module.exports.cli = function(opts) {
151155
152156 if ( opts . simple ) {
153157 output . add ( [ precompiled , '\n' ] ) ;
154- } else if ( opts . partial ) {
155- if ( opts . amd && ( opts . templates . length == 1 && ! opts . hasDirectory ) ) {
156- output . add ( 'return ' ) ;
157- }
158- output . add ( [ 'Handlebars.partials[\'' , template . name , '\'] = template(' , precompiled , ');\n' ] ) ;
159158 } else {
160- if ( opts . amd && ( opts . templates . length == 1 && ! opts . hasDirectory ) ) {
159+ if ( opts . amd && ! multiple ) {
161160 output . add ( 'return ' ) ;
162161 }
163- output . add ( [ 'templates [\'', template . name , '\'] = template(' , precompiled , ');\n' ] ) ;
162+ output . add ( [ objectName , ' [\'', template . name , '\'] = template(' , precompiled , ');\n' ] ) ;
164163 }
165164 } ) ;
166165
167166 // Output the content
168167 if ( ! opts . simple ) {
169168 if ( opts . amd ) {
170- if ( opts . templates . length > 1 || ( opts . templates . length == 1 && opts . hasDirectory ) ) {
171- if ( opts . partial ) {
172- output . add ( 'return Handlebars.partials;\n' ) ;
173- } else {
174- output . add ( 'return templates;\n' ) ;
175- }
169+ if ( multiple ) {
170+ output . add ( [ 'return ' , objectName , ';\n' ] ) ;
176171 }
177172 output . add ( '});' ) ;
178173 } else if ( ! opts . commonjs ) {
0 commit comments