summaryrefslogtreecommitdiffstats
path: root/lib/handlebars
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars')
-rw-r--r--lib/handlebars/base.js2
-rw-r--r--lib/handlebars/compiler/compiler.js61
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js106
-rw-r--r--lib/handlebars/exception.js19
-rw-r--r--lib/handlebars/helpers/block-helper-missing.js12
-rw-r--r--lib/handlebars/helpers/each.js15
-rw-r--r--lib/handlebars/helpers/with.js8
-rw-r--r--lib/handlebars/no-conflict.js1
-rw-r--r--lib/handlebars/runtime.js26
-rw-r--r--lib/handlebars/utils.js8
10 files changed, 31 insertions, 227 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 84a8915..836422d 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -4,7 +4,7 @@ import {registerDefaultHelpers} from './helpers';
import {registerDefaultDecorators} from './decorators';
import logger from './logger';
-export const VERSION = '4.0.4';
+export const VERSION = '4.0.5';
export const COMPILER_REVISION = 7;
export const REVISION_CHANGES = {
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 987d0d4..040e99a 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -49,8 +49,6 @@ Compiler.prototype = {
this.opcodes = [];
this.children = [];
this.options = options;
- this.stringParams = options.stringParams;
- this.trackIds = options.trackIds;
options.blockParams = options.blockParams || [];
@@ -393,49 +391,7 @@ Compiler.prototype = {
},
pushParam: function(val) {
- let value = val.value != null ? val.value : val.original || '';
-
- if (this.stringParams) {
- if (value.replace) {
- value = value
- .replace(/^(\.?\.\/)*/g, '')
- .replace(/\//g, '.');
- }
-
- if (val.depth) {
- this.addDepth(val.depth);
- }
- this.opcode('getContext', val.depth || 0);
- this.opcode('pushStringParam', value, val.type);
-
- if (val.type === 'SubExpression') {
- // SubExpressions get evaluated and passed in
- // in string params mode.
- this.accept(val);
- }
- } else {
- if (this.trackIds) {
- let blockParamIndex;
- if (val.parts && !AST.helpers.scopedId(val) && !val.depth) {
- blockParamIndex = this.blockParamIndex(val.parts[0]);
- }
- if (blockParamIndex) {
- let blockParamChild = val.parts.slice(1).join('.');
- this.opcode('pushId', 'BlockParam', blockParamIndex, blockParamChild);
- } else {
- value = val.original || value;
- if (value.replace) {
- value = value
- .replace(/^this(?:\.|$)/, '')
- .replace(/^\.\//, '')
- .replace(/^\.$/, '');
- }
-
- this.opcode('pushId', val.type, value);
- }
- }
- this.accept(val);
- }
+ this.accept(val);
},
setupFullMustacheParams: function(sexpr, program, inverse, omitEmpty) {
@@ -505,25 +461,12 @@ export function compile(input, options = {}, env) {
}
// Template is only compiled on first use and cached after that point.
- function ret(context, execOptions) {
+ return function(context, execOptions) {
if (!compiled) {
compiled = compileInput();
}
return compiled.call(this, context, execOptions);
- }
- ret._setup = function(setupOptions) {
- if (!compiled) {
- compiled = compileInput();
- }
- return compiled._setup(setupOptions);
- };
- ret._child = function(i, data, blockParams, depths) {
- if (!compiled) {
- compiled = compileInput();
- }
- return compiled._child(i, data, blockParams, depths);
};
- return ret;
}
function argEquals(a, b) {
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index 97939df..1708032 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -57,8 +57,6 @@ JavaScriptCompiler.prototype = {
compile: function(environment, options, context, asObject) {
this.environment = environment;
this.options = options;
- this.stringParams = this.options.stringParams;
- this.trackIds = this.options.trackIds;
this.precompile = !asObject;
this.name = this.environment.name;
@@ -498,37 +496,7 @@ JavaScriptCompiler.prototype = {
this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
},
- // [pushStringParam]
- //
- // On stack, before: ...
- // On stack, after: string, currentContext, ...
- //
- // This opcode is designed for use in string mode, which
- // provides the string value of a parameter along with its
- // depth rather than resolving it immediately.
- pushStringParam: function(string, type) {
- this.pushContext();
- this.pushString(type);
-
- // If it's a subexpression, the string result
- // will be pushed after this opcode.
- if (type !== 'SubExpression') {
- if (typeof string === 'string') {
- this.pushString(string);
- } else {
- this.pushStackLiteral(string);
- }
- }
- },
-
emptyHash: function(omitEmpty) {
- if (this.trackIds) {
- this.push('{}'); // hashIds
- }
- if (this.stringParams) {
- this.push('{}'); // hashContexts
- this.push('{}'); // hashTypes
- }
this.pushStackLiteral(omitEmpty ? 'undefined' : '{}');
},
pushHash: function() {
@@ -541,14 +509,6 @@ JavaScriptCompiler.prototype = {
let hash = this.hash;
this.hash = this.hashes.pop();
- if (this.trackIds) {
- this.push(this.objectLiteral(hash.ids));
- }
- if (this.stringParams) {
- this.push(this.objectLiteral(hash.contexts));
- this.push(this.objectLiteral(hash.types));
- }
-
this.push(this.objectLiteral(hash.values));
},
@@ -727,44 +687,7 @@ JavaScriptCompiler.prototype = {
//
// Pops a value off the stack and assigns it to the current hash
assignToHash: function(key) {
- let value = this.popStack(),
- context,
- type,
- id;
-
- if (this.trackIds) {
- id = this.popStack();
- }
- if (this.stringParams) {
- type = this.popStack();
- context = this.popStack();
- }
-
- let hash = this.hash;
- if (context) {
- hash.contexts[key] = context;
- }
- if (type) {
- hash.types[key] = type;
- }
- if (id) {
- hash.ids[key] = id;
- }
- hash.values[key] = value;
- },
-
- pushId: function(type, name, child) {
- if (type === 'BlockParam') {
- this.pushStackLiteral(
- 'blockParams[' + name[0] + '].path[' + name[1] + ']'
- + (child ? ' + ' + JSON.stringify('.' + child) : ''));
- } else if (type === 'PathExpression') {
- this.pushString(name);
- } else if (type === 'SubExpression') {
- this.pushStackLiteral('true');
- } else {
- this.pushStackLiteral('null');
- }
+ this.hash.values[key] = this.popStack();
},
// HELPERS
@@ -997,9 +920,6 @@ JavaScriptCompiler.prototype = {
setupParams: function(helper, paramSize, params) {
let options = {},
- contexts = [],
- types = [],
- ids = [],
objectArgs = !params,
param;
@@ -1010,14 +930,6 @@ JavaScriptCompiler.prototype = {
options.name = this.quotedString(helper);
options.hash = this.popStack();
- if (this.trackIds) {
- options.hashIds = this.popStack();
- }
- if (this.stringParams) {
- options.hashTypes = this.popStack();
- options.hashContexts = this.popStack();
- }
-
let inverse = this.popStack(),
program = this.popStack();
@@ -1034,28 +946,12 @@ JavaScriptCompiler.prototype = {
while (i--) {
param = this.popStack();
params[i] = param;
-
- if (this.trackIds) {
- ids[i] = this.popStack();
- }
- if (this.stringParams) {
- types[i] = this.popStack();
- contexts[i] = this.popStack();
- }
}
if (objectArgs) {
options.args = this.source.generateArray(params);
}
- if (this.trackIds) {
- options.ids = this.source.generateArray(ids);
- }
- if (this.stringParams) {
- options.types = this.source.generateArray(types);
- options.contexts = this.source.generateArray(contexts);
- }
-
if (this.options.data) {
options.data = 'data';
}
diff --git a/lib/handlebars/exception.js b/lib/handlebars/exception.js
index 52499c0..af675d9 100644
--- a/lib/handlebars/exception.js
+++ b/lib/handlebars/exception.js
@@ -12,7 +12,7 @@ function Exception(message, node) {
message += ' - ' + line + ':' + column;
}
- let tmp = Error.prototype.constructor.call(this, message);
+ let tmp = Error.prototype.constructor.call(this, message, loc && loc.source, line);
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
for (let idx = 0; idx < errorProps.length; idx++) {
@@ -24,9 +24,20 @@ function Exception(message, node) {
Error.captureStackTrace(this, Exception);
}
- if (loc) {
- this.lineNumber = line;
- this.column = column;
+ try {
+ if (loc) {
+ this.lineNumber = line;
+
+ // Work around issue under safari where we can't directly set the column value
+ /* istanbul ignore next */
+ if (Object.defineProperty) {
+ Object.defineProperty(this, 'column', {value: column});
+ } else {
+ this.column = column;
+ }
+ }
+ } catch (nop) {
+ /* Ignore if the browser is very particular */
}
}
diff --git a/lib/handlebars/helpers/block-helper-missing.js b/lib/handlebars/helpers/block-helper-missing.js
index 6639ddb..e6d162f 100644
--- a/lib/handlebars/helpers/block-helper-missing.js
+++ b/lib/handlebars/helpers/block-helper-missing.js
@@ -1,4 +1,4 @@
-import {appendContextPath, createFrame, isArray} from '../utils';
+import {isArray} from '../utils';
export default function(instance) {
instance.registerHelper('blockHelperMissing', function(context, options) {
@@ -11,21 +11,11 @@ export default function(instance) {
return inverse(this);
} else if (isArray(context)) {
if (context.length > 0) {
- if (options.ids) {
- options.ids = [options.name];
- }
-
return instance.helpers.each(context, options);
} else {
return inverse(this);
}
} else {
- if (options.data && options.ids) {
- let data = createFrame(options.data);
- data.contextPath = appendContextPath(options.data.contextPath, options.name);
- options = {data: data};
- }
-
return fn(context, options);
}
});
diff --git a/lib/handlebars/helpers/each.js b/lib/handlebars/helpers/each.js
index fb11903..914928d 100644
--- a/lib/handlebars/helpers/each.js
+++ b/lib/handlebars/helpers/each.js
@@ -1,4 +1,4 @@
-import {appendContextPath, blockParams, createFrame, isArray, isFunction} from '../utils';
+import {createFrame, isArray, isFunction} from '../utils';
import Exception from '../exception';
export default function(instance) {
@@ -11,12 +11,7 @@ export default function(instance) {
inverse = options.inverse,
i = 0,
ret = '',
- data,
- contextPath;
-
- if (options.data && options.ids) {
- contextPath = appendContextPath(options.data.contextPath, options.ids[0]) + '.';
- }
+ data;
if (isFunction(context)) { context = context.call(this); }
@@ -30,15 +25,11 @@ export default function(instance) {
data.index = index;
data.first = index === 0;
data.last = !!last;
-
- if (contextPath) {
- data.contextPath = contextPath + field;
- }
}
ret = ret + fn(context[field], {
data: data,
- blockParams: blockParams([context[field], field], [contextPath + field, null])
+ blockParams: [context[field], field]
});
}
diff --git a/lib/handlebars/helpers/with.js b/lib/handlebars/helpers/with.js
index 7418cd0..bb352c5 100644
--- a/lib/handlebars/helpers/with.js
+++ b/lib/handlebars/helpers/with.js
@@ -1,4 +1,4 @@
-import {appendContextPath, blockParams, createFrame, isEmpty, isFunction} from '../utils';
+import {isEmpty, isFunction} from '../utils';
export default function(instance) {
instance.registerHelper('with', function(context, options) {
@@ -8,14 +8,10 @@ export default function(instance) {
if (!isEmpty(context)) {
let data = options.data;
- if (options.data && options.ids) {
- data = createFrame(options.data);
- data.contextPath = appendContextPath(options.data.contextPath, options.ids[0]);
- }
return fn(context, {
data: data,
- blockParams: blockParams([context], [data && data.contextPath])
+ blockParams: [context]
});
} else {
return options.inverse(this);
diff --git a/lib/handlebars/no-conflict.js b/lib/handlebars/no-conflict.js
index ad41e96..40a44d7 100644
--- a/lib/handlebars/no-conflict.js
+++ b/lib/handlebars/no-conflict.js
@@ -8,5 +8,6 @@ export default function(Handlebars) {
if (root.Handlebars === Handlebars) {
root.Handlebars = $Handlebars;
}
+ return Handlebars;
};
}
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index b47d961..55eb1c1 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -38,9 +38,6 @@ export function template(templateSpec, env) {
function invokePartialWrapper(partial, context, options) {
if (options.hash) {
context = Utils.extend({}, context, options.hash);
- if (options.ids) {
- options.ids[0] = true;
- }
}
partial = env.VM.resolvePartial.call(this, partial, context, options);
@@ -132,7 +129,7 @@ export function template(templateSpec, env) {
function ret(context, options = {}) {
let data = options.data;
- ret._setup(options);
+ _setup(options);
if (!options.partial && templateSpec.useData) {
data = initData(context, data);
}
@@ -140,7 +137,7 @@ export function template(templateSpec, env) {
blockParams = templateSpec.useBlockParams ? [] : undefined;
if (templateSpec.useDepths) {
if (options.depths) {
- depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
+ depths = context != options.depths[0] ? [context].concat(options.depths) : options.depths;
} else {
depths = [context];
}
@@ -154,7 +151,7 @@ export function template(templateSpec, env) {
}
ret.isTop = true;
- ret._setup = function(options) {
+ function _setup(options) {
if (!options.partial) {
container.helpers = container.merge(options.helpers, env.helpers);
@@ -169,25 +166,15 @@ export function template(templateSpec, env) {
container.partials = options.partials;
container.decorators = options.decorators;
}
- };
-
- ret._child = function(i, data, blockParams, depths) {
- if (templateSpec.useBlockParams && !blockParams) {
- throw new Exception('must pass block params');
- }
- if (templateSpec.useDepths && !depths) {
- throw new Exception('must pass parent depths');
- }
+ }
- return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
- };
return ret;
}
export function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
function prog(context, options = {}) {
let currentDepths = depths;
- if (depths && context !== depths[0]) {
+ if (depths && context != depths[0]) {
currentDepths = [context].concat(depths);
}
@@ -224,9 +211,6 @@ export function resolvePartial(partial, context, options) {
export function invokePartial(partial, context, options) {
options.partial = true;
- if (options.ids) {
- options.data.contextPath = options.ids[0] || options.data.contextPath;
- }
let partialBlock;
if (options.fn && options.fn !== noop) {
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
index 2584601..9d08394 100644
--- a/lib/handlebars/utils.js
+++ b/lib/handlebars/utils.js
@@ -98,11 +98,3 @@ export function createFrame(object) {
return frame;
}
-export function blockParams(params, ids) {
- params.path = ids;
- return params;
-}
-
-export function appendContextPath(contextPath, id) {
- return (contextPath ? contextPath + '.' : '') + id;
-}