-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathexample.js
More file actions
41 lines (35 loc) · 1018 Bytes
/
Copy pathexample.js
File metadata and controls
41 lines (35 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { parse as acornParse } from 'acorn';
import { parseFunction } from './dist/module';
// `node` is an AST Node
function bobbyPlugin(node, result) {
const bobby = 'bobby';
return { ...result, bobby };
}
function barryPlugin(node, result) {
return { ...result, barry: 'barry barry' };
}
const result = parseFunction(bobbyPlugin.toString(), {
parse: acornParse,
plugins: [bobbyPlugin, barryPlugin], // supports array of plugins
parserOptions: {},
});
console.log(result);
/* {
name: 'bobbyPlugin',
body: "\n const bobby = 'bobby';\n\n return { ...result, bobby };\n",
args: [ 'node', 'result' ],
params: 'node, result',
defaults: { node: undefined, result: undefined },
value: '(function bobbyPlugin(node, result) {\n const ' +
"bobby = 'bobby';\n\n return { ...result, bobby };\n" +
'})',
isValid: true,
isArrow: false,
isAsync: false,
isNamed: true,
isAnonymous: false,
isGenerator: false,
isExpression: false,
bobby: 'bobby',
barry: 'barry barry'
} */