Skip to content

Commit 31396b2

Browse files
Make loadPartialConfig's options optional (#12200)
1 parent 47250ff commit 31396b2

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/babel-core/src/config/partial.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ type LoadPartialConfigOpts = {
157157
};
158158

159159
export const loadPartialConfig = gensync<[any], PartialConfig | null>(
160-
function* (inputOpts: LoadPartialConfigOpts): Handler<PartialConfig | null> {
161-
const { showIgnoredFiles, ...opts } = inputOpts;
160+
function* (opts?: LoadPartialConfigOpts): Handler<PartialConfig | null> {
161+
let showIgnoredFiles = false;
162+
// We only extract showIgnoredFiles if opts is an object, so that
163+
// loadPrivatePartialConfig can throw the appropriate error if it's not.
164+
if (typeof opts === "object" && opts !== null && !Array.isArray(opts)) {
165+
({ showIgnoredFiles, ...opts } = opts);
166+
}
167+
162168
const result: ?PrivPartialConfig = yield* loadPrivatePartialConfig(opts);
163169
if (!result) return null;
164170

packages/babel-core/test/config-chain.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,17 @@ describe("buildConfigChain", function () {
13301330
]),
13311331
});
13321332
});
1333+
1334+
it("loadPartialConfig can be called with no arguments", () => {
1335+
const cwd = process.cwd();
1336+
1337+
try {
1338+
process.chdir(fixture("config-files", "babelrc-extended"));
1339+
expect(() => babel.loadPartialConfig()).not.toThrow();
1340+
} finally {
1341+
process.chdir(cwd);
1342+
}
1343+
});
13331344
});
13341345

13351346
it("should throw when `test` presents but `filename` is not passed", () => {

0 commit comments

Comments
 (0)