From 2a7fdc4f7273c5e824d1ecfa09b523abb8badec4 Mon Sep 17 00:00:00 2001 From: Justin Helmer Date: Wed, 4 Apr 2018 08:40:23 -0700 Subject: [PATCH] hot.accept tap interceptor returns T/F based on the number of args addresses #6919 --- lib/HotModuleReplacementPlugin.js | 8 ++++++-- test/hotCases/define/issue-6962/a.js | 3 +++ test/hotCases/define/issue-6962/index.js | 1 + test/hotCases/define/issue-6962/module.js | 19 +++++++++++++++++++ .../define/issue-6962/webpack.config.js | 11 +++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/hotCases/define/issue-6962/a.js create mode 100644 test/hotCases/define/issue-6962/index.js create mode 100644 test/hotCases/define/issue-6962/module.js create mode 100644 test/hotCases/define/issue-6962/webpack.config.js diff --git a/lib/HotModuleReplacementPlugin.js b/lib/HotModuleReplacementPlugin.js index 2ceccf123e1..96dd7f82b3e 100644 --- a/lib/HotModuleReplacementPlugin.js +++ b/lib/HotModuleReplacementPlugin.js @@ -343,13 +343,17 @@ module.exports = class HotModuleReplacementPlugin { parser.state.module.addDependency(dep); requests.push(request); }); - if (expr.arguments.length > 1) + if (expr.arguments.length > 1) { parser.hooks.hotAcceptCallback.call( expr.arguments[1], requests ); - else + parser.walkExpression(expr.arguments[1]); // other args are ignored + return true; + } else { parser.hooks.hotAcceptWithoutCallback.call(expr, requests); + return true; + } } } }); diff --git a/test/hotCases/define/issue-6962/a.js b/test/hotCases/define/issue-6962/a.js new file mode 100644 index 00000000000..4fd27070716 --- /dev/null +++ b/test/hotCases/define/issue-6962/a.js @@ -0,0 +1,3 @@ +export default 1; +--- +export default 2; diff --git a/test/hotCases/define/issue-6962/index.js b/test/hotCases/define/issue-6962/index.js new file mode 100644 index 00000000000..78b4fb26bba --- /dev/null +++ b/test/hotCases/define/issue-6962/index.js @@ -0,0 +1 @@ +import "./module"; diff --git a/test/hotCases/define/issue-6962/module.js b/test/hotCases/define/issue-6962/module.js new file mode 100644 index 00000000000..ee5dfe5eb07 --- /dev/null +++ b/test/hotCases/define/issue-6962/module.js @@ -0,0 +1,19 @@ +import value1 from "./a"; + +it("should have the expected static path defined", function() { + DEFINE_PATH.should.be.eql('./a'); +}); + +it("should hot.accept the module located at the static file path without breaking the compiler", function() { + module.hot.accept("./a"); + value1.should.be.eql(1); +}); + +it("should hot.accept the module located at the defined file path without breaking the compiler, when one argument is passed to hot.accept", function() { + module.hot.accept(DEFINE_PATH); +}); + +it("should hot.accept the module located at the defined file path without breaking the compiler, when multiple arguments are passed to hot.accept", function(done) { + module.hot.accept(DEFINE_PATH, () => done()); + NEXT(require("../../update")(done)); +}); diff --git a/test/hotCases/define/issue-6962/webpack.config.js b/test/hotCases/define/issue-6962/webpack.config.js new file mode 100644 index 00000000000..3d212ee5e1c --- /dev/null +++ b/test/hotCases/define/issue-6962/webpack.config.js @@ -0,0 +1,11 @@ +"use strict"; + +const webpack = require("../../../../"); + +module.exports = { + plugins: [ + new webpack.DefinePlugin({ + DEFINE_PATH: JSON.stringify("./a") + }) + ] +};