Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(node) {
if (node.async || node.generator) {
// Although this code transforms only the subtree rooted at the given
// Function node, that node might contain other generator functions
// that will also be transformed. It might help performance to ignore
// nested functions, and rely on the traversal to visit them later,
// but that's a small optimization. Starting here instead of at the
// root of the AST is the key optimization, since huge async/generator
// functions are relatively rare.
regenerator.transform(convertNodePath(this));
}
}
}
exit(node) {
if (node.async || node.generator) {
// Although this code transforms only the subtree rooted at the given
// Function node, that node might contain other generator functions
// that will also be transformed. It might help performance to ignore
// nested functions, and rely on the traversal to visit them later,
// but that's a small optimization. Starting here instead of at the
// root of the AST is the key optimization, since huge async/generator
// functions are relatively rare.
regenerator.transform(convertNodePath(this));
}
}
}
transform: function (code, id) {
// if `opts.include` is omitted or has zero length, filter
// will return `true` by default. Otherwise, an ID must match
// one or more of the minimatch patterns, and must not match
// any of the `opts.exclude` patterns.
if (!filter(id)) {
return;
}
// proceed with the transformation...
var res;
if (withSourceMap) {
var inputAst = recastParse(code, {
sourceFileName: id
});
var outputAst = regeneratorTransform(inputAst);
res = recastPrint(outputAst, {
sourceMapName: id
});
} else {
res = regeneratorCompile(code);
}
return {
code: res.code,
map: withSourceMap && res.map ? res.map : { mappings: '' }
};
}
};
transform: function (code, id) {
// if `opts.include` is omitted or has zero length, filter
// will return `true` by default. Otherwise, an ID must match
// one or more of the minimatch patterns, and must not match
// any of the `opts.exclude` patterns.
if (!filter(id)) {
return;
}
// proceed with the transformation...
var res;
if (withSourceMap) {
var inputAst = recast.parse(code, {
sourceFileName: id
});
var outputAst = regenerator.transform(inputAst);
res = recast.print(outputAst, {
sourceMapName: id
});
} else {
res = regenerator.compile(code);
}
return {
code: res.code,
map: withSourceMap && res.map ? res.map : { mappings: '' }
};
}
};
var genFunc = {
type: "FunctionDeclaration",
id: builder.createIdentifier("genFunc"),
params: [ builder.createIdentifier("context") ],
defaults: [ ],
rest: null,
body: {
type: "BlockStatement",
body: ast.body
},
generator: true,
expression: false
};
console.log(escodegen.generate(genFunc));
regenerator.transform(genFunc);
var body = genFunc.body.body;
var success = false;
for (var i = 0; i < body.length; i++) {
var stmt = body[i];
if (stmt.type === "ReturnStatement") {
var arg = stmt.argument;
if (arg.type === "CallExpression") {
var callee = arg.callee;
if (callee.type === "MemberExpression") {
if (callee.object.type === "Identifier" &&
callee.property.type === "Identifier") {
var objName = callee.object.name;
var propName = callee.property.name;
${escodegen.generate(ast)}
}`;
generator = new Function(debugCode);
} else {
var entry = {
type: "Program",
body: [functionDeclaration(
identifier("entry"),
[identifier(contextName)],
blockStatement(ast.body),
true
)]
};
debugCode = escodegen.generate(regenerator.transform(entry));
generator = new Function(debugCode + "\n" + "return entry;");
}
if (options.debug) {
console.log(debugCode);
}
return generator;
};
Machine.prototype.$transform = function (code, filename) {
var ast = recast.parse(code);
filename = filename || ('file' + (++this.$anonFileId));
var transformed = transform(ast, { filename: filename });
if (!isGenSupported) {
transformed = regenerator.transform(transformed);
}
return recast.print(transformed).code;
};
}
if (options['class'] !== false) {
ast = es6class.transform(ast);
}
if (options.rest !== false) {
ast = es6restParams.transform(ast);
}
if (options.defaultParams !== false) {
ast = es6defaultParams.transform(ast);
}
if (options.generator !== false) {
ast = regenerator.transform(ast);
}
if (options.regexpu !== false) {
ast = regexpu.transform(ast);
}
if (options.spread !== false) {
ast = es6spread.transform(ast);
}
if (options.templates !== false) {
ast = es6templates.transform(ast);
}
if (options.generator !== false && options.includeRuntime) {
var runtime = fs.readFileSync(regenerator.runtime.path, 'utf8');