Merge branch 'master' of github.com:6to5/6to5

This commit is contained in:
Sebastian McKenzie
2015-02-03 19:55:29 +11:00
16 changed files with 66 additions and 111 deletions

View File

@@ -25,7 +25,7 @@ function File(opts) {
this.data = {};
this.lastStatements = [];
this.opts = this.normaliseOptions(opts);
this.opts = this.normalizeOptions(opts);
this.ast = {};
this.buildTransformers();
@@ -88,7 +88,7 @@ File.validOptions = [
"accept"
];
File.prototype.normaliseOptions = function (opts) {
File.prototype.normalizeOptions = function (opts) {
opts = clone(opts);
for (var key in opts) {
@@ -118,7 +118,7 @@ File.prototype.normaliseOptions = function (opts) {
ast: true
});
// normalise windows path separators to unix
// normalize windows path separators to unix
opts.filename = opts.filename.replace(/\\/g, "/");
opts.basename = path.basename(opts.filename, path.extname(opts.filename));

View File

@@ -24,7 +24,7 @@ function CodeGenerator(ast, opts, code) {
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
this.format = CodeGenerator.normaliseOptions(code, opts);
this.format = CodeGenerator.normalizeOptions(code, opts);
this.ast = ast;
this.whitespace = new Whitespace(this.tokens, this.comments);
@@ -39,7 +39,7 @@ each(Buffer.prototype, function (fn, key) {
};
});
CodeGenerator.normaliseOptions = function (code, opts) {
CodeGenerator.normalizeOptions = function (code, opts) {
var style = " ";
if (code) {
var indent = detectIndent(code).indent;

View File

@@ -131,7 +131,7 @@ var hookExtensions = function (_exts) {
hookExtensions(util.canCompile.EXTENSIONS);
module.exports = function (opts) {
// normalise options
// normalize options
opts = opts || {};
if (opts.only != null) onlyRegex = util.regexify(opts.only);

View File

@@ -14,7 +14,7 @@ function transform(code, opts) {
}
transform.fromAst = function (ast, code, opts) {
ast = util.normaliseAst(ast);
ast = util.normalizeAst(ast);
var file = new File(opts);
file.addCode(code);

View File

@@ -171,12 +171,12 @@ DefaultFormatter.prototype.getModuleName = function () {
if (!opts.keepModuleIdExtensions) {
// remove extension
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, "");
}
moduleName += filenameRelative;
// normalise path separators
// normalize path separators
moduleName = moduleName.replace(/\\/g, "/");
return moduleName;
@@ -230,7 +230,7 @@ DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
nodes.push(this.buildExportsWildcard(ref, node));
} else {
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
// importing a default so we need to normalise it
// importing a default so we need to normalize it
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
} else {
ref = t.memberExpression(ref, t.getSpecifierId(specifier));

View File

@@ -20,12 +20,12 @@ function Transformer(key, transformer, opts) {
this.playground = !!transformer.playground;
this.secondPass = !!transformer.secondPass;
this.optional = !!transformer.optional;
this.handlers = this.normalise(transformer);
this.handlers = this.normalize(transformer);
this.opts = opts || {};
this.key = key;
}
Transformer.prototype.normalise = function (transformer) {
Transformer.prototype.normalize = function (transformer) {
var self = this;
if (isFunction(transformer)) {

View File

@@ -29,7 +29,7 @@ var isVar = function (node, parent) {
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(node, parent);
};
var standardiseLets = function (declars) {
var standardizeLets = function (declars) {
for (var i = 0; i < declars.length; i++) {
delete declars[i]._let;
}
@@ -283,7 +283,7 @@ BlockScoping.prototype.getLetReferences = function () {
if (!this.hasLetReferences) return;
// set let references to plain var references
standardiseLets(declarators);
standardizeLets(declarators);
var state = {
letReferences: this.letReferences,

View File

@@ -26,7 +26,7 @@ exports.ExportDeclaration = function (node, parent, scope, context, file) {
var i;
if (node.declaration) {
// make sure variable exports have an initialiser
// make sure variable exports have an initializer
// this is done here to avoid duplicating it in the module formatters
if (t.isVariableDeclaration(node.declaration)) {
var declar = node.declaration.declarations[0];

View File

@@ -58,7 +58,7 @@ var spec = function (node, body, objId, initProps, file) {
var props = node.properties;
var prop, key;
// normalise key
// normalize key
for (var i = 0; i < props.length; i++) {
prop = props[i];

View File

@@ -179,7 +179,7 @@ Scope.prototype.getInfo = function () {
var info = block._scopeInfo = {};
var bindings = info.bindings = object();
var bindings = info.bindings = object();
var references = info.references = object();
var types = info.types = object();
var declarationKinds = info.declarationKinds = {
@@ -373,101 +373,56 @@ Scope.prototype.getAllDeclarationsOfKind = function (kind) {
return ids;
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
*/
//
Scope.prototype.getReference = function (id, decl) {
return id && (this.getOwnReference(id, decl) || this.parentGetReference(id, decl));
Scope.prototype.get = function (id, type) {
return id && (this.getOwn(id, type) || this.parentGet(id, type));
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
*/
Scope.prototype.getOwnReference = function (id, decl) {
var refs = this.references;
if (decl) refs = this.bindings;
return has(refs, id) && refs[id];
Scope.prototype.getOwn = function (id, type) {
var refs = {
reference: this.references,
binding: this.bindings,
type: this.types
}[type];
return refs && has(refs, id) && refs[id];
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
*/
Scope.prototype.parentGetReference = function (id, decl) {
return this.parent && this.parent.getReference(id, decl);
Scope.prototype.parentGet = function (id, type) {
return this.parent && this.parent.get(id, type);
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
* @returns {Boolean}
*/
Scope.prototype.hasReference = function (id, decl) {
Scope.prototype.has = function (id, type) {
if (!id) return false;
if (this.hasOwnReference(id, decl)) return true;
if (this.parentHasReference(id, decl)) return true;
if (this.hasOwn(id, type)) return true;
if (this.parentHas(id, type)) return true;
if (contains(Scope.defaultDeclarations, id)) return true;
return false;
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
* @returns {Boolean}
*/
Scope.prototype.hasOwnReference = function (id, decl) {
return !!this.getOwnReference(id, decl);
Scope.prototype.hasOwn = function (id, type) {
return !!this.getOwn(id, type);
};
/**
* Description
*
* @param {String} [id]
* @param {Boolean} [decl]
* @returns {Boolean}
*/
Scope.prototype.parentHasReference = function (id, decl) {
return this.parent && this.parent.hasReference(id, decl);
Scope.prototype.parentHas = function (id, type) {
return this.parent && this.parent.has(id, type);
};
Scope.prototype.getBinding = function (id) {
return this.getReference(id, true);
};
Scope.prototype.hasBinding = function (id) {
return this.hasReference(id, true);
};
Scope.prototype.getOwnBinding = function (id) {
return this.getOwnReference(id, true);
};
Scope.prototype.hasOwnBinding = function (id) {
return this.hasOwnReference(id, true);
};
Scope.prototype.parentGetBinding = function (id) {
return this.parentGetReference(id, true);
};
Scope.prototype.parentHasBinding = function (id) {
return this.parentHasReference(id, true);
};
each({
reference: "Reference",
binding: "Binding",
type: "Type"
}, function (title, type) {
each([
"get",
"has",
"getOwn",
"hasOwn",
"parentGet",
"parentHas",
], function (methodName) {
Scope.prototype[methodName + title] = function (id) {
return this[methodName](id, type);
};
});
});

View File

@@ -123,7 +123,7 @@ exports.repeat = function (width, cha) {
return result;
};
exports.normaliseAst = function (ast, comments, tokens) {
exports.normalizeAst = function (ast, comments, tokens) {
if (ast && ast.type === "Program") {
return t.file(ast, comments || [], tokens || []);
} else {
@@ -150,7 +150,7 @@ exports.parse = function (opts, code, callback) {
estraverse.attachComments(ast, comments, tokens);
ast = exports.normaliseAst(ast, comments, tokens);
ast = exports.normalizeAst(ast, comments, tokens);
if (callback) {
return callback(ast);