Skip to content

Commit

Permalink
Merge pull request #139 from jhnns/fix/const-regex
Browse files Browse the repository at this point in the history
Fix const regex
  • Loading branch information
jhnns authored Apr 24, 2018
2 parents 6ffd4d1 + 460dfd1 commit c059ffc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/moduleEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions testLib/constModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,3 +41,6 @@ exports.i = function () {
exports.j = function () {
return j;
};
exports.k = function () {
return k;
};
9 changes: 6 additions & 3 deletions testLib/sharedTestCases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

Expand Down

0 comments on commit c059ffc

Please sign in to comment.