Update for let and optional parameters

This commit is contained in:
kpdecker
2015-04-20 02:38:28 -05:00
parent 0263aa48bc
commit 4bed826d0e
15 changed files with 236 additions and 239 deletions
+15 -17
View File
@@ -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(']');