Skip to content

Commit

Permalink
emit correct code for typeof require.resolve(Weak) and require
Browse files Browse the repository at this point in the history
fixes #5198
  • Loading branch information
sokra committed Jul 7, 2017
1 parent 4bb3018 commit b95af19
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dependencies/CommonJsPlugin.js
Expand Up @@ -54,7 +54,7 @@ class CommonJsPlugin {

const requireExpressions = ["require", "require.resolve", "require.resolveWeak"];
for(let expression of requireExpressions) {
parser.plugin(`typeof ${expression}`, ParserHelpers.toConstantDependency("function"));
parser.plugin(`typeof ${expression}`, ParserHelpers.toConstantDependency(JSON.stringify("function")));
parser.plugin(`evaluate typeof ${expression}`, ParserHelpers.evaluateToString("function"));
parser.plugin(`evaluate Identifier ${expression}`, ParserHelpers.evaluateToIdentifier(expression, true));
}
Expand Down
4 changes: 4 additions & 0 deletions test/cases/parsing/typeof/index.js
Expand Up @@ -26,6 +26,9 @@ it("should answer typeof require.include correctly", function() {
it("should answer typeof require.ensure correctly", function() {
(typeof require.ensure).should.be.eql("function");
});
it("should answer typeof require.resolve correctly", function() {
(typeof require.resolve).should.be.eql("function");
});
it("should answer typeof System correctly", function() {
(typeof System).should.be.eql("object");
});
Expand All @@ -41,6 +44,7 @@ it("should not parse filtered stuff", function() {
if(!(typeof require === "function")) require("fail");
if(typeof require == "undefined") require = require("fail");
if(typeof require === "undefined") require = require("fail");
if(typeof require.resolve !== "function") require("fail");
if(typeof module == "undefined") module = require("fail");
if(typeof module === "undefined") module = require("fail");
if(typeof module != "object") module = require("fail");
Expand Down

0 comments on commit b95af19

Please sign in to comment.