Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const regex #139

Merged
merged 1 commit into from Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/moduleEnv.js
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
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
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