This commit is contained in:
Sebastian McKenzie
2015-01-22 19:23:56 +11:00
parent 8678917e2a
commit 8f68f62f8a
20 changed files with 113 additions and 50 deletions

60
.jscsrc Normal file
View File

@@ -0,0 +1,60 @@
{
"excludeFiles": ["lib/6to5/transformation/templates"],
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireBlocksOnNewline": 1,
"requireCommaBeforeLineBreak": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"requireSpacesInForStatement": true,
"requireCurlyBraces": [
"do"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"validateLineBreaks": "LF",
"validateQuoteMarks": "\"",
"validateIndentation": 2
}

View File

@@ -1,3 +1 @@
node_modules
test
lib/6to5/transformation/templates

View File

@@ -4,6 +4,7 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
JSHINT_CMD = node_modules/jshint/bin/jshint
MOCHA_CMD = node_modules/mocha/bin/_mocha
JSCS_CMD = node_modules/jscs/bin/jscs
export NODE_ENV = test
@@ -27,6 +28,7 @@ clean:
lint:
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
$(JSCS_CMD) lib bin
test-clean:
rm -rf test/tmp

View File

@@ -77,7 +77,7 @@ module.exports = function (commander, filenames) {
if (chunk !== null) code += chunk;
});
process.stdin.on("end", function() {
process.stdin.on("end", function () {
results.push(util.transform(commander.filename, code));
output();
});
@@ -117,7 +117,7 @@ module.exports = function (commander, filenames) {
persistent: true,
ignoreInitial: true
}).on("all", function (type, filename) {
if (type === "add" || type === "change" || type === "unlink" ) {
if (type === "add" || type === "change" || type === "unlink") {
console.log(type, filename);
walk();
}

View File

@@ -28,7 +28,7 @@ commander.option("-R, --react-compat", "Makes the react transformer produce pre-
commander.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false);
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
commander.on("--help", function(){
commander.on("--help", function () {
var outKeys = function (title, obj) {
console.log(" " + title + ":");
console.log();

View File

@@ -102,13 +102,13 @@ Buffer.prototype._newline = function (removeLast) {
* If buffer ends with a newline and some spaces after it, trim those spaces.
*/
Buffer.prototype._removeSpacesAfterLastNewline = function () {
var lastNewlineIndex = this.buf.lastIndexOf('\n');
var lastNewlineIndex = this.buf.lastIndexOf("\n");
if (lastNewlineIndex === -1)
return;
var index = this.buf.length - 1;
while (index > lastNewlineIndex) {
if (this.buf[index] !== ' ') {
if (this.buf[index] !== " ") {
break;
}

View File

@@ -40,7 +40,7 @@ _.each(Buffer.prototype, function (fn, key) {
CodeGenerator.normaliseOptions = function (code, opts) {
var indent = detectIndent(code);
var style = indent.indent;
if (!style || style === " ") style = " ";
if (!style || style === " ") style = " ";
return _.merge({
parentheses: true,

View File

@@ -101,7 +101,7 @@ Whitespace.prototype.getNewlinesBetween = function (startToken, endToken) {
var lines = 0;
for (var line = start; line < end; line++) {
if (typeof this.used[line] === 'undefined') {
if (typeof this.used[line] === "undefined") {
this.used[line] = true;
lines++;
}

View File

@@ -8,22 +8,17 @@ var t = require("../../types");
/**
* Description
*
* @param {Object} methodNode
* @param {Object} className
* @param {Object} superName
* @param {Boolean} isLoose
* @param {Scope} scope
* @param {File} file
* @param {Object} opts
*/
function ReplaceSupers(methodNode, className, superName, isLoose, scope, file) {
function ReplaceSupers(opts) {
this.topLevelThisReference = null;
this.methodNode = methodNode;
this.className = className;
this.superName = superName;
this.isLoose = isLoose;
this.scope = scope;
this.file = file;
this.methodNode = opts.methodNode;
this.className = opts.className;
this.superName = opts.superName;
this.isLoose = opts.isLoose;
this.scope = opts.scope;
this.file = opts.file;
}
/**

View File

@@ -2,7 +2,7 @@
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function(resolve, reject) {
return new Promise(function (resolve, reject) {
var callNext = step.bind(gen.next);
var callThrow = step.bind(gen.throw);

View File

@@ -3,4 +3,3 @@
raw: { value: Object.freeze(raw) }
}));
});

View File

@@ -246,10 +246,10 @@ var letReferenceFunctionVisitor = {
var letReferenceBlockVisitor = {
enter: function (node, parent, scope, context, state) {
if (t.isFunction(node)) {
traverse(node, letReferenceFunctionVisitor, scope, state);
return context.skip();
}
if (t.isFunction(node)) {
traverse(node, letReferenceFunctionVisitor, scope, state);
return context.skip();
}
}
};

View File

@@ -137,7 +137,14 @@ Class.prototype.buildBody = function () {
for (var i = 0; i < classBody.length; i++) {
var node = classBody[i];
if (t.isMethodDefinition(node)) {
var replaceSupers = new ReplaceSupers(node, this.className, this.superName, this.isLoose, this.scope, this.file);
var replaceSupers = new ReplaceSupers({
methodNode: node,
className: this.className,
superName: this.superName,
isLoose: this.isLoose,
scope: this.scope,
file: this.file
});
replaceSupers.replace();
if (node.key.name === "constructor") {

View File

@@ -2,7 +2,6 @@
var traverse = require("../../../traverse");
var t = require("../../../types");
var _ = require("lodash");
var visitor = {
enter: function (node, parent, scope, context, state) {

View File

@@ -65,24 +65,24 @@ var pushObjectPattern = function (opts, nodes, pattern, parentId) {
for (var i = 0; i < pattern.properties.length; i++) {
var prop = pattern.properties[i];
if (t.isSpreadProperty(prop)) {
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i2 = 0; i2 < pattern.properties.length; i2++) {
var prop2 = pattern.properties[i2];
// get all the keys that appear in this object before the current spread
var keys = [];
for (var i2 = 0; i2 < pattern.properties.length; i2++) {
var prop2 = pattern.properties[i2];
if (i2 >= i) break;
if (t.isSpreadProperty(prop2)) continue;
if (i2 >= i) break;
if (t.isSpreadProperty(prop2)) continue;
var key = prop2.key;
if (t.isIdentifier(key)) {
key = t.literal(prop2.key.name);
}
keys.push(key);
var key = prop2.key;
if (t.isIdentifier(key)) {
key = t.literal(prop2.key.name);
}
keys = t.arrayExpression(keys);
keys.push(key);
}
keys = t.arrayExpression(keys);
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
nodes.push(buildVariableAssign(opts, prop.argument, value));
var value = t.callExpression(opts.file.addHelper("object-without-properties"), [parentId, keys]);
nodes.push(buildVariableAssign(opts, prop.argument, value));
} else {
if (t.isLiteral(prop.key)) prop.computed = true;

View File

@@ -19,7 +19,7 @@ exports.ForOfStatement = function (node, parent, scope, context, file) {
t.ensureBlock(node);
// add the value declaration to the new loop body
if (declar){
if (declar) {
if (build.shouldUnshift) {
block.body.unshift(declar);
} else {

View File

@@ -66,7 +66,7 @@ exports.CallExpression = function (node, parent, scope, context, file) {
node.arguments = [];
var nodes;
if (args.length === 1 && args[0].argument.name === 'arguments') {
if (args.length === 1 && args[0].argument.name === "arguments") {
nodes = [args[0].argument];
} else {
nodes = build(args, file);

View File

@@ -39,7 +39,7 @@ exports.XJSAttribute = {
}
};
var isCompatTag = function(tagName) {
var isCompatTag = function (tagName) {
return /^[a-z]|\-/.test(tagName);
};

View File

@@ -77,16 +77,18 @@ t.is = function (type, node, opts, skipAliasCheck) {
if (!typeMatches && !skipAliasCheck) {
var aliases = t.FLIPPED_ALIAS_KEYS[type];
if (typeof aliases !== 'undefined')
if (typeof aliases !== "undefined") {
typeMatches = aliases.indexOf(node.type) > -1;
}
}
if (!typeMatches) {
return false;
}
if (typeof opts !== 'undefined')
if (typeof opts !== "undefined") {
return t.shallowEqual(node, opts);
}
return true;
};
@@ -316,7 +318,7 @@ t.toIdentifier = function (name) {
name = "_" + name;
}
return name || '_';
return name || "_";
};
/**

View File

@@ -56,6 +56,7 @@
"browserify": "8.1.1",
"chai": "1.10.0",
"istanbul": "0.3.5",
"jscs": "^1.10.0",
"jshint-stylish": "1.0.0",
"matcha": "0.6.0",
"mocha": "2.1.0",