regenerator
Advanced tools
Comparing version 0.5.0 to 0.5.3
@@ -18,2 +18,4 @@ /** | ||
var meta = require("./meta"); | ||
var runtimeProperty = require("./util").runtimeProperty; | ||
var runtimeKeysMethod = runtimeProperty("keys"); | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
@@ -321,3 +323,3 @@ | ||
if (this.tryEntries.length === 0) { | ||
// To avoid adding a needless [] to the majority of wrapGenerator | ||
// To avoid adding a needless [] to the majority of runtime.wrap | ||
// argument lists, force the caller to handle this case specially. | ||
@@ -530,7 +532,3 @@ return null; | ||
b.callExpression( | ||
b.memberExpression( | ||
b.identifier("wrapGenerator"), | ||
b.identifier("keys"), | ||
false | ||
), | ||
runtimeKeysMethod, | ||
[self.explodeExpression(path.get("right"))] | ||
@@ -537,0 +535,0 @@ ) |
@@ -11,2 +11,3 @@ /** | ||
var b = require("recast").types.builders; | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
@@ -30,1 +31,9 @@ | ||
}; | ||
exports.runtimeProperty = function(name) { | ||
return b.memberExpression( | ||
b.identifier("regeneratorRuntime"), | ||
b.identifier(name), | ||
false | ||
); | ||
}; |
@@ -20,2 +20,6 @@ /** | ||
var Emitter = require("./emit").Emitter; | ||
var runtimeProperty = require("./util").runtimeProperty; | ||
var runtimeWrapMethod = runtimeProperty("wrap"); | ||
var runtimeMarkMethod = runtimeProperty("mark"); | ||
var runtimeValuesMethod = runtimeProperty("values"); | ||
@@ -53,3 +57,2 @@ exports.transform = function(node) { | ||
var argsId = path.scope.declareTemporary("args$"); | ||
var wrapGeneratorId = b.identifier("wrapGenerator"); | ||
var shouldAliasArguments = renameArguments(path, argsId); | ||
@@ -74,3 +77,3 @@ var vars = hoist(path); | ||
var wrapGenArgs = [ | ||
var wrapArgs = [ | ||
emitter.getContextFunction(innerFnId), | ||
@@ -83,7 +86,7 @@ outerFnId, | ||
if (tryEntryList) { | ||
wrapGenArgs.push(tryEntryList); | ||
wrapArgs.push(tryEntryList); | ||
} | ||
outerBody.push(b.returnStatement( | ||
b.callExpression(wrapGeneratorId, wrapGenArgs) | ||
b.callExpression(runtimeWrapMethod, wrapArgs) | ||
)); | ||
@@ -93,8 +96,2 @@ | ||
var markMethod = b.memberExpression( | ||
wrapGeneratorId, | ||
b.identifier("mark"), | ||
false | ||
); | ||
if (n.FunctionDeclaration.check(node)) { | ||
@@ -144,3 +141,3 @@ var pp = path.parent; | ||
// | ||
// var gen = wrapGenerator.mark(function *gen() { | ||
// var gen = runtime.mark(function *gen() { | ||
// return gen; | ||
@@ -154,3 +151,3 @@ // }); | ||
// Remove the FunctionDeclaration so that we can add it back as a | ||
// FunctionExpression passed to wrapGenerator.mark. | ||
// FunctionExpression passed to runtime.mark. | ||
path.replace(); | ||
@@ -165,3 +162,3 @@ | ||
node.id, | ||
b.callExpression(markMethod, [node]) | ||
b.callExpression(runtimeMarkMethod, [node]) | ||
) | ||
@@ -192,3 +189,3 @@ ]); | ||
n.FunctionExpression.assert(node); | ||
return b.callExpression(markMethod, [node]); | ||
return b.callExpression(runtimeMarkMethod, [node]); | ||
} | ||
@@ -205,7 +202,3 @@ }, | ||
b.callExpression( | ||
b.memberExpression( | ||
b.identifier("wrapGenerator"), | ||
b.identifier("values"), | ||
false | ||
), | ||
runtimeValuesMethod, | ||
[node.right] | ||
@@ -296,7 +289,4 @@ ) | ||
if (n.CallExpression.check(decl.init) && | ||
n.MemberExpression.check(decl.init.callee) && | ||
n.Identifier.check(decl.init.callee.object) && | ||
n.Identifier.check(decl.init.callee.property) && | ||
decl.init.callee.object.name === "wrapGenerator" && | ||
decl.init.callee.property.name === "mark") { | ||
types.astNodesAreEquivalent(decl.init.callee, | ||
runtimeMarkMethod)) { | ||
return true; | ||
@@ -303,0 +293,0 @@ } |
28
main.js
@@ -14,2 +14,3 @@ /** | ||
var fs = require("fs"); | ||
var through = require("through"); | ||
var transform = require("./lib/visit").transform; | ||
@@ -22,5 +23,14 @@ var utils = require("./lib/util"); | ||
require("./runtime/dev"); | ||
function regenerator(source, options) { | ||
options = normalizeOptions(options); | ||
if (isFileName(source)) { | ||
// If source is a file name, assume we were invoked as a browserify | ||
// transform, and return a stream. | ||
// TODO Move the normal behavior into regenerator.compile in v0.6. | ||
return createStream(options); | ||
} | ||
var runtime = options.includeRuntime ? fs.readFileSync( | ||
@@ -51,2 +61,20 @@ regenerator.runtime.dev, "utf-8" | ||
function isFileName(str) { | ||
return /\.js$/.test(str) && fs.existsSync(str); | ||
} | ||
function createStream(options) { | ||
var data = []; | ||
return through(write, end); | ||
function write(buf) { | ||
data.push(buf); | ||
} | ||
function end() { | ||
this.queue(regenerator(data.join(""), options)); | ||
this.queue(null); | ||
} | ||
} | ||
function normalizeOptions(options) { | ||
@@ -53,0 +81,0 @@ options = utils.defaults(options || {}, { |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.5.3", | ||
"homepage": "http://github.com/facebook/regenerator", | ||
@@ -36,2 +36,3 @@ "repository": { | ||
"private": "~0.1.5", | ||
"through": "~2.3.4", | ||
"defs": "~0.6.2" | ||
@@ -38,0 +39,0 @@ }, |
@@ -17,22 +17,19 @@ /** | ||
// functions that return Generator objects. | ||
GeneratorFunction, | ||
// Undefined value, more compressible than void 0. | ||
undefined | ||
GeneratorFunction | ||
) { | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
var undefined; // More compressible than void 0. | ||
if (global.wrapGenerator) { | ||
if (global.regeneratorRuntime) { | ||
return; | ||
} | ||
function wrapGenerator(innerFn, outerFn, self, tryList) { | ||
var runtime = global.regeneratorRuntime = | ||
typeof exports === "undefined" ? {} : exports; | ||
function wrap(innerFn, outerFn, self, tryList) { | ||
return new Generator(innerFn, outerFn, self || null, tryList || []); | ||
} | ||
runtime.wrap = wrap; | ||
global.wrapGenerator = wrapGenerator; | ||
if (typeof exports !== "undefined") { | ||
exports.wrapGenerator = wrapGenerator; | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
@@ -53,3 +50,3 @@ var GenStateSuspendedYield = "suspendedYield"; | ||
wrapGenerator.mark = function(genFun) { | ||
runtime.mark = function(genFun) { | ||
genFun.__proto__ = GFp; | ||
@@ -65,3 +62,3 @@ genFun.prototype = Object.create(Gp); | ||
wrapGenerator.isGeneratorFunction = function(genFun) { | ||
runtime.isGeneratorFunction = function(genFun) { | ||
var ctor = genFun && genFun.constructor; | ||
@@ -236,3 +233,3 @@ return ctor ? GeneratorFunction.name === ctor.name : false; | ||
wrapGenerator.keys = function(object) { | ||
runtime.keys = function(object) { | ||
var keys = []; | ||
@@ -286,3 +283,3 @@ for (var key in object) { | ||
} | ||
wrapGenerator.values = values; | ||
runtime.values = values; | ||
@@ -289,0 +286,0 @@ Context.prototype = { |
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
972668
18
26785
6
14
2
+ Addedthrough@~2.3.4
+ Addedthrough@2.3.8(transitive)