@vxrn/compiler 1.1.397
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +45 -0
- package/dist/cjs/configure.cjs +34 -0
- package/dist/cjs/configure.js +29 -0
- package/dist/cjs/configure.js.map +6 -0
- package/dist/cjs/configure.native.js +35 -0
- package/dist/cjs/configure.native.js.map +6 -0
- package/dist/cjs/constants.cjs +65 -0
- package/dist/cjs/constants.js +34 -0
- package/dist/cjs/constants.js.map +6 -0
- package/dist/cjs/constants.native.js +65 -0
- package/dist/cjs/constants.native.js.map +6 -0
- package/dist/cjs/index.cjs +124 -0
- package/dist/cjs/index.js +113 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/cjs/index.native.js +123 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/cjs/refresh-runtime.cjs +295 -0
- package/dist/cjs/refresh-runtime.js +296 -0
- package/dist/cjs/refresh-runtime.js.map +6 -0
- package/dist/cjs/refresh-runtime.native.js +316 -0
- package/dist/cjs/refresh-runtime.native.js.map +6 -0
- package/dist/cjs/transformBabel.cjs +111 -0
- package/dist/cjs/transformBabel.js +116 -0
- package/dist/cjs/transformBabel.js.map +6 -0
- package/dist/cjs/transformBabel.native.js +152 -0
- package/dist/cjs/transformBabel.native.js.map +6 -0
- package/dist/cjs/transformSWC.cjs +261 -0
- package/dist/cjs/transformSWC.js +256 -0
- package/dist/cjs/transformSWC.js.map +6 -0
- package/dist/cjs/transformSWC.native.js +275 -0
- package/dist/cjs/transformSWC.native.js.map +6 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.js +14 -0
- package/dist/cjs/types.js.map +6 -0
- package/dist/cjs/types.native.js +15 -0
- package/dist/cjs/types.native.js.map +6 -0
- package/dist/esm/configure.js +13 -0
- package/dist/esm/configure.js.map +6 -0
- package/dist/esm/configure.mjs +10 -0
- package/dist/esm/configure.mjs.map +1 -0
- package/dist/esm/configure.native.js +13 -0
- package/dist/esm/configure.native.js.map +6 -0
- package/dist/esm/constants.js +18 -0
- package/dist/esm/constants.js.map +6 -0
- package/dist/esm/constants.mjs +38 -0
- package/dist/esm/constants.mjs.map +1 -0
- package/dist/esm/constants.native.js +41 -0
- package/dist/esm/constants.native.js.map +6 -0
- package/dist/esm/index.js +102 -0
- package/dist/esm/index.js.map +6 -0
- package/dist/esm/index.mjs +99 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +104 -0
- package/dist/esm/index.native.js.map +6 -0
- package/dist/esm/refresh-runtime.js +280 -0
- package/dist/esm/refresh-runtime.js.map +6 -0
- package/dist/esm/refresh-runtime.mjs +266 -0
- package/dist/esm/refresh-runtime.mjs.map +1 -0
- package/dist/esm/refresh-runtime.native.js +290 -0
- package/dist/esm/refresh-runtime.native.js.map +6 -0
- package/dist/esm/transformBabel.js +95 -0
- package/dist/esm/transformBabel.js.map +6 -0
- package/dist/esm/transformBabel.mjs +76 -0
- package/dist/esm/transformBabel.mjs.map +1 -0
- package/dist/esm/transformBabel.native.js +125 -0
- package/dist/esm/transformBabel.native.js.map +6 -0
- package/dist/esm/transformSWC.js +246 -0
- package/dist/esm/transformSWC.js.map +6 -0
- package/dist/esm/transformSWC.mjs +237 -0
- package/dist/esm/transformSWC.mjs.map +1 -0
- package/dist/esm/transformSWC.native.js +257 -0
- package/dist/esm/transformSWC.native.js.map +6 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +6 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +1 -0
- package/dist/esm/types.native.js.map +6 -0
- package/package.json +54 -0
- package/src/configure.ts +17 -0
- package/src/constants.ts +21 -0
- package/src/index.ts +166 -0
- package/src/refresh-runtime.js +619 -0
- package/src/transformBabel.ts +218 -0
- package/src/transformSWC.ts +381 -0
- package/src/types.ts +36 -0
- package/types/configure.d.ts +10 -0
- package/types/configure.d.ts.map +1 -0
- package/types/constants.d.ts +9 -0
- package/types/constants.d.ts.map +1 -0
- package/types/index.d.ts +12 -0
- package/types/index.d.ts.map +1 -0
- package/types/transformBabel.d.ts +12 -0
- package/types/transformBabel.d.ts.map +1 -0
- package/types/transformSWC.d.ts +7 -0
- package/types/transformSWC.d.ts.map +1 -0
- package/types/types.d.ts +29 -0
- package/types/types.d.ts.map +1 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var transformBabel_exports = {};
|
|
33
|
+
__export(transformBabel_exports, {
|
|
34
|
+
getBabelOptions: () => getBabelOptions,
|
|
35
|
+
transformBabel: () => transformBabel
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(transformBabel_exports);
|
|
38
|
+
var import_core = __toESM(require("@babel/core"), 1),
|
|
39
|
+
import_node_path = require("node:path"),
|
|
40
|
+
import_configure = require("./configure.cjs"),
|
|
41
|
+
import_constants = require("./constants.cjs");
|
|
42
|
+
function getBabelOptions(props) {
|
|
43
|
+
if (props.userSetting === "babel") return {
|
|
44
|
+
plugins: getPlugins(props, !0)
|
|
45
|
+
};
|
|
46
|
+
if (typeof props.userSetting > "u" || typeof props.userSetting == "object" && props.userSetting.transform === "babel") {
|
|
47
|
+
if (props.userSetting?.excludeDefaultPlugins) return props.userSetting;
|
|
48
|
+
const plugins = getPlugins(props);
|
|
49
|
+
if (plugins.length) return {
|
|
50
|
+
plugins
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const getPlugins = (props, force = !1) => {
|
|
56
|
+
let plugins = [];
|
|
57
|
+
return (force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(props)), shouldBabelReanimated(props) && ((0, import_constants.debug)?.("Using babel reanimated on file"), plugins.push("react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && ((0, import_constants.debug)?.("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && ((0, import_constants.debug)?.("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins;
|
|
58
|
+
};
|
|
59
|
+
async function transformBabel(id, code, options) {
|
|
60
|
+
const compilerPlugin = options.plugins?.find(x => x && x[0] === "babel-plugin-react-compiler"),
|
|
61
|
+
out = await new Promise((res, rej) => {
|
|
62
|
+
import_core.default.transform(code, {
|
|
63
|
+
filename: id,
|
|
64
|
+
compact: !1,
|
|
65
|
+
minified: !1,
|
|
66
|
+
presets: ["@babel/preset-typescript"],
|
|
67
|
+
...options
|
|
68
|
+
}, (err, result) => {
|
|
69
|
+
if (!result || err) return rej(err || "no res");
|
|
70
|
+
res(result.code);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
return compilerPlugin && out.includes(compilerPlugin[1] === "18" ? "react-compiler-runtime" : "react/compiler-runtime") && console.info(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)}`), out;
|
|
74
|
+
}
|
|
75
|
+
const getBasePlugins = ({
|
|
76
|
+
development
|
|
77
|
+
}) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
|
|
78
|
+
development
|
|
79
|
+
}], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
|
|
80
|
+
helpers: !0,
|
|
81
|
+
// NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
|
|
82
|
+
regenerator: !1
|
|
83
|
+
}]],
|
|
84
|
+
NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/,
|
|
85
|
+
SPEC_FILE_RE = /[\/\\]specs?[\/\\]/,
|
|
86
|
+
shouldBabelReactNativeCodegen = ({
|
|
87
|
+
id,
|
|
88
|
+
environment
|
|
89
|
+
}) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)),
|
|
90
|
+
shouldBabelReactCompiler = props => !(!import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) || !/.*(.tsx?)$/.test(props.id) || props.code.startsWith("// disable-compiler")),
|
|
91
|
+
getBabelReactCompilerPlugin = props => ["babel-plugin-react-compiler", {
|
|
92
|
+
target: props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19"
|
|
93
|
+
}];
|
|
94
|
+
function shouldBabelGenerators({
|
|
95
|
+
code
|
|
96
|
+
}) {
|
|
97
|
+
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) return import_constants.asyncGeneratorRegex.test(code);
|
|
98
|
+
}
|
|
99
|
+
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"],
|
|
100
|
+
REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|")),
|
|
101
|
+
REANIMATED_IGNORED_PATHS = [
|
|
102
|
+
// React and React Native libraries are not likely to use reanimated.
|
|
103
|
+
// This can also avoid the "[BABEL] Note: The code generator has deoptimised the styling of ... as it exceeds the max of 500KB" warning since the react-native source code also contains `useAnimatedProps`.
|
|
104
|
+
"react-native-prebuilt", "node_modules/.vxrn/react-native"],
|
|
105
|
+
REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.map(s => s.replace(/\//g, "/")).join("|"));
|
|
106
|
+
function shouldBabelReanimated({
|
|
107
|
+
code,
|
|
108
|
+
id
|
|
109
|
+
}) {
|
|
110
|
+
return import_configure.configuration.enableReanimated ? !!(!REANIMATED_IGNORED_PATHS_REGEX.test(id) && REANIMATED_REGEX.test(code)) : !1;
|
|
111
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var transformBabel_exports = {};
|
|
24
|
+
__export(transformBabel_exports, {
|
|
25
|
+
getBabelOptions: () => getBabelOptions,
|
|
26
|
+
transformBabel: () => transformBabel
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(transformBabel_exports);
|
|
29
|
+
var import_core = __toESM(require("@babel/core"), 1), import_node_path = require("node:path"), import_configure = require("./configure"), import_constants = require("./constants");
|
|
30
|
+
function getBabelOptions(props) {
|
|
31
|
+
if (props.userSetting === "babel")
|
|
32
|
+
return {
|
|
33
|
+
plugins: getPlugins(props, !0)
|
|
34
|
+
};
|
|
35
|
+
if (typeof props.userSetting > "u" || typeof props.userSetting == "object" && props.userSetting.transform === "babel") {
|
|
36
|
+
if (props.userSetting?.excludeDefaultPlugins)
|
|
37
|
+
return props.userSetting;
|
|
38
|
+
const plugins = getPlugins(props);
|
|
39
|
+
if (plugins.length)
|
|
40
|
+
return {
|
|
41
|
+
plugins
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const getPlugins = (props, force = !1) => {
|
|
47
|
+
let plugins = [];
|
|
48
|
+
return (force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(props)), shouldBabelReanimated(props) && ((0, import_constants.debug)?.("Using babel reanimated on file"), plugins.push("react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && ((0, import_constants.debug)?.("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && ((0, import_constants.debug)?.("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins;
|
|
49
|
+
};
|
|
50
|
+
async function transformBabel(id, code, options) {
|
|
51
|
+
const compilerPlugin = options.plugins?.find((x) => x && x[0] === "babel-plugin-react-compiler"), out = await new Promise((res, rej) => {
|
|
52
|
+
import_core.default.transform(
|
|
53
|
+
code,
|
|
54
|
+
{
|
|
55
|
+
filename: id,
|
|
56
|
+
compact: !1,
|
|
57
|
+
minified: !1,
|
|
58
|
+
presets: ["@babel/preset-typescript"],
|
|
59
|
+
...options
|
|
60
|
+
},
|
|
61
|
+
(err, result) => {
|
|
62
|
+
if (!result || err)
|
|
63
|
+
return rej(err || "no res");
|
|
64
|
+
res(result.code);
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
return compilerPlugin && out.includes(compilerPlugin[1] === "18" ? "react-compiler-runtime" : "react/compiler-runtime") && console.info(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)}`), out;
|
|
69
|
+
}
|
|
70
|
+
const getBasePlugins = ({ development }) => [
|
|
71
|
+
["@babel/plugin-transform-destructuring"],
|
|
72
|
+
["@babel/plugin-transform-react-jsx", { development }],
|
|
73
|
+
["@babel/plugin-transform-async-generator-functions"],
|
|
74
|
+
["@babel/plugin-transform-async-to-generator"],
|
|
75
|
+
[
|
|
76
|
+
"@babel/plugin-transform-runtime",
|
|
77
|
+
{
|
|
78
|
+
helpers: !0,
|
|
79
|
+
// NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
|
|
80
|
+
regenerator: !1
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
], NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/, SPEC_FILE_RE = /[\/\\]specs?[\/\\]/, shouldBabelReactNativeCodegen = ({ id, environment }) => (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id)), shouldBabelReactCompiler = (props) => !(!import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) || !/.*(.tsx?)$/.test(props.id) || props.code.startsWith("// disable-compiler")), getBabelReactCompilerPlugin = (props) => ["babel-plugin-react-compiler", { target: props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19" }];
|
|
84
|
+
function shouldBabelGenerators({ code }) {
|
|
85
|
+
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS)
|
|
86
|
+
return import_constants.asyncGeneratorRegex.test(code);
|
|
87
|
+
}
|
|
88
|
+
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
89
|
+
"worklet",
|
|
90
|
+
"useAnimatedGestureHandler",
|
|
91
|
+
"useAnimatedScrollHandler",
|
|
92
|
+
"useFrameCallback",
|
|
93
|
+
"useAnimatedStyle",
|
|
94
|
+
"useAnimatedProps",
|
|
95
|
+
"createAnimatedPropAdapter",
|
|
96
|
+
"useDerivedValue",
|
|
97
|
+
"useAnimatedReaction",
|
|
98
|
+
"useWorkletCallback",
|
|
99
|
+
"withTiming",
|
|
100
|
+
"withSpring",
|
|
101
|
+
"withDecay",
|
|
102
|
+
"withRepeat",
|
|
103
|
+
"runOnUI",
|
|
104
|
+
"executeOnUIRuntimeSync"
|
|
105
|
+
], REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|")), REANIMATED_IGNORED_PATHS = [
|
|
106
|
+
// React and React Native libraries are not likely to use reanimated.
|
|
107
|
+
// This can also avoid the "[BABEL] Note: The code generator has deoptimised the styling of ... as it exceeds the max of 500KB" warning since the react-native source code also contains `useAnimatedProps`.
|
|
108
|
+
"react-native-prebuilt",
|
|
109
|
+
"node_modules/.vxrn/react-native"
|
|
110
|
+
], REANIMATED_IGNORED_PATHS_REGEX = new RegExp(
|
|
111
|
+
REANIMATED_IGNORED_PATHS.map((s) => s.replace(/\//g, "/")).join("|")
|
|
112
|
+
);
|
|
113
|
+
function shouldBabelReanimated({ code, id }) {
|
|
114
|
+
return import_configure.configuration.enableReanimated ? !!(!REANIMATED_IGNORED_PATHS_REGEX.test(id) && REANIMATED_REGEX.test(code)) : !1;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=transformBabel.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/transformBabel.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAkB,oCAClB,mBAAyB,sBACzB,mBAA8B,wBAC9B,mBAA2C;AAOpC,SAAS,gBAAgB,OAA6C;AAC3E,MAAI,MAAM,gBAAgB;AACxB,WAAO;AAAA,MACL,SAAS,WAAW,OAAO,EAAI;AAAA,IACjC;AAEF,MACE,OAAO,MAAM,cAAgB,OAC5B,OAAO,MAAM,eAAgB,YAAY,MAAM,YAAY,cAAc,SAC1E;AACA,QAAI,MAAM,aAAa;AACrB,aAAO,MAAM;AAEf,UAAM,UAAU,WAAW,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BAAiB,KAAK,IAAI,KAFjE;AAOX;",
|
|
5
|
+
"names": ["babel"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
+
mod
|
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
+
var transformBabel_exports = {};
|
|
25
|
+
__export(transformBabel_exports, {
|
|
26
|
+
getBabelOptions: () => getBabelOptions,
|
|
27
|
+
transformBabel: () => transformBabel
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(transformBabel_exports);
|
|
30
|
+
var import_core = __toESM(require("@babel/core"), 1), import_node_path = require("node:path"), import_configure = require("./configure"), import_constants = require("./constants");
|
|
31
|
+
function getBabelOptions(props) {
|
|
32
|
+
if (props.userSetting === "babel")
|
|
33
|
+
return {
|
|
34
|
+
plugins: getPlugins(props, !0)
|
|
35
|
+
};
|
|
36
|
+
if (typeof props.userSetting > "u" || typeof props.userSetting == "object" && props.userSetting.transform === "babel") {
|
|
37
|
+
var _props_userSetting;
|
|
38
|
+
if (!((_props_userSetting = props.userSetting) === null || _props_userSetting === void 0) && _props_userSetting.excludeDefaultPlugins)
|
|
39
|
+
return props.userSetting;
|
|
40
|
+
var plugins = getPlugins(props);
|
|
41
|
+
if (plugins.length)
|
|
42
|
+
return {
|
|
43
|
+
plugins
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var getPlugins = function(props) {
|
|
49
|
+
var force = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, plugins = [];
|
|
50
|
+
return (force || shouldBabelGenerators(props)) && (plugins = getBasePlugins(props)), shouldBabelReanimated(props) && (import_constants.debug === null || import_constants.debug === void 0 || (0, import_constants.debug)("Using babel reanimated on file"), plugins.push("react-native-reanimated/plugin")), shouldBabelReactCompiler(props) && (import_constants.debug === null || import_constants.debug === void 0 || (0, import_constants.debug)("Using babel react compiler on file"), plugins.push(getBabelReactCompilerPlugin(props))), shouldBabelReactNativeCodegen(props) && (import_constants.debug === null || import_constants.debug === void 0 || (0, import_constants.debug)("Using babel @react-native/babel-plugin-codegen on file"), plugins.push("@react-native/babel-plugin-codegen")), plugins;
|
|
51
|
+
};
|
|
52
|
+
async function transformBabel(id, code, options) {
|
|
53
|
+
var _options_plugins, compilerPlugin = (_options_plugins = options.plugins) === null || _options_plugins === void 0 ? void 0 : _options_plugins.find(function(x) {
|
|
54
|
+
return x && x[0] === "babel-plugin-react-compiler";
|
|
55
|
+
}), out = await new Promise(function(res, rej) {
|
|
56
|
+
import_core.default.transform(code, {
|
|
57
|
+
filename: id,
|
|
58
|
+
compact: !1,
|
|
59
|
+
minified: !1,
|
|
60
|
+
presets: [
|
|
61
|
+
"@babel/preset-typescript"
|
|
62
|
+
],
|
|
63
|
+
...options
|
|
64
|
+
}, function(err, result) {
|
|
65
|
+
if (!result || err)
|
|
66
|
+
return rej(err || "no res");
|
|
67
|
+
res(result.code);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
return compilerPlugin && out.includes(compilerPlugin[1] === "18" ? "react-compiler-runtime" : "react/compiler-runtime") && console.info(` \u{1FA84} [compiler] ${(0, import_node_path.relative)(process.cwd(), id)}`), out;
|
|
71
|
+
}
|
|
72
|
+
var getBasePlugins = function(param) {
|
|
73
|
+
var { development } = param;
|
|
74
|
+
return [
|
|
75
|
+
[
|
|
76
|
+
"@babel/plugin-transform-destructuring"
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
"@babel/plugin-transform-react-jsx",
|
|
80
|
+
{
|
|
81
|
+
development
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"@babel/plugin-transform-async-generator-functions"
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"@babel/plugin-transform-async-to-generator"
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
"@babel/plugin-transform-runtime",
|
|
92
|
+
{
|
|
93
|
+
helpers: !0,
|
|
94
|
+
// NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
|
|
95
|
+
regenerator: !1
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
];
|
|
99
|
+
}, NATIVE_COMPONENT_RE = /NativeComponent\.[jt]sx?$/, SPEC_FILE_RE = /[\/\\]specs?[\/\\]/, shouldBabelReactNativeCodegen = function(param) {
|
|
100
|
+
var { id, environment } = param;
|
|
101
|
+
return (environment === "ios" || environment === "android") && (NATIVE_COMPONENT_RE.test(id) || SPEC_FILE_RE.test(id));
|
|
102
|
+
}, shouldBabelReactCompiler = function(props) {
|
|
103
|
+
return !(!import_configure.configuration.enableCompiler || Array.isArray(import_configure.configuration.enableCompiler) && !import_configure.configuration.enableCompiler.includes(props.environment) || !/.*(.tsx?)$/.test(props.id) || props.code.startsWith("// disable-compiler"));
|
|
104
|
+
}, getBabelReactCompilerPlugin = function(props) {
|
|
105
|
+
var target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
|
|
106
|
+
return [
|
|
107
|
+
"babel-plugin-react-compiler",
|
|
108
|
+
{
|
|
109
|
+
target
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
};
|
|
113
|
+
function shouldBabelGenerators(param) {
|
|
114
|
+
var { code } = param;
|
|
115
|
+
if (process.env.VXRN_USE_BABEL_FOR_GENERATORS)
|
|
116
|
+
return import_constants.asyncGeneratorRegex.test(code);
|
|
117
|
+
}
|
|
118
|
+
var REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
119
|
+
"worklet",
|
|
120
|
+
"useAnimatedGestureHandler",
|
|
121
|
+
"useAnimatedScrollHandler",
|
|
122
|
+
"useFrameCallback",
|
|
123
|
+
"useAnimatedStyle",
|
|
124
|
+
"useAnimatedProps",
|
|
125
|
+
"createAnimatedPropAdapter",
|
|
126
|
+
"useDerivedValue",
|
|
127
|
+
"useAnimatedReaction",
|
|
128
|
+
"useWorkletCallback",
|
|
129
|
+
"withTiming",
|
|
130
|
+
"withSpring",
|
|
131
|
+
"withDecay",
|
|
132
|
+
"withRepeat",
|
|
133
|
+
"runOnUI",
|
|
134
|
+
"executeOnUIRuntimeSync"
|
|
135
|
+
], REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|")), REANIMATED_IGNORED_PATHS = [
|
|
136
|
+
// React and React Native libraries are not likely to use reanimated.
|
|
137
|
+
// This can also avoid the "[BABEL] Note: The code generator has deoptimised the styling of ... as it exceeds the max of 500KB" warning since the react-native source code also contains `useAnimatedProps`.
|
|
138
|
+
"react-native-prebuilt",
|
|
139
|
+
"node_modules/.vxrn/react-native"
|
|
140
|
+
], REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.map(function(s) {
|
|
141
|
+
return s.replace(/\//g, "/");
|
|
142
|
+
}).join("|"));
|
|
143
|
+
function shouldBabelReanimated(param) {
|
|
144
|
+
var { code, id } = param;
|
|
145
|
+
return import_configure.configuration.enableReanimated ? !!(!REANIMATED_IGNORED_PATHS_REGEX.test(id) && REANIMATED_REGEX.test(code)) : !1;
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
getBabelOptions,
|
|
150
|
+
transformBabel
|
|
151
|
+
});
|
|
152
|
+
//# sourceMappingURL=transformBabel.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Users/n8/one/packages/compiler/src/transformBabel.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;kBAAkB,oCAClB,mBAAyB,sBACzB,mBAA8B,wBAC9B,mBAA2C;AAOpC,SAASA,gBAAgBC,OAAY;AAC1C,MAAIA,MAAMC,gBAAgB;AACxB,WAAO;MACLC,SAASC,WAAWH,OAAO,EAAA;IAC7B;AAEF,MACE,OAAOA,MAAMC,cAAgB,OAC5B,OAAOD,MAAMC,eAAgB,YAAYD,MAAMC,YAAYG,cAAc,SAC1E;QACIJ;AAAJ,QAAIA,wBAAAA,MAAMC,iBAAW,QAAjBD,uBAAAA,WAAAA,mBAAmBK;AACrB,aAAOL,MAAMC;AAEf,QAAMC,UAAUC,WAAWH,KAAAA;AAC3B,QAAIE,QAAQI;AACV,aAAO;QACLJ;MACF;EAEJ;AACA,SAAO;AACT;AAEA,IAAMC,aAAa,SAACH,OA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,MAAMD,GAAE,IAAV;AAC7B,SAAK8B,+BAAcmB,mBAGf,IAACJ,+BAA+BhB,KAAK7B,EAAAA,KAAOyC,iBAAiBZ,KAAK5B,IAAAA,KAF7D;AAOX;",
|
|
5
|
+
"names": ["getBabelOptions", "props", "userSetting", "plugins", "getPlugins", "transform", "excludeDefaultPlugins", "length", "force", "shouldBabelGenerators", "getBasePlugins", "shouldBabelReanimated", "debug", "push", "shouldBabelReactCompiler", "getBabelReactCompilerPlugin", "shouldBabelReactNativeCodegen", "transformBabel", "id", "code", "options", "compilerPlugin", "find", "x", "out", "Promise", "res", "rej", "babel", "filename", "compact", "minified", "presets", "err", "result", "includes", "console", "info", "relative", "process", "cwd", "development", "helpers", "regenerator", "NATIVE_COMPONENT_RE", "SPEC_FILE_RE", "environment", "test", "configuration", "enableCompiler", "Array", "isArray", "startsWith", "target", "reactForRNVersion", "env", "VXRN_USE_BABEL_FOR_GENERATORS", "asyncGeneratorRegex", "REANIMATED_AUTOWORKLETIZATION_KEYWORDS", "REANIMATED_REGEX", "RegExp", "join", "REANIMATED_IGNORED_PATHS", "REANIMATED_IGNORED_PATHS_REGEX", "map", "s", "replace", "enableReanimated"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var transformSWC_exports = {};
|
|
22
|
+
__export(transformSWC_exports, {
|
|
23
|
+
transformSWC: () => transformSWC,
|
|
24
|
+
transformSWCStripJSX: () => transformSWCStripJSX
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(transformSWC_exports);
|
|
27
|
+
var import_core = require("@swc/core"),
|
|
28
|
+
import_node_path = require("node:path"),
|
|
29
|
+
import_ts_deepmerge = require("ts-deepmerge"),
|
|
30
|
+
import_configure = require("./configure.cjs"),
|
|
31
|
+
import_constants = require("./constants.cjs");
|
|
32
|
+
async function transformSWC(id, code, options, swcOptions) {
|
|
33
|
+
if (id.includes(".vite") || (id = id.split("?")[0].replace(process.cwd(), ""), id === import_constants.runtimePublicPath)) return;
|
|
34
|
+
const parser = getParser(id, options.forceJSX);
|
|
35
|
+
if (!parser) return;
|
|
36
|
+
const enableNativeCSS = import_configure.configuration.enableNativeCSS &&
|
|
37
|
+
// temp fix idk why this error:
|
|
38
|
+
// node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx (19:9): "createInteropElement" is not exported by "../../node_modules/react-native-css-interop/dist/runtime/jsx-dev-runtime.js", imported by "node_modules/react-native-reanimated/src/component/LayoutAnimationConfig.tsx
|
|
39
|
+
!id.includes("node_modules"),
|
|
40
|
+
refresh = options.environment !== "ssr" && !options.production && !options.noHMR && !options.forceJSX,
|
|
41
|
+
reactConfig = {
|
|
42
|
+
refresh,
|
|
43
|
+
development: !options.forceJSX && !options.production,
|
|
44
|
+
runtime: "automatic",
|
|
45
|
+
importSource: "react",
|
|
46
|
+
...(enableNativeCSS ? {
|
|
47
|
+
importSource: "react-native-css-interop",
|
|
48
|
+
pragma: "createInteropElement",
|
|
49
|
+
// swc doesnt actually change the import right
|
|
50
|
+
runtime: "classic"
|
|
51
|
+
} : {})
|
|
52
|
+
},
|
|
53
|
+
transformOptions = (() => {
|
|
54
|
+
if (options.environment === "client" || options.environment === "ssr") return {
|
|
55
|
+
sourceMaps: !0,
|
|
56
|
+
jsc: {
|
|
57
|
+
target: "es2020",
|
|
58
|
+
parser,
|
|
59
|
+
transform: {
|
|
60
|
+
useDefineForClassFields: !0,
|
|
61
|
+
react: reactConfig
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const opts = options.es5 || !process.env.VXRN_USE_BABEL_FOR_GENERATORS && import_constants.asyncGeneratorRegex.test(code) ? {
|
|
66
|
+
jsc: {
|
|
67
|
+
parser,
|
|
68
|
+
target: "es5",
|
|
69
|
+
transform: {
|
|
70
|
+
useDefineForClassFields: !0,
|
|
71
|
+
react: reactConfig
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} : {
|
|
75
|
+
...(!options.forceJSX && {
|
|
76
|
+
env: SWC_ENV
|
|
77
|
+
}),
|
|
78
|
+
jsc: {
|
|
79
|
+
...(options.forceJSX && {
|
|
80
|
+
target: "esnext"
|
|
81
|
+
}),
|
|
82
|
+
parser,
|
|
83
|
+
transform: {
|
|
84
|
+
useDefineForClassFields: !0,
|
|
85
|
+
react: reactConfig
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
sourceMaps: shouldSourceMap(),
|
|
91
|
+
module: {
|
|
92
|
+
importInterop: "none",
|
|
93
|
+
type: "nodenext"
|
|
94
|
+
},
|
|
95
|
+
...(options.mode === "serve-cjs" && {
|
|
96
|
+
module: {
|
|
97
|
+
importInterop: "none",
|
|
98
|
+
type: "commonjs",
|
|
99
|
+
strict: !0
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
...opts
|
|
103
|
+
};
|
|
104
|
+
})(),
|
|
105
|
+
finalOptions = (0, import_ts_deepmerge.merge)({
|
|
106
|
+
filename: id,
|
|
107
|
+
swcrc: !1,
|
|
108
|
+
configFile: !1,
|
|
109
|
+
...transformOptions
|
|
110
|
+
}, swcOptions || {}),
|
|
111
|
+
result = await (async () => {
|
|
112
|
+
try {
|
|
113
|
+
return (0, import_constants.debug)?.(`transformSWC ${id} using options:
|
|
114
|
+
${JSON.stringify(finalOptions, null, 2)}`), await (0, import_core.transform)(code, finalOptions);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
const message = e.message,
|
|
117
|
+
fileStartIndex = message.indexOf("\u256D\u2500[");
|
|
118
|
+
if (fileStartIndex !== -1) {
|
|
119
|
+
const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)]/);
|
|
120
|
+
match && (e.line = match[1], e.column = match[2]);
|
|
121
|
+
}
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
enableNativeCSS && result.code.includes("createInteropElement") && (result.code = `import { createInteropElement } from 'react-native-css-interop/jsx-dev-runtime'
|
|
126
|
+
${result.code}`);
|
|
127
|
+
const shouldHMR = refresh && refreshContentRE.test(result.code);
|
|
128
|
+
if (options.fixNonTypeSpecificImports || id.includes("node_modules") && parser.syntax === "typescript") {
|
|
129
|
+
const typeExportsMatch = code.match(/^\s*export\s+type\s+([^\s]+)/gi);
|
|
130
|
+
if (typeExportsMatch) for (const typeExport of Array.from(typeExportsMatch)) {
|
|
131
|
+
const [_export, _type, name] = typeExport.split(/\s+/);
|
|
132
|
+
if (name.startsWith("{") || name.includes("<")) continue;
|
|
133
|
+
if (!new RegExp(`export (const|let|class|function) ${name}\\s+`).test(result.code)) {
|
|
134
|
+
const fakeExport = `export let ${name} = {};`;
|
|
135
|
+
console.info(` \u26A0\uFE0F Fixing non-type-specifc import in node_module, this should be fixed upstream: ${fakeExport} in ${id}`), result.code += `
|
|
136
|
+
${fakeExport}
|
|
137
|
+
`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return !result || options.noHMR || !shouldHMR ? result : (wrapSourceInRefreshRuntime(id, result, options, shouldHMR), {
|
|
142
|
+
code: result.code
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const SWC_ENV = {
|
|
146
|
+
targets: {
|
|
147
|
+
node: "4"
|
|
148
|
+
},
|
|
149
|
+
// debug: true,
|
|
150
|
+
include: [],
|
|
151
|
+
// this breaks the uniswap app for any file with a ...spread
|
|
152
|
+
exclude: ["transform-spread", "transform-destructuring", "transform-object-rest-spread",
|
|
153
|
+
// `transform-async-to-generator` is relying on `transform-destructuring`.
|
|
154
|
+
// If we exclude `transform-destructuring` but not `transform-async-to-generator`, the SWC binary will panic
|
|
155
|
+
// with error: `called `Option::unwrap()` on a `None` value`.
|
|
156
|
+
// See: https://github.com/swc-project/swc/blob/v1.7.14/crates/swc_ecma_compat_es2015/src/generator.rs#L703-L705
|
|
157
|
+
"transform-async-to-generator", "transform-regenerator"
|
|
158
|
+
// Similar to above
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/;
|
|
162
|
+
function shouldSourceMap() {
|
|
163
|
+
return process.env.VXRN_ENABLE_SOURCE_MAP === "1";
|
|
164
|
+
}
|
|
165
|
+
function wrapSourceInRefreshRuntime(id, result, options, shouldHMR) {
|
|
166
|
+
return options.environment === "client" || options.environment === "ssr" ? wrapSourceInRefreshRuntimeWeb(id, result, shouldHMR) : wrapSourceInRefreshRuntimeNative(id, result, options, shouldHMR);
|
|
167
|
+
}
|
|
168
|
+
function wrapSourceInRefreshRuntimeWeb(id, result, shouldHMR) {
|
|
169
|
+
const sourceMap = JSON.parse(result.map);
|
|
170
|
+
sourceMap.mappings = ";;" + sourceMap.mappings, result.code = `import * as RefreshRuntime from "${import_constants.runtimePublicPath}";
|
|
171
|
+
|
|
172
|
+
${result.code}`, shouldHMR && (sourceMap.mappings = ";;;;;;" + sourceMap.mappings, result.code = `if (!window.$RefreshReg$) throw new Error("React refresh preamble was not loaded. Something is wrong.");
|
|
173
|
+
const prevRefreshReg = window.$RefreshReg$;
|
|
174
|
+
const prevRefreshSig = window.$RefreshSig$;
|
|
175
|
+
window.$RefreshReg$ = RefreshRuntime.getRefreshReg("${id}");
|
|
176
|
+
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
177
|
+
|
|
178
|
+
${result.code}
|
|
179
|
+
|
|
180
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
181
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
182
|
+
`), result.code += `
|
|
183
|
+
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
184
|
+
RefreshRuntime.registerExportsForReactRefresh("${id}", currentExports);
|
|
185
|
+
import.meta.hot.accept((nextExports) => {
|
|
186
|
+
if (!nextExports) return;
|
|
187
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate("${id}", currentExports, nextExports);
|
|
188
|
+
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
function wrapSourceInRefreshRuntimeNative(id, result, options, shouldHMR) {
|
|
194
|
+
const prefixCode = options.mode === "build" ? `
|
|
195
|
+
import 'react-native'
|
|
196
|
+
import 'react'
|
|
197
|
+
import '@vxrn/vite-native-client'
|
|
198
|
+
` : "";
|
|
199
|
+
if (options.production) return `
|
|
200
|
+
${prefixCode}
|
|
201
|
+
module.url = '${id}'
|
|
202
|
+
${result.code}
|
|
203
|
+
`;
|
|
204
|
+
shouldHMR && (result.code = `const RefreshRuntime = __cachedModules["react-refresh/cjs/react-refresh-runtime.development"];
|
|
205
|
+
const prevRefreshReg = globalThis.$RefreshReg$;
|
|
206
|
+
const prevRefreshSig = globalThis.$RefreshSig$ || (() => {
|
|
207
|
+
console.info("no react refresh setup!")
|
|
208
|
+
return (x) => x
|
|
209
|
+
});
|
|
210
|
+
globalThis.$RefreshReg$ = (type, id) => RefreshRuntime.register(type, "${id}" + " " + id);
|
|
211
|
+
globalThis.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
212
|
+
|
|
213
|
+
${prefixCode}
|
|
214
|
+
|
|
215
|
+
module.url = '${id}'
|
|
216
|
+
module.hot = createHotContext(module.url)
|
|
217
|
+
|
|
218
|
+
${result.code}
|
|
219
|
+
|
|
220
|
+
if (module.hot) {
|
|
221
|
+
globalThis.$RefreshReg$ = prevRefreshReg;
|
|
222
|
+
globalThis.$RefreshSig$ = prevRefreshSig;
|
|
223
|
+
globalThis['lastHmrExports'] = JSON.stringify(Object.keys(exports))
|
|
224
|
+
}
|
|
225
|
+
`), result.code = `${result.code}
|
|
226
|
+
|
|
227
|
+
if (module.hot) {
|
|
228
|
+
if (module.hot.accept) {
|
|
229
|
+
module.hot.accept((nextExports) => {
|
|
230
|
+
RefreshRuntime.performReactRefresh()
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}`;
|
|
234
|
+
}
|
|
235
|
+
function getParser(id, forceJSX = !1) {
|
|
236
|
+
if (id.endsWith("one-entry-native")) return import_constants.parsers[".tsx"];
|
|
237
|
+
const extension = (0, import_node_path.extname)(id);
|
|
238
|
+
let parser = extension ? import_constants.parsers[extension] : import_constants.parsers[".js"];
|
|
239
|
+
return extension === ".js" && (forceJSX && (parser = import_constants.parsers[".jsx"]), id.includes("expo-modules-core") && (parser = import_constants.parsers[".jsx"])), parser;
|
|
240
|
+
}
|
|
241
|
+
const transformSWCStripJSX = async (id, code) => {
|
|
242
|
+
const parser = getParser(id);
|
|
243
|
+
if (parser) return await (0, import_core.transform)(code, {
|
|
244
|
+
filename: id,
|
|
245
|
+
swcrc: !1,
|
|
246
|
+
configFile: !1,
|
|
247
|
+
sourceMaps: shouldSourceMap(),
|
|
248
|
+
jsc: {
|
|
249
|
+
target: "es2019",
|
|
250
|
+
parser,
|
|
251
|
+
transform: {
|
|
252
|
+
useDefineForClassFields: !0,
|
|
253
|
+
react: {
|
|
254
|
+
development: !0,
|
|
255
|
+
runtime: "automatic",
|
|
256
|
+
refresh: !1
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
};
|