Skip to content

Commit

Permalink
refactor(test): replace specialized preset functions with makePresetF…
Browse files Browse the repository at this point in the history
…romPlugin
  • Loading branch information
Xunnamius committed Jan 9, 2023
1 parent 0b9b023 commit 435e993
Showing 1 changed file with 5 additions and 36 deletions.
41 changes: 5 additions & 36 deletions test/helpers/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PluginObj, PluginPass as State } from '@babel/core';
import type { PluginItem, PluginObj, PluginPass as State } from '@babel/core';
import type { PluginTesterOptions } from '../../src/index';

/**
Expand Down Expand Up @@ -32,27 +32,6 @@ export function makePluginWithOrderTracking(orderArray: number[], orderInt: numb
};
};
}
/**
* When called, returns a babel preset containing a no-op plugin that tracks
* invocation order.
*/
export function makePresetWithPluginWithOrderTracking(
orderArray: number[],
orderInt: number
): NonNullable<PluginTesterOptions['preset']> {
return () => ({
plugins: [
{
name: 'order-tracker',
visitor: {
Program() {
orderArray.push(orderInt);
}
}
}
]
});
}

/**
* When called, returns a babel plugin that appends a string to all identifiers.
Expand All @@ -71,22 +50,12 @@ export function makePluginThatAppendsToIdentifier(suffix: string) {
}

/**
* When called, returns a babel preset containing a plugin that appends a string
* to all identifiers.
* When called, returns a babel preset containing the provided plugin.
*/
export function makePresetWithPluginThatAppendsToIdentifier(
suffix: string
export function makePresetFromPlugin(
pluginOrFn: PluginItem | (() => PluginObj<unknown>)
): NonNullable<PluginTesterOptions['preset']> {
return () => ({
plugins: [
{
name: suffix,
visitor: {
Identifier(idPath) {
idPath.node.name += `_${suffix}`;
}
}
}
]
plugins: [typeof pluginOrFn == 'function' ? pluginOrFn() : pluginOrFn]
});
}

0 comments on commit 435e993

Please sign in to comment.