Skip to content

Commit

Permalink
Only keep assumptions used in the tests, everything else will be in o…
Browse files Browse the repository at this point in the history
…ther PRs
  • Loading branch information
nicolo-ribaudo committed Nov 27, 2020
1 parent 9aaf0da commit da76ea2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
16 changes: 0 additions & 16 deletions packages/babel-core/src/config/validation/options.js
Expand Up @@ -332,25 +332,9 @@ type EnvPath = $ReadOnly<{
export type NestingPath = RootPath | OverridesPath | EnvPath;

export const assumptionsNames = new Set<string>([
"arrayLikeIsIterable",
"arrayIndexedIteration",
"copyReexports",
"ignoreFunctionLength",
"ignoreToPrimitiveHint",
"inheritsAsObjectCreate",
"iterableIsArray",
"mutableTemplateObject",
"newableArrowFunctions",
"noDocumentAll",
"objectRestNoSymbols",
"privateFieldsAsPublic",
"setClassMethods",
"setComputedProperties",
"setModuleMeta",
"setPublicClassFields",
"setSpreadProperties",
"skipForOfIterationClosing",
"superAsFunctionCall",
]);

function getSource(loc: NestingPath): OptionsSource {
Expand Down
29 changes: 13 additions & 16 deletions packages/babel-core/test/assumptions.js
Expand Up @@ -34,11 +34,11 @@ describe("assumptions", () => {
assumptions: {
setPublicClassFields: true,
},
presets: [() => ({ assumptions: { setClassMethods: true } })],
presets: [() => ({ assumptions: { mutableTemplateObject: true } })],
}).assumptions,
).toEqual({
setPublicClassFields: true,
setClassMethods: true,
mutableTemplateObject: true,
// This is enabled by default
newableArrowFunctions: true,
});
Expand Down Expand Up @@ -93,7 +93,6 @@ describe("assumptions", () => {
const makePlugin = () =>
jest.fn(api => {
api.assumption("setPublicClassFields");
api.assumption("mutableTemplateObject");
return {};
});

Expand All @@ -110,11 +109,11 @@ describe("assumptions", () => {

run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});
run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});

expect(plugin).toHaveBeenCalledTimes(1);
Expand All @@ -125,11 +124,11 @@ describe("assumptions", () => {

run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});
run(plugin, {
setPublicClassFields: true,
setClassMethods: true,
mutableTemplateObject: true,
});

expect(plugin).toHaveBeenCalledTimes(1);
Expand All @@ -140,11 +139,11 @@ describe("assumptions", () => {

run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});
run(plugin, {
setPublicClassFields: false,
setClassMethods: true,
mutableTemplateObject: true,
});

expect(plugin).toHaveBeenCalledTimes(2);
Expand All @@ -154,13 +153,11 @@ describe("assumptions", () => {
const plugin = makePlugin();

run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});
run(plugin, {
setPublicClassFields: false,
setClassMethods: true,
mutableTemplateObject: true,
mutableTemplateObject: false,
setPublicClassFields: true,
});

expect(plugin).toHaveBeenCalledTimes(2);
Expand All @@ -171,10 +168,10 @@ describe("assumptions", () => {

run(plugin, {
setPublicClassFields: true,
setClassMethods: false,
mutableTemplateObject: false,
});
run(plugin, {
setClassMethods: true,
mutableTemplateObject: true,
});

expect(plugin).toHaveBeenCalledTimes(2);
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-helper-plugin-utils/src/index.js
Expand Up @@ -2,12 +2,12 @@ export function declare(builder) {
return (api, options, dirname) => {
let clonedApi;

for (const [name, create] of Object.entries(apiPolyfills)) {
for (const [name] of Object.keys(apiPolyfills)) {
if (api[name]) continue;

// TODO: Use ??= when flow lets us to do so
clonedApi = clonedApi ?? copyApiObject(api);
clonedApi[name] = create(clonedApi);
clonedApi[name] = apiPolyfills[name](clonedApi);
}

return builder(clonedApi ?? api, options || {}, dirname);
Expand Down

0 comments on commit da76ea2

Please sign in to comment.