Compare commits

...

6 Commits

Author SHA1 Message Date
Sebastian McKenzie
876d69798c v2.4.3 2015-01-02 05:19:42 +11:00
Sebastian McKenzie
1a963ddc06 remove unused variable 2015-01-02 05:19:00 +11:00
Sebastian McKenzie
beb5acea6b better addImport with good hoisting etc 2015-01-02 05:18:03 +11:00
Sebastian McKenzie
6a290f233e add 2.4.3 changelog 2015-01-02 05:01:18 +11:00
Sebastian McKenzie
74563d88ed upgrade acorn-6to5 2015-01-02 05:00:23 +11:00
Sebastian McKenzie
a18177026c add support for statements in asyncToGenerator and bluebirdCoroutines transformers 2015-01-02 04:58:59 +11:00
14 changed files with 101 additions and 15 deletions

View File

@@ -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`.

View File

@@ -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) {

View File

@@ -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;
};

View File

@@ -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"));
};

View File

@@ -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")));
};

View File

@@ -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",

View File

@@ -0,0 +1,3 @@
async function foo() {
var wat = await bar();
}

View 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();
});

View File

@@ -0,0 +1,3 @@
async function foo() {
var wat = await bar();
}

View 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();
});