Skip to content

Commit 118836f

Browse files
committed
Throw exception if id tracking args are passed
Fixes #1151
1 parent ee6fadf commit 118836f

2 files changed

Lines changed: 37 additions & 28 deletions

File tree

lib/handlebars/compiler/compiler.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

442431
export 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+
472472
function argEquals(a, b) {
473473
if (a === b) {
474474
return true;

spec/compiler.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,25 @@ describe('compiler', function() {
4848
it('can pass through an empty string', function() {
4949
equal(Handlebars.compile('')(), '');
5050
});
51+
52+
it('throws on desupported options', function() {
53+
shouldThrow(function() {
54+
Handlebars.compile('Dudes', {trackIds: true});
55+
}, Error, 'TrackIds and stringParams are no longer supported. See Github #1145');
56+
shouldThrow(function() {
57+
Handlebars.compile('Dudes', {stringParams: true});
58+
}, Error, 'TrackIds and stringParams are no longer supported. See Github #1145');
59+
});
5160
});
5261

5362
describe('#precompile', function() {
5463
it('should fail with invalid input', function() {
5564
shouldThrow(function() {
5665
Handlebars.precompile(null);
57-
}, Error, 'You must pass a string or Handlebars AST to Handlebars.precompile. You passed null');
66+
}, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed null');
5867
shouldThrow(function() {
5968
Handlebars.precompile({});
60-
}, Error, 'You must pass a string or Handlebars AST to Handlebars.precompile. You passed [object Object]');
69+
}, Error, 'You must pass a string or Handlebars AST to Handlebars.compile. You passed [object Object]');
6170
});
6271

6372
it('can utilize AST instance', function() {

0 commit comments

Comments
 (0)