more microoptimizations

This commit is contained in:
Sebastian McKenzie
2014-12-15 22:35:58 +11:00
parent 3d975da530
commit 473b6d6a91
4 changed files with 14 additions and 8 deletions

View File

@@ -20,11 +20,12 @@ transform.fromAst = function (ast, code, opts) {
};
transform._ensureTransformerNames = function (type, keys) {
_.each(keys, function (key) {
for (var i in keys) {
var key = keys[i];
if (!_.has(transform.transformers, key)) {
throw new ReferenceError("unknown transformer " + key + " specified in " + type);
}
});
}
};
transform.transformers = {};

View File

@@ -26,7 +26,7 @@ exports.Function = function (node, parent, file, scope) {
var check = function (node, parent) {
if (!t.isIdentifier(node) || !t.isReferenced(node, parent)) return;
if (_.contains(ids, node.name)) {
if (ids.indexOf(node.name) >= 0) {
throw file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
}
@@ -41,7 +41,7 @@ exports.Function = function (node, parent, file, scope) {
// we're accessing a variable that's already defined within this function
var has = scope.get(param.name);
if (has && !_.contains(node.params, has)) {
if (has && node.params.indexOf(has) < 0) {
iife = true;
}
}

View File

@@ -270,9 +270,10 @@ LetScoping.prototype.initialiseLoopLets = function () {
}
if (isLet(node)) {
_.each(node.declarations, function (declar) {
for (var i in node.declarations) {
var declar = node.declarations[i];
declar.init = declar.init || t.identifier("undefined");
});
}
}
});
};

View File

@@ -10,11 +10,13 @@ exports.ImportDeclaration = function (node, parent, file) {
var nodes = [];
if (node.specifiers.length) {
if (!file.moduleFormatter.importSpecifier) return;
for (var i in node.specifiers) {
file.moduleFormatter.importSpecifier(node.specifiers[i], node, nodes, parent);
}
} else {
file.moduleFormatter.import(node, nodes, parent);
if (!file.moduleFormatter.importDeclaration) return;
file.moduleFormatter.importDeclaration(node, nodes, parent);
}
inheritsComments(node, nodes);
@@ -33,8 +35,10 @@ exports.ExportDeclaration = function (node, parent, file) {
declar.init = declar.init || t.identifier("undefined");
}
file.moduleFormatter.export(node, nodes, parent);
if (!file.moduleFormatter.exportDeclaration) return;
file.moduleFormatter.exportDeclaration(node, nodes, parent);
} else {
if (!file.moduleFormatter.exportSpecifier) return;
for (var i in node.specifiers) {
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
}