From b95af19651525033d7e8613c2d8bc514b698fdbf Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Fri, 7 Jul 2017 10:26:58 +0200 Subject: [PATCH] emit correct code for typeof require.resolve(Weak) and require fixes #5198 --- lib/dependencies/CommonJsPlugin.js | 2 +- test/cases/parsing/typeof/index.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/dependencies/CommonJsPlugin.js b/lib/dependencies/CommonJsPlugin.js index eb367534667..ef9af51ccc7 100644 --- a/lib/dependencies/CommonJsPlugin.js +++ b/lib/dependencies/CommonJsPlugin.js @@ -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)); } diff --git a/test/cases/parsing/typeof/index.js b/test/cases/parsing/typeof/index.js index 15b8edbd53e..a3142febb7f 100644 --- a/test/cases/parsing/typeof/index.js +++ b/test/cases/parsing/typeof/index.js @@ -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"); }); @@ -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");