Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove _shadowFunctionLiteral use #388

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/regenerator-transform/src/visit.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,9 @@ exports.getVisitor = ({ types: t }) => ({

if (context.usesArguments) {
vars = vars || t.variableDeclaration("var", []);
const argumentIdentifier = t.identifier("arguments");
// we need to do this as otherwise arguments in arrow functions gets hoisted
argumentIdentifier._shadowedFunctionLiteral = path;
vars.declarations.push(t.variableDeclarator(
t.clone(argsId), argumentIdentifier
t.clone(argsId),
t.identifier("arguments"),
));
}

Expand Down
28 changes: 28 additions & 0 deletions test/tests.transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var assert = require("assert");
var recast = require("recast");
var v8 = require("v8");
var types = recast.types;
var n = types.namedTypes;
var transform = require("..").transform;
Expand Down Expand Up @@ -331,3 +332,30 @@ context("functions", function() {
});
});
});

describe("ast serialization", function() {
function getAST() {
return require("@babel/core").transformSync(
`function* foo() {
arguments;
}`,
{
ast: true,
configFile: false,
plugins: [require("../packages/regenerator-transform")],
},
).ast;
}

it("produces an ast that is JSON serializable", function() {
assert.doesNotThrow(function() {
JSON.stringify(getAST());
});
})

it("produces an ast that is serializable with v8's serializer", function() {
assert.doesNotThrow(function() {
v8.serialize(getAST());
});
})
})