summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/code-gen.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-04-20 02:38:28 -0500
committerkpdecker <kpdecker@gmail.com>2015-04-20 02:38:28 -0500
commit4bed826d0e210c336fb9e500835b1c1926562da5 (patch)
treeafd32d4dc7b4c2fcf6c38d0355def38ddaffdcc0 /lib/handlebars/compiler/code-gen.js
parent0263aa48bc8c8cdcd332edd01a644a9a0fd1cc81 (diff)
downloadhandlebars.js-4bed826d0e210c336fb9e500835b1c1926562da5.zip
handlebars.js-4bed826d0e210c336fb9e500835b1c1926562da5.tar.gz
handlebars.js-4bed826d0e210c336fb9e500835b1c1926562da5.tar.bz2
Update for let and optional parameters
Diffstat (limited to 'lib/handlebars/compiler/code-gen.js')
-rw-r--r--lib/handlebars/compiler/code-gen.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js
index 0c40e00..bc7bc07 100644
--- a/lib/handlebars/compiler/code-gen.js
+++ b/lib/handlebars/compiler/code-gen.js
@@ -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(']');