Skip to content

Commit 2a7fdc4

Browse files
author
Justin Helmer
committed
hot.accept tap interceptor returns T/F based on the number of args
addresses webpack#6919
1 parent f5bd213 commit 2a7fdc4

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

lib/HotModuleReplacementPlugin.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,17 @@ module.exports = class HotModuleReplacementPlugin {
343343
parser.state.module.addDependency(dep);
344344
requests.push(request);
345345
});
346-
if (expr.arguments.length > 1)
346+
if (expr.arguments.length > 1) {
347347
parser.hooks.hotAcceptCallback.call(
348348
expr.arguments[1],
349349
requests
350350
);
351-
else
351+
parser.walkExpression(expr.arguments[1]); // other args are ignored
352+
return true;
353+
} else {
352354
parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
355+
return true;
356+
}
353357
}
354358
}
355359
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default 1;
2+
---
3+
export default 2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./module";
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import value1 from "./a";
2+
3+
it("should have the expected static path defined", function() {
4+
DEFINE_PATH.should.be.eql('./a');
5+
});
6+
7+
it("should hot.accept the module located at the static file path without breaking the compiler", function() {
8+
module.hot.accept("./a");
9+
value1.should.be.eql(1);
10+
});
11+
12+
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() {
13+
module.hot.accept(DEFINE_PATH);
14+
});
15+
16+
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) {
17+
module.hot.accept(DEFINE_PATH, () => done());
18+
NEXT(require("../../update")(done));
19+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
const webpack = require("../../../../");
4+
5+
module.exports = {
6+
plugins: [
7+
new webpack.DefinePlugin({
8+
DEFINE_PATH: JSON.stringify("./a")
9+
})
10+
]
11+
};

0 commit comments

Comments
 (0)