1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const extname_js_1 = require("./libs/extname.js");
|
4 | function generateConfig(filePath, code, _options) {
|
5 | const plugins = [
|
6 | 'asyncGenerators',
|
7 | 'bigInt',
|
8 | 'classProperties',
|
9 | 'classPrivateProperties',
|
10 | 'classPrivateMethods',
|
11 | 'decorators-legacy',
|
12 | 'doExpressions',
|
13 | 'dynamicImport',
|
14 | 'exportDefaultFrom',
|
15 | 'exportNamespaceFrom',
|
16 | 'functionBind',
|
17 | 'functionSent',
|
18 | 'importMeta',
|
19 | 'logicalAssignment',
|
20 | 'nullishCoalescingOperator',
|
21 | 'numericSeparator',
|
22 | 'objectRestSpread',
|
23 | 'optionalCatchBinding',
|
24 | 'optionalChaining',
|
25 | ['pipelineOperator', { proposal: 'smart' }],
|
26 | 'throwExpressions',
|
27 | ];
|
28 |
|
29 |
|
30 | const flowPlugins = [['flow', { all: true }], 'flowComments'];
|
31 |
|
32 | const dynamicFlowPlugins = code.includes('@flow') ? flowPlugins : [];
|
33 | const fileExt = (0, extname_js_1.getExtNameFromFilePath)(filePath);
|
34 | switch (fileExt) {
|
35 | case '.ts':
|
36 | plugins.push('typescript');
|
37 | break;
|
38 | case '.tsx':
|
39 | plugins.push('typescript', 'jsx');
|
40 | break;
|
41 |
|
42 |
|
43 |
|
44 | case '.js':
|
45 | plugins.push('jsx', ...dynamicFlowPlugins);
|
46 | break;
|
47 | case '.jsx':
|
48 | plugins.push('jsx', ...dynamicFlowPlugins);
|
49 | break;
|
50 | case '.flow.js':
|
51 | plugins.push('jsx', ...flowPlugins);
|
52 | break;
|
53 | case '.flow.jsx':
|
54 | plugins.push('jsx', ...flowPlugins);
|
55 | break;
|
56 | case '.flow':
|
57 | plugins.push('jsx', ...flowPlugins);
|
58 | break;
|
59 | case '.vue':
|
60 | plugins.push('typescript', 'vue');
|
61 | break;
|
62 | case '.svelte':
|
63 | plugins.push('typescript', 'svelte');
|
64 | break;
|
65 | default:
|
66 | plugins.push('jsx', ...dynamicFlowPlugins);
|
67 | break;
|
68 | }
|
69 |
|
70 |
|
71 | return {
|
72 | sourceType: 'module',
|
73 | plugins,
|
74 | allowUndeclaredExports: true,
|
75 | };
|
76 | }
|
77 | exports.default = generateConfig;
|