@@ -94,7 +94,9 @@ module.exports.cli = function(opts) {
94
94
if ( opts . simple && opts . min ) {
95
95
throw new Handlebars . Exception ( 'Unable to minimize simple output' ) ;
96
96
}
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 ) {
98
100
throw new Handlebars . Exception ( 'Unable to output multiple templates in simple mode' ) ;
99
101
}
100
102
@@ -109,6 +111,8 @@ module.exports.cli = function(opts) {
109
111
}
110
112
}
111
113
114
+ const objectName = opts . partial ? 'Handlebars.partials' : 'templates' ;
115
+
112
116
let output = new SourceNode ( ) ;
113
117
if ( ! opts . simple ) {
114
118
if ( opts . amd ) {
@@ -151,28 +155,19 @@ module.exports.cli = function(opts) {
151
155
152
156
if ( opts . simple ) {
153
157
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' ] ) ;
159
158
} else {
160
- if ( opts . amd && ( opts . templates . length == 1 && ! opts . hasDirectory ) ) {
159
+ if ( opts . amd && ! multiple ) {
161
160
output . add ( 'return ' ) ;
162
161
}
163
- output . add ( [ 'templates [\'', template . name , '\'] = template(' , precompiled , ');\n' ] ) ;
162
+ output . add ( [ objectName , ' [\'', template . name , '\'] = template(' , precompiled , ');\n' ] ) ;
164
163
}
165
164
} ) ;
166
165
167
166
// Output the content
168
167
if ( ! opts . simple ) {
169
168
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' ] ) ;
176
171
}
177
172
output . add ( '});' ) ;
178
173
} else if ( ! opts . commonjs ) {
0 commit comments