Skip to content

Commit

Permalink
fix parsing of requires in requires
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Dec 23, 2019
1 parent bd21c4d commit 2623157
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/dependencies/CommonJsImportsParserPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ class CommonJsImportsParserPlugin {
dep.asiSafe = !parser.isAsiPosition(expr.range[0]);
dep.loc = expr.callee.loc;
parser.state.module.addDependency(dep);
parser.walkExpressions(expr.arguments);
return true;
}
};
Expand Down
3 changes: 3 additions & 0 deletions test/cases/cjs-tree-shaking/parsing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should parse nested requires successfully", () => {
expect(require("./nested-require").value).toBe(42);
});
2 changes: 2 additions & 0 deletions test/cases/cjs-tree-shaking/parsing/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exports.fn = a => a + 1;
exports.value = 41;
1 change: 1 addition & 0 deletions test/cases/cjs-tree-shaking/parsing/nested-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.value = require("./module").fn(require("./module").value);

0 comments on commit 2623157

Please sign in to comment.