regenerator
Advanced tools
Comparing version 0.6.0 to 0.6.1
@@ -24,2 +24,3 @@ /** | ||
var runtimeValuesMethod = runtimeProperty("values"); | ||
var runtimeAsyncMethod = runtimeProperty("async"); | ||
@@ -37,3 +38,3 @@ exports.transform = function(node) { | ||
if (!node.generator) { | ||
if (!node.generator && !node.async) { | ||
return; | ||
@@ -52,5 +53,10 @@ } | ||
if (node.async) { | ||
awaitVisitor.visit(path.get("body")); | ||
} | ||
var outerFnId = node.id || ( | ||
node.id = path.scope.parent.declareTemporary("callee$") | ||
); | ||
var innerFnId = b.identifier(node.id.name + "$"); | ||
@@ -80,3 +86,5 @@ var contextId = path.scope.declareTemporary("context$"); | ||
emitter.getContextFunction(innerFnId), | ||
outerFnId, | ||
// Async functions don't care about the outer function because they | ||
// don't need it to be marked and don't inherit from its .prototype. | ||
node.async ? b.literal(null) : outerFnId, | ||
b.thisExpression() | ||
@@ -90,8 +98,15 @@ ]; | ||
outerBody.push(b.returnStatement( | ||
b.callExpression(runtimeWrapMethod, wrapArgs) | ||
)); | ||
var wrapCall = b.callExpression( | ||
node.async ? runtimeAsyncMethod : runtimeWrapMethod, | ||
wrapArgs | ||
); | ||
outerBody.push(b.returnStatement(wrapCall)); | ||
node.body = b.blockStatement(outerBody); | ||
if (node.async) { | ||
node.async = false; | ||
return; | ||
} | ||
if (n.FunctionDeclaration.check(node)) { | ||
@@ -333,1 +348,12 @@ var pp = path.parent; | ||
} | ||
var awaitVisitor = types.PathVisitor.fromMethodsObject({ | ||
visitFunction: function(path) { | ||
return false; // Don't descend into nested function scopes. | ||
}, | ||
visitAwaitExpression: function(path) { | ||
// Convert await expressions to yield expressions. | ||
return b.yieldExpression(path.value.argument, false); | ||
} | ||
}); |
@@ -19,3 +19,3 @@ /** | ||
var types = recast.types; | ||
var genFunExp = /\bfunction\s*\*/; | ||
var genOrAsyncFunExp = /\bfunction\s*\*|\basync\b/; | ||
var blockBindingExp = /\b(let|const)\s+/; | ||
@@ -49,4 +49,4 @@ var runtimePath = path.join(__dirname, "runtime.js"); | ||
if (!genFunExp.test(source)) { | ||
// Shortcut: no generators to transform. | ||
if (!genOrAsyncFunExp.test(source)) { | ||
// Shortcut: no generators or async functions to transform. | ||
return { code: runtime + source }; | ||
@@ -177,3 +177,3 @@ } | ||
exports.runtime = function runtime() { | ||
require("regenerator/runtime"); | ||
require("./runtime"); | ||
}; |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"homepage": "http://github.com/facebook/regenerator", | ||
@@ -33,4 +33,5 @@ "repository": { | ||
"commander": "~2.1.0", | ||
"esprima-fb": "5001.1.0-dev-harmony-fb", | ||
"esprima-fb": "~6001.1001.0-dev-harmony-fb", | ||
"recast": "~0.7.1", | ||
"promise": "~5.0.0", | ||
"private": "~0.1.5", | ||
@@ -37,0 +38,0 @@ "through": "~2.3.4", |
@@ -21,2 +21,3 @@ /** | ||
var undefined; // More compressible than void 0. | ||
var Promise = global.Promise || (global.Promise = require("promise")); | ||
@@ -56,2 +57,27 @@ if (global.regeneratorRuntime) { | ||
runtime.async = function(innerFn, self, tryList) { | ||
return new Promise(function(resolve, reject) { | ||
var generator = wrap(innerFn, self, tryList); | ||
var callNext = step.bind(generator.next); | ||
var callThrow = step.bind(generator.throw); | ||
function step(arg) { | ||
try { | ||
var info = this(arg); | ||
var value = info.value; | ||
} catch (error) { | ||
return reject(error); | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(callNext, callThrow); | ||
} | ||
} | ||
callNext(); | ||
}); | ||
}; | ||
// Ensure isGeneratorFunction works when Function#name not supported. | ||
@@ -58,0 +84,0 @@ if (GeneratorFunction.name !== "GeneratorFunction") { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1
80497
7
16
2152
2
+ Addedpromise@~5.0.0
+ Addedasap@1.0.0(transitive)
+ Addedpromise@5.0.0(transitive)
- Removedesprima-fb@5001.1.0-dev-harmony-fb(transitive)