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

Add global assignment in SequenceExpression to target for function generation. #57

Merged
merged 2 commits into from
Jan 21, 2019
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
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ function createStubFunctionASTNode(functionName, leadingComments, params) {
function _generateStubs(data, options) {
var ast = esprima.parseScript(data, { attachComment: options.comment });
var stubs = [];
var functionName;
estraverse.traverse(ast, {
leave: function (node) {
if (node.type === 'ExpressionStatement'
&& isGlobalAssignmentExpression(node.expression)) {
var functionName = node.expression.left.property.name;
functionName = node.expression.left.property.name;
stubs.push(createStubFunctionASTNode(functionName, node.leadingComments, node.expression.right.params));
} else if (node.type === 'ExpressionStatement'
&& node.expression.type === 'SequenceExpression') {
node.expression.expressions.forEach(function (expression) {
if (isGlobalAssignmentExpression(expression)) {
functionName = expression.left.property.name;
stubs.push(createStubFunctionASTNode(functionName, node.leadingComments, expression.right.params));
}
});
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ function foo() {
*/
// leading line comment for boo
function boo(message) {
}
function test() {
}
function X() {
}
4 changes: 4 additions & 0 deletions test/fixtures/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ global.foo = function () {
// leading line comment for boo
global.boo = function (message) {
};
function test() {
};
var X = 'x';
global.test = test, global.X = X;