more microoptimizations
This commit is contained in:
@@ -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 = {};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user