@@ -421,41 +421,20 @@ Compiler.prototype = {
421421 }
422422} ;
423423
424- export function precompile ( input , options , env ) {
425- if ( input == null || ( typeof input !== 'string' && input . type !== 'Program' ) ) {
426- throw new Exception ( 'You must pass a string or Handlebars AST to Handlebars.precompile. You passed ' + input ) ;
427- }
428-
429- options = options || { } ;
430- if ( ! ( 'data' in options ) ) {
431- options . data = true ;
432- }
433- if ( options . compat ) {
434- options . useDepths = true ;
435- }
424+ export function precompile ( input , options = { } , env ) {
425+ validateInput ( input , options ) ;
436426
437- let ast = env . parse ( input , options ) ,
438- environment = new env . Compiler ( ) . compile ( ast , options ) ;
427+ let environment = compileEnvironment ( input , options , env ) ;
439428 return new env . JavaScriptCompiler ( ) . compile ( environment , options ) ;
440429}
441430
442431export function compile ( input , options = { } , env ) {
443- if ( input == null || ( typeof input !== 'string' && input . type !== 'Program' ) ) {
444- throw new Exception ( 'You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input ) ;
445- }
446-
447- if ( ! ( 'data' in options ) ) {
448- options . data = true ;
449- }
450- if ( options . compat ) {
451- options . useDepths = true ;
452- }
432+ validateInput ( input , options ) ;
453433
454434 let compiled ;
455435
456436 function compileInput ( ) {
457- let ast = env . parse ( input , options ) ,
458- environment = new env . Compiler ( ) . compile ( ast , options ) ,
437+ let environment = compileEnvironment ( input , options , env ) ,
459438 templateSpec = new env . JavaScriptCompiler ( ) . compile ( environment , options , undefined , true ) ;
460439 return env . template ( templateSpec ) ;
461440 }
@@ -469,6 +448,27 @@ export function compile(input, options = {}, env) {
469448 } ;
470449}
471450
451+ function validateInput ( input , options ) {
452+ if ( input == null || ( typeof input !== 'string' && input . type !== 'Program' ) ) {
453+ throw new Exception ( 'You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input ) ;
454+ }
455+
456+ if ( options . trackIds || options . stringParams ) {
457+ throw new Exception ( 'TrackIds and stringParams are no longer supported. See Github #1145' ) ;
458+ }
459+
460+ if ( ! ( 'data' in options ) ) {
461+ options . data = true ;
462+ }
463+ if ( options . compat ) {
464+ options . useDepths = true ;
465+ }
466+ }
467+ function compileEnvironment ( input , options , env ) {
468+ let ast = env . parse ( input , options ) ;
469+ return new env . Compiler ( ) . compile ( ast , options ) ;
470+ }
471+
472472function argEquals ( a , b ) {
473473 if ( a === b ) {
474474 return true ;
0 commit comments