Skip to content

Commit

Permalink
Fixes to composeWith with returnNewGenerator parameter. (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 12, 2020
1 parent 35de769 commit 668d91f
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,15 +677,14 @@ class Generator extends EventEmitter {
composeWith(generator, options, returnNewGenerator = false) {
if (typeof options === 'boolean') {
returnNewGenerator = options;
options = {};
}

let instantiatedGenerator;

if (Array.isArray(generator)) {
generator.forEach(gen => {
this.composeWith(gen, options);
});
return this;
const generators = generator.map(gen => this.composeWith(gen, options));
return returnNewGenerator ? generators : this;
}

const instantiate = (Generator, path) => {
Expand Down Expand Up @@ -728,10 +727,6 @@ class Generator extends EventEmitter {
options,
arguments: options.arguments
});

if (!instantiatedGenerator) {
return this;
}
} else {
throw err;
}
Expand Down Expand Up @@ -766,17 +761,17 @@ class Generator extends EventEmitter {
instantiatedGenerator = instantiate(generator.Generator, generator.path);
}

if (!instantiatedGenerator) {
return returnNewGenerator ? instantiatedGenerator : this;
}

if (this._running) {
instantiatedGenerator.run();
} else {
this._composedWith.push(instantiatedGenerator);
}

if (returnNewGenerator) {
return instantiatedGenerator;
}

return this;
return returnNewGenerator ? instantiatedGenerator : this;
}

/**
Expand Down

0 comments on commit 668d91f

Please sign in to comment.