-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.mjs
More file actions
43 lines (34 loc) · 1.23 KB
/
index.mjs
File metadata and controls
43 lines (34 loc) · 1.23 KB
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
42
43
import createJsLoader from '../../loaders/javascript.mjs';
import createJsParser from '../../parsers/javascript.mjs';
/**
* This generator parses Javascript sources passed into the generator's input
* field. This is separate from the Markdown parsing step since it's not as
* commonly used and can take up a significant amount of memory.
*
* Putting this with the rest of the generators allows it to be lazily loaded
* so we're only parsing the Javascript sources when we need to.
*
* @typedef {unknown} Input
*
* @type {GeneratorMetadata<Input, Array<JsProgram>>}
*/
export default {
name: 'ast-js',
version: '1.0.0',
description: 'Parses Javascript source files passed into the input.',
dependsOn: 'ast',
/**
* @param {Input} _
* @param {Partial<GeneratorOptions>} options
*/
async generate(_, options) {
const { loadFiles } = createJsLoader();
// Load all of the Javascript sources into memory
const sourceFiles = loadFiles(options.input ?? []);
const { parseJsSources } = createJsParser();
// Parse the Javascript sources into ASTs
const parsedJsFiles = await parseJsSources(sourceFiles);
// Return the ASTs so they can be used in another generator
return parsedJsFiles;
},
};