Skip to content

Commit db26265

Browse files
committed
fix test and linting
1 parent c06b066 commit db26265

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

lib/NormalModule.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ class NormalModule extends Module {
339339
}
340340

341341
splitVariablesInUniqueNamedChunks(vars) {
342+
const startState = [
343+
[]
344+
];
342345
return vars.reduce((chunks, variable) => {
343346
const current = chunks[chunks.length - 1];
344347
// check if variable with same name exists already
@@ -353,7 +356,7 @@ class NormalModule extends Module {
353356
current.push(variable);
354357
}
355358
return chunks;
356-
}, [[]]);
359+
}, startState);
357360
}
358361

359362
sourceBlock(block, availableVars, dependencyTemplates, source, outputOptions, requestShortener) {
@@ -369,7 +372,12 @@ class NormalModule extends Module {
369372
variable, availableVars, dependencyTemplates, outputOptions, requestShortener))
370373
.filter(Boolean);
371374

372-
// if we actually have variables
375+
/**
376+
* if we actually have variables
377+
* this is important as how #splitVariablesInUniqueNamedChunks works
378+
* it will always return an array in an array which would lead to a IIFE wrapper around
379+
* a module if we do this with an empty vars array.
380+
*/
373381
if(vars.length > 0) {
374382
/**
375383
* Split all variables up into chunks of unique names.

test/NormalModule.test.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,22 @@ describe("NormalModule", function() {
246246
let variables;
247247
beforeEach(function() {
248248
variables = [{
249-
name: "foo"
250-
},
251-
{
252-
name: "bar"
253-
},
254-
{
255-
name: "baz"
256-
},
257-
{
258-
name: "some"
259-
},
260-
{
261-
name: "more"
262-
}
263-
];
249+
name: "foo"
250+
}, {
251+
name: "bar"
252+
}, {
253+
name: "baz"
254+
}, {
255+
name: "some"
256+
}, {
257+
name: "more"
258+
}];
264259
});
265260
describe("given an empty array of vars", function() {
266261
it("returns an empty array", function() {
267-
normalModule.splitVariablesInUniqueNamedChunks([]).should.eql([]);
262+
normalModule.splitVariablesInUniqueNamedChunks([]).should.eql([
263+
[]
264+
]);
268265
});
269266
});
270267
describe("given an array of distrinct variables", function() {

0 commit comments

Comments
 (0)