New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

regenerator

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regenerator - npm Package Compare versions

Comparing version 0.2.11 to 0.3.0

19

lib/util.js

@@ -10,2 +10,4 @@ /**

var hasOwn = Object.prototype.hasOwnProperty;
exports.guessTabWidth = function(source) {

@@ -37,1 +39,18 @@ var counts = []; // Sparse array.

};
exports.extend = function(obj) {
var len = arguments.length;
var extension;
for (var i = 1; i < len; ++i) {
if ((extension = arguments[i])) {
for (var key in extension) {
if (hasOwn.call(extension, key)) {
obj[key] = extension[key];
}
}
}
}
return obj;
};

47

main.js

@@ -14,6 +14,7 @@ /**

var transform = require("./lib/visit").transform;
var guessTabWidth = require("./lib/util").guessTabWidth;
var utils = require("./lib/util");
var recast = require("recast");
var esprimaHarmony = require("esprima");
var genFunExp = /\bfunction\s*\*/;
var blockBindingExp = /\b(let|const)\s+/;

@@ -26,7 +27,6 @@ assert.ok(

function regenerator(source, options) {
if (!options) {
options = {
includeRuntime: false
};
}
options = utils.extend(options || {}, {
includeRuntime: false,
supportBlockBinding: true
});

@@ -41,11 +41,38 @@ var runtime = options.includeRuntime ? fs.readFileSync(

var supportBlockBinding = !!options.supportBlockBinding;
if (supportBlockBinding) {
if (!blockBindingExp.test(source)) {
supportBlockBinding = false;
}
}
var recastOptions = {
tabWidth: guessTabWidth(source),
tabWidth: utils.guessTabWidth(source),
// Use the harmony branch of Esprima that installs with regenerator
// instead of the master branch that recast provides.
esprima: esprimaHarmony
esprima: esprimaHarmony,
range: supportBlockBinding
};
var ast = recast.parse(source, recastOptions);
var es5 = recast.print(transform(ast), recastOptions);
var recastAst = recast.parse(source, recastOptions);
var ast = recastAst.program;
// Transpile let/const into var declarations.
if (supportBlockBinding) {
var defsResult = require("defs")(ast, {
ast: true,
disallowUnknownReferences: false,
disallowDuplicated: false,
disallowVars: false,
loopClosures: "iife"
});
if (defsResult.errors) {
throw new Error(defsResult.errors.join("\n"))
}
}
recastAst.program = transform(ast);
var es5 = recast.print(recastAst, recastOptions);
return runtime + es5;

@@ -52,0 +79,0 @@ }

@@ -19,3 +19,3 @@ {

],
"version": "0.2.11",
"version": "0.3.0",
"homepage": "http://github.com/facebook/regenerator",

@@ -35,4 +35,5 @@ "repository": {

"ast-types": ">= 0.3.8",
"recast": "~0.4.23",
"private": "~0.0.5"
"recast": "~0.4.25",
"private": "~0.0.5",
"defs": "~0.6.0"
},

@@ -39,0 +40,0 @@ "devDependencies": {

@@ -71,3 +71,3 @@ /**

enqueue("mocha", [
"--harmony-generators",
"--harmony",
"--reporter", "spec",

@@ -74,0 +74,0 @@ "./test/tests.es6.js"

@@ -1051,1 +1051,59 @@ /**

});
describe("block binding", function() {
it("should translate block binding correctly", function() {
"use strict";
function *gen() {
var a$0 = 0, a$1 = 1;
let a = 3;
{
let a = 1;
yield a + a$0;
}
{
let a = 2;
yield a - 1 + a$1;
}
yield a;
}
var g = gen();
assert.deepEqual(g.next(), { value: 1, done: false });
assert.deepEqual(g.next(), { value: 2, done: false });
assert.deepEqual(g.next(), { value: 3, done: false });
assert.deepEqual(g.next(), { value: void 0, done: true });
});
it("should translate block binding with iife correctly", function() {
"use strict";
function *gen() {
let arr = [];
for (let x = 0; x < 3; x++) {
let y = x;
arr.push(function() { return y; });
}
{
let x;
while( x = arr.pop() ) {
yield x;
}
}
}
var g = gen();
assert.equal(g.next().value(), 2);
assert.equal(g.next().value(), 1);
assert.equal(g.next().value(), 0);
assert.deepEqual(g.next(), { value: void 0, done: true });
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc