-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
index.ts
33 lines (28 loc) 路 894 Bytes
/
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
import { declare } from "@babel/helper-plugin-utils";
import type { NodePath } from "@babel/traverse";
import type * as t from "@babel/types";
import syntaxImportAttributes from "@babel/plugin-syntax-import-attributes";
export default declare(api => {
api.assertVersion(7);
return {
name: "proposal-import-attributes-to-assertions",
inherits: syntaxImportAttributes,
manipulateOptions({ generatorOpts }) {
generatorOpts.importAttributesKeyword = "assert";
},
visitor: {
"ImportDeclaration|ExportNamedDeclaration|ExportAllDeclaration"(
path: NodePath<
| t.ImportDeclaration
| t.ExportNamedDeclaration
| t.ExportAllDeclaration
>,
) {
const { node } = path;
if (!node.attributes) return;
node.assertions = node.attributes;
node.attributes = null;
},
},
};
});