Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5eda35ff4 | ||
|
|
b5e1221c54 | ||
|
|
03942da57a | ||
|
|
e469c864bc | ||
|
|
9d50cae9fd | ||
|
|
249d749580 | ||
|
|
ea860ac5a5 | ||
|
|
30259f3a99 | ||
|
|
a3d7a29961 | ||
|
|
8ce762846e | ||
|
|
8092716b79 | ||
|
|
b7ba54724c | ||
|
|
7f7ee41315 | ||
|
|
b33f05bd3d | ||
|
|
1ae6eabedd | ||
|
|
973be9ad96 | ||
|
|
979ce93499 | ||
|
|
642e36c259 | ||
|
|
efaf56c6de | ||
|
|
a0c7950d8a | ||
|
|
f7be1b74d7 | ||
|
|
e264ac03b3 | ||
|
|
425f0c5fdf | ||
|
|
960a70287d | ||
|
|
c25c33e3ee | ||
|
|
d72081f82c | ||
|
|
d4debc3c85 | ||
|
|
7894f1a079 | ||
|
|
5ffaeb5e9f | ||
|
|
e50a7406ad | ||
|
|
962eeed252 | ||
|
|
2d8944fbd5 | ||
|
|
ddfb492ed9 | ||
|
|
3d98364adb | ||
|
|
3affa543ef | ||
|
|
2a47afebde | ||
|
|
f2fc6d8852 | ||
|
|
28c4c18ee2 | ||
|
|
968db67d0a | ||
|
|
b22ef22e36 | ||
|
|
044ce45d98 | ||
|
|
69f2a0d3f1 | ||
|
|
4b66dcb738 | ||
|
|
dfc6f1d1cf | ||
|
|
a64e040ac7 | ||
|
|
4f9414dbb0 | ||
|
|
bc6b31efbc | ||
|
|
244aed1ae9 | ||
|
|
4fdb2ce939 | ||
|
|
fe57eb554c | ||
|
|
3b798943e3 | ||
|
|
4ff66a5cfc | ||
|
|
5477a990bc | ||
|
|
656ca422a5 | ||
|
|
7a3071a094 | ||
|
|
77361582f4 | ||
|
|
f585039430 | ||
|
|
21dcb6037a | ||
|
|
d10d96d19a | ||
|
|
64766eea44 | ||
|
|
a9e682836b | ||
|
|
f504b8d529 | ||
|
|
30b2b55c86 | ||
|
|
836bc3a9a4 | ||
|
|
630bfcc6cd | ||
|
|
117203010a | ||
|
|
f0986fe9c7 | ||
|
|
4379441277 | ||
|
|
a955af06e0 | ||
|
|
8f69e59f29 | ||
|
|
efda5ca897 |
96
CHANGELOG.md
96
CHANGELOG.md
@@ -11,6 +11,90 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 3.0.15
|
||||
|
||||
* **Bug Fix**
|
||||
* Use `debug/node` instead of `debug` to avoid browserify using the browser version that references `window`.
|
||||
|
||||
## 3.0.14
|
||||
|
||||
* **New Feature**
|
||||
* Add `--optional` argument to `6to5-node`.
|
||||
* **Bug Fix**
|
||||
* Fix bug in `asyncToGenerator` helper where it was incorrectly calling generator iterator functions.
|
||||
|
||||
## 3.0.13
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix modules loose mode using `modules` instead of `es6.modules`.
|
||||
|
||||
## 3.0.12
|
||||
|
||||
* **Internal**
|
||||
* Add internal debug messages.
|
||||
* **Bug Fix**
|
||||
* Add `noScope` option to `traverse.clearProperties`.
|
||||
|
||||
## 3.0.11
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `ast-types` `RestElement` definition.
|
||||
* Make `es6.forOf` loose mode more versatile and support destructuring.
|
||||
|
||||
## 3.0.10
|
||||
|
||||
* **Bug Fix**
|
||||
* In `types.getIds` make sure the `declaration` inside of `ExportDeclaration` is actually a `Declaration`.
|
||||
|
||||
## 3.0.9
|
||||
|
||||
* **Bug Fix**
|
||||
* Make `t.isReferenced` more powerful, actually take into consideration all contexts were identifier nodes aren't actually references.
|
||||
* Don't camelcase underscores when converting a string to a valid identifier.
|
||||
|
||||
## 3.0.8
|
||||
|
||||
* **Bug Fix**
|
||||
* Split up default function declaration exports due to regenerator destroying the parent export declaration.
|
||||
|
||||
## 3.0.7
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.4.9`.
|
||||
* **Bug Fix**
|
||||
* Add id to function express scope tracking.
|
||||
|
||||
## 3.0.6
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix block scope variable tracking stopping whenever it hits a new scope.
|
||||
* Fix block scope variable tracking breaking on all block statement scopes that have a for loop parent.
|
||||
|
||||
## 3.0.5
|
||||
|
||||
* **Internal**
|
||||
* More reliable default parameter scope.
|
||||
|
||||
## 3.0.4
|
||||
|
||||
* **Bug Fix**
|
||||
* Remove traversal stops from block scope tracking.
|
||||
|
||||
## 3.0.3
|
||||
|
||||
* **Internal**
|
||||
* Ignore options starting with `_`.
|
||||
|
||||
## 3.0.2
|
||||
|
||||
* **Internal**
|
||||
* Add common plugin options to valid options list.
|
||||
|
||||
## 3.0.1
|
||||
|
||||
* **Internal**
|
||||
* Downgrade `kexec` as `1.1.0` throws compilation errors.
|
||||
|
||||
## 3.0.0
|
||||
|
||||
* **Polish**
|
||||
@@ -45,13 +129,13 @@ _Note: Gaps between patch versions are faulty/broken releases._
|
||||
* This shorthand has been removed from the playground.
|
||||
* `6to5/polyfill` can now only be required **once**.
|
||||
* **CLI**
|
||||
* `--indent` option has been removed.
|
||||
* `--include-regenerator` option has been removed.
|
||||
* `--amd-modules-id` option has been removed, use `--module-ids` instead.
|
||||
* `--indent` option has been removed.
|
||||
* `--include-regenerator` option has been removed.
|
||||
* `--amd-modules-id` option has been removed, use `--module-ids` instead.
|
||||
* **Options**
|
||||
* `amdModuleIds` option has been removed, use `moduleIds` instead.
|
||||
* `includeRegenerator` has been removed.
|
||||
* `ignoreRegex` fallback has now been dropped from the require hook. `register(/foo/);`, `register({ ignoreRegex: /foo/ })` -> `register({ ignore: /foo/ })`.
|
||||
* `amdModuleIds` option has been removed, use `moduleIds` instead.
|
||||
* `includeRegenerator` has been removed.
|
||||
* `ignoreRegex` fallback has now been dropped from the require hook. `register(/foo/);`, `register({ ignoreRegex: /foo/ })` -> `register({ ignore: /foo/ })`.
|
||||
* **Modules**
|
||||
* Module interop now only collapses to `module.exports` when there's a **single** export that's default.
|
||||
* Imports and exports are now illegal anywhere except the root level by default. Set `modules` to [loose mode](http://6to5.org/docs/usage/loose) to allow them everywhere.
|
||||
|
||||
22
README.md
22
README.md
@@ -2,28 +2,6 @@
|
||||
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://gratipay.com/sebmck">
|
||||
<img alt="Gratipay" src="https://img.shields.io/gratipay/sebmck.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://travis-ci.org/6to5/6to5">
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&label=travis">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Coverage" src="http://img.shields.io/codeclimate/coverage/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
|
||||
<a href="https://david-dm.org/6to5/6to5">
|
||||
<img alt="Dependency Status" src="http://img.shields.io/david/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
|
||||
</p>
|
||||
|
||||
@@ -19,6 +19,7 @@ program.option("-r, --experimental", "Enable experimental support for proposed E
|
||||
program.option("-g, --playground", "Enable playground support");
|
||||
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||
program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list);
|
||||
|
||||
var pkg = require("../package.json");
|
||||
program.version(pkg.version);
|
||||
@@ -33,6 +34,7 @@ to5.register({
|
||||
playground: program.playground,
|
||||
blacklist: program.blacklist,
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
ignore: program.ignore
|
||||
});
|
||||
|
||||
@@ -43,6 +45,7 @@ var _eval = function (code, filename) {
|
||||
filename: filename,
|
||||
blacklist: ["useStrict"].concat(program.blacklist || []),
|
||||
whitelist: program.whitelist,
|
||||
optional: program.optional,
|
||||
experimental: program.experimental,
|
||||
playground: program.playground
|
||||
}).code;
|
||||
@@ -61,8 +64,18 @@ if (program.eval || program.print) {
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
var i = 0;
|
||||
var ignoreNext = false;
|
||||
_.each(args, function (arg, i2) {
|
||||
if (arg[0] !== "-") {
|
||||
if (ignoreNext) {
|
||||
ignoreNext = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg[0] === "-") {
|
||||
if (program[arg.slice(2)]) {
|
||||
ignoreNext = true;
|
||||
}
|
||||
} else {
|
||||
i = i2;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ File.normaliseOptions = function (opts) {
|
||||
opts = clone(opts);
|
||||
|
||||
for (var key in opts) {
|
||||
if (File.validOptions.indexOf(key) < 0) {
|
||||
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
|
||||
throw new ReferenceError("Unknown option: " + key);
|
||||
}
|
||||
}
|
||||
@@ -312,7 +312,7 @@ File.prototype.parse = function (code) {
|
||||
|
||||
var opts = this.opts;
|
||||
|
||||
opts.allowImportExportEverywhere = this.isLoose("modules");
|
||||
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
|
||||
|
||||
return util.parse(opts, code, function (tree) {
|
||||
self.transform(tree);
|
||||
@@ -323,9 +323,11 @@ File.prototype.parse = function (code) {
|
||||
File.prototype.transform = function (ast) {
|
||||
var self = this;
|
||||
|
||||
util.debug(this.opts.filename);
|
||||
|
||||
this.ast = ast;
|
||||
this.lastStatements = t.getLastStatements(ast.program);
|
||||
this.scope = new Scope(ast.program, null, this);
|
||||
this.scope = new Scope(ast.program, ast, null, this);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
var astRun = function (key) {
|
||||
@@ -349,7 +351,6 @@ File.prototype.generate = function () {
|
||||
|
||||
var result = {
|
||||
code: "",
|
||||
opts: opts,
|
||||
map: null,
|
||||
ast: null
|
||||
};
|
||||
|
||||
@@ -87,7 +87,11 @@ exports.CallExpression = function (node, print) {
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
this.push(keyword);
|
||||
if (node.delegate) this.push("*");
|
||||
|
||||
if (node.delegate || node.all) {
|
||||
this.push("*");
|
||||
}
|
||||
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
|
||||
@@ -34,9 +34,9 @@ def("ImportBatchSpecifier")
|
||||
.field("name", def("Identifier"));
|
||||
|
||||
def("RestElement")
|
||||
.bases("Node")
|
||||
.bases("Pattern")
|
||||
.build("argument")
|
||||
.field("argument", def("Pattern"));
|
||||
.field("argument", def("expression"));
|
||||
|
||||
// Abstract references
|
||||
def("VirtualPropertyExpression")
|
||||
|
||||
@@ -9,6 +9,12 @@ var visitor = {
|
||||
|
||||
if (t.isAwaitExpression(node)) {
|
||||
node.type = "YieldExpression";
|
||||
|
||||
if (node.all) {
|
||||
// await* foo; -> yield Promise.all(foo);
|
||||
node.all = false;
|
||||
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
var gen = fn.apply(this, arguments);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
var callNext = step.bind(gen.next);
|
||||
var callThrow = step.bind(gen.throw);
|
||||
var callNext = step.bind(null, "next");
|
||||
var callThrow = step.bind(null, "throw");
|
||||
|
||||
function step(arg) {
|
||||
function step(key, arg) {
|
||||
try {
|
||||
var info = this(arg);
|
||||
var info = gen[key](arg);
|
||||
var value = info.value;
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
|
||||
@@ -2,6 +2,7 @@ for (var LOOP_OBJECT = OBJECT,
|
||||
IS_ARRAY = Array.isArray(LOOP_OBJECT),
|
||||
INDEX = 0,
|
||||
LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {
|
||||
var ID;
|
||||
if (IS_ARRAY) {
|
||||
if (INDEX >= LOOP_OBJECT.length) break;
|
||||
ID = LOOP_OBJECT[INDEX++];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module.exports = TransformerPass;
|
||||
|
||||
var traverse = require("../traverse");
|
||||
var util = require("../util");
|
||||
var _ = require("lodash");
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,8 @@ var transformVisitor = {
|
||||
TransformerPass.prototype.transform = function () {
|
||||
var file = this.file;
|
||||
|
||||
util.debug(file.opts.filename + ": Running transformer " + this.transformer.key);
|
||||
|
||||
this.astRun("before");
|
||||
|
||||
var state = { file: file, handlers: this.handlers, pass: this };
|
||||
|
||||
@@ -20,11 +20,7 @@ exports.ForOfStatement = function (node, parent, scope, context, file) {
|
||||
|
||||
// add the value declaration to the new loop body
|
||||
if (declar) {
|
||||
if (build.shouldUnshift) {
|
||||
block.body.unshift(declar);
|
||||
} else {
|
||||
block.body.push(declar);
|
||||
}
|
||||
block.body.push(declar);
|
||||
}
|
||||
|
||||
// push the rest of the original loop body onto our new body
|
||||
@@ -45,9 +41,9 @@ var loose = function (node, parent, scope, context, file) {
|
||||
id = left;
|
||||
} else if (t.isVariableDeclaration(left)) {
|
||||
// for (var i of test)
|
||||
id = left.declarations[0].id;
|
||||
id = scope.generateUidIdentifier("ref");
|
||||
declar = t.variableDeclaration(left.kind, [
|
||||
t.variableDeclarator(id)
|
||||
t.variableDeclarator(left.declarations[0].id, id)
|
||||
]);
|
||||
} else {
|
||||
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
|
||||
@@ -61,10 +57,15 @@ var loose = function (node, parent, scope, context, file) {
|
||||
ID: id
|
||||
});
|
||||
|
||||
if (!declar) {
|
||||
// no declaration so we need to remove the variable declaration at the top of
|
||||
// the for-of-loose template
|
||||
loop.body.body.shift();
|
||||
}
|
||||
|
||||
return {
|
||||
shouldUnshift: true,
|
||||
declar: declar,
|
||||
loop: loop
|
||||
declar: declar,
|
||||
loop: loop
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
var traverse = require("../../../traverse");
|
||||
var util = require("../../../util");
|
||||
var t = require("../../../types");
|
||||
|
||||
var hasDefaults = function (node) {
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
@@ -10,12 +11,20 @@ var hasDefaults = function (node) {
|
||||
return false;
|
||||
};
|
||||
|
||||
var iifeVisitor = {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (t.isReferencedIdentifier(node, parent) && scope.hasOwn(node.name)) {
|
||||
state.iife = true;
|
||||
context.stop();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, scope) {
|
||||
if (!hasDefaults(node)) return;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var iife = false;
|
||||
var body = [];
|
||||
|
||||
var argsIdentifier = t.identifier("arguments");
|
||||
@@ -23,6 +32,8 @@ exports.Function = function (node, parent, scope) {
|
||||
|
||||
var lastNonDefaultParam = 0;
|
||||
|
||||
var state = { iife: false, scope: scope };
|
||||
|
||||
for (var i = 0; i < node.params.length; i++) {
|
||||
var param = node.params[i];
|
||||
|
||||
@@ -36,10 +47,12 @@ exports.Function = function (node, parent, scope) {
|
||||
|
||||
node.params[i] = scope.generateUidIdentifier("x");
|
||||
|
||||
// we're accessing a variable that's already defined within this function
|
||||
var localDeclar = scope.get(left.name, true);
|
||||
if (localDeclar !== left) {
|
||||
iife = true;
|
||||
if (!state.iife) {
|
||||
if (t.isIdentifier(right) && scope.hasOwn(right.name)) {
|
||||
state.iife = true;
|
||||
} else {
|
||||
traverse(right, iifeVisitor, scope, state);
|
||||
}
|
||||
}
|
||||
|
||||
var defNode = util.template("default-parameter", {
|
||||
@@ -55,7 +68,7 @@ exports.Function = function (node, parent, scope) {
|
||||
// we need to cut off all trailing default parameters
|
||||
node.params = node.params.slice(0, lastNonDefaultParam);
|
||||
|
||||
if (iife) {
|
||||
if (state.iife) {
|
||||
var container = t.functionExpression(null, [], node.body, node.generator);
|
||||
container._aliasFunction = true;
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ exports.Function = function (node, parent, scope) {
|
||||
|
||||
var rest = node.params.pop().argument;
|
||||
|
||||
t.ensureBlock(node);
|
||||
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
// otherwise `arguments` will be remapped in arrow functions
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
// in this transformer we have to split up classes and function declarations
|
||||
// from their exports. why? because sometimes we need to replace classes with
|
||||
// nodes that aren't allowed in the same contexts. also, if you're exporting
|
||||
// a generator function as a default then regenerator will destroy the export
|
||||
// declaration and leave a variable declaration in it's place... yeah, handy.
|
||||
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.ExportDeclaration = function (node, parent, scope) {
|
||||
@@ -16,6 +22,10 @@ exports.ExportDeclaration = function (node, parent, scope) {
|
||||
]);
|
||||
node.declaration = temp;
|
||||
return [declar, node];
|
||||
} else if (t.isFunctionDeclaration(declar)) {
|
||||
node._blockHoist = 2;
|
||||
node.declaration = declar.id;
|
||||
return [declar, node];
|
||||
}
|
||||
} else {
|
||||
if (t.isFunctionDeclaration(declar)) {
|
||||
|
||||
@@ -110,8 +110,8 @@ TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent,
|
||||
|
||||
var ourScope = scope;
|
||||
// we're entering a new scope so let's construct it!
|
||||
if (t.isScope(node)) {
|
||||
ourScope = new Scope(node, scope);
|
||||
if (!opts.noScope && t.isScope(node)) {
|
||||
ourScope = new Scope(node, parent, scope);
|
||||
}
|
||||
|
||||
node = this.enterNode(obj, key, node, opts.enter, parent, ourScope, state);
|
||||
@@ -177,7 +177,7 @@ function traverseNode(node, opts, scope, state) {
|
||||
function traverse(parent, opts, scope, state) {
|
||||
if (!parent) return;
|
||||
|
||||
if (!scope) {
|
||||
if (!opts.noScope && !scope) {
|
||||
if (parent.type !== "Program" && parent.type !== "File") {
|
||||
throw new Error("Must pass a scope unless traversing a Program/File got a " + parent.type + " node");
|
||||
}
|
||||
@@ -217,7 +217,10 @@ function clearNode(node) {
|
||||
}
|
||||
}
|
||||
|
||||
var clearVisitor = { enter: clearNode };
|
||||
var clearVisitor = {
|
||||
noScope: true,
|
||||
enter: clearNode
|
||||
};
|
||||
|
||||
function clearComments(comments) {
|
||||
for (var i = 0; i < comments.length; i++) {
|
||||
|
||||
@@ -14,15 +14,18 @@ var FOR_KEYS = ["left", "init"];
|
||||
* within.
|
||||
*
|
||||
* @param {Node} block
|
||||
* @param {Node} parentBlock
|
||||
* @param {Scope} [parent]
|
||||
* @param {File} [file]
|
||||
*/
|
||||
|
||||
function Scope(block, parent, file) {
|
||||
function Scope(block, parentBlock, parent, file) {
|
||||
this.parent = parent;
|
||||
this.block = block;
|
||||
this.file = parent ? parent.file : file;
|
||||
|
||||
this.parentBlock = parentBlock;
|
||||
this.block = block;
|
||||
|
||||
var info = this.getInfo();
|
||||
this.references = info.references;
|
||||
this.declarations = info.declarations;
|
||||
@@ -169,8 +172,7 @@ var programReferenceVisitor = {
|
||||
var blockVariableVisitor = {
|
||||
enter: function (node, parent, scope, context, add) {
|
||||
if (t.isBlockScoped(node)) {
|
||||
add(node, false, true);
|
||||
context.stop();
|
||||
add(node, false, t.isLet(node));
|
||||
} else if (t.isScope(node)) {
|
||||
context.skip();
|
||||
}
|
||||
@@ -197,7 +199,8 @@ Scope.prototype.getInfo = function () {
|
||||
}
|
||||
};
|
||||
|
||||
if (parent && t.isBlockStatement(block) && t.isFor(parent.block)) {
|
||||
if (parent && t.isBlockStatement(block) && t.isFor(parent.block, { body: block })) {
|
||||
// delegate block let declarations to the parent loop
|
||||
return info;
|
||||
}
|
||||
|
||||
@@ -241,6 +244,14 @@ Scope.prototype.getInfo = function () {
|
||||
});
|
||||
}
|
||||
|
||||
if (t.isFunctionExpression(block) && block.id) {
|
||||
if (!t.isProperty(this.parentBlock, { method: true })) {
|
||||
// SpiderMonkey AST doesn't use MethodDefinition here when it probably
|
||||
// should since they should be semantically the same?
|
||||
add(block.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Program
|
||||
|
||||
if (t.isProgram(block)) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var toFastProperties = require("../helpers/to-fast-properties");
|
||||
var esutils = require("esutils");
|
||||
var object = require("../helpers/object");
|
||||
var Node = require("./node");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -225,7 +226,7 @@ t.prependToMemberExpression = function (member, append) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Check if the input `node` is a reference to a bound variable.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Object} parent
|
||||
@@ -233,45 +234,94 @@ t.prependToMemberExpression = function (member, append) {
|
||||
*/
|
||||
|
||||
t.isReferenced = function (node, parent) {
|
||||
// we're a property key and we aren't computed so we aren't referenced
|
||||
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
|
||||
|
||||
if (t.isFunction(parent)) {
|
||||
// we're a function param
|
||||
if (_.contains(parent.params, node)) return false;
|
||||
|
||||
for (var i = 0; i < parent.params.length; i++) {
|
||||
var param = parent.params[i];
|
||||
if (param === node) {
|
||||
return false;
|
||||
} else if (t.isRestElement(param) && param.argument === node) {
|
||||
return false;
|
||||
}
|
||||
// yes: PARENT[NODE]
|
||||
// yes: NODE.child
|
||||
// no: parent.CHILD
|
||||
if (t.isMemberExpression(parent)) {
|
||||
if (parent.property === node && parent.computed) {
|
||||
return true;
|
||||
} else if (parent.object === node) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
|
||||
// yes: { [NODE]: "" }
|
||||
if (t.isProperty(parent)) {
|
||||
return parent.key === node && parent.computed;
|
||||
}
|
||||
|
||||
// no: var NODE = init;
|
||||
// yes: var id = NODE;
|
||||
if (t.isVariableDeclarator(parent)) {
|
||||
return parent.id !== node;
|
||||
}
|
||||
|
||||
// no: function NODE() {}
|
||||
// no: function foo(NODE) {}
|
||||
if (t.isFunction(parent)) {
|
||||
for (var i = 0; i < parent.params.length; i++) {
|
||||
var param = parent.params[i];
|
||||
if (param === node) return false;
|
||||
}
|
||||
|
||||
return parent.id !== node;
|
||||
}
|
||||
|
||||
// no: class NODE {}
|
||||
if (t.isClass(parent)) {
|
||||
return parent.id !== node;
|
||||
}
|
||||
|
||||
// yes: class { [NODE](){} }
|
||||
if (t.isMethodDefinition(parent)) {
|
||||
return parent.key === node && parent.computed;
|
||||
}
|
||||
|
||||
// no: NODE: for (;;) {}
|
||||
if (t.isLabeledStatement(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we're a catch clause param
|
||||
if (t.isCatchClause(parent) && parent.param === node) return false;
|
||||
// no: try {} catch (NODE) {}
|
||||
if (t.isCatchClause(parent)) {
|
||||
return parent.param !== node;
|
||||
}
|
||||
|
||||
// we're a variable declarator id so we aren't referenced
|
||||
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
|
||||
// no: function foo(...NODE) {}
|
||||
if (t.isRestElement(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var isMemberExpression = t.isMemberExpression(parent);
|
||||
// no: [NODE = foo] = [];
|
||||
// yes: [foo = NODE] = [];
|
||||
if (t.isAssignmentPattern(parent)) {
|
||||
return parent.right !== node;
|
||||
}
|
||||
|
||||
// we're in a member expression and we're the computed property so we're referenced
|
||||
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed;
|
||||
// no: [NODE] = [];
|
||||
// no: ({ NODE }) = [];
|
||||
if (t.isPattern(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we're in a member expression and we're the object so we're referenced
|
||||
var isObject = isMemberExpression && parent.object === node;
|
||||
// no: import NODE from "bar";
|
||||
if (t.isImportSpecifier(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// we are referenced
|
||||
if (!isMemberExpression || isComputedProperty || isObject) return true;
|
||||
// no: import * as NODE from "foo";
|
||||
if (t.isImportBatchSpecifier(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
// no: class Foo { private NODE; }
|
||||
if (t.isPrivateDeclaration(parent)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -316,13 +366,10 @@ t.toIdentifier = function (name) {
|
||||
name = name.replace(/^[-0-9]+/, "");
|
||||
|
||||
// camel case
|
||||
name = name.replace(/[-_\s]+(.)?/g, function (match, c) {
|
||||
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
|
||||
return c ? c.toUpperCase() : "";
|
||||
});
|
||||
|
||||
// remove underscores from start of name
|
||||
name = name.replace(/^\_/, "");
|
||||
|
||||
if (!t.isValidIdentifier(name)) {
|
||||
name = "_" + name;
|
||||
}
|
||||
@@ -443,7 +490,11 @@ t.toBlock = function (node, parent) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Description
|
||||
* Return a list of identifiers that will be assigned
|
||||
* as a result of runtime evaluation.
|
||||
*
|
||||
* If an identifier is passed as `node` instead of a
|
||||
* declaration then it's assumed to be an assignable.
|
||||
*
|
||||
* @param {Object} node
|
||||
* @param {Boolean} [map]
|
||||
@@ -452,15 +503,15 @@ t.toBlock = function (node, parent) {
|
||||
*/
|
||||
|
||||
t.getIds = function (node, map, ignoreTypes) {
|
||||
ignoreTypes = ignoreTypes || [];
|
||||
|
||||
var search = [].concat(node);
|
||||
var ids = {};
|
||||
var ids = object();
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
if (_.contains(ignoreTypes, id.type)) continue;
|
||||
|
||||
// blacklist types
|
||||
if (ignoreTypes && ignoreTypes.indexOf(id.type) >= 0) continue;
|
||||
|
||||
var nodeKeys = t.getIds.nodes[id.type];
|
||||
var arrKeys = t.getIds.arrays[id.type];
|
||||
@@ -469,6 +520,10 @@ t.getIds = function (node, map, ignoreTypes) {
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (t.isExportDeclaration(id)) {
|
||||
if (t.isDeclaration(node.declaration)) {
|
||||
search.push(node.declaration);
|
||||
}
|
||||
} else if (nodeKeys) {
|
||||
for (i = 0; i < nodeKeys.length; i++) {
|
||||
key = nodeKeys[i];
|
||||
@@ -508,7 +563,6 @@ t.getIds.nodes = {
|
||||
t.getIds.arrays = {
|
||||
PrivateDeclaration: ["declarations"],
|
||||
ComprehensionExpression: ["blocks"],
|
||||
ExportDeclaration: ["specifiers", "declaration"],
|
||||
ImportDeclaration: ["specifiers"],
|
||||
VariableDeclaration: ["declarations"],
|
||||
ArrayPattern: ["elements"],
|
||||
|
||||
@@ -5,6 +5,7 @@ require("./patch");
|
||||
var estraverse = require("estraverse");
|
||||
var codeFrame = require("./helpers/code-frame");
|
||||
var traverse = require("./traverse");
|
||||
var debug = require("debug/node");
|
||||
var acorn = require("acorn-6to5");
|
||||
var path = require("path");
|
||||
var util = require("util");
|
||||
@@ -14,6 +15,8 @@ var _ = require("lodash");
|
||||
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.debug = debug("6to5");
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || exports.canCompile.EXTENSIONS;
|
||||
var ext = path.extname(filename);
|
||||
|
||||
15
package.json
15
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "3.0.2",
|
||||
"version": "3.0.15",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
@@ -37,28 +37,29 @@
|
||||
"chalk": "^0.5.1",
|
||||
"chokidar": "0.12.6",
|
||||
"commander": "2.6.0",
|
||||
"core-js": "0.4.6",
|
||||
"detect-indent": "^3.0.0",
|
||||
"core-js": "^0.4.9",
|
||||
"debug": "^2.1.1",
|
||||
"detect-indent": "3.0.0",
|
||||
"estraverse": "1.9.1",
|
||||
"esutils": "1.1.6",
|
||||
"esvalid": "1.1.0",
|
||||
"fs-readdir-recursive": "0.1.0",
|
||||
"js-tokenizer": "^1.3.3",
|
||||
"js-tokenizer": "1.3.3",
|
||||
"lodash": "3.0.0",
|
||||
"output-file-sync": "^1.1.0",
|
||||
"output-file-sync": "1.1.0",
|
||||
"private": "0.1.6",
|
||||
"regenerator-6to5": "0.8.9-6",
|
||||
"regexpu": "1.1.0",
|
||||
"roadrunner": "1.0.4",
|
||||
"source-map": "0.1.43",
|
||||
"source-map-support": "0.2.9",
|
||||
"supports-color": "^1.2.0"
|
||||
"supports-color": "1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "8.1.1",
|
||||
"chai": "1.10.0",
|
||||
"istanbul": "0.3.5",
|
||||
"jscs": "^1.10.0",
|
||||
"jscs": "1.10.0",
|
||||
"jshint": "2.6.0",
|
||||
"jshint-stylish": "1.0.0",
|
||||
"matcha": "0.6.0",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"name": "6to5-runtime",
|
||||
"description": "6to5 selfContained runtime",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.14",
|
||||
"repository": "6to5/6to5",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>"
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
var genHelpers = require("./_generator-helpers");
|
||||
var transform = require("../lib/6to5/transformation/transform");
|
||||
var sourceMap = require("source-map");
|
||||
var codeFrame = require("../lib/6to5/helpers/code-frame");
|
||||
var esvalid = require("esvalid");
|
||||
var Module = require("module");
|
||||
var helper = require("./_helper");
|
||||
@@ -85,7 +86,7 @@ var run = function (task, done) {
|
||||
fn.call(global, fakeRequire, chai.assert, done);
|
||||
} catch (err) {
|
||||
err.message = exec.loc + ": " + err.message;
|
||||
err.message += util.codeFrame(execCode);
|
||||
err.message += codeFrame(execCode);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(gen.next); var callThrow = step.bind(gen["throw"]); function step(arg) { try { var info = this(arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var _prototypeProperties = function (child, staticProps, instanceProps) { if (staticProps) Object.defineProperties(child, staticProps); if (instanceProps) Object.defineProperties(child.prototype, instanceProps); };
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(gen.next); var callThrow = step.bind(gen["throw"]); function step(arg) { try { var info = this(arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var foo = _asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(gen.next); var callThrow = step.bind(gen["throw"]); function step(arg) { try { var info = this(arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
var _asyncToGenerator = function (fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, "next"); var callThrow = step.bind(null, "throw"); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; };
|
||||
|
||||
var foo = _asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var i = undefined;
|
||||
var _ref;
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
i = _iterator[_i++];
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
i = _i.value;
|
||||
_ref = _i.value;
|
||||
}
|
||||
}
|
||||
var i = _ref;
|
||||
}
|
||||
@@ -1,25 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var i;
|
||||
var _ref;
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
i = _iterator[_i++];
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
i = _i.value;
|
||||
_ref = _i.value;
|
||||
}
|
||||
var i = _ref;
|
||||
}
|
||||
|
||||
for (var _iterator2 = numbers, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||
var i;
|
||||
var _ref2;
|
||||
if (_isArray2) {
|
||||
if (_i2 >= _iterator2.length) break;
|
||||
i = _iterator2[_i2++];
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if (_i2.done) break;
|
||||
i = _i2.value;
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
}
|
||||
var i = _ref2;
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
for (var _iterator = arr, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
||||
var i;
|
||||
var _ref;
|
||||
if (_isArray) {
|
||||
if (_i >= _iterator.length) break;
|
||||
i = _iterator[_i++];
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if (_i.done) break;
|
||||
i = _i.value;
|
||||
_ref = _i.value;
|
||||
}
|
||||
}
|
||||
var i = _ref;
|
||||
}
|
||||
6
test/fixtures/transformation/regenerator/default-parameters/exec.js
vendored
Normal file
6
test/fixtures/transformation/regenerator/default-parameters/exec.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
function* foo(bar = "bar") {
|
||||
return bar;
|
||||
}
|
||||
|
||||
assert.deepEqual(foo().next().value, "bar");
|
||||
assert.deepEqual(foo("foo").next().value, "foo");
|
||||
5
test/fixtures/transformation/regenerator/destructuring/exec.js
vendored
Normal file
5
test/fixtures/transformation/regenerator/destructuring/exec.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function* foo({ bar }) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
assert(foo({ bar: "bar" }).next().value, "bar");
|
||||
5
test/fixtures/transformation/regenerator/rest-parameters/exec.js
vendored
Normal file
5
test/fixtures/transformation/regenerator/rest-parameters/exec.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function* foo(...items) {
|
||||
return items;
|
||||
}
|
||||
|
||||
assert.deepEqual(foo(1, 2, 3).next().value, [1, 2, 3]);
|
||||
Reference in New Issue
Block a user