Skip to content

Commit

Permalink
Merge pull request #8844 from webpack/bugfix/8829
Browse files Browse the repository at this point in the history
fixes #8829
  • Loading branch information
sokra committed Feb 28, 2019
2 parents 3496426 + ab517aa commit 5e9b9fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/APIPlugin.js
Expand Up @@ -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));
}
});
};

Expand Down
9 changes: 9 additions & 0 deletions test/cases/parsing/typeof/index.js
Expand Up @@ -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");
Expand Down

0 comments on commit 5e9b9fe

Please sign in to comment.