Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests, refactor how optional chaining handles
- Loading branch information
Showing
11 changed files
with
106 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
module.exports = 1; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
it("should handle optional members", () => { | ||
expect( | ||
module.hot?.accept((() => {throw new Error("fail")})()) | ||
).toBe(null); | ||
it("should evaluate optional members", () => { | ||
if (!module.hot) { | ||
expect( | ||
module.hot?.accept((() => {throw new Error("fail")})()) | ||
).toBe(undefined); | ||
} | ||
}); | ||
|
||
it("should evaluate optional chaining as a part of statement", () => { | ||
if (module.hot?.accept) { | ||
module.hot?.accept("./a.js"); | ||
} else { | ||
expect(module.hot).toBe(undefined); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const supportsOptionalChaining = require("../../../helpers/supportsOptionalChaining"); | ||
|
||
/** | ||
* @param {import("../../../../").Configuration} config | ||
* @returns {boolean} | ||
*/ | ||
module.exports = function (config) { | ||
if (config.mode === "production") return false; | ||
if (config.optimization && config.optimization.minimizer) return false; | ||
|
||
return supportsOptionalChaining(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var supportsOptionalChaining = require("../../../helpers/supportsOptionalChaining"); | ||
|
||
module.exports = function (config) { | ||
return supportsOptionalChaining(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = function supportsOptionalChaining() { | ||
try { | ||
var f = eval("(function f() { return ({a: true}) ?.a })"); | ||
return f(); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
it("should run module.hot.accept(…)", function() { | ||
module?.hot?.accept("./a", function() {}); | ||
}); | ||
|
||
it("should skip rest members", function() { | ||
module?.hot.accept(); | ||
}); |