Skip to content

Commit

Permalink
Switch files to a set
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored and nicolo-ribaudo committed Oct 9, 2020
1 parent ee5ca31 commit 5dc7c49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
18 changes: 10 additions & 8 deletions packages/babel-core/src/config/config-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type ConfigChain = {
plugins: Array<UnloadedDescriptor>,
presets: Array<UnloadedDescriptor>,
options: Array<ValidatedOptions>,
files: Array<string>,
files: Set<string>,
};

export type PresetInstance = {
Expand Down Expand Up @@ -72,7 +72,7 @@ export function* buildPresetChain(
plugins: dedupDescriptors(chain.plugins),
presets: dedupDescriptors(chain.presets),
options: chain.options.map(o => normalizeOptions(o)),
files: [],
files: new Set(),
};
}

Expand Down Expand Up @@ -131,7 +131,7 @@ export type RootConfigChain = ConfigChain & {
config: ConfigFile | void,
ignore: IgnoreFile | void,
isIgnored: boolean,
files: Array<string>,
files: Set<string>,
};

/**
Expand Down Expand Up @@ -221,7 +221,7 @@ export function* buildRootChain(
));

if (ignoreFile) {
fileChain.files.push(ignoreFile.filepath);
fileChain.files.add(ignoreFile.filepath);
}

if (
Expand Down Expand Up @@ -249,7 +249,7 @@ export function* buildRootChain(
}

if (babelrcFile && isIgnored) {
fileChain.files.push(babelrcFile.filepath);
fileChain.files.add(babelrcFile.filepath);
}
}

Expand Down Expand Up @@ -385,7 +385,7 @@ const loadFileChainWalker = makeChainWalker({
function* loadFileChain(input, context, files, baseLogger) {
const chain = yield* loadFileChainWalker(input, context, files, baseLogger);
if (chain) {
chain.files.push(input.filepath);
chain.files.add(input.filepath);
}

return chain;
Expand Down Expand Up @@ -649,7 +649,9 @@ function mergeChain(target: ConfigChain, source: ConfigChain): ConfigChain {
target.options.push(...source.options);
target.plugins.push(...source.plugins);
target.presets.push(...source.presets);
target.files.push(...source.files);
for (const file of source.files) {
target.files.add(file);
}

return target;
}
Expand All @@ -670,7 +672,7 @@ function emptyChain(): ConfigChain {
options: [],
presets: [],
plugins: [],
files: [],
files: new Set(),
};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/babel-core/src/config/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type PrivPartialConfig = {
ignore: IgnoreFile | void,
babelrc: ConfigFile | void,
config: ConfigFile | void,
files: Array<string>,
files: Set<string>,
};

export default function* loadPrivatePartialConfig(
Expand Down Expand Up @@ -196,15 +196,15 @@ class PartialConfig {
babelignore: string | void;
config: string | void;
isIgnored: boolean;
files: Array<string>;
files: Set<string>;

constructor(
options: ValidatedOptions,
babelrc: string | void,
ignore: string | void,
config: string | void,
isIgnored: boolean,
files: Array<string>,
files: Set<string>,
) {
this.options = options;
this.babelignore = ignore;
Expand Down
8 changes: 5 additions & 3 deletions packages/babel-core/test/config-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,11 @@ describe("buildConfigChain", function () {
root: path.dirname(filename),
comments: true,
},
files: [
files: new Set([
fixture("config-files", ".babelignore"),
fixture("config-files", "babelrc-extended", ".babelrc-extended"),
fixture("config-files", "babelrc-extended", ".babelrc"),
],
]),
});
});

Expand Down Expand Up @@ -1325,7 +1325,9 @@ describe("buildConfigChain", function () {
cwd: path.dirname(filename),
root: path.dirname(filename),
},
files: [fixture("config-files", "babelignore", ".babelignore")],
files: new Set([
fixture("config-files", "babelignore", ".babelignore"),
]),
});
});
});
Expand Down

0 comments on commit 5dc7c49

Please sign in to comment.