Lazily inject imports to the JSX runtime (#12493)
This commit is contained in:
@@ -27,13 +27,20 @@ export default declare((api, options) => {
|
||||
state.pure =
|
||||
PURE_ANNOTATION ?? !pass.get("@babel/plugin-react-jsx/pragmaSet");
|
||||
} else {
|
||||
state.jsxCallee = pass.get("@babel/plugin-react-jsx/jsxIdentifier")();
|
||||
state.jsxStaticCallee = pass.get(
|
||||
"@babel/plugin-react-jsx/jsxStaticIdentifier",
|
||||
)();
|
||||
state.createElementCallee = pass.get(
|
||||
"@babel/plugin-react-jsx/createElementIdentifier",
|
||||
)();
|
||||
const getter = get => ({ enumerable: true, configurable: true, get });
|
||||
|
||||
// TODO(Babel 8): helper-builder-react-jsx expects those properties to be AST nodes, but we want to
|
||||
// generate them lazily so that we only inject imports when needed.
|
||||
// These should actually be functions.
|
||||
Object.defineProperties(state, {
|
||||
jsxCallee: getter(pass.get("@babel/plugin-react-jsx/jsxIdentifier")),
|
||||
jsxStaticCallee: getter(
|
||||
pass.get("@babel/plugin-react-jsx/jsxStaticIdentifier"),
|
||||
),
|
||||
createElementCallee: getter(
|
||||
pass.get("@babel/plugin-react-jsx/createElementIdentifier"),
|
||||
),
|
||||
});
|
||||
|
||||
state.pure =
|
||||
PURE_ANNOTATION ??
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { Fragment as _Fragment } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsx(_Fragment, {
|
||||
children: /*#__PURE__*/_jsxs("div", {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import * as react from "react";
|
||||
var y = react.createElement("div", {
|
||||
foo: 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsxs("div", {
|
||||
children: ["foo", "bar", "baz", /*#__PURE__*/_jsx("div", {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { Fragment as _Fragment } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { createElement as _createElement } from "react";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsx(_Fragment, {
|
||||
children: /*#__PURE__*/_jsxs("div", {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { Fragment as _Fragment } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsx(_Fragment, {
|
||||
children: /*#__PURE__*/_jsx("div", {})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsxs("div", {
|
||||
children: [/*#__PURE__*/_jsx("span", {}), [/*#__PURE__*/_jsx("span", {}, '0'), /*#__PURE__*/_jsx("span", {}, '1')]]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsxs("div", {
|
||||
children: [/*#__PURE__*/_jsx("div", {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { jsxs as _jsxs } from "react/jsx-runtime";
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
|
||||
var x = /*#__PURE__*/_jsxs("div", {
|
||||
children: [/*#__PURE__*/_jsx("div", {}, "1"), /*#__PURE__*/_jsx("div", {
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
const foo = /*#__PURE__*/undefined.jsx("p", {});
|
||||
var _reactJsxRuntime = require("react/jsx-runtime");
|
||||
|
||||
const foo = /*#__PURE__*/_reactJsxRuntime.jsx("p", {});
|
||||
|
||||
Reference in New Issue
Block a user