Merge branch 'master' of github.com:6to5/6to5
This commit is contained in:
commit
f2d1fc47d1
@ -333,8 +333,8 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
* **Polish**
|
* **Polish**
|
||||||
* Rest parameters now allocate the array before populating.
|
* Rest parameters now allocate the array before populating.
|
||||||
* **Internal**
|
* **Internal**
|
||||||
* `for...in` loops have been changed to optimised `for` loops - better performance and no enumeration of protoype keys.
|
* `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 optimised thanks to [gaearon](https://github.com/gaearon).
|
* Parts of the code generator have now been optimized thanks to [gaearon](https://github.com/gaearon).
|
||||||
|
|
||||||
## 2.12.3
|
## 2.12.3
|
||||||
|
|
||||||
@ -357,7 +357,7 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
|||||||
* **Bug Fix**
|
* **Bug Fix**
|
||||||
* Support non-string JSX literals.
|
* Support non-string JSX literals.
|
||||||
* **New Feature**
|
* **New Feature**
|
||||||
* Loose mode for some transformers that enables non-spec behaviour.
|
* Loose mode for some transformers that enables non-spec behavior.
|
||||||
* **Internal**
|
* **Internal**
|
||||||
* Uglify `--mangle sort` has been added to the build script, cutting minified scripts in half.
|
* 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
|
## 1.13.2
|
||||||
|
|
||||||
* Optimise `Array.from` usage by adding a helper method.
|
* Optimize `Array.from` usage by adding a helper method.
|
||||||
* Upgrade `acorn-6to5`.
|
* Upgrade `acorn-6to5`.
|
||||||
|
|
||||||
## 1.13.1
|
## 1.13.1
|
||||||
|
|||||||
2
NOTES.md
2
NOTES.md
@ -1,3 +1,3 @@
|
|||||||
# Notes
|
# 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).
|
||||||
|
|||||||
@ -25,7 +25,7 @@ function File(opts) {
|
|||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
||||||
this.lastStatements = [];
|
this.lastStatements = [];
|
||||||
this.opts = this.normaliseOptions(opts);
|
this.opts = this.normalizeOptions(opts);
|
||||||
this.ast = {};
|
this.ast = {};
|
||||||
|
|
||||||
this.buildTransformers();
|
this.buildTransformers();
|
||||||
@ -88,7 +88,7 @@ File.validOptions = [
|
|||||||
"accept"
|
"accept"
|
||||||
];
|
];
|
||||||
|
|
||||||
File.prototype.normaliseOptions = function (opts) {
|
File.prototype.normalizeOptions = function (opts) {
|
||||||
opts = clone(opts);
|
opts = clone(opts);
|
||||||
|
|
||||||
for (var key in opts) {
|
for (var key in opts) {
|
||||||
@ -118,7 +118,7 @@ File.prototype.normaliseOptions = function (opts) {
|
|||||||
ast: true
|
ast: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// normalise windows path separators to unix
|
// normalize windows path separators to unix
|
||||||
opts.filename = opts.filename.replace(/\\/g, "/");
|
opts.filename = opts.filename.replace(/\\/g, "/");
|
||||||
|
|
||||||
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
opts.basename = path.basename(opts.filename, path.extname(opts.filename));
|
||||||
|
|||||||
@ -24,7 +24,7 @@ function CodeGenerator(ast, opts, code) {
|
|||||||
|
|
||||||
this.comments = ast.comments || [];
|
this.comments = ast.comments || [];
|
||||||
this.tokens = ast.tokens || [];
|
this.tokens = ast.tokens || [];
|
||||||
this.format = CodeGenerator.normaliseOptions(code, opts);
|
this.format = CodeGenerator.normalizeOptions(code, opts);
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
|
|
||||||
this.whitespace = new Whitespace(this.tokens, this.comments);
|
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 = " ";
|
var style = " ";
|
||||||
if (code) {
|
if (code) {
|
||||||
var indent = detectIndent(code).indent;
|
var indent = detectIndent(code).indent;
|
||||||
|
|||||||
@ -131,7 +131,7 @@ var hookExtensions = function (_exts) {
|
|||||||
hookExtensions(util.canCompile.EXTENSIONS);
|
hookExtensions(util.canCompile.EXTENSIONS);
|
||||||
|
|
||||||
module.exports = function (opts) {
|
module.exports = function (opts) {
|
||||||
// normalise options
|
// normalize options
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
if (opts.only != null) onlyRegex = util.regexify(opts.only);
|
||||||
|
|||||||
@ -14,7 +14,7 @@ function transform(code, opts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transform.fromAst = function (ast, code, opts) {
|
transform.fromAst = function (ast, code, opts) {
|
||||||
ast = util.normaliseAst(ast);
|
ast = util.normalizeAst(ast);
|
||||||
|
|
||||||
var file = new File(opts);
|
var file = new File(opts);
|
||||||
file.addCode(code);
|
file.addCode(code);
|
||||||
|
|||||||
@ -171,12 +171,12 @@ DefaultFormatter.prototype.getModuleName = function () {
|
|||||||
|
|
||||||
if (!opts.keepModuleIdExtensions) {
|
if (!opts.keepModuleIdExtensions) {
|
||||||
// remove extension
|
// remove extension
|
||||||
filenameRelative = filenameRelative.replace(/\.(.*?)$/, "");
|
filenameRelative = filenameRelative.replace(/\.(\w*?)$/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleName += filenameRelative;
|
moduleName += filenameRelative;
|
||||||
|
|
||||||
// normalise path separators
|
// normalize path separators
|
||||||
moduleName = moduleName.replace(/\\/g, "/");
|
moduleName = moduleName.replace(/\\/g, "/");
|
||||||
|
|
||||||
return moduleName;
|
return moduleName;
|
||||||
@ -230,7 +230,7 @@ DefaultFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
|
|||||||
nodes.push(this.buildExportsWildcard(ref, node));
|
nodes.push(this.buildExportsWildcard(ref, node));
|
||||||
} else {
|
} else {
|
||||||
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
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]);
|
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||||
} else {
|
} else {
|
||||||
ref = t.memberExpression(ref, t.getSpecifierId(specifier));
|
ref = t.memberExpression(ref, t.getSpecifierId(specifier));
|
||||||
|
|||||||
@ -20,12 +20,12 @@ function Transformer(key, transformer, opts) {
|
|||||||
this.playground = !!transformer.playground;
|
this.playground = !!transformer.playground;
|
||||||
this.secondPass = !!transformer.secondPass;
|
this.secondPass = !!transformer.secondPass;
|
||||||
this.optional = !!transformer.optional;
|
this.optional = !!transformer.optional;
|
||||||
this.handlers = this.normalise(transformer);
|
this.handlers = this.normalize(transformer);
|
||||||
this.opts = opts || {};
|
this.opts = opts || {};
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transformer.prototype.normalise = function (transformer) {
|
Transformer.prototype.normalize = function (transformer) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if (isFunction(transformer)) {
|
if (isFunction(transformer)) {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ var isVar = function (node, parent) {
|
|||||||
return t.isVariableDeclaration(node, { kind: "var" }) && !isLet(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++) {
|
for (var i = 0; i < declars.length; i++) {
|
||||||
delete declars[i]._let;
|
delete declars[i]._let;
|
||||||
}
|
}
|
||||||
@ -283,7 +283,7 @@ BlockScoping.prototype.getLetReferences = function () {
|
|||||||
if (!this.hasLetReferences) return;
|
if (!this.hasLetReferences) return;
|
||||||
|
|
||||||
// set let references to plain var references
|
// set let references to plain var references
|
||||||
standardiseLets(declarators);
|
standardizeLets(declarators);
|
||||||
|
|
||||||
var state = {
|
var state = {
|
||||||
letReferences: this.letReferences,
|
letReferences: this.letReferences,
|
||||||
|
|||||||
@ -26,7 +26,7 @@ exports.ExportDeclaration = function (node, parent, scope, context, file) {
|
|||||||
var i;
|
var i;
|
||||||
|
|
||||||
if (node.declaration) {
|
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
|
// this is done here to avoid duplicating it in the module formatters
|
||||||
if (t.isVariableDeclaration(node.declaration)) {
|
if (t.isVariableDeclaration(node.declaration)) {
|
||||||
var declar = node.declaration.declarations[0];
|
var declar = node.declaration.declarations[0];
|
||||||
|
|||||||
@ -58,7 +58,7 @@ var spec = function (node, body, objId, initProps, file) {
|
|||||||
var props = node.properties;
|
var props = node.properties;
|
||||||
var prop, key;
|
var prop, key;
|
||||||
|
|
||||||
// normalise key
|
// normalize key
|
||||||
|
|
||||||
for (var i = 0; i < props.length; i++) {
|
for (var i = 0; i < props.length; i++) {
|
||||||
prop = props[i];
|
prop = props[i];
|
||||||
|
|||||||
@ -373,101 +373,56 @@ Scope.prototype.getAllDeclarationsOfKind = function (kind) {
|
|||||||
return ids;
|
return ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
//
|
||||||
* Description
|
|
||||||
*
|
|
||||||
* @param {String} [id]
|
|
||||||
* @param {Boolean} [decl]
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scope.prototype.getReference = function (id, decl) {
|
Scope.prototype.get = function (id, type) {
|
||||||
return id && (this.getOwnReference(id, decl) || this.parentGetReference(id, decl));
|
return id && (this.getOwn(id, type) || this.parentGet(id, type));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Scope.prototype.getOwn = function (id, type) {
|
||||||
* Description
|
var refs = {
|
||||||
*
|
reference: this.references,
|
||||||
* @param {String} [id]
|
binding: this.bindings,
|
||||||
* @param {Boolean} [decl]
|
type: this.types
|
||||||
*/
|
}[type];
|
||||||
|
return refs && has(refs, id) && refs[id];
|
||||||
Scope.prototype.getOwnReference = function (id, decl) {
|
|
||||||
var refs = this.references;
|
|
||||||
if (decl) refs = this.bindings;
|
|
||||||
return has(refs, id) && refs[id];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Scope.prototype.parentGet = function (id, type) {
|
||||||
* Description
|
return this.parent && this.parent.get(id, type);
|
||||||
*
|
|
||||||
* @param {String} [id]
|
|
||||||
* @param {Boolean} [decl]
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scope.prototype.parentGetReference = function (id, decl) {
|
|
||||||
return this.parent && this.parent.getReference(id, decl);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Scope.prototype.has = function (id, type) {
|
||||||
* Description
|
|
||||||
*
|
|
||||||
* @param {String} [id]
|
|
||||||
* @param {Boolean} [decl]
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scope.prototype.hasReference = function (id, decl) {
|
|
||||||
if (!id) return false;
|
if (!id) return false;
|
||||||
if (this.hasOwnReference(id, decl)) return true;
|
if (this.hasOwn(id, type)) return true;
|
||||||
if (this.parentHasReference(id, decl)) return true;
|
if (this.parentHas(id, type)) return true;
|
||||||
if (contains(Scope.defaultDeclarations, id)) return true;
|
if (contains(Scope.defaultDeclarations, id)) return true;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Scope.prototype.hasOwn = function (id, type) {
|
||||||
* Description
|
return !!this.getOwn(id, type);
|
||||||
*
|
|
||||||
* @param {String} [id]
|
|
||||||
* @param {Boolean} [decl]
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scope.prototype.hasOwnReference = function (id, decl) {
|
|
||||||
return !!this.getOwnReference(id, decl);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
Scope.prototype.parentHas = function (id, type) {
|
||||||
* Description
|
return this.parent && this.parent.has(id, type);
|
||||||
*
|
|
||||||
* @param {String} [id]
|
|
||||||
* @param {Boolean} [decl]
|
|
||||||
* @returns {Boolean}
|
|
||||||
*/
|
|
||||||
|
|
||||||
Scope.prototype.parentHasReference = function (id, decl) {
|
|
||||||
return this.parent && this.parent.hasReference(id, decl);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Scope.prototype.getBinding = function (id) {
|
each({
|
||||||
return this.getReference(id, true);
|
reference: "Reference",
|
||||||
};
|
binding: "Binding",
|
||||||
|
type: "Type"
|
||||||
Scope.prototype.hasBinding = function (id) {
|
}, function (title, type) {
|
||||||
return this.hasReference(id, true);
|
each([
|
||||||
};
|
"get",
|
||||||
|
"has",
|
||||||
Scope.prototype.getOwnBinding = function (id) {
|
"getOwn",
|
||||||
return this.getOwnReference(id, true);
|
"hasOwn",
|
||||||
};
|
"parentGet",
|
||||||
|
"parentHas",
|
||||||
Scope.prototype.hasOwnBinding = function (id) {
|
], function (methodName) {
|
||||||
return this.hasOwnReference(id, true);
|
Scope.prototype[methodName + title] = function (id) {
|
||||||
};
|
return this[methodName](id, type);
|
||||||
|
|
||||||
Scope.prototype.parentGetBinding = function (id) {
|
|
||||||
return this.parentGetReference(id, true);
|
|
||||||
};
|
|
||||||
|
|
||||||
Scope.prototype.parentHasBinding = function (id) {
|
|
||||||
return this.parentHasReference(id, true);
|
|
||||||
};
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -123,7 +123,7 @@ exports.repeat = function (width, cha) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.normaliseAst = function (ast, comments, tokens) {
|
exports.normalizeAst = function (ast, comments, tokens) {
|
||||||
if (ast && ast.type === "Program") {
|
if (ast && ast.type === "Program") {
|
||||||
return t.file(ast, comments || [], tokens || []);
|
return t.file(ast, comments || [], tokens || []);
|
||||||
} else {
|
} else {
|
||||||
@ -150,7 +150,7 @@ exports.parse = function (opts, code, callback) {
|
|||||||
|
|
||||||
estraverse.attachComments(ast, comments, tokens);
|
estraverse.attachComments(ast, comments, tokens);
|
||||||
|
|
||||||
ast = exports.normaliseAst(ast, comments, tokens);
|
ast = exports.normalizeAst(ast, comments, tokens);
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback(ast);
|
return callback(ast);
|
||||||
|
|||||||
@ -3,7 +3,7 @@ var path = require("path");
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
var humanise = function (val, noext) {
|
var humanize = function (val, noext) {
|
||||||
if (noext) val = path.basename(val, path.extname(val));
|
if (noext) val = path.basename(val, path.extname(val));
|
||||||
return val.replace(/-/g, " ");
|
return val.replace(/-/g, " ");
|
||||||
};
|
};
|
||||||
@ -37,7 +37,7 @@ exports.get = function (entryName, entryLoc) {
|
|||||||
var suite = {
|
var suite = {
|
||||||
options: {},
|
options: {},
|
||||||
tests: [],
|
tests: [],
|
||||||
title: humanise(suiteName),
|
title: humanize(suiteName),
|
||||||
filename: entryLoc + "/" + suiteName
|
filename: entryLoc + "/" + suiteName
|
||||||
};
|
};
|
||||||
suites.push(suite);
|
suites.push(suite);
|
||||||
@ -83,7 +83,7 @@ exports.get = function (entryName, entryLoc) {
|
|||||||
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
if (taskOptsLoc) _.merge(taskOpts, require(taskOptsLoc));
|
||||||
|
|
||||||
var test = {
|
var test = {
|
||||||
title: humanise(taskName, true),
|
title: humanize(taskName, true),
|
||||||
disabled: taskName[0] === ".",
|
disabled: taskName[0] === ".",
|
||||||
options: taskOpts,
|
options: taskOpts,
|
||||||
exec: {
|
exec: {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ var exec = function (loc) {
|
|||||||
try {
|
try {
|
||||||
var file = fs.readFileSync(loc, "utf8");
|
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
|
// both thrown as SyntaxErrors in acorn
|
||||||
// SyntaxError: var null;
|
// SyntaxError: var null;
|
||||||
// ReferenceError: 1++; (runtime)
|
// ReferenceError: 1++; (runtime)
|
||||||
|
|||||||
@ -37,7 +37,7 @@ require("./_transformation-helper")({
|
|||||||
"Syntax/UseStrictEscapeSequence",
|
"Syntax/UseStrictEscapeSequence",
|
||||||
"Syntax/UseStrictLineContinuation",
|
"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
|
// these both fail because of filter between blocks
|
||||||
"ArrayComprehension/Simple",
|
"ArrayComprehension/Simple",
|
||||||
"GeneratorComprehension/Simple",
|
"GeneratorComprehension/Simple",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user