Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2018-04-24 14:29:51 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2018-04-24 14:29:51 +0300
commit460dfd1eb65cff2935fae460a6c71b0171b226c7 (patch)
tree6d724a4b39df388ee7cde407ca6b9b05db019c87
parent6ffd4d1405c9f812f7bcd3b915f4da262afec754 (diff)
Fix const regex
Fixes an issue where const wasn't properly detected when using destructering.
-rw-r--r--lib/moduleEnv.js2
-rw-r--r--testLib/constModule.js4
-rw-r--r--testLib/sharedTestCases.js9
3 files changed, 11 insertions, 4 deletions
diff --git a/lib/moduleEnv.js b/lib/moduleEnv.js
index 599e332..3b05bca 100644
--- a/lib/moduleEnv.js
+++ b/lib/moduleEnv.js
@@ -42,7 +42,7 @@ var moduleWrapper0 = Module.wrapper[0],
// However, since most projects have a seperate linting step which catches these const re-assignment
// errors anyway, it's probably still a reasonable trade-off.
// Test the regular expresssion at https://regex101.com/r/dvnZPv/2 and also check out testLib/constModule.js.
- matchConst = /(^|\s|\}|;)const(\/\*|\s)/gm,
+ matchConst = /(^|\s|\}|;)const(\/\*|\s|{)/gm,
nodeRequire,
currentModule;
diff --git a/testLib/constModule.js b/testLib/constModule.js
index efff495..360a0f5 100644
--- a/testLib/constModule.js
+++ b/testLib/constModule.js
@@ -9,6 +9,7 @@ const
g = "g";
const/*wtf this is valid*/h = "h";
const /*and this is also*/i = "i";
+const{k} = {k: "k"};
exports.a = function () {
return a;
@@ -40,3 +41,6 @@ exports.i = function () {
exports.j = function () {
return j;
};
+exports.k = function () {
+ return k;
+};
diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js
index 6cd9b2e..9b709c2 100644
--- a/testLib/sharedTestCases.js
+++ b/testLib/sharedTestCases.js
@@ -388,10 +388,13 @@ module.exports = function () {
it("should be possible to set a const variable", function () {
var constModule = rewire("./constModule");
+ var varNames = Object.keys(constModule);
- "abcdefghij".split("").forEach(letter => {
- constModule.__set__(letter, "this has been changed"); // should not throw
- expect(constModule[letter]()).to.equal("this has been changed");
+ expect(varNames.length).to.be.greaterThan(0);
+
+ varNames.forEach(varName => {
+ constModule.__set__(varName, "this has been changed"); // should not throw
+ expect(constModule[varName]()).to.equal("this has been changed");
});
});