fix linting errors

This commit is contained in:
Sebastian McKenzie
2014-11-04 15:53:11 +11:00
parent 287cbbb6a1
commit d7ae3b506a
18 changed files with 87 additions and 61 deletions

View File

@@ -7,7 +7,7 @@ Error.captureStackTrace = Error.captureStackTrace || function (obj) {
getFileName: function () { return "filename"; },
getLineNumber: function () { return 1; },
getColumnNumber: function () { return 1; },
getFunctionName: function () { return "functionName" }
getFunctionName: function () { return "functionName"; }
};
obj.stack = Error.prepareStackTrace(obj, [frame, frame, frame]);
@@ -32,7 +32,7 @@ transform.eval = function (code, opts) {
transform.run = function (code, opts) {
opts = opts || {};
opts.sourceMap = "inline";
return Function(transform(code, opts).code)();
return new Function(transform(code, opts).code)();
};
transform.load = function (url, callback, opts, hold) {
@@ -43,12 +43,12 @@ transform.load = function (url, callback, opts, hold) {
xhr.open("GET", url, true);
if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain");
xhr.onreadystatechange = function() {
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) return;
var status = xhr.status;
if (status === 0 || status === 200) {
var param = [xhr.responseText, options];
var param = [xhr.responseText, opts];
if (!hold) transform.run.apply(transform, param);
if (callback) callback(param);
} else {
@@ -77,7 +77,7 @@ var runScripts = function () {
var opts = {};
if (script.src) {
transform.load(script.src, function(param) {
transform.load(script.src, function (param) {
scripts[i] = param;
exec();
}, opts, true);
@@ -93,7 +93,7 @@ var runScripts = function () {
if (types.indexOf(_script.type) >= 0) scripts.push(_script);
}
for (var i in scripts) {
for (i in scripts) {
run(scripts[i], i);
}

View File

@@ -82,7 +82,7 @@ File.prototype.addDeclaration = function (name) {
};
File.prototype.errorWithNode = function (node, msg) {
var loc
var loc;
if (node.loc) {
loc = node.loc.start;

View File

@@ -6,13 +6,12 @@ module.exports = function (code, ast, opts) {
module.exports.CodeGenerator = CodeGenerator;
var sourceMap = require("source-map");
var assert = require("assert");
var util = require("./util");
var t = require("./types");
var _ = require("lodash");
function CodeGenerator(code, ast, opts) {
opts = opts || {}
opts = opts || {};
this.tabWidth = 2;
this.code = code;
@@ -205,7 +204,7 @@ CodeGenerator.prototype.printSequence = function (print, nodes, opts) {
return self.hasWhitespaceBetween(startToken, endToken);
};
opts.print = function (node, i) {
opts.print = function (node) {
var needs = function (fn) {
if (!self.opts.whitespace) return;

View File

@@ -1,5 +1,4 @@
var t = require("../types");
var _ = require("lodash");
exports.UnaryExpression = function (node, print) {
this.push(node.operator);
@@ -75,8 +74,8 @@ exports.ExpressionStatement = function (node, print) {
exports.BinaryExpression =
exports.LogicalExpression =
exports.AssignmentExpression = function (node, print, parent) {
print(node.left)
exports.AssignmentExpression = function (node, print) {
print(node.left);
this.push(" " + node.operator + " ");
print(node.right);
};
@@ -86,7 +85,7 @@ exports.MemberExpression = function (node, print) {
if (node.computed) {
this.push("[");
print(node.property)
print(node.property);
this.push("]");
} else {
this.push(".");

View File

@@ -14,7 +14,7 @@ exports.XJSIdentifier = function (node) {
};
exports.XJSNamespacedName = function (node, print) {
print(node.namespace)
print(node.namespace);
this.push(":");
print(node.name);
};
@@ -68,7 +68,7 @@ exports.XJSOpeningElement = function (node, print) {
this.push(" ");
this.printJoin(print, node.attributes, " ");
}
this.push(node.selfClosing ? " />" : ">");;
this.push(node.selfClosing ? " />" : ">");
};
exports.XJSClosingElement = function (node, print) {

View File

@@ -1,5 +1,4 @@
var t = require("../types");
var _ = require("lodash");
exports.WithStatement = function (node, print) {
this.keyword("with");
@@ -127,7 +126,7 @@ exports.CatchClause = function (node, print) {
exports.ThrowStatement = function (node, print) {
this.push("throw ");
print(node.argument)
print(node.argument);
this.semicolon();
};

View File

@@ -5,7 +5,7 @@ exports.TaggedTemplateExpression = function (node, print) {
print(node.quasi);
};
exports.TemplateElement = function (node, print) {
exports.TemplateElement = function (node) {
this.push(node.value.raw, true);
};

View File

@@ -58,7 +58,7 @@ exports.ArrayPattern = function (node, print) {
this.push("[");
_.each(elems, function(elem, i) {
_.each(elems, function (elem, i) {
if (!elem) {
// If the array expression ends with a hole, that hole
// will be ignored by the interpreter, but if it ends with

View File

@@ -1,14 +1,14 @@
module.exports = IgnoreFormatter;
function IgnoreFormatter(file) {
function IgnoreFormatter() {
}
IgnoreFormatter.prototype.import = function (node, nodes) {
IgnoreFormatter.prototype.import = function () {
};
IgnoreFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
IgnoreFormatter.prototype.importSpecifier = function () {
};
@@ -16,6 +16,6 @@ IgnoreFormatter.prototype.export = function (node, nodes) {
nodes.push(node.declaration);
};
IgnoreFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
IgnoreFormatter.prototype.exportSpecifier = function () {
};

View File

@@ -1,11 +1,7 @@
module.exports = transform;
var Transformer = require("./transformer");
var generate = require("./generator");
var assert = require("assert");
var File = require("./file");
var util = require("./util");
var chai = require("chai");
var _ = require("lodash");
function transform(code, opts) {

View File

@@ -32,8 +32,6 @@ Transformer.prototype.transform = function (file) {
transformer.ast.enter(ast, file);
}
var self = this;
var build = function (exit) {
return function (node, parent, opts) {
// add any node type aliases that exist

View File

@@ -40,11 +40,11 @@ var buildClass = function (node, file, scope) {
CLASS_NAME: className
});
var block = container.callee.body;
var body = block.body;
var construct = body[0].declarations[0].init;
var block = container.callee.body;
var body = block.body;
var constructor = body[0].declarations[0].init;
if (node.id) construct.id = className;
if (node.id) constructor.id = className;
var returnStatement = body.pop();
@@ -55,18 +55,32 @@ var buildClass = function (node, file, scope) {
container.callee.params.push(superClassCallee);
}
buildClassBody(file, construct, body, className, superName, node);
buildClassBody({
file: file,
body: body,
node: node,
className: className,
superName: superName,
constructor: constructor,
});
if (body.length === 1) {
// only a constructor so no need for a closure container
return construct;
return constructor;
} else {
body.push(returnStatement);
return container;
}
};
var buildClassBody = function (file, construct, body, className, superName, node) {
var buildClassBody = function (opts) {
var file = opts.file;
var body = opts.body;
var node = opts.node;
var constructor = opts.constructor;
var className = opts.className;
var superName = opts.superName;
var instanceMutatorMap = {};
var staticMutatorMap = {};
var hasConstructor = false;
@@ -82,7 +96,7 @@ var buildClassBody = function (file, construct, body, className, superName, node
if (methodName === "constructor") {
if (node.kind === "") {
hasConstructor = true;
addConstructor(construct, method);
addConstructor(constructor, method);
} else {
throw file.errorWithNode(node, "unknown kind for constructor method");
}
@@ -102,7 +116,7 @@ var buildClassBody = function (file, construct, body, className, superName, node
});
if (!hasConstructor && superName) {
construct.body.body.push(util.template("class-super-constructor-call", {
constructor.body.body.push(util.template("class-super-constructor-call", {
SUPER_NAME: superName
}, true));
}

View File

@@ -1,5 +1,4 @@
var traverse = require("../traverse");
var util = require("../util");
var t = require("../types");
var _ = require("lodash");

View File

@@ -45,9 +45,16 @@ var pushArrayPattern = function (kind, nodes, pattern, parentId) {
});
};
var pushPattern = function (kind, nodes, pattern, parentId, file, scope) {
var pushPattern = function (opts) {
var kind = opts.kind;
var nodes = opts.nodes;
var pattern = opts.pattern;
var parentId = opts.id;
var file = opts.file;
var scope = opts.scope;
if (parentId.type !== "MemberExpression" && parentId.type !== "Identifier") {
var key = t.identifier(file.generateUid("ref"));
var key = t.identifier(file.generateUid("ref", scope));
nodes.push(t.variableDeclaration("var", [
t.variableDeclarator(key, parentId)
@@ -92,7 +99,16 @@ exports.Function = function (node, parent, file, scope) {
hasDestructuring = true;
var parentId = t.identifier(file.generateUid("ref", scope));
pushPattern("var", nodes, pattern, parentId, file, scope);
pushPattern({
kind: "var",
nodes: nodes,
pattern: pattern,
id: parentId,
file: file,
scope: scope
});
return parentId;
});
@@ -140,7 +156,14 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
var patternId = declar.init;
var pattern = declar.id;
if (t.isPattern(pattern) && patternId) {
pushPattern(node.kind, nodes, pattern, patternId, file, scope);
pushPattern({
kind: node.kind,
nodes: nodes,
pattern: pattern,
id: patternId,
file: file,
scope: scope
});
} else {
nodes.push(buildVariableAssign(node.kind, declar.id, declar.init));
}

View File

@@ -1,5 +1,4 @@
var traverse = require("../traverse");
var util = require("../util");
var t = require("../types");
var _ = require("lodash");
@@ -116,7 +115,7 @@ var run = function (forParent, block, parent, file, scope) {
traverse(block, function (node, parent, opts) {
if (t.isFunction(node)) {
traverse(node, function (node, parent, opts2) {
traverse(node, function (node, parent) {
if (!t.isIdentifier(node)) return;
if (!t.isReferenced(node, parent)) return;
if (opts.scope.hasOwn(node.name)) return;
@@ -192,14 +191,13 @@ var run = function (forParent, block, parent, file, scope) {
};
// hoist `var` declarations
traverse(block, function (node, parent) {
traverse(block, function (node) {
if (t.isForStatement(node)) {
if (isVar(node.init)) {
node.init = t.sequenceExpression(pushDeclar(node.init));
}
} else if (t.isFor(node)) {
if (isVar(node.left)) {
body.push()
node.left = node.left.declarations[0].id;
}
} else if (isVar(node)) {

View File

@@ -81,7 +81,7 @@ function traverse(parent, callbacks, opts) {
handle(parent, key);
}
});
};
}
traverse.removeProperties = function (tree) {
var clear = function (node) {

View File

@@ -218,13 +218,13 @@ t.needsParans = function (node, parent) {
var parentPos = PRECEDENCE[parentOp];
var nodeOp = node.operator;
var nodeOp = PRECEDENCE[nodeOp];
var nodePos = PRECEDENCE[nodeOp];
if (parentPos > nodeOp) {
if (parentPos > nodePos) {
return true;
}
if (parentPos === nodeOp && parent.right === node) {
if (parentPos === nodePos && parent.right === node) {
return true;
}
}
@@ -255,13 +255,13 @@ t.needsParans = function (node, parent) {
//
if (t.isYieldExpression(node)) {
return t.isBinary(parent)
|| t.isUnaryLike(parent)
|| t.isCallExpression(parent)
|| t.isMemberExpression(parent)
|| t.isNewExpression(parent)
|| t.isConditionalExpression(parent)
|| t.isYieldExpression(parent);
return t.isBinary(parent) ||
t.isUnaryLike(parent) ||
t.isCallExpression(parent) ||
t.isMemberExpression(parent) ||
t.isNewExpression(parent) ||
t.isConditionalExpression(parent) ||
t.isYieldExpression(parent);
}
if (t.isNewExpression(parent) && parent.callee === node) {
@@ -338,8 +338,8 @@ _.each([
[">>", "<<", ">>>"],
["+", "-"],
["*", "/", "%"]
], function(tier, i) {
_.each(tier, function(op) {
], function (tier, i) {
_.each(tier, function (op) {
PRECEDENCE[op] = i;
});
});