Skip to content

Commit 3f77b82

Browse files
committed
Remove stringParams and trackIds mode
Closes #1145
1 parent 205c61c commit 3f77b82

11 files changed

Lines changed: 8 additions & 651 deletions

File tree

lib/handlebars/compiler/compiler.js

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ Compiler.prototype = {
4949
this.opcodes = [];
5050
this.children = [];
5151
this.options = options;
52-
this.stringParams = options.stringParams;
53-
this.trackIds = options.trackIds;
5452

5553
options.blockParams = options.blockParams || [];
5654

@@ -393,49 +391,7 @@ Compiler.prototype = {
393391
},
394392

395393
pushParam: function(val) {
396-
let value = val.value != null ? val.value : val.original || '';
397-
398-
if (this.stringParams) {
399-
if (value.replace) {
400-
value = value
401-
.replace(/^(\.?\.\/)*/g, '')
402-
.replace(/\//g, '.');
403-
}
404-
405-
if (val.depth) {
406-
this.addDepth(val.depth);
407-
}
408-
this.opcode('getContext', val.depth || 0);
409-
this.opcode('pushStringParam', value, val.type);
410-
411-
if (val.type === 'SubExpression') {
412-
// SubExpressions get evaluated and passed in
413-
// in string params mode.
414-
this.accept(val);
415-
}
416-
} else {
417-
if (this.trackIds) {
418-
let blockParamIndex;
419-
if (val.parts && !AST.helpers.scopedId(val) && !val.depth) {
420-
blockParamIndex = this.blockParamIndex(val.parts[0]);
421-
}
422-
if (blockParamIndex) {
423-
let blockParamChild = val.parts.slice(1).join('.');
424-
this.opcode('pushId', 'BlockParam', blockParamIndex, blockParamChild);
425-
} else {
426-
value = val.original || value;
427-
if (value.replace) {
428-
value = value
429-
.replace(/^this(?:\.|$)/, '')
430-
.replace(/^\.\//, '')
431-
.replace(/^\.$/, '');
432-
}
433-
434-
this.opcode('pushId', val.type, value);
435-
}
436-
}
437-
this.accept(val);
438-
}
394+
this.accept(val);
439395
},
440396

441397
setupFullMustacheParams: function(sexpr, program, inverse, omitEmpty) {

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ JavaScriptCompiler.prototype = {
5757
compile: function(environment, options, context, asObject) {
5858
this.environment = environment;
5959
this.options = options;
60-
this.stringParams = this.options.stringParams;
61-
this.trackIds = this.options.trackIds;
6260
this.precompile = !asObject;
6361

6462
this.name = this.environment.name;
@@ -498,37 +496,7 @@ JavaScriptCompiler.prototype = {
498496
this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
499497
},
500498

501-
// [pushStringParam]
502-
//
503-
// On stack, before: ...
504-
// On stack, after: string, currentContext, ...
505-
//
506-
// This opcode is designed for use in string mode, which
507-
// provides the string value of a parameter along with its
508-
// depth rather than resolving it immediately.
509-
pushStringParam: function(string, type) {
510-
this.pushContext();
511-
this.pushString(type);
512-
513-
// If it's a subexpression, the string result
514-
// will be pushed after this opcode.
515-
if (type !== 'SubExpression') {
516-
if (typeof string === 'string') {
517-
this.pushString(string);
518-
} else {
519-
this.pushStackLiteral(string);
520-
}
521-
}
522-
},
523-
524499
emptyHash: function(omitEmpty) {
525-
if (this.trackIds) {
526-
this.push('{}'); // hashIds
527-
}
528-
if (this.stringParams) {
529-
this.push('{}'); // hashContexts
530-
this.push('{}'); // hashTypes
531-
}
532500
this.pushStackLiteral(omitEmpty ? 'undefined' : '{}');
533501
},
534502
pushHash: function() {
@@ -541,14 +509,6 @@ JavaScriptCompiler.prototype = {
541509
let hash = this.hash;
542510
this.hash = this.hashes.pop();
543511

544-
if (this.trackIds) {
545-
this.push(this.objectLiteral(hash.ids));
546-
}
547-
if (this.stringParams) {
548-
this.push(this.objectLiteral(hash.contexts));
549-
this.push(this.objectLiteral(hash.types));
550-
}
551-
552512
this.push(this.objectLiteral(hash.values));
553513
},
554514

@@ -727,44 +687,7 @@ JavaScriptCompiler.prototype = {
727687
//
728688
// Pops a value off the stack and assigns it to the current hash
729689
assignToHash: function(key) {
730-
let value = this.popStack(),
731-
context,
732-
type,
733-
id;
734-
735-
if (this.trackIds) {
736-
id = this.popStack();
737-
}
738-
if (this.stringParams) {
739-
type = this.popStack();
740-
context = this.popStack();
741-
}
742-
743-
let hash = this.hash;
744-
if (context) {
745-
hash.contexts[key] = context;
746-
}
747-
if (type) {
748-
hash.types[key] = type;
749-
}
750-
if (id) {
751-
hash.ids[key] = id;
752-
}
753-
hash.values[key] = value;
754-
},
755-
756-
pushId: function(type, name, child) {
757-
if (type === 'BlockParam') {
758-
this.pushStackLiteral(
759-
'blockParams[' + name[0] + '].path[' + name[1] + ']'
760-
+ (child ? ' + ' + JSON.stringify('.' + child) : ''));
761-
} else if (type === 'PathExpression') {
762-
this.pushString(name);
763-
} else if (type === 'SubExpression') {
764-
this.pushStackLiteral('true');
765-
} else {
766-
this.pushStackLiteral('null');
767-
}
690+
this.hash.values[key] = this.popStack();
768691
},
769692

770693
// HELPERS
@@ -997,9 +920,6 @@ JavaScriptCompiler.prototype = {
997920

998921
setupParams: function(helper, paramSize, params) {
999922
let options = {},
1000-
contexts = [],
1001-
types = [],
1002-
ids = [],
1003923
objectArgs = !params,
1004924
param;
1005925

@@ -1010,14 +930,6 @@ JavaScriptCompiler.prototype = {
1010930
options.name = this.quotedString(helper);
1011931
options.hash = this.popStack();
1012932

1013-
if (this.trackIds) {
1014-
options.hashIds = this.popStack();
1015-
}
1016-
if (this.stringParams) {
1017-
options.hashTypes = this.popStack();
1018-
options.hashContexts = this.popStack();
1019-
}
1020-
1021933
let inverse = this.popStack(),
1022934
program = this.popStack();
1023935

@@ -1034,28 +946,12 @@ JavaScriptCompiler.prototype = {
1034946
while (i--) {
1035947
param = this.popStack();
1036948
params[i] = param;
1037-
1038-
if (this.trackIds) {
1039-
ids[i] = this.popStack();
1040-
}
1041-
if (this.stringParams) {
1042-
types[i] = this.popStack();
1043-
contexts[i] = this.popStack();
1044-
}
1045949
}
1046950

1047951
if (objectArgs) {
1048952
options.args = this.source.generateArray(params);
1049953
}
1050954

1051-
if (this.trackIds) {
1052-
options.ids = this.source.generateArray(ids);
1053-
}
1054-
if (this.stringParams) {
1055-
options.types = this.source.generateArray(types);
1056-
options.contexts = this.source.generateArray(contexts);
1057-
}
1058-
1059955
if (this.options.data) {
1060956
options.data = 'data';
1061957
}

lib/handlebars/helpers/block-helper-missing.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {appendContextPath, createFrame, isArray} from '../utils';
1+
import {isArray} from '../utils';
22

33
export default function(instance) {
44
instance.registerHelper('blockHelperMissing', function(context, options) {
@@ -11,21 +11,11 @@ export default function(instance) {
1111
return inverse(this);
1212
} else if (isArray(context)) {
1313
if (context.length > 0) {
14-
if (options.ids) {
15-
options.ids = [options.name];
16-
}
17-
1814
return instance.helpers.each(context, options);
1915
} else {
2016
return inverse(this);
2117
}
2218
} else {
23-
if (options.data && options.ids) {
24-
let data = createFrame(options.data);
25-
data.contextPath = appendContextPath(options.data.contextPath, options.name);
26-
options = {data: data};
27-
}
28-
2919
return fn(context, options);
3020
}
3121
});

lib/handlebars/helpers/each.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {appendContextPath, blockParams, createFrame, isArray, isFunction} from '../utils';
1+
import {createFrame, isArray, isFunction} from '../utils';
22
import Exception from '../exception';
33

44
export default function(instance) {
@@ -11,12 +11,7 @@ export default function(instance) {
1111
inverse = options.inverse,
1212
i = 0,
1313
ret = '',
14-
data,
15-
contextPath;
16-
17-
if (options.data && options.ids) {
18-
contextPath = appendContextPath(options.data.contextPath, options.ids[0]) + '.';
19-
}
14+
data;
2015

2116
if (isFunction(context)) { context = context.call(this); }
2217

@@ -30,15 +25,11 @@ export default function(instance) {
3025
data.index = index;
3126
data.first = index === 0;
3227
data.last = !!last;
33-
34-
if (contextPath) {
35-
data.contextPath = contextPath + field;
36-
}
3728
}
3829

3930
ret = ret + fn(context[field], {
4031
data: data,
41-
blockParams: blockParams([context[field], field], [contextPath + field, null])
32+
blockParams: [context[field], field]
4233
});
4334
}
4435

lib/handlebars/helpers/with.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {appendContextPath, blockParams, createFrame, isEmpty, isFunction} from '../utils';
1+
import {isEmpty, isFunction} from '../utils';
22

33
export default function(instance) {
44
instance.registerHelper('with', function(context, options) {
@@ -8,14 +8,10 @@ export default function(instance) {
88

99
if (!isEmpty(context)) {
1010
let data = options.data;
11-
if (options.data && options.ids) {
12-
data = createFrame(options.data);
13-
data.contextPath = appendContextPath(options.data.contextPath, options.ids[0]);
14-
}
1511

1612
return fn(context, {
1713
data: data,
18-
blockParams: blockParams([context], [data && data.contextPath])
14+
blockParams: [context]
1915
});
2016
} else {
2117
return options.inverse(this);

lib/handlebars/runtime.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ export function template(templateSpec, env) {
3838
function invokePartialWrapper(partial, context, options) {
3939
if (options.hash) {
4040
context = Utils.extend({}, context, options.hash);
41-
if (options.ids) {
42-
options.ids[0] = true;
43-
}
4441
}
4542

4643
partial = env.VM.resolvePartial.call(this, partial, context, options);
@@ -224,9 +221,6 @@ export function resolvePartial(partial, context, options) {
224221

225222
export function invokePartial(partial, context, options) {
226223
options.partial = true;
227-
if (options.ids) {
228-
options.data.contextPath = options.ids[0] || options.data.contextPath;
229-
}
230224

231225
let partialBlock;
232226
if (options.fn && options.fn !== noop) {

lib/handlebars/utils.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,3 @@ export function createFrame(object) {
9898
return frame;
9999
}
100100

101-
export function blockParams(params, ids) {
102-
params.path = ids;
103-
return params;
104-
}
105-
106-
export function appendContextPath(contextPath, id) {
107-
return (contextPath ? contextPath + '.' : '') + id;
108-
}

print-script

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ var template = Handlebars.precompile(script, {
1616
assumeObjects: true,
1717
compat: false,
1818
strict: true,
19-
trackIds: true,
2019
knownHelpersOnly: false
2120
});
2221

0 commit comments

Comments
 (0)