/
index.ts
37 lines (32 loc) 路 1.07 KB
/
index.ts
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
/* eslint-disable @babel/development/plugin-name */
import { declare } from "@babel/helper-plugin-utils";
import syntaxDecorators from "@babel/plugin-syntax-decorators";
import {
createClassFeaturePlugin,
FEATURES,
} from "@babel/helper-create-class-features-plugin";
import legacyVisitor from "./transformer-legacy";
import transformer2021_12 from "./transformer-2021-12";
import type { Options } from "@babel/plugin-syntax-decorators";
export default declare((api, options: Options) => {
api.assertVersion(7);
// Options are validated in @babel/plugin-syntax-decorators
const { legacy, version } = options;
if (legacy || version === "legacy") {
return {
name: "proposal-decorators",
inherits: syntaxDecorators,
visitor: legacyVisitor,
};
} else if (version === "2021-12") {
return transformer2021_12(api, options);
} else {
return createClassFeaturePlugin({
name: "proposal-decorators",
api,
feature: FEATURES.decorators,
inherits: syntaxDecorators,
// loose: options.loose, Not supported
});
}
});