MCPcopy Create free account
hub / github.com/babel/babel / createPlugin

Function createPlugin

packages/babel-plugin-transform-react-jsx/src/create-plugin.ts:64–834  ·  view source on GitHub ↗
({
  name,
  development,
}: {
  name: string;
  development: Development;
})

Source from the content-addressed store, hash-verified

62}
63
64export default function createPlugin<const Development extends boolean>({
65 name,
66 development,
67}: {
68 name: string;
69 development: Development;
70}) {
71 type Opts = Development extends true ? OptionsDevelopment : Options;
72 return declare((_, options: Opts) => {
73 const {
74 pure: PURE_ANNOTATION,
75
76 throwIfNamespace = true,
77
78 filter,
79
80 runtime: RUNTIME_DEFAULT = "automatic",
81
82 importSource: IMPORT_SOURCE_DEFAULT = DEFAULT.importSource,
83 pragma: PRAGMA_DEFAULT = DEFAULT.pragma,
84 pragmaFrag: PRAGMA_FRAG_DEFAULT = DEFAULT.pragmaFrag,
85 } = options;
86
87 const sourceSelf = development
88 ? (options as OptionsDevelopment).sourceSelf
89 : undefined;
90
91 if ("useSpread" in options) {
92 throw new Error(
93 '@babel/plugin-transform-react-jsx: Since Babel 8, an inline object with spread elements is always used, and the "useSpread" option is no longer available. Please remove it from your config.',
94 );
95 }
96
97 if ("useBuiltIns" in options) {
98 const useBuiltInsFormatted = JSON.stringify(options.useBuiltIns);
99 throw new Error(
100 `@babel/plugin-transform-react-jsx: Since "useBuiltIns" is removed in Babel 8, you can remove it from the config.
101- Babel 8 now transforms JSX spread to object spread. If you need to transpile object spread with
102\`useBuiltIns: ${useBuiltInsFormatted}\`, you can use the following config
103{
104 "plugins": [
105 "@babel/plugin-transform-react-jsx"
106 ["@babel/plugin-transform-object-rest-spread", { "loose": true, "useBuiltIns": ${useBuiltInsFormatted} }]
107 ]
108}`,
109 );
110 }
111
112 if (filter != null && RUNTIME_DEFAULT === "automatic") {
113 throw new Error(
114 '@babel/plugin-transform-react-jsx: "filter" option can not be used with automatic runtime. If you are upgrading from Babel 7, please specify `runtime: "classic"`.',
115 );
116 }
117
118 let commentsNode: t.Node | null = null;
119
120 return {
121 name,

Callers 2

index.tsFile · 0.85
development.tsFile · 0.85

Calls 1

declareFunction · 0.90

Tested by

no test coverage detected