Skip to content

Commit

Permalink
Bit more refactoring from last PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth committed Oct 6, 2017
1 parent 586a738 commit d511cfc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/babel-core/src/config/option-manager.js
Expand Up @@ -291,9 +291,10 @@ const loadConfig = makeWeakCache((config): {
* Load a generic plugin/preset from the given descriptor loaded from the config object.
*/
const loadDescriptor = makeWeakCache(
(descriptor: BasicDescriptor, cache): LoadedDescriptor => {
const { value, options = {}, dirname, alias, loc } = descriptor;

(
{ value, options = {}, dirname, alias, loc }: BasicDescriptor,
cache,
): LoadedDescriptor => {
let item = value;
if (typeof value === "function") {
const api = Object.assign(Object.create(context), {
Expand All @@ -302,12 +303,10 @@ const loadDescriptor = makeWeakCache(
});

try {
item = value(api, options, { dirname: descriptor.dirname });
item = value(api, options, { dirname });
} catch (e) {
if (descriptor.alias) {
e.message += ` (While processing: ${JSON.stringify(
descriptor.alias,
)})`;
if (alias) {
e.message += ` (While processing: ${JSON.stringify(alias)})`;
}
throw e;
}
Expand All @@ -317,7 +316,7 @@ const loadDescriptor = makeWeakCache(
throw new Error("Plugin/Preset did not return an object.");
}

return { value: item, options, descriptor, dirname, alias, loc };
return { value: item, options, dirname, alias, loc };
},
);

Expand Down

0 comments on commit d511cfc

Please sign in to comment.