Debian Codegraph @

packages/babel-plugin-proposal-decorators/src/index.ts

raw
1 /* eslint-disable @babel/development/plugin-name */
2
3 import { declare } from "@babel/helper-plugin-utils";
4 import syntaxDecorators from "@babel/plugin-syntax-decorators";
5 import {
6 createClassFeaturePlugin,
7 FEATURES,
8 } from "@babel/helper-create-class-features-plugin";
9 import legacyVisitor from "./transformer-legacy";
10 import transformer2022_03 from "./transformer-2022-03";
11 import type { Options as SyntaxOptions } from "@babel/plugin-syntax-decorators";
12
13 interface Options extends SyntaxOptions {
14 /** @depreated use `constantSuper` assumption instead. Only supported in 2021-12 version. */
15 loose?: boolean;
16 }
17
18 export type { Options };
19
20 export default declare((api, options: Options) => {
21 api.assertVersion(7);
22
23 // Options are validated in @babel/plugin-syntax-decorators
24 if (!process.env.BABEL_8_BREAKING) {
25 // eslint-disable-next-line no-var
26 var { legacy } = options;
27 }
28 const { version } = options;
29
30 if (
31 process.env.BABEL_8_BREAKING
32 ? version === "legacy"
33 : legacy || version === "legacy"
34 ) {
35 return {
36 name: "proposal-decorators",
37 inherits: syntaxDecorators,
38 visitor: legacyVisitor,
39 };
40 } else if (version === "2021-12" || version === "2022-03") {
41 return transformer2022_03(api, options, version);
42 } else if (!process.env.BABEL_8_BREAKING) {
43 api.assertVersion("^7.0.2");
44 return createClassFeaturePlugin({
45 name: "proposal-decorators",
46
47 api,
48 feature: FEATURES.decorators,
49 inherits: syntaxDecorators,
50 // loose: options.loose, Not supported
51 });
52 } else {
53 throw new Error(
54 "The '.version' option must be one of 'legacy', '2021-12' or '2022-03'.",
55 );
56 }
57 });