Debian Codegraph @

packages/babel-plugin-proposal-dynamic-import/src/index.ts

raw
1 import { declare } from "@babel/helper-plugin-utils";
2 import syntaxDynamicImport from "@babel/plugin-syntax-dynamic-import";
3
4 const SUPPORTED_MODULES = ["commonjs", "amd", "systemjs"];
5
6 const MODULES_NOT_FOUND = `\
7 @babel/plugin-proposal-dynamic-import depends on a modules
8 transform plugin. Supported plugins are:
9 - @babel/plugin-transform-modules-commonjs ^7.4.0
10 - @babel/plugin-transform-modules-amd ^7.4.0
11 - @babel/plugin-transform-modules-systemjs ^7.4.0
12
13 If you are using Webpack or Rollup and thus don't want
14 Babel to transpile your imports and exports, you can use
15 the @babel/plugin-syntax-dynamic-import plugin and let your
16 bundler handle dynamic imports.
17 `;
18
19 declare const PACKAGE_JSON: { name: string; version: string };
20
21 export default declare(api => {
22 api.assertVersion(7);
23
24 return {
25 name: "proposal-dynamic-import",
26 inherits: syntaxDynamicImport.default,
27
28 pre() {
29 this.file.set(
30 "@babel/plugin-proposal-dynamic-import",
31 PACKAGE_JSON.version,
32 );
33 },
34
35 visitor: {
36 Program() {
37 const modules = this.file.get("@babel/plugin-transform-modules-*");
38
39 if (!SUPPORTED_MODULES.includes(modules)) {
40 throw new Error(MODULES_NOT_FOUND);
41 }
42 },
43 },
44 };
45 });