Skip to content

Commit

Permalink
Merge pull request #57 from fossamagna/fix-in-sequcen-expression
Browse files Browse the repository at this point in the history
Add global assignment in SequenceExpression to target for function generation.
  • Loading branch information
fossamagna committed Jan 21, 2019
2 parents da6a490 + 7d4ebf1 commit 8176603
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
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;

0 comments on commit 8176603

Please sign in to comment.