@umijs/ast 4.0.21 → 4.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,6 @@
1
+ import type { ParserPlugin } from '@umijs/bundler-utils/compiled/babel/parser';
1
2
  import * as t from '@umijs/bundler-utils/compiled/babel/types';
2
- export declare function parse(code: string): t.File;
3
+ export declare function parse(code: string, opts?: {
4
+ excludePlugins?: ParserPlugin[];
5
+ includePlugins?: ParserPlugin[];
6
+ }): t.File;
@@ -26,22 +26,28 @@ __export(parse_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(parse_exports);
28
28
  var parser = __toESM(require("@umijs/bundler-utils/compiled/babel/parser"));
29
- function parse2(code) {
29
+ function parse2(code, opts = {}) {
30
+ const excludePlugins = opts.excludePlugins || [];
31
+ const includePlugins = opts.includePlugins || [];
32
+ const plugins = [
33
+ "jsx",
34
+ "typescript",
35
+ "classProperties",
36
+ "dynamicImport",
37
+ "exportDefaultFrom",
38
+ "exportNamespaceFrom",
39
+ "functionBind",
40
+ "nullishCoalescingOperator",
41
+ "objectRestSpread",
42
+ "optionalChaining",
43
+ "decorators-legacy",
44
+ ...includePlugins
45
+ ].filter((p) => {
46
+ return !excludePlugins.includes(p);
47
+ });
30
48
  return parser.parse(code, {
31
49
  sourceType: "module",
32
- plugins: [
33
- "jsx",
34
- "typescript",
35
- "classProperties",
36
- "dynamicImport",
37
- "exportDefaultFrom",
38
- "exportNamespaceFrom",
39
- "functionBind",
40
- "nullishCoalescingOperator",
41
- "objectRestSpread",
42
- "optionalChaining",
43
- "decorators-legacy"
44
- ],
50
+ plugins,
45
51
  allowAwaitOutsideFunction: true
46
52
  });
47
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/ast",
3
- "version": "4.0.21",
3
+ "version": "4.0.23",
4
4
  "description": "@umijs/ast",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/ast#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -21,7 +21,7 @@
21
21
  "test": "umi-scripts jest-turbo"
22
22
  },
23
23
  "dependencies": {
24
- "@umijs/bundler-utils": "4.0.21"
24
+ "@umijs/bundler-utils": "4.0.23"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"