Skip to content

Commit b63574a

Browse files
committed
Provide a mechanism for tests to set their desired parser plugins
1 parent e126a3e commit b63574a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

__tests__/helper.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,27 @@ import getProp from '../src/getProp';
22

33
const parser = require('@babel/parser');
44

5+
const defaultPlugins = ['jsx', 'functionBind', 'estree', 'objectRestSpread', 'optionalChaining'];
6+
let plugins = [...defaultPlugins];
7+
8+
export function changePlugins(pluginOrFn) {
9+
if (Array.isArray(pluginOrFn)) {
10+
plugins = pluginOrFn;
11+
} else if (typeof pluginOrFn === 'function') {
12+
plugins = pluginOrFn(plugins);
13+
} else {
14+
throw new Error('changePlugins argument should be either an array or a function');
15+
}
16+
}
17+
18+
/* eslint-disable */
19+
beforeEach(() => {
20+
plugins = [...defaultPlugins];
21+
});
22+
/* eslint-enable */
23+
524
function parse(code) {
6-
return parser.parse(code, {
7-
plugins: [
8-
'estree',
9-
'functionBind',
10-
'jsx',
11-
'objectRestSpread',
12-
'optionalChaining',
13-
],
14-
});
25+
return parser.parse(code, { plugins });
1526
}
1627

1728
export function getOpeningElement(code) {

0 commit comments

Comments
 (0)