Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
876d69798c | ||
|
|
1a963ddc06 | ||
|
|
beb5acea6b | ||
|
|
6a290f233e | ||
|
|
74563d88ed | ||
|
|
a18177026c |
@@ -2,6 +2,11 @@
|
||||
|
||||
Gaps between patch versions are faulty/broken releases.
|
||||
|
||||
## 2.4.3
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
* Add support for `FunctionDeclaration`s in `bluebirdCoroutines` and `asyncToGenerators` transformers.
|
||||
|
||||
## 2.4.2
|
||||
|
||||
* Upgrade `acorn-6to5`.
|
||||
|
||||
@@ -10,10 +10,11 @@ var t = require("./types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
this.dynamicImports = [];
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.transformers = this.getTransformers();
|
||||
this.uids = {};
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = [
|
||||
@@ -156,7 +157,8 @@ File.prototype.parseShebang = function (code) {
|
||||
File.prototype.addImport = function (id, source) {
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
this.ast.program.body.unshift(declar);
|
||||
declar._blockHoist = 3;
|
||||
this.dynamicImports.push(declar);
|
||||
};
|
||||
|
||||
File.prototype.addDeclaration = function (name) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ast = {
|
||||
before: function (ast, file) {
|
||||
ast.program.body = file.dynamicImports.concat(ast.program.body);
|
||||
}
|
||||
};
|
||||
|
||||
exports.ImportDeclaration = function (node, parent, file) {
|
||||
var nodes = [];
|
||||
|
||||
@@ -11,6 +17,12 @@ exports.ImportDeclaration = function (node, parent, file) {
|
||||
file.moduleFormatter.importDeclaration(node, nodes, parent);
|
||||
}
|
||||
|
||||
if (nodes.length === 1) {
|
||||
// inherit `_blockHoist`
|
||||
// this for `_blockHoist` in File.prototype.addImport
|
||||
nodes[0]._blockHoist = node._blockHoist;
|
||||
}
|
||||
|
||||
return nodes;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var bluebirdCoroutines = require("./optional-bluebird-coroutines");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
@@ -8,7 +7,5 @@ exports.manipulateOptions = bluebirdCoroutines.manipulateOptions;
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
bluebirdCoroutines._Function(node);
|
||||
|
||||
return t.callExpression(file.addDeclaration("async-to-generator"), [node]);
|
||||
return bluebirdCoroutines._Function(node, file.addDeclaration("async-to-generator"));
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ exports.manipulateOptions = function (opts) {
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports._Function = function (node) {
|
||||
exports._Function = function (node, callId) {
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
@@ -21,14 +21,25 @@ exports._Function = function (node) {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var call = t.callExpression(callId, [node]);
|
||||
|
||||
if (t.isFunctionDeclaration(node)) {
|
||||
var declar = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(node.id, call)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
return declar;
|
||||
} else {
|
||||
return call;
|
||||
}
|
||||
};
|
||||
|
||||
exports.Function = function (node, parent, file) {
|
||||
if (!node.async || node.generator) return;
|
||||
|
||||
exports._Function(node);
|
||||
|
||||
var id = t.identifier("Bluebird");
|
||||
file.addImport(id, "bluebird");
|
||||
return t.callExpression(t.memberExpression(id, t.identifier("coroutine")), [node]);
|
||||
|
||||
return exports._Function(node, t.memberExpression(id, t.identifier("coroutine")));
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.4.2",
|
||||
"version": "2.4.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -35,7 +35,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-2",
|
||||
"acorn-6to5": "0.11.1-3",
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
|
||||
3
test/fixtures/transformation/optional-async-to-generator/statement/actual.js
vendored
Normal file
3
test/fixtures/transformation/optional-async-to-generator/statement/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
async function foo() {
|
||||
var wat = await bar();
|
||||
}
|
||||
42
test/fixtures/transformation/optional-async-to-generator/statement/expected.js
vendored
Normal file
42
test/fixtures/transformation/optional-async-to-generator/statement/expected.js
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
|
||||
var _asyncToGenerator = function (fn) {
|
||||
return function () {
|
||||
var gen = fn.apply(this, arguments);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
function step(getNext) {
|
||||
var next;
|
||||
try {
|
||||
next = getNext();
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
|
||||
return;
|
||||
}
|
||||
if (next.done) {
|
||||
resolve(next.value);
|
||||
|
||||
return;
|
||||
}
|
||||
Promise.resolve(next.value).then(function (v) {
|
||||
step(function () {
|
||||
return gen.next(v);
|
||||
});
|
||||
}, function (e) {
|
||||
step(function () {
|
||||
return gen["throw"](e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
step(function () {
|
||||
return gen.next();
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var foo = _asyncToGenerator(function* foo() {
|
||||
var wat = yield bar();
|
||||
});
|
||||
3
test/fixtures/transformation/optional-bluebird-coroutines/statement/actual.js
vendored
Normal file
3
test/fixtures/transformation/optional-bluebird-coroutines/statement/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
async function foo() {
|
||||
var wat = await bar();
|
||||
}
|
||||
11
test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js
vendored
Normal file
11
test/fixtures/transformation/optional-bluebird-coroutines/statement/expected.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var Bluebird = _interopRequire(require("bluebird"));
|
||||
|
||||
var foo = Bluebird.coroutine(function* foo() {
|
||||
var wat = yield bar();
|
||||
});
|
||||
Reference in New Issue
Block a user