diff --git a/lib/APIPlugin.js b/lib/APIPlugin.js index 6cd80646dcd..bc084f011bc 100644 --- a/lib/APIPlugin.js +++ b/lib/APIPlugin.js @@ -58,12 +58,12 @@ class APIPlugin { REPLACEMENTS[key] ) ); - parser.hooks.evaluateTypeof - .for(key) - .tap( - "APIPlugin", - ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]) - ); + const type = REPLACEMENT_TYPES[key]; + if (type) { + parser.hooks.evaluateTypeof + .for(key) + .tap("APIPlugin", ParserHelpers.evaluateToString(type)); + } }); }; diff --git a/test/cases/parsing/typeof/index.js b/test/cases/parsing/typeof/index.js index 93e366595ce..b8bf95b0e8d 100644 --- a/test/cases/parsing/typeof/index.js +++ b/test/cases/parsing/typeof/index.js @@ -29,6 +29,15 @@ it("should answer typeof require.ensure correctly", function() { it("should answer typeof require.resolve correctly", function() { expect((typeof require.resolve)).toBe("function"); }); +it("should answer typeof __non_webpack_require__ correctly", function() { + var oldValue; + eval("oldValue = require;"); + expect((typeof __non_webpack_require__)).toBe("function"); + eval("require = undefined;"); + expect((typeof __non_webpack_require__)).toBe("undefined"); + eval("require = oldValue;"); + expect((typeof __non_webpack_require__)).toBe("function"); +}); it("should not parse filtered stuff", function() { if(typeof require != "function") require("fail");