-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
typescript.js
39 lines (38 loc) · 1.17 KB
/
typescript.js
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
import { parse } from '@babel/parser';
import { getContent } from '../utils/file';
export default async function parseTypescript(filename) {
const content = await getContent(filename);
// Enable all known compatible @babel/parser plugins at the time of writing.
// Because we only parse them, not evaluate any code, it is safe to do so.
// note that babel/parser 7+ does not support *, due to plugin incompatibilities
return parse(content, {
sourceType: 'module',
plugins: [
'typescript',
'jsx',
'asyncGenerators',
'bigInt',
'classProperties',
'classPrivateProperties',
'classPrivateMethods',
// ['decorators', { decoratorsBeforeExport: true }],
'decorators-legacy',
'doExpressions',
'dynamicImport',
'exportDefaultFrom',
'exportNamespaceFrom',
'functionBind',
'functionSent',
'importMeta',
'logicalAssignment',
'nullishCoalescingOperator',
'numericSeparator',
'objectRestSpread',
'optionalCatchBinding',
'optionalChaining',
['pipelineOperator', { proposal: 'minimal' }],
'throwExpressions',
'importAssertions',
],
});
}