Update for let and optional parameters
This commit is contained in:
+4
-4
@@ -7,9 +7,9 @@ import { Compiler, compile, precompile } from './handlebars/compiler/compiler';
|
||||
import JavaScriptCompiler from './handlebars/compiler/javascript-compiler';
|
||||
import Visitor from './handlebars/compiler/visitor';
|
||||
|
||||
var _create = Handlebars.create;
|
||||
let _create = Handlebars.create;
|
||||
function create() {
|
||||
var hb = _create();
|
||||
let hb = _create();
|
||||
|
||||
hb.compile = function(input, options) {
|
||||
return compile(input, options, hb);
|
||||
@@ -27,14 +27,14 @@ function create() {
|
||||
return hb;
|
||||
}
|
||||
|
||||
var inst = create();
|
||||
let inst = create();
|
||||
inst.create = create;
|
||||
|
||||
inst.Visitor = Visitor;
|
||||
|
||||
/*jshint -W040 */
|
||||
/* istanbul ignore next */
|
||||
var $Handlebars = global.Handlebars;
|
||||
let $Handlebars = global.Handlebars;
|
||||
/* istanbul ignore next */
|
||||
inst.noConflict = function() {
|
||||
if (global.Handlebars === inst) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as runtime from './handlebars/runtime';
|
||||
|
||||
// For compatibility and usage outside of module systems, make the Handlebars object a namespace
|
||||
function create() {
|
||||
var hb = new base.HandlebarsEnvironment();
|
||||
let hb = new base.HandlebarsEnvironment();
|
||||
|
||||
Utils.extend(hb, base);
|
||||
hb.SafeString = SafeString;
|
||||
@@ -26,12 +26,12 @@ function create() {
|
||||
return hb;
|
||||
}
|
||||
|
||||
var Handlebars = create();
|
||||
let Handlebars = create();
|
||||
Handlebars.create = create;
|
||||
|
||||
/*jshint -W040 */
|
||||
/* istanbul ignore next */
|
||||
var root = typeof global !== 'undefined' ? global : window,
|
||||
let root = typeof global !== 'undefined' ? global : window,
|
||||
$Handlebars = root.Handlebars;
|
||||
/* istanbul ignore next */
|
||||
Handlebars.noConflict = function() {
|
||||
|
||||
+25
-22
@@ -1,10 +1,10 @@
|
||||
import * as Utils from './utils';
|
||||
import Exception from './exception';
|
||||
|
||||
export var VERSION = '3.0.1';
|
||||
export var COMPILER_REVISION = 6;
|
||||
export const VERSION = '3.0.1';
|
||||
export const COMPILER_REVISION = 6;
|
||||
|
||||
export var REVISION_CHANGES = {
|
||||
export const REVISION_CHANGES = {
|
||||
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
|
||||
2: '== 1.0.0-rc.3',
|
||||
3: '== 1.0.0-rc.4',
|
||||
@@ -13,10 +13,10 @@ export var REVISION_CHANGES = {
|
||||
6: '>= 2.0.0-beta.1'
|
||||
};
|
||||
|
||||
var isArray = Utils.isArray,
|
||||
isFunction = Utils.isFunction,
|
||||
toString = Utils.toString,
|
||||
objectType = '[object Object]';
|
||||
const isArray = Utils.isArray,
|
||||
isFunction = Utils.isFunction,
|
||||
toString = Utils.toString,
|
||||
objectType = '[object Object]';
|
||||
|
||||
export function HandlebarsEnvironment(helpers, partials) {
|
||||
this.helpers = helpers || {};
|
||||
@@ -70,7 +70,7 @@ function registerDefaultHelpers(instance) {
|
||||
});
|
||||
|
||||
instance.registerHelper('blockHelperMissing', function(context, options) {
|
||||
var inverse = options.inverse,
|
||||
let inverse = options.inverse,
|
||||
fn = options.fn;
|
||||
|
||||
if (context === true) {
|
||||
@@ -89,7 +89,7 @@ function registerDefaultHelpers(instance) {
|
||||
}
|
||||
} else {
|
||||
if (options.data && options.ids) {
|
||||
var data = createFrame(options.data);
|
||||
let data = createFrame(options.data);
|
||||
data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name);
|
||||
options = {data: data};
|
||||
}
|
||||
@@ -103,10 +103,13 @@ function registerDefaultHelpers(instance) {
|
||||
throw new Exception('Must pass iterator to #each');
|
||||
}
|
||||
|
||||
var fn = options.fn, inverse = options.inverse;
|
||||
var i = 0, ret = '', data;
|
||||
let fn = options.fn,
|
||||
inverse = options.inverse,
|
||||
i = 0,
|
||||
ret = '',
|
||||
data,
|
||||
contextPath;
|
||||
|
||||
var contextPath;
|
||||
if (options.data && options.ids) {
|
||||
contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
|
||||
}
|
||||
@@ -137,13 +140,13 @@ function registerDefaultHelpers(instance) {
|
||||
|
||||
if (context && typeof context === 'object') {
|
||||
if (isArray(context)) {
|
||||
for (var j = context.length; i < j; i++) {
|
||||
for (let j = context.length; i < j; i++) {
|
||||
execIteration(i, i, i === context.length - 1);
|
||||
}
|
||||
} else {
|
||||
var priorKey;
|
||||
let priorKey;
|
||||
|
||||
for (var key in context) {
|
||||
for (let key in context) {
|
||||
if (context.hasOwnProperty(key)) {
|
||||
// We're running the iterations one step out of sync so we can detect
|
||||
// the last iteration without have to scan the object twice and create
|
||||
@@ -188,11 +191,11 @@ function registerDefaultHelpers(instance) {
|
||||
instance.registerHelper('with', function(context, options) {
|
||||
if (isFunction(context)) { context = context.call(this); }
|
||||
|
||||
var fn = options.fn;
|
||||
let fn = options.fn;
|
||||
|
||||
if (!Utils.isEmpty(context)) {
|
||||
if (options.data && options.ids) {
|
||||
var data = createFrame(options.data);
|
||||
let data = createFrame(options.data);
|
||||
data.contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]);
|
||||
options = {data: data};
|
||||
}
|
||||
@@ -204,7 +207,7 @@ function registerDefaultHelpers(instance) {
|
||||
});
|
||||
|
||||
instance.registerHelper('log', function(message, options) {
|
||||
var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
|
||||
let level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
|
||||
instance.log(level, message);
|
||||
});
|
||||
|
||||
@@ -213,7 +216,7 @@ function registerDefaultHelpers(instance) {
|
||||
});
|
||||
}
|
||||
|
||||
export var logger = {
|
||||
export let logger = {
|
||||
methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
|
||||
|
||||
// State enum
|
||||
@@ -226,16 +229,16 @@ export var logger = {
|
||||
// Can be overridden in the host environment
|
||||
log: function(level, message) {
|
||||
if (typeof console !== 'undefined' && logger.level <= level) {
|
||||
var method = logger.methodMap[level];
|
||||
let method = logger.methodMap[level];
|
||||
(console[method] || console.log).call(console, message); // eslint-disable-line no-console
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export var log = logger.log;
|
||||
export let log = logger.log;
|
||||
|
||||
export function createFrame(object) {
|
||||
var frame = Utils.extend({}, object);
|
||||
let frame = Utils.extend({}, object);
|
||||
frame._parent = object;
|
||||
return frame;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var AST = {
|
||||
let AST = {
|
||||
Program: function(statements, blockParams, strip, locInfo) {
|
||||
this.loc = locInfo;
|
||||
this.type = 'Program';
|
||||
|
||||
@@ -6,7 +6,7 @@ import { extend } from '../utils';
|
||||
|
||||
export { parser };
|
||||
|
||||
var yy = {};
|
||||
let yy = {};
|
||||
extend(yy, Helpers, AST);
|
||||
|
||||
export function parse(input, options) {
|
||||
@@ -20,6 +20,6 @@ export function parse(input, options) {
|
||||
return new yy.SourceLocation(options && options.srcName, locInfo);
|
||||
};
|
||||
|
||||
var strip = new WhitespaceControl();
|
||||
let strip = new WhitespaceControl();
|
||||
return strip.accept(parser.parse(input));
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/*global define */
|
||||
import {isArray} from '../utils';
|
||||
|
||||
var SourceNode;
|
||||
let SourceNode;
|
||||
|
||||
try {
|
||||
/* istanbul ignore next */
|
||||
if (typeof define !== 'function' || !define.amd) {
|
||||
// We don't support this in AMD environments. For these environments, we asusme that
|
||||
// they are running on the browser and thus have no need for the source-map library.
|
||||
var SourceMap = require('source-map');
|
||||
let SourceMap = require('source-map');
|
||||
SourceNode = SourceMap.SourceNode;
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -49,9 +49,9 @@ if (!SourceNode) {
|
||||
|
||||
function castChunk(chunk, codeGen, loc) {
|
||||
if (isArray(chunk)) {
|
||||
var ret = [];
|
||||
let ret = [];
|
||||
|
||||
for (var i = 0, len = chunk.length; i < len; i++) {
|
||||
for (let i = 0, len = chunk.length; i < len; i++) {
|
||||
ret.push(codeGen.wrap(chunk[i], loc));
|
||||
}
|
||||
return ret;
|
||||
@@ -77,7 +77,7 @@ CodeGen.prototype = {
|
||||
},
|
||||
|
||||
merge: function() {
|
||||
var source = this.empty();
|
||||
let source = this.empty();
|
||||
this.each(function(line) {
|
||||
source.add([' ', line, '\n']);
|
||||
});
|
||||
@@ -85,21 +85,19 @@ CodeGen.prototype = {
|
||||
},
|
||||
|
||||
each: function(iter) {
|
||||
for (var i = 0, len = this.source.length; i < len; i++) {
|
||||
for (let i = 0, len = this.source.length; i < len; i++) {
|
||||
iter(this.source[i]);
|
||||
}
|
||||
},
|
||||
|
||||
empty: function(loc) {
|
||||
loc = loc || this.currentLocation || {start: {}};
|
||||
empty: function(loc = this.currentLocation || {start: {}}) {
|
||||
return new SourceNode(loc.start.line, loc.start.column, this.srcFile);
|
||||
},
|
||||
wrap: function(chunk, loc) {
|
||||
wrap: function(chunk, loc = this.currentLocation || {start: {}}) {
|
||||
if (chunk instanceof SourceNode) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
loc = loc || this.currentLocation || {start: {}};
|
||||
chunk = castChunk(chunk, this, loc);
|
||||
|
||||
return new SourceNode(loc.start.line, loc.start.column, this.srcFile, chunk);
|
||||
@@ -121,18 +119,18 @@ CodeGen.prototype = {
|
||||
},
|
||||
|
||||
objectLiteral: function(obj) {
|
||||
var pairs = [];
|
||||
let pairs = [];
|
||||
|
||||
for (var key in obj) {
|
||||
for (let key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
var value = castChunk(obj[key], this);
|
||||
let value = castChunk(obj[key], this);
|
||||
if (value !== 'undefined') {
|
||||
pairs.push([this.quotedString(key), ':', value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ret = this.generateList(pairs);
|
||||
let ret = this.generateList(pairs);
|
||||
ret.prepend('{');
|
||||
ret.add('}');
|
||||
return ret;
|
||||
@@ -140,9 +138,9 @@ CodeGen.prototype = {
|
||||
|
||||
|
||||
generateList: function(entries, loc) {
|
||||
var ret = this.empty(loc);
|
||||
let ret = this.empty(loc);
|
||||
|
||||
for (var i = 0, len = entries.length; i < len; i++) {
|
||||
for (let i = 0, len = entries.length; i < len; i++) {
|
||||
if (i) {
|
||||
ret.add(',');
|
||||
}
|
||||
@@ -154,7 +152,7 @@ CodeGen.prototype = {
|
||||
},
|
||||
|
||||
generateArray: function(entries, loc) {
|
||||
var ret = this.generateList(entries, loc);
|
||||
let ret = this.generateList(entries, loc);
|
||||
ret.prepend('[');
|
||||
ret.add(']');
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ import Exception from '../exception';
|
||||
import {isArray, indexOf} from '../utils';
|
||||
import AST from './ast';
|
||||
|
||||
var slice = [].slice;
|
||||
|
||||
const slice = [].slice;
|
||||
|
||||
export function Compiler() {}
|
||||
|
||||
@@ -16,13 +15,13 @@ Compiler.prototype = {
|
||||
compiler: Compiler,
|
||||
|
||||
equals: function(other) {
|
||||
var len = this.opcodes.length;
|
||||
let len = this.opcodes.length;
|
||||
if (other.opcodes.length !== len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var opcode = this.opcodes[i],
|
||||
for (let i = 0; i < len; i++) {
|
||||
let opcode = this.opcodes[i],
|
||||
otherOpcode = other.opcodes[i];
|
||||
if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) {
|
||||
return false;
|
||||
@@ -32,7 +31,7 @@ Compiler.prototype = {
|
||||
// We know that length is the same between the two arrays because they are directly tied
|
||||
// to the opcode behavior above.
|
||||
len = this.children.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (!this.children[i].equals(other.children[i])) {
|
||||
return false;
|
||||
}
|
||||
@@ -54,7 +53,7 @@ Compiler.prototype = {
|
||||
options.blockParams = options.blockParams || [];
|
||||
|
||||
// These changes will propagate to the other compiler components
|
||||
var knownHelpers = options.knownHelpers;
|
||||
let knownHelpers = options.knownHelpers;
|
||||
options.knownHelpers = {
|
||||
'helperMissing': true,
|
||||
'blockHelperMissing': true,
|
||||
@@ -66,7 +65,7 @@ Compiler.prototype = {
|
||||
'lookup': true
|
||||
};
|
||||
if (knownHelpers) {
|
||||
for (var name in knownHelpers) {
|
||||
for (let name in knownHelpers) {
|
||||
if (name in knownHelpers) {
|
||||
options.knownHelpers[name] = knownHelpers[name];
|
||||
}
|
||||
@@ -77,8 +76,9 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
compileProgram: function(program) {
|
||||
var result = new this.compiler().compile(program, this.options); // eslint-disable-line new-cap
|
||||
var guid = this.guid++;
|
||||
let childCompiler = new this.compiler(), // eslint-disable-line new-cap
|
||||
result = childCompiler.compile(program, this.options),
|
||||
guid = this.guid++;
|
||||
|
||||
this.usePartial = this.usePartial || result.usePartial;
|
||||
|
||||
@@ -90,7 +90,7 @@ Compiler.prototype = {
|
||||
|
||||
accept: function(node) {
|
||||
this.sourceNode.unshift(node);
|
||||
var ret = this[node.type](node);
|
||||
let ret = this[node.type](node);
|
||||
this.sourceNode.shift();
|
||||
return ret;
|
||||
},
|
||||
@@ -98,14 +98,15 @@ Compiler.prototype = {
|
||||
Program: function(program) {
|
||||
this.options.blockParams.unshift(program.blockParams);
|
||||
|
||||
var body = program.body;
|
||||
for (var i = 0, l = body.length; i < l; i++) {
|
||||
let body = program.body,
|
||||
bodyLength = body.length;
|
||||
for (let i = 0; i < bodyLength; i++) {
|
||||
this.accept(body[i]);
|
||||
}
|
||||
|
||||
this.options.blockParams.shift();
|
||||
|
||||
this.isSimple = l === 1;
|
||||
this.isSimple = bodyLength === 1;
|
||||
this.blockParams = program.blockParams ? program.blockParams.length : 0;
|
||||
|
||||
return this;
|
||||
@@ -114,13 +115,13 @@ Compiler.prototype = {
|
||||
BlockStatement: function(block) {
|
||||
transformLiteralToPath(block);
|
||||
|
||||
var program = block.program,
|
||||
let program = block.program,
|
||||
inverse = block.inverse;
|
||||
|
||||
program = program && this.compileProgram(program);
|
||||
inverse = inverse && this.compileProgram(inverse);
|
||||
|
||||
var type = this.classifySexpr(block);
|
||||
let type = this.classifySexpr(block);
|
||||
|
||||
if (type === 'helper') {
|
||||
this.helperSexpr(block, program, inverse);
|
||||
@@ -150,14 +151,14 @@ Compiler.prototype = {
|
||||
PartialStatement: function(partial) {
|
||||
this.usePartial = true;
|
||||
|
||||
var params = partial.params;
|
||||
let params = partial.params;
|
||||
if (params.length > 1) {
|
||||
throw new Exception('Unsupported number of partial arguments: ' + params.length, partial);
|
||||
} else if (!params.length) {
|
||||
params.push({type: 'PathExpression', parts: [], depth: 0});
|
||||
}
|
||||
|
||||
var partialName = partial.name.original,
|
||||
let partialName = partial.name.original,
|
||||
isDynamic = partial.name.type === 'SubExpression';
|
||||
if (isDynamic) {
|
||||
this.accept(partial.name);
|
||||
@@ -165,7 +166,7 @@ Compiler.prototype = {
|
||||
|
||||
this.setupFullMustacheParams(partial, undefined, undefined, true);
|
||||
|
||||
var indent = partial.indent || '';
|
||||
let indent = partial.indent || '';
|
||||
if (this.options.preventIndent && indent) {
|
||||
this.opcode('appendContent', indent);
|
||||
indent = '';
|
||||
@@ -195,7 +196,7 @@ Compiler.prototype = {
|
||||
|
||||
SubExpression: function(sexpr) {
|
||||
transformLiteralToPath(sexpr);
|
||||
var type = this.classifySexpr(sexpr);
|
||||
let type = this.classifySexpr(sexpr);
|
||||
|
||||
if (type === 'simple') {
|
||||
this.simpleSexpr(sexpr);
|
||||
@@ -206,7 +207,7 @@ Compiler.prototype = {
|
||||
}
|
||||
},
|
||||
ambiguousSexpr: function(sexpr, program, inverse) {
|
||||
var path = sexpr.path,
|
||||
let path = sexpr.path,
|
||||
name = path.parts[0],
|
||||
isBlock = program != null || inverse != null;
|
||||
|
||||
@@ -226,7 +227,7 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
helperSexpr: function(sexpr, program, inverse) {
|
||||
var params = this.setupFullMustacheParams(sexpr, program, inverse),
|
||||
let params = this.setupFullMustacheParams(sexpr, program, inverse),
|
||||
path = sexpr.path,
|
||||
name = path.parts[0];
|
||||
|
||||
@@ -246,7 +247,7 @@ Compiler.prototype = {
|
||||
this.addDepth(path.depth);
|
||||
this.opcode('getContext', path.depth);
|
||||
|
||||
var name = path.parts[0],
|
||||
let name = path.parts[0],
|
||||
scoped = AST.helpers.scopedId(path),
|
||||
blockParamId = !path.depth && !scoped && this.blockParamIndex(name);
|
||||
|
||||
@@ -284,11 +285,13 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
Hash: function(hash) {
|
||||
var pairs = hash.pairs, i, l;
|
||||
let pairs = hash.pairs,
|
||||
i = 0,
|
||||
l = pairs.length;
|
||||
|
||||
this.opcode('pushHash');
|
||||
|
||||
for (i = 0, l = pairs.length; i < l; i++) {
|
||||
for (; i < l; i++) {
|
||||
this.pushParam(pairs[i].value);
|
||||
}
|
||||
while (i--) {
|
||||
@@ -311,25 +314,24 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
classifySexpr: function(sexpr) {
|
||||
var isSimple = AST.helpers.simpleId(sexpr.path);
|
||||
let isSimple = AST.helpers.simpleId(sexpr.path);
|
||||
|
||||
var isBlockParam = isSimple && !!this.blockParamIndex(sexpr.path.parts[0]);
|
||||
let isBlockParam = isSimple && !!this.blockParamIndex(sexpr.path.parts[0]);
|
||||
|
||||
// a mustache is an eligible helper if:
|
||||
// * its id is simple (a single part, not `this` or `..`)
|
||||
var isHelper = !isBlockParam && AST.helpers.helperExpression(sexpr);
|
||||
let isHelper = !isBlockParam && AST.helpers.helperExpression(sexpr);
|
||||
|
||||
// if a mustache is an eligible helper but not a definite
|
||||
// helper, it is ambiguous, and will be resolved in a later
|
||||
// pass or at runtime.
|
||||
var isEligible = !isBlockParam && (isHelper || isSimple);
|
||||
|
||||
var options = this.options;
|
||||
let isEligible = !isBlockParam && (isHelper || isSimple);
|
||||
|
||||
// if ambiguous, we can possibly resolve the ambiguity now
|
||||
// An eligible helper is one that does not have a complex path, i.e. `this.foo`, `../foo` etc.
|
||||
if (isEligible && !isHelper) {
|
||||
var name = sexpr.path.parts[0];
|
||||
let name = sexpr.path.parts[0],
|
||||
options = this.options;
|
||||
|
||||
if (options.knownHelpers[name]) {
|
||||
isHelper = true;
|
||||
@@ -348,13 +350,13 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
pushParams: function(params) {
|
||||
for (var i = 0, l = params.length; i < l; i++) {
|
||||
for (let i = 0, l = params.length; i < l; i++) {
|
||||
this.pushParam(params[i]);
|
||||
}
|
||||
},
|
||||
|
||||
pushParam: function(val) {
|
||||
var value = val.value != null ? val.value : val.original || '';
|
||||
let value = val.value != null ? val.value : val.original || '';
|
||||
|
||||
if (this.stringParams) {
|
||||
if (value.replace) {
|
||||
@@ -376,12 +378,12 @@ Compiler.prototype = {
|
||||
}
|
||||
} else {
|
||||
if (this.trackIds) {
|
||||
var blockParamIndex;
|
||||
let blockParamIndex;
|
||||
if (val.parts && !AST.helpers.scopedId(val) && !val.depth) {
|
||||
blockParamIndex = this.blockParamIndex(val.parts[0]);
|
||||
}
|
||||
if (blockParamIndex) {
|
||||
var blockParamChild = val.parts.slice(1).join('.');
|
||||
let blockParamChild = val.parts.slice(1).join('.');
|
||||
this.opcode('pushId', 'BlockParam', blockParamIndex, blockParamChild);
|
||||
} else {
|
||||
value = val.original || value;
|
||||
@@ -399,7 +401,7 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
setupFullMustacheParams: function(sexpr, program, inverse, omitEmpty) {
|
||||
var params = sexpr.params;
|
||||
let params = sexpr.params;
|
||||
this.pushParams(params);
|
||||
|
||||
this.opcode('pushProgram', program);
|
||||
@@ -415,8 +417,8 @@ Compiler.prototype = {
|
||||
},
|
||||
|
||||
blockParamIndex: function(name) {
|
||||
for (var depth = 0, len = this.options.blockParams.length; depth < len; depth++) {
|
||||
var blockParams = this.options.blockParams[depth],
|
||||
for (let depth = 0, len = this.options.blockParams.length; depth < len; depth++) {
|
||||
let blockParams = this.options.blockParams[depth],
|
||||
param = blockParams && indexOf(blockParams, name);
|
||||
if (blockParams && param >= 0) {
|
||||
return [depth, param];
|
||||
@@ -438,18 +440,16 @@ export function precompile(input, options, env) {
|
||||
options.useDepths = true;
|
||||
}
|
||||
|
||||
var ast = env.parse(input, options);
|
||||
var environment = new env.Compiler().compile(ast, options);
|
||||
let ast = env.parse(input, options),
|
||||
environment = new env.Compiler().compile(ast, options);
|
||||
return new env.JavaScriptCompiler().compile(environment, options);
|
||||
}
|
||||
|
||||
export function compile(input, options, env) {
|
||||
export function compile(input, options = {}, env) {
|
||||
if (input == null || (typeof input !== 'string' && input.type !== 'Program')) {
|
||||
throw new Exception('You must pass a string or Handlebars AST to Handlebars.compile. You passed ' + input);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
if (!('data' in options)) {
|
||||
options.data = true;
|
||||
}
|
||||
@@ -457,12 +457,12 @@ export function compile(input, options, env) {
|
||||
options.useDepths = true;
|
||||
}
|
||||
|
||||
var compiled;
|
||||
let compiled;
|
||||
|
||||
function compileInput() {
|
||||
var ast = env.parse(input, options);
|
||||
var environment = new env.Compiler().compile(ast, options);
|
||||
var templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true);
|
||||
let ast = env.parse(input, options),
|
||||
environment = new env.Compiler().compile(ast, options),
|
||||
templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true);
|
||||
return env.template(templateSpec);
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ function argEquals(a, b) {
|
||||
}
|
||||
|
||||
if (isArray(a) && isArray(b) && a.length === b.length) {
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!argEquals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
@@ -505,7 +505,7 @@ function argEquals(a, b) {
|
||||
|
||||
function transformLiteralToPath(sexpr) {
|
||||
if (!sexpr.path.parts) {
|
||||
var literal = sexpr.path;
|
||||
let literal = sexpr.path;
|
||||
// Casting to string here to make false and 0 literal values play nicely with the rest
|
||||
// of the system.
|
||||
sexpr.path = new AST.PathExpression(false, 0, [literal.original + ''], literal.original + '', literal.loc);
|
||||
|
||||
@@ -36,13 +36,13 @@ export function preparePath(data, parts, locInfo) {
|
||||
/*jshint -W040 */
|
||||
locInfo = this.locInfo(locInfo);
|
||||
|
||||
var original = data ? '@' : '',
|
||||
let original = data ? '@' : '',
|
||||
dig = [],
|
||||
depth = 0,
|
||||
depthString = '';
|
||||
|
||||
for (var i = 0, l = parts.length; i < l; i++) {
|
||||
var part = parts[i].part,
|
||||
for (let i = 0, l = parts.length; i < l; i++) {
|
||||
let part = parts[i].part,
|
||||
// If we have [] syntax then we do not treat path references as operators,
|
||||
// i.e. foo.[this] resolves to approximately context.foo['this']
|
||||
isLiteral = parts[i].original !== part;
|
||||
@@ -66,7 +66,7 @@ export function preparePath(data, parts, locInfo) {
|
||||
export function prepareMustache(path, params, hash, open, strip, locInfo) {
|
||||
/*jshint -W040 */
|
||||
// Must use charAt to support IE pre-10
|
||||
var escapeFlag = open.charAt(3) || open.charAt(2),
|
||||
let escapeFlag = open.charAt(3) || open.charAt(2),
|
||||
escaped = escapeFlag !== '{' && escapeFlag !== '&';
|
||||
|
||||
return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));
|
||||
@@ -75,13 +75,13 @@ export function prepareMustache(path, params, hash, open, strip, locInfo) {
|
||||
export function prepareRawBlock(openRawBlock, content, close, locInfo) {
|
||||
/*jshint -W040 */
|
||||
if (openRawBlock.path.original !== close) {
|
||||
var errorNode = {loc: openRawBlock.path.loc};
|
||||
let errorNode = {loc: openRawBlock.path.loc};
|
||||
|
||||
throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode);
|
||||
}
|
||||
|
||||
locInfo = this.locInfo(locInfo);
|
||||
var program = new this.Program([content], null, {}, locInfo);
|
||||
let program = new this.Program([content], null, {}, locInfo);
|
||||
|
||||
return new this.BlockStatement(
|
||||
openRawBlock.path, openRawBlock.params, openRawBlock.hash,
|
||||
@@ -94,14 +94,14 @@ export function prepareBlock(openBlock, program, inverseAndProgram, close, inver
|
||||
/*jshint -W040 */
|
||||
// When we are chaining inverse calls, we will not have a close path
|
||||
if (close && close.path && openBlock.path.original !== close.path.original) {
|
||||
var errorNode = {loc: openBlock.path.loc};
|
||||
let errorNode = {loc: openBlock.path.loc};
|
||||
|
||||
throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode);
|
||||
}
|
||||
|
||||
program.blockParams = openBlock.blockParams;
|
||||
|
||||
var inverse,
|
||||
let inverse,
|
||||
inverseStrip;
|
||||
|
||||
if (inverseAndProgram) {
|
||||
|
||||
@@ -24,8 +24,8 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
compilerInfo: function() {
|
||||
var revision = COMPILER_REVISION,
|
||||
versions = REVISION_CHANGES[revision];
|
||||
const revision = COMPILER_REVISION,
|
||||
versions = REVISION_CHANGES[revision];
|
||||
return [revision, versions];
|
||||
},
|
||||
|
||||
@@ -84,7 +84,7 @@ JavaScriptCompiler.prototype = {
|
||||
this.useDepths = this.useDepths || environment.useDepths || this.options.compat;
|
||||
this.useBlockParams = this.useBlockParams || environment.useBlockParams;
|
||||
|
||||
var opcodes = environment.opcodes,
|
||||
let opcodes = environment.opcodes,
|
||||
opcode,
|
||||
firstLoc,
|
||||
i,
|
||||
@@ -107,13 +107,13 @@ JavaScriptCompiler.prototype = {
|
||||
throw new Exception('Compile completed with content left on stack');
|
||||
}
|
||||
|
||||
var fn = this.createFunctionContext(asObject);
|
||||
let fn = this.createFunctionContext(asObject);
|
||||
if (!this.isChild) {
|
||||
var ret = {
|
||||
let ret = {
|
||||
compiler: this.compilerInfo(),
|
||||
main: fn
|
||||
};
|
||||
var programs = this.context.programs;
|
||||
let programs = this.context.programs;
|
||||
for (i = 0, l = programs.length; i < l; i++) {
|
||||
if (programs[i]) {
|
||||
ret[i] = programs[i];
|
||||
@@ -166,9 +166,9 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
createFunctionContext: function(asObject) {
|
||||
var varDeclarations = '';
|
||||
let varDeclarations = '';
|
||||
|
||||
var locals = this.stackVars.concat(this.registers.list);
|
||||
let locals = this.stackVars.concat(this.registers.list);
|
||||
if (locals.length > 0) {
|
||||
varDeclarations += ', ' + locals.join(', ');
|
||||
}
|
||||
@@ -179,9 +179,9 @@ JavaScriptCompiler.prototype = {
|
||||
// as the source nodes are reused in situ. For the non-source node compilation mode,
|
||||
// aliases will not be used, but this case is already being run on the client and
|
||||
// we aren't concern about minimizing the template size.
|
||||
var aliasCount = 0;
|
||||
for (var alias in this.aliases) { // eslint-disable-line guard-for-in
|
||||
var node = this.aliases[alias];
|
||||
let aliasCount = 0;
|
||||
for (let alias in this.aliases) { // eslint-disable-line guard-for-in
|
||||
let node = this.aliases[alias];
|
||||
|
||||
if (this.aliases.hasOwnProperty(alias) && node.children && node.referenceCount > 1) {
|
||||
varDeclarations += ', alias' + (++aliasCount) + '=' + alias;
|
||||
@@ -189,7 +189,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
var params = ['depth0', 'helpers', 'partials', 'data'];
|
||||
let params = ['depth0', 'helpers', 'partials', 'data'];
|
||||
|
||||
if (this.useBlockParams || this.useDepths) {
|
||||
params.push('blockParams');
|
||||
@@ -199,7 +199,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
|
||||
// Perform a second pass over the output to merge content when possible
|
||||
var source = this.mergeSource(varDeclarations);
|
||||
let source = this.mergeSource(varDeclarations);
|
||||
|
||||
if (asObject) {
|
||||
params.push(source);
|
||||
@@ -210,14 +210,14 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
},
|
||||
mergeSource: function(varDeclarations) {
|
||||
var isSimple = this.environment.isSimple,
|
||||
let isSimple = this.environment.isSimple,
|
||||
appendOnly = !this.forceBuffer,
|
||||
appendFirst,
|
||||
|
||||
sourceSeen,
|
||||
bufferStart,
|
||||
bufferEnd;
|
||||
this.source.each(function(line) {
|
||||
this.source.each((line) => {
|
||||
if (line.appendToBuffer) {
|
||||
if (bufferStart) {
|
||||
line.prepend(' + ');
|
||||
@@ -279,11 +279,11 @@ JavaScriptCompiler.prototype = {
|
||||
// replace it on the stack with the result of properly
|
||||
// invoking blockHelperMissing.
|
||||
blockValue: function(name) {
|
||||
var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
let blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
this.setupHelperArgs(name, 0, params);
|
||||
|
||||
var blockName = this.popStack();
|
||||
let blockName = this.popStack();
|
||||
params.splice(1, 0, blockName);
|
||||
|
||||
this.push(this.source.functionCall(blockHelperMissing, 'call', params));
|
||||
@@ -297,13 +297,13 @@ JavaScriptCompiler.prototype = {
|
||||
// On stack, after, if lastHelper: value
|
||||
ambiguousBlockValue: function() {
|
||||
// We're being a bit cheeky and reusing the options value from the prior exec
|
||||
var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
let blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
this.setupHelperArgs('', 0, params, true);
|
||||
|
||||
this.flushInline();
|
||||
|
||||
var current = this.topStack();
|
||||
let current = this.topStack();
|
||||
params.splice(1, 0, current);
|
||||
|
||||
this.pushSource([
|
||||
@@ -339,13 +339,11 @@ JavaScriptCompiler.prototype = {
|
||||
// Otherwise, the empty string is appended
|
||||
append: function() {
|
||||
if (this.isInline()) {
|
||||
this.replaceStack(function(current) {
|
||||
return [' != null ? ', current, ' : ""'];
|
||||
});
|
||||
this.replaceStack((current) => [' != null ? ', current, ' : ""']);
|
||||
|
||||
this.pushSource(this.appendToBuffer(this.popStack()));
|
||||
} else {
|
||||
var local = this.popStack();
|
||||
let local = this.popStack();
|
||||
this.pushSource(['if (', local, ' != null) { ', this.appendToBuffer(local, undefined, true), ' }']);
|
||||
if (this.environment.isSimple) {
|
||||
this.pushSource(['else { ', this.appendToBuffer("''", undefined, true), ' }']);
|
||||
@@ -393,7 +391,7 @@ JavaScriptCompiler.prototype = {
|
||||
// Looks up the value of `name` on the current context and pushes
|
||||
// it onto the stack.
|
||||
lookupOnContext: function(parts, falsy, scoped) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
|
||||
if (!scoped && this.options.compat && !this.lastContext) {
|
||||
// The depthed query is expected to handle the undefined logic for the root level that
|
||||
@@ -444,11 +442,11 @@ JavaScriptCompiler.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
var len = parts.length;
|
||||
let len = parts.length;
|
||||
for (; i < len; i++) {
|
||||
/*eslint-disable no-loop-func */
|
||||
this.replaceStack(function(current) {
|
||||
var lookup = this.nameLookup(current, parts[i], type);
|
||||
this.replaceStack((current) => {
|
||||
let lookup = this.nameLookup(current, parts[i], type);
|
||||
// We want to ensure that zero and false are handled properly if the context (falsy flag)
|
||||
// needs to have the special handling for these values.
|
||||
if (!falsy) {
|
||||
@@ -513,7 +511,7 @@ JavaScriptCompiler.prototype = {
|
||||
this.hash = {values: [], types: [], contexts: [], ids: []};
|
||||
},
|
||||
popHash: function() {
|
||||
var hash = this.hash;
|
||||
let hash = this.hash;
|
||||
this.hash = this.hashes.pop();
|
||||
|
||||
if (this.trackIds) {
|
||||
@@ -575,11 +573,11 @@ JavaScriptCompiler.prototype = {
|
||||
//
|
||||
// If the helper is not found, `helperMissing` is called.
|
||||
invokeHelper: function(paramSize, name, isSimple) {
|
||||
var nonHelper = this.popStack();
|
||||
var helper = this.setupHelper(paramSize, name);
|
||||
var simple = isSimple ? [helper.name, ' || '] : '';
|
||||
let nonHelper = this.popStack(),
|
||||
helper = this.setupHelper(paramSize, name),
|
||||
simple = isSimple ? [helper.name, ' || '] : '';
|
||||
|
||||
var lookup = ['('].concat(simple, nonHelper);
|
||||
let lookup = ['('].concat(simple, nonHelper);
|
||||
if (!this.options.strict) {
|
||||
lookup.push(' || ', this.aliasable('helpers.helperMissing'));
|
||||
}
|
||||
@@ -596,7 +594,7 @@ JavaScriptCompiler.prototype = {
|
||||
// This operation is used when the helper is known to exist,
|
||||
// so a `helperMissing` fallback is not required.
|
||||
invokeKnownHelper: function(paramSize, name) {
|
||||
var helper = this.setupHelper(paramSize, name);
|
||||
let helper = this.setupHelper(paramSize, name);
|
||||
this.push(this.source.functionCall(helper.name, 'call', helper.callParams));
|
||||
},
|
||||
|
||||
@@ -615,14 +613,14 @@ JavaScriptCompiler.prototype = {
|
||||
invokeAmbiguous: function(name, helperCall) {
|
||||
this.useRegister('helper');
|
||||
|
||||
var nonHelper = this.popStack();
|
||||
let nonHelper = this.popStack();
|
||||
|
||||
this.emptyHash();
|
||||
var helper = this.setupHelper(0, name, helperCall);
|
||||
let helper = this.setupHelper(0, name, helperCall);
|
||||
|
||||
var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
|
||||
let helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
|
||||
|
||||
var lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
|
||||
let lookup = ['(', '(helper = ', helperName, ' || ', nonHelper, ')'];
|
||||
if (!this.options.strict) {
|
||||
lookup[0] = '(helper = ';
|
||||
lookup.push(
|
||||
@@ -647,7 +645,7 @@ JavaScriptCompiler.prototype = {
|
||||
// This operation pops off a context, invokes a partial with that context,
|
||||
// and pushes the result of the invocation back.
|
||||
invokePartial: function(isDynamic, name, indent) {
|
||||
var params = [],
|
||||
let params = [],
|
||||
options = this.setupParams(name, 1, params, false);
|
||||
|
||||
if (isDynamic) {
|
||||
@@ -683,7 +681,7 @@ JavaScriptCompiler.prototype = {
|
||||
//
|
||||
// Pops a value off the stack and assigns it to the current hash
|
||||
assignToHash: function(key) {
|
||||
var value = this.popStack(),
|
||||
let value = this.popStack(),
|
||||
context,
|
||||
type,
|
||||
id;
|
||||
@@ -696,7 +694,7 @@ JavaScriptCompiler.prototype = {
|
||||
context = this.popStack();
|
||||
}
|
||||
|
||||
var hash = this.hash;
|
||||
let hash = this.hash;
|
||||
if (context) {
|
||||
hash.contexts[key] = context;
|
||||
}
|
||||
@@ -728,13 +726,13 @@ JavaScriptCompiler.prototype = {
|
||||
compiler: JavaScriptCompiler,
|
||||
|
||||
compileChildren: function(environment, options) {
|
||||
var children = environment.children, child, compiler;
|
||||
let children = environment.children, child, compiler;
|
||||
|
||||
for (var i = 0, l = children.length; i < l; i++) {
|
||||
for (let i = 0, l = children.length; i < l; i++) {
|
||||
child = children[i];
|
||||
compiler = new this.compiler(); // eslint-disable-line new-cap
|
||||
|
||||
var index = this.matchExistingProgram(child);
|
||||
let index = this.matchExistingProgram(child);
|
||||
|
||||
if (index == null) {
|
||||
this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
|
||||
@@ -756,8 +754,8 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
},
|
||||
matchExistingProgram: function(child) {
|
||||
for (var i = 0, len = this.context.environments.length; i < len; i++) {
|
||||
var environment = this.context.environments[i];
|
||||
for (let i = 0, len = this.context.environments.length; i < len; i++) {
|
||||
let environment = this.context.environments[i];
|
||||
if (environment && environment.equals(child)) {
|
||||
return i;
|
||||
}
|
||||
@@ -765,7 +763,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
programExpression: function(guid) {
|
||||
var child = this.environment.children[guid],
|
||||
let child = this.environment.children[guid],
|
||||
programParams = [child.index, 'data', child.blockParams];
|
||||
|
||||
if (this.useBlockParams || this.useDepths) {
|
||||
@@ -811,7 +809,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
replaceStack: function(callback) {
|
||||
var prefix = ['('],
|
||||
let prefix = ['('],
|
||||
stack,
|
||||
createdStack,
|
||||
usedLiteral;
|
||||
@@ -822,7 +820,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
|
||||
// We want to merge the inline statement into the replacement statement via ','
|
||||
var top = this.popStack(true);
|
||||
let top = this.popStack(true);
|
||||
|
||||
if (top instanceof Literal) {
|
||||
// Literals do not need to be inlined
|
||||
@@ -832,13 +830,13 @@ JavaScriptCompiler.prototype = {
|
||||
} else {
|
||||
// Get or create the current stack name for use by the inline
|
||||
createdStack = true;
|
||||
var name = this.incrStack();
|
||||
let name = this.incrStack();
|
||||
|
||||
prefix = ['((', this.push(name), ' = ', top, ')'];
|
||||
stack = this.topStack();
|
||||
}
|
||||
|
||||
var item = callback.call(this, stack);
|
||||
let item = callback.call(this, stack);
|
||||
|
||||
if (!usedLiteral) {
|
||||
this.popStack();
|
||||
@@ -858,15 +856,15 @@ JavaScriptCompiler.prototype = {
|
||||
return 'stack' + this.stackSlot;
|
||||
},
|
||||
flushInline: function() {
|
||||
var inlineStack = this.inlineStack;
|
||||
let inlineStack = this.inlineStack;
|
||||
this.inlineStack = [];
|
||||
for (var i = 0, len = inlineStack.length; i < len; i++) {
|
||||
var entry = inlineStack[i];
|
||||
for (let i = 0, len = inlineStack.length; i < len; i++) {
|
||||
let entry = inlineStack[i];
|
||||
/* istanbul ignore if */
|
||||
if (entry instanceof Literal) {
|
||||
this.compileStack.push(entry);
|
||||
} else {
|
||||
var stack = this.incrStack();
|
||||
let stack = this.incrStack();
|
||||
this.pushSource([stack, ' = ', entry, ';']);
|
||||
this.compileStack.push(stack);
|
||||
}
|
||||
@@ -877,7 +875,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
popStack: function(wrapped) {
|
||||
var inline = this.isInline(),
|
||||
let inline = this.isInline(),
|
||||
item = (inline ? this.inlineStack : this.compileStack).pop();
|
||||
|
||||
if (!wrapped && (item instanceof Literal)) {
|
||||
@@ -895,7 +893,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
topStack: function() {
|
||||
var stack = (this.isInline() ? this.inlineStack : this.compileStack),
|
||||
let stack = (this.isInline() ? this.inlineStack : this.compileStack),
|
||||
item = stack[stack.length - 1];
|
||||
|
||||
/* istanbul ignore if */
|
||||
@@ -923,7 +921,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
aliasable: function(name) {
|
||||
var ret = this.aliases[name];
|
||||
let ret = this.aliases[name];
|
||||
if (ret) {
|
||||
ret.referenceCount++;
|
||||
return ret;
|
||||
@@ -937,9 +935,9 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
setupHelper: function(paramSize, name, blockHelper) {
|
||||
var params = [],
|
||||
let params = [],
|
||||
paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
|
||||
var foundHelper = this.nameLookup('helpers', name, 'helper');
|
||||
let foundHelper = this.nameLookup('helpers', name, 'helper');
|
||||
|
||||
return {
|
||||
params: params,
|
||||
@@ -950,7 +948,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
setupParams: function(helper, paramSize, params) {
|
||||
var options = {}, contexts = [], types = [], ids = [], param;
|
||||
let options = {}, contexts = [], types = [], ids = [], param;
|
||||
|
||||
options.name = this.quotedString(helper);
|
||||
options.hash = this.popStack();
|
||||
@@ -963,7 +961,7 @@ JavaScriptCompiler.prototype = {
|
||||
options.hashContexts = this.popStack();
|
||||
}
|
||||
|
||||
var inverse = this.popStack(),
|
||||
let inverse = this.popStack(),
|
||||
program = this.popStack();
|
||||
|
||||
// Avoid setting fn and inverse if neither are set. This allows
|
||||
@@ -975,7 +973,7 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
// The parameters go on to the stack in order (making sure that they are evaluated in order)
|
||||
// so we need to pop them off the stack in reverse order
|
||||
var i = paramSize;
|
||||
let i = paramSize;
|
||||
while (i--) {
|
||||
param = this.popStack();
|
||||
params[i] = param;
|
||||
@@ -1007,7 +1005,7 @@ JavaScriptCompiler.prototype = {
|
||||
},
|
||||
|
||||
setupHelperArgs: function(helper, paramSize, params, useRegister) {
|
||||
var options = this.setupParams(helper, paramSize, params, true);
|
||||
let options = this.setupParams(helper, paramSize, params, true);
|
||||
options = this.objectLiteral(options);
|
||||
if (useRegister) {
|
||||
this.useRegister('options');
|
||||
@@ -1022,7 +1020,7 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
|
||||
(function() {
|
||||
var reservedWords = (
|
||||
const reservedWords = (
|
||||
'break else new var' +
|
||||
' case finally return void' +
|
||||
' catch for switch while' +
|
||||
@@ -1041,9 +1039,9 @@ JavaScriptCompiler.prototype = {
|
||||
' null true false'
|
||||
).split(' ');
|
||||
|
||||
var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
|
||||
const compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
|
||||
|
||||
for (var i = 0, l = reservedWords.length; i < l; i++) {
|
||||
for (let i = 0, l = reservedWords.length; i < l; i++) {
|
||||
compilerWords[reservedWords[i]] = true;
|
||||
}
|
||||
}());
|
||||
@@ -1053,9 +1051,8 @@ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
|
||||
};
|
||||
|
||||
function strictLookup(requireTerminal, compiler, parts, type) {
|
||||
var stack = compiler.popStack();
|
||||
|
||||
var i = 0,
|
||||
let stack = compiler.popStack(),
|
||||
i = 0,
|
||||
len = parts.length;
|
||||
if (requireTerminal) {
|
||||
len--;
|
||||
|
||||
@@ -12,9 +12,9 @@ export function PrintVisitor() {
|
||||
PrintVisitor.prototype = new Visitor();
|
||||
|
||||
PrintVisitor.prototype.pad = function(string) {
|
||||
var out = '';
|
||||
let out = '';
|
||||
|
||||
for (var i = 0, l = this.padding; i < l; i++) {
|
||||
for (let i = 0, l = this.padding; i < l; i++) {
|
||||
out = out + ' ';
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ PrintVisitor.prototype.pad = function(string) {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.Program = function(program) {
|
||||
var out = '',
|
||||
let out = '',
|
||||
body = program.body,
|
||||
i, l;
|
||||
|
||||
if (program.blockParams) {
|
||||
var blockParams = 'BLOCK PARAMS: [';
|
||||
let blockParams = 'BLOCK PARAMS: [';
|
||||
for (i = 0, l = program.blockParams.length; i < l; i++) {
|
||||
blockParams += ' ' + program.blockParams[i];
|
||||
}
|
||||
@@ -50,7 +50,7 @@ PrintVisitor.prototype.MustacheStatement = function(mustache) {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.BlockStatement = function(block) {
|
||||
var out = '';
|
||||
let out = '';
|
||||
|
||||
out = out + this.pad('BLOCK:');
|
||||
this.padding++;
|
||||
@@ -75,7 +75,7 @@ PrintVisitor.prototype.BlockStatement = function(block) {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.PartialStatement = function(partial) {
|
||||
var content = 'PARTIAL:' + partial.name.original;
|
||||
let content = 'PARTIAL:' + partial.name.original;
|
||||
if (partial.params[0]) {
|
||||
content += ' ' + this.accept(partial.params[0]);
|
||||
}
|
||||
@@ -94,9 +94,11 @@ PrintVisitor.prototype.CommentStatement = function(comment) {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.SubExpression = function(sexpr) {
|
||||
var params = sexpr.params, paramStrings = [], hash;
|
||||
let params = sexpr.params,
|
||||
paramStrings = [],
|
||||
hash;
|
||||
|
||||
for (var i = 0, l = params.length; i < l; i++) {
|
||||
for (let i = 0, l = params.length; i < l; i++) {
|
||||
paramStrings.push(this.accept(params[i]));
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ PrintVisitor.prototype.SubExpression = function(sexpr) {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.PathExpression = function(id) {
|
||||
var path = id.parts.join('/');
|
||||
let path = id.parts.join('/');
|
||||
return (id.data ? '@' : '') + 'PATH:' + path;
|
||||
};
|
||||
|
||||
@@ -134,10 +136,10 @@ PrintVisitor.prototype.NullLiteral = function() {
|
||||
};
|
||||
|
||||
PrintVisitor.prototype.Hash = function(hash) {
|
||||
var pairs = hash.pairs;
|
||||
var joinedPairs = [];
|
||||
let pairs = hash.pairs,
|
||||
joinedPairs = [];
|
||||
|
||||
for (var i = 0, l = pairs.length; i < l; i++) {
|
||||
for (let i = 0, l = pairs.length; i < l; i++) {
|
||||
joinedPairs.push(this.accept(pairs[i]));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Visitor.prototype = {
|
||||
|
||||
// Visits a given value. If mutating, will replace the value if necessary.
|
||||
acceptKey: function(node, name) {
|
||||
var value = this.accept(node[name]);
|
||||
let value = this.accept(node[name]);
|
||||
if (this.mutating) {
|
||||
// Hacky sanity check:
|
||||
if (value && (!value.type || !AST[value.type])) {
|
||||
@@ -34,7 +34,7 @@ Visitor.prototype = {
|
||||
// Traverses a given array. If mutating, empty respnses will be removed
|
||||
// for child elements.
|
||||
acceptArray: function(array) {
|
||||
for (var i = 0, l = array.length; i < l; i++) {
|
||||
for (let i = 0, l = array.length; i < l; i++) {
|
||||
this.acceptKey(array, i);
|
||||
|
||||
if (!array[i]) {
|
||||
@@ -55,7 +55,7 @@ Visitor.prototype = {
|
||||
}
|
||||
this.current = object;
|
||||
|
||||
var ret = this[object.type](object);
|
||||
let ret = this[object.type](object);
|
||||
|
||||
this.current = this.parents.shift();
|
||||
|
||||
|
||||
@@ -5,19 +5,19 @@ function WhitespaceControl() {
|
||||
WhitespaceControl.prototype = new Visitor();
|
||||
|
||||
WhitespaceControl.prototype.Program = function(program) {
|
||||
var isRoot = !this.isRootSeen;
|
||||
let isRoot = !this.isRootSeen;
|
||||
this.isRootSeen = true;
|
||||
|
||||
var body = program.body;
|
||||
for (var i = 0, l = body.length; i < l; i++) {
|
||||
var current = body[i],
|
||||
let body = program.body;
|
||||
for (let i = 0, l = body.length; i < l; i++) {
|
||||
let current = body[i],
|
||||
strip = this.accept(current);
|
||||
|
||||
if (!strip) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var _isPrevWhitespace = isPrevWhitespace(body, i, isRoot),
|
||||
let _isPrevWhitespace = isPrevWhitespace(body, i, isRoot),
|
||||
_isNextWhitespace = isNextWhitespace(body, i, isRoot),
|
||||
|
||||
openStandalone = strip.openStandalone && _isPrevWhitespace,
|
||||
@@ -63,7 +63,7 @@ WhitespaceControl.prototype.BlockStatement = function(block) {
|
||||
this.accept(block.inverse);
|
||||
|
||||
// Find the inverse program that is involed with whitespace stripping.
|
||||
var program = block.program || block.inverse,
|
||||
let program = block.program || block.inverse,
|
||||
inverse = block.program && block.inverse,
|
||||
firstInverse = inverse,
|
||||
lastInverse = inverse;
|
||||
@@ -77,7 +77,7 @@ WhitespaceControl.prototype.BlockStatement = function(block) {
|
||||
}
|
||||
}
|
||||
|
||||
var strip = {
|
||||
let strip = {
|
||||
open: block.openStrip.open,
|
||||
close: block.closeStrip.close,
|
||||
|
||||
@@ -92,7 +92,7 @@ WhitespaceControl.prototype.BlockStatement = function(block) {
|
||||
}
|
||||
|
||||
if (inverse) {
|
||||
var inverseStrip = block.inverseStrip;
|
||||
let inverseStrip = block.inverseStrip;
|
||||
|
||||
if (inverseStrip.open) {
|
||||
omitLeft(program.body, null, true);
|
||||
@@ -125,7 +125,7 @@ WhitespaceControl.prototype.MustacheStatement = function(mustache) {
|
||||
WhitespaceControl.prototype.PartialStatement =
|
||||
WhitespaceControl.prototype.CommentStatement = function(node) {
|
||||
/* istanbul ignore next */
|
||||
var strip = node.strip || {};
|
||||
let strip = node.strip || {};
|
||||
return {
|
||||
inlineStandalone: true,
|
||||
open: strip.open,
|
||||
@@ -141,7 +141,7 @@ function isPrevWhitespace(body, i, isRoot) {
|
||||
|
||||
// Nodes that end with newlines are considered whitespace (but are special
|
||||
// cased for strip operations)
|
||||
var prev = body[i - 1],
|
||||
let prev = body[i - 1],
|
||||
sibling = body[i - 2];
|
||||
if (!prev) {
|
||||
return isRoot;
|
||||
@@ -156,7 +156,7 @@ function isNextWhitespace(body, i, isRoot) {
|
||||
i = -1;
|
||||
}
|
||||
|
||||
var next = body[i + 1],
|
||||
let next = body[i + 1],
|
||||
sibling = body[i + 2];
|
||||
if (!next) {
|
||||
return isRoot;
|
||||
@@ -175,12 +175,12 @@ function isNextWhitespace(body, i, isRoot) {
|
||||
// If mulitple is truthy then all whitespace will be stripped out until non-whitespace
|
||||
// content is met.
|
||||
function omitRight(body, i, multiple) {
|
||||
var current = body[i == null ? 0 : i + 1];
|
||||
let current = body[i == null ? 0 : i + 1];
|
||||
if (!current || current.type !== 'ContentStatement' || (!multiple && current.rightStripped)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var original = current.value;
|
||||
let original = current.value;
|
||||
current.value = current.value.replace(multiple ? (/^\s+/) : (/^[ \t]*\r?\n?/), '');
|
||||
current.rightStripped = current.value !== original;
|
||||
}
|
||||
@@ -193,13 +193,13 @@ function omitRight(body, i, multiple) {
|
||||
// If mulitple is truthy then all whitespace will be stripped out until non-whitespace
|
||||
// content is met.
|
||||
function omitLeft(body, i, multiple) {
|
||||
var current = body[i == null ? body.length - 1 : i - 1];
|
||||
let current = body[i == null ? body.length - 1 : i - 1];
|
||||
if (!current || current.type !== 'ContentStatement' || (!multiple && current.leftStripped)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We omit the last node if it's whitespace only and not preceeded by a non-content node.
|
||||
var original = current.value;
|
||||
let original = current.value;
|
||||
current.value = current.value.replace(multiple ? (/\s+$/) : (/[ \t]+$/), '');
|
||||
current.leftStripped = current.value !== original;
|
||||
return current.leftStripped;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
||||
const errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
||||
|
||||
function Exception(message, node) {
|
||||
var loc = node && node.loc,
|
||||
let loc = node && node.loc,
|
||||
line,
|
||||
column;
|
||||
if (loc) {
|
||||
@@ -12,10 +12,10 @@ function Exception(message, node) {
|
||||
message += ' - ' + line + ':' + column;
|
||||
}
|
||||
|
||||
var tmp = Error.prototype.constructor.call(this, message);
|
||||
let tmp = Error.prototype.constructor.call(this, message);
|
||||
|
||||
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
||||
for (var idx = 0; idx < errorProps.length; idx++) {
|
||||
for (let idx = 0; idx < errorProps.length; idx++) {
|
||||
this[errorProps[idx]] = tmp[errorProps[idx]];
|
||||
}
|
||||
|
||||
|
||||
+16
-19
@@ -3,13 +3,13 @@ import Exception from './exception';
|
||||
import { COMPILER_REVISION, REVISION_CHANGES, createFrame } from './base';
|
||||
|
||||
export function checkRevision(compilerInfo) {
|
||||
var compilerRevision = compilerInfo && compilerInfo[0] || 1,
|
||||
currentRevision = COMPILER_REVISION;
|
||||
const compilerRevision = compilerInfo && compilerInfo[0] || 1,
|
||||
currentRevision = COMPILER_REVISION;
|
||||
|
||||
if (compilerRevision !== currentRevision) {
|
||||
if (compilerRevision < currentRevision) {
|
||||
var runtimeVersions = REVISION_CHANGES[currentRevision],
|
||||
compilerVersions = REVISION_CHANGES[compilerRevision];
|
||||
const runtimeVersions = REVISION_CHANGES[currentRevision],
|
||||
compilerVersions = REVISION_CHANGES[compilerRevision];
|
||||
throw new Exception('Template was precompiled with an older version of Handlebars than the current runtime. ' +
|
||||
'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
|
||||
} else {
|
||||
@@ -41,7 +41,7 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
|
||||
partial = env.VM.resolvePartial.call(this, partial, context, options);
|
||||
var result = env.VM.invokePartial.call(this, partial, context, options);
|
||||
let result = env.VM.invokePartial.call(this, partial, context, options);
|
||||
|
||||
if (result == null && env.compile) {
|
||||
options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
|
||||
@@ -49,8 +49,8 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
if (result != null) {
|
||||
if (options.indent) {
|
||||
var lines = result.split('\n');
|
||||
for (var i = 0, l = lines.length; i < l; i++) {
|
||||
let lines = result.split('\n');
|
||||
for (let i = 0, l = lines.length; i < l; i++) {
|
||||
if (!lines[i] && i + 1 === l) {
|
||||
break;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
|
||||
// Just add water
|
||||
var container = {
|
||||
let container = {
|
||||
strict: function(obj, name) {
|
||||
if (!(name in obj)) {
|
||||
throw new Exception('"' + name + '" not defined in ' + obj);
|
||||
@@ -74,8 +74,8 @@ export function template(templateSpec, env) {
|
||||
return obj[name];
|
||||
},
|
||||
lookup: function(depths, name) {
|
||||
var len = depths.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
const len = depths.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (depths[i] && depths[i][name] != null) {
|
||||
return depths[i][name];
|
||||
}
|
||||
@@ -94,7 +94,7 @@ export function template(templateSpec, env) {
|
||||
|
||||
programs: [],
|
||||
program: function(i, data, declaredBlockParams, blockParams, depths) {
|
||||
var programWrapper = this.programs[i],
|
||||
let programWrapper = this.programs[i],
|
||||
fn = this.fn(i);
|
||||
if (data || depths || blockParams || declaredBlockParams) {
|
||||
programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
|
||||
@@ -111,7 +111,7 @@ export function template(templateSpec, env) {
|
||||
return value;
|
||||
},
|
||||
merge: function(param, common) {
|
||||
var obj = param || common;
|
||||
let obj = param || common;
|
||||
|
||||
if (param && common && (param !== common)) {
|
||||
obj = Utils.extend({}, common, param);
|
||||
@@ -124,15 +124,14 @@ export function template(templateSpec, env) {
|
||||
compilerInfo: templateSpec.compiler
|
||||
};
|
||||
|
||||
function ret(context, options) {
|
||||
options = options || {};
|
||||
var data = options.data;
|
||||
function ret(context, options = {}) {
|
||||
let data = options.data;
|
||||
|
||||
ret._setup(options);
|
||||
if (!options.partial && templateSpec.useData) {
|
||||
data = initData(context, data);
|
||||
}
|
||||
var depths,
|
||||
let depths,
|
||||
blockParams = templateSpec.useBlockParams ? [] : undefined;
|
||||
if (templateSpec.useDepths) {
|
||||
depths = options.depths ? [context].concat(options.depths) : [context];
|
||||
@@ -169,9 +168,7 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
|
||||
export function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
|
||||
function prog(context, options) {
|
||||
options = options || {};
|
||||
|
||||
function prog(context, options = {}) {
|
||||
return fn.call(container,
|
||||
context,
|
||||
container.helpers, container.partials,
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*jshint -W004 */
|
||||
var escape = {
|
||||
const escape = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
@@ -8,16 +8,16 @@ var escape = {
|
||||
'`': '`'
|
||||
};
|
||||
|
||||
var badChars = /[&<>"'`]/g;
|
||||
var possible = /[&<>"'`]/;
|
||||
const badChars = /[&<>"'`]/g,
|
||||
possible = /[&<>"'`]/;
|
||||
|
||||
function escapeChar(chr) {
|
||||
return escape[chr];
|
||||
}
|
||||
|
||||
export function extend(obj /* , ...source */) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
for (var key in arguments[i]) {
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
for (let key in arguments[i]) {
|
||||
if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
|
||||
obj[key] = arguments[i][key];
|
||||
}
|
||||
@@ -27,11 +27,11 @@ export function extend(obj /* , ...source */) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
export var toString = Object.prototype.toString;
|
||||
export let toString = Object.prototype.toString;
|
||||
|
||||
// Sourced from lodash
|
||||
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
|
||||
/*eslint-disable func-style */
|
||||
/*eslint-disable func-style, no-var */
|
||||
var isFunction = function(value) {
|
||||
return typeof value === 'function';
|
||||
};
|
||||
@@ -43,16 +43,16 @@ if (isFunction(/x/)) {
|
||||
};
|
||||
}
|
||||
export var isFunction;
|
||||
/*eslint-enable func-style */
|
||||
/*eslint-enable func-style, no-var */
|
||||
|
||||
/* istanbul ignore next */
|
||||
export var isArray = Array.isArray || function(value) {
|
||||
export const isArray = Array.isArray || function(value) {
|
||||
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
|
||||
};
|
||||
|
||||
// Older IE versions do not directly support indexOf so we must implement our own, sadly.
|
||||
export function indexOf(array, value) {
|
||||
for (var i = 0, len = array.length; i < len; i++) {
|
||||
for (let i = 0, len = array.length; i < len; i++) {
|
||||
if (array[i] === value) {
|
||||
return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user