forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
56 lines (49 loc) · 1.58 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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 as SyntaxOptions } from "@babel/plugin-syntax-decorators";
interface Options extends SyntaxOptions {
/** @depreated use `constantSuper` assumption instead. Only supported in 2021-12 version. */
loose?: boolean;
}
export type { Options };
export default declare((api, options: Options) => {
api.assertVersion(7);
// Options are validated in @babel/plugin-syntax-decorators
if (!process.env.BABEL_8_BREAKING) {
// eslint-disable-next-line no-var
var { legacy } = options;
}
const { version } = options;
if (
process.env.BABEL_8_BREAKING
? version === "legacy"
: legacy || version === "legacy"
) {
return {
name: "proposal-decorators",
inherits: syntaxDecorators,
visitor: legacyVisitor,
};
} else if (version === "2021-12") {
return transformer2021_12(api, options);
} else if (!process.env.BABEL_8_BREAKING) {
return createClassFeaturePlugin({
name: "proposal-decorators",
api,
feature: FEATURES.decorators,
inherits: syntaxDecorators,
// loose: options.loose, Not supported
});
} else {
throw new Error(
"The '.version' option must be one of 'legacy' or '2021-12'",
);
}
});