diff --git a/CHANGELOG.md b/CHANGELOG.md index 64eab031b1..eb2aa6685b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -333,8 +333,8 @@ _Note: Gaps between patch versions are faulty/broken releases._ * **Polish** * Rest parameters now allocate the array before populating. * **Internal** - * `for...in` loops have been changed to optimised `for` loops - better performance and no enumeration of protoype keys. - * Parts of the code generator have now been optimised thanks to [gaearon](https://github.com/gaearon). + * `for...in` loops have been changed to optimized `for` loops - better performance and no enumeration of protoype keys. + * Parts of the code generator have now been optimized thanks to [gaearon](https://github.com/gaearon). ## 2.12.3 @@ -357,7 +357,7 @@ _Note: Gaps between patch versions are faulty/broken releases._ * **Bug Fix** * Support non-string JSX literals. * **New Feature** - * Loose mode for some transformers that enables non-spec behaviour. + * Loose mode for some transformers that enables non-spec behavior. * **Internal** * Uglify `--mangle sort` has been added to the build script, cutting minified scripts in half. @@ -795,7 +795,7 @@ _Note: Gaps between patch versions are faulty/broken releases._ ## 1.13.2 - * Optimise `Array.from` usage by adding a helper method. + * Optimize `Array.from` usage by adding a helper method. * Upgrade `acorn-6to5`. ## 1.13.1 diff --git a/NOTES.md b/NOTES.md index 731ad31e9a..71d2a5b7f5 100644 --- a/NOTES.md +++ b/NOTES.md @@ -1,3 +1,3 @@ # Notes - * Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224). + * Wildcard exports/imports wont normalize if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224). diff --git a/lib/6to5/file.js b/lib/6to5/file.js index 44d0a7794b..924776e29c 100644 --- a/lib/6to5/file.js +++ b/lib/6to5/file.js @@ -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)); diff --git a/lib/6to5/generation/index.js b/lib/6to5/generation/index.js index ad587cf66c..657aada805 100644 --- a/lib/6to5/generation/index.js +++ b/lib/6to5/generation/index.js @@ -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; diff --git a/lib/6to5/register.js b/lib/6to5/register.js index bd2f60d006..68f40886fd 100644 --- a/lib/6to5/register.js +++ b/lib/6to5/register.js @@ -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); diff --git a/lib/6to5/transformation/index.js b/lib/6to5/transformation/index.js index e861e43721..eec84eae40 100644 --- a/lib/6to5/transformation/index.js +++ b/lib/6to5/transformation/index.js @@ -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); diff --git a/lib/6to5/transformation/modules/_default.js b/lib/6to5/transformation/modules/_default.js index 4d46305f25..3d06f64b9c 100644 --- a/lib/6to5/transformation/modules/_default.js +++ b/lib/6to5/transformation/modules/_default.js @@ -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)); diff --git a/lib/6to5/transformation/transformer.js b/lib/6to5/transformation/transformer.js index 4ec0c92803..02efb7396e 100644 --- a/lib/6to5/transformation/transformer.js +++ b/lib/6to5/transformation/transformer.js @@ -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)) { diff --git a/lib/6to5/transformation/transformers/es6/block-scoping.js b/lib/6to5/transformation/transformers/es6/block-scoping.js index 5e8b87b879..998efed593 100644 --- a/lib/6to5/transformation/transformers/es6/block-scoping.js +++ b/lib/6to5/transformation/transformers/es6/block-scoping.js @@ -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, diff --git a/lib/6to5/transformation/transformers/es6/modules.js b/lib/6to5/transformation/transformers/es6/modules.js index b893690bc0..abb911f0b5 100644 --- a/lib/6to5/transformation/transformers/es6/modules.js +++ b/lib/6to5/transformation/transformers/es6/modules.js @@ -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]; diff --git a/lib/6to5/transformation/transformers/es6/properties.computed.js b/lib/6to5/transformation/transformers/es6/properties.computed.js index cd01c828c4..5091488ca7 100644 --- a/lib/6to5/transformation/transformers/es6/properties.computed.js +++ b/lib/6to5/transformation/transformers/es6/properties.computed.js @@ -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]; diff --git a/lib/6to5/traverse/scope.js b/lib/6to5/traverse/scope.js index 333cabc367..aa2cdb2264 100644 --- a/lib/6to5/traverse/scope.js +++ b/lib/6to5/traverse/scope.js @@ -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); + }; + }); +}); diff --git a/lib/6to5/util.js b/lib/6to5/util.js index f60534e3bb..49b381ef29 100644 --- a/lib/6to5/util.js +++ b/lib/6to5/util.js @@ -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); diff --git a/test/_helper.js b/test/_helper.js index 72cfd950c4..bb8c7c3341 100644 --- a/test/_helper.js +++ b/test/_helper.js @@ -3,7 +3,7 @@ var path = require("path"); var fs = require("fs"); var _ = require("lodash"); -var humanise = function (val, noext) { +var humanize = function (val, noext) { if (noext) val = path.basename(val, path.extname(val)); return val.replace(/-/g, " "); }; @@ -37,7 +37,7 @@ exports.get = function (entryName, entryLoc) { var suite = { options: {}, tests: [], - title: humanise(suiteName), + title: humanize(suiteName), filename: entryLoc + "/" + suiteName }; suites.push(suite); @@ -83,7 +83,7 @@ exports.get = function (entryName, entryLoc) { if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc)); var test = { - title: humanise(taskName, true), + title: humanize(taskName, true), disabled: taskName[0] === ".", options: taskOpts, exec: { diff --git a/test/test262.js b/test/test262.js index 5a0be6f844..11c96abcfe 100644 --- a/test/test262.js +++ b/test/test262.js @@ -20,7 +20,7 @@ var exec = function (loc) { try { var file = fs.readFileSync(loc, "utf8"); - // this normalises syntax and early runtime reference errors since they're + // this normalizes syntax and early runtime reference errors since they're // both thrown as SyntaxErrors in acorn // SyntaxError: var null; // ReferenceError: 1++; (runtime) diff --git a/test/traceur.js b/test/traceur.js index afb0722e1f..72dc64e7fc 100644 --- a/test/traceur.js +++ b/test/traceur.js @@ -37,7 +37,7 @@ require("./_transformation-helper")({ "Syntax/UseStrictEscapeSequence", "Syntax/UseStrictLineContinuation", - // experimental es7 - the spec hasn't been finalised yet + // experimental es7 - the spec hasn't been finalized yet // these both fail because of filter between blocks "ArrayComprehension/Simple", "GeneratorComprehension/Simple",