@vxrn/compiler 1.27.1 → 2.0.0-beta.45.1

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.
Files changed (89) hide show
  1. package/dist/cjs/cache.cjs +106 -117
  2. package/dist/cjs/configure.cjs +26 -28
  3. package/dist/cjs/constants.cjs +56 -60
  4. package/dist/cjs/index.cjs +420 -443
  5. package/dist/cjs/reactNativeCodegen.cjs +105 -114
  6. package/dist/cjs/reactNativeViewConfig.cjs +362 -381
  7. package/dist/cjs/refresh-runtime.cjs +390 -397
  8. package/dist/cjs/transformBabel.cjs +273 -263
  9. package/dist/cjs/transformHermesAsync.cjs +36 -47
  10. package/dist/cjs/transformHermesLoops.cjs +279 -281
  11. package/dist/cjs/transformSWC.cjs +183 -200
  12. package/dist/cjs/transformWorklets.cjs +107 -95
  13. package/dist/cjs/types.cjs +9 -11
  14. package/dist/cjs/worklets/autoworklet.cjs +277 -222
  15. package/dist/cjs/worklets/globals.cjs +124 -60
  16. package/dist/cjs/worklets/hash.cjs +23 -27
  17. package/dist/cjs/worklets/scope.cjs +338 -359
  18. package/dist/cjs/worklets/serialize.cjs +73 -75
  19. package/dist/cjs/worklets/transform.cjs +217 -222
  20. package/dist/cjs/worklets/types.cjs +9 -11
  21. package/dist/esm/cache.mjs +90 -97
  22. package/dist/esm/cache.mjs.map +1 -1
  23. package/dist/esm/configure.mjs +11 -10
  24. package/dist/esm/configure.mjs.map +1 -1
  25. package/dist/esm/constants.mjs +41 -41
  26. package/dist/esm/constants.mjs.map +1 -1
  27. package/dist/esm/index.js +417 -425
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/index.mjs +417 -425
  30. package/dist/esm/index.mjs.map +1 -1
  31. package/dist/esm/reactNativeCodegen.mjs +90 -88
  32. package/dist/esm/reactNativeCodegen.mjs.map +1 -1
  33. package/dist/esm/reactNativeViewConfig.mjs +347 -362
  34. package/dist/esm/reactNativeViewConfig.mjs.map +1 -1
  35. package/dist/esm/refresh-runtime.mjs +372 -376
  36. package/dist/esm/refresh-runtime.mjs.map +1 -1
  37. package/dist/esm/transformBabel.mjs +255 -237
  38. package/dist/esm/transformBabel.mjs.map +1 -1
  39. package/dist/esm/transformHermesAsync.mjs +20 -21
  40. package/dist/esm/transformHermesAsync.mjs.map +1 -1
  41. package/dist/esm/transformHermesLoops.mjs +264 -255
  42. package/dist/esm/transformHermesLoops.mjs.map +1 -1
  43. package/dist/esm/transformSWC.mjs +163 -171
  44. package/dist/esm/transformSWC.mjs.map +1 -1
  45. package/dist/esm/transformWorklets.mjs +89 -69
  46. package/dist/esm/transformWorklets.mjs.map +1 -1
  47. package/dist/esm/types.mjs +0 -2
  48. package/dist/esm/worklets/autoworklet.mjs +258 -200
  49. package/dist/esm/worklets/autoworklet.mjs.map +1 -1
  50. package/dist/esm/worklets/globals.mjs +109 -42
  51. package/dist/esm/worklets/globals.mjs.map +1 -1
  52. package/dist/esm/worklets/hash.mjs +10 -9
  53. package/dist/esm/worklets/hash.mjs.map +1 -1
  54. package/dist/esm/worklets/scope.mjs +325 -341
  55. package/dist/esm/worklets/scope.mjs.map +1 -1
  56. package/dist/esm/worklets/serialize.mjs +60 -58
  57. package/dist/esm/worklets/serialize.mjs.map +1 -1
  58. package/dist/esm/worklets/transform.mjs +201 -197
  59. package/dist/esm/worklets/transform.mjs.map +1 -1
  60. package/dist/esm/worklets/types.mjs +0 -2
  61. package/package.json +7 -6
  62. package/src/transformBabel.test.ts +77 -17
  63. package/src/transformBabel.ts +28 -12
  64. package/types/transformBabel.d.ts +12 -0
  65. package/types/transformBabel.d.ts.map +1 -1
  66. package/types/transformSWC.d.ts +1 -4
  67. package/types/transformSWC.d.ts.map +1 -1
  68. package/dist/cjs/transformBabel.test.cjs +0 -652
  69. package/dist/cjs/transformHermesLoops.test.cjs +0 -257
  70. package/dist/cjs/transformSWC.test.cjs +0 -117
  71. package/dist/cjs/transformWorklets.test.cjs +0 -604
  72. package/dist/esm/transformBabel.test.mjs +0 -629
  73. package/dist/esm/transformBabel.test.mjs.map +0 -1
  74. package/dist/esm/transformHermesLoops.test.mjs +0 -234
  75. package/dist/esm/transformHermesLoops.test.mjs.map +0 -1
  76. package/dist/esm/transformSWC.test.mjs +0 -118
  77. package/dist/esm/transformSWC.test.mjs.map +0 -1
  78. package/dist/esm/transformWorklets.test.mjs +0 -581
  79. package/dist/esm/transformWorklets.test.mjs.map +0 -1
  80. package/dist/esm/types.mjs.map +0 -1
  81. package/dist/esm/worklets/types.mjs.map +0 -1
  82. package/types/transformBabel.test.d.ts +0 -2
  83. package/types/transformBabel.test.d.ts.map +0 -1
  84. package/types/transformHermesLoops.test.d.ts +0 -2
  85. package/types/transformHermesLoops.test.d.ts.map +0 -1
  86. package/types/transformSWC.test.d.ts +0 -2
  87. package/types/transformSWC.test.d.ts.map +0 -1
  88. package/types/transformWorklets.test.d.ts +0 -2
  89. package/types/transformWorklets.test.d.ts.map +0 -1
@@ -5,38 +5,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
21
  };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var transformBabel_exports = {};
35
28
  __export(transformBabel_exports, {
36
- findUserBabelConfig: () => findUserBabelConfig,
37
- getBabelOptions: () => getBabelOptions,
38
- transformBabel: () => transformBabel,
39
- transformOxcReactCompiler: () => transformOxcReactCompiler
29
+ findUserBabelConfig: () => findUserBabelConfig,
30
+ getBabelOptions: () => getBabelOptions,
31
+ stripFlowTypes: () => stripFlowTypes,
32
+ transformBabel: () => transformBabel,
33
+ transformOxcReactCompiler: () => transformOxcReactCompiler
40
34
  });
41
35
  module.exports = __toCommonJS(transformBabel_exports);
42
36
  var import_node_fs = require("node:fs");
@@ -45,260 +39,276 @@ var import_utils = require("@vxrn/utils");
45
39
  var import_vite = require("vite");
46
40
  var import_configure = require("./configure.cjs");
47
41
  var import_constants = require("./constants.cjs");
48
- const USER_BABEL_CONFIG_FILES = ["babel.config.js", "babel.config.cjs", "babel.config.mjs", "babel.config.json", ".babelrc", ".babelrc.js", ".babelrc.json"];
49
- const ONE_GENERATED_MARKER = "@one-generated";
42
+ const USER_BABEL_CONFIG_FILES = [
43
+ "babel.config.js",
44
+ "babel.config.cjs",
45
+ "babel.config.mjs",
46
+ "babel.config.json",
47
+ ".babelrc",
48
+ ".babelrc.js",
49
+ ".babelrc.json"
50
+ ];
51
+ const ONE_GENERATED_MARKER = "@one/generated bundler-config";
50
52
  function findUserBabelConfig(projectRoot) {
51
- if (!projectRoot) return null;
52
- for (const name of USER_BABEL_CONFIG_FILES) {
53
- const fullPath = (0, import_node_path.join)(projectRoot, name);
54
- if ((0, import_node_fs.existsSync)(fullPath)) {
55
- try {
56
- const content = (0, import_node_fs.readFileSync)(fullPath, "utf8");
57
- if (content.includes(ONE_GENERATED_MARKER)) {
58
- continue;
59
- }
60
- } catch {
61
- continue;
62
- }
63
- return fullPath;
64
- }
65
- }
66
- return null;
53
+ if (!projectRoot) return null;
54
+ for (const name of USER_BABEL_CONFIG_FILES) {
55
+ const fullPath = (0, import_node_path.join)(projectRoot, name);
56
+ if ((0, import_node_fs.existsSync)(fullPath)) {
57
+ try {
58
+ const content = (0, import_node_fs.readFileSync)(fullPath, "utf8");
59
+ if (content.includes(ONE_GENERATED_MARKER)) {
60
+ continue;
61
+ }
62
+ } catch {
63
+ continue;
64
+ }
65
+ return fullPath;
66
+ }
67
+ }
68
+ return null;
67
69
  }
68
70
  function getBabelOptions(props) {
69
- props = {
70
- ...props,
71
- id: (0, import_vite.normalizePath)(props.id.split("?")[0])
72
- };
73
- const isProjectFile = !props.id.includes("node_modules");
74
- const userBabelConfig = isProjectFile && props.projectRoot ? findUserBabelConfig(props.projectRoot) : null;
75
- if (props.userSetting === "babel") {
76
- return getOptions(props, true, userBabelConfig);
77
- }
78
- if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
79
- if (props.userSetting?.excludeDefaultPlugins) {
80
- return {
81
- ...props.userSetting,
82
- ...(userBabelConfig ? {
83
- configFile: userBabelConfig,
84
- babelrc: true
85
- } : {})
86
- };
87
- }
88
- return getOptions(props, false, userBabelConfig);
89
- }
90
- const userSetting = props.userSetting;
91
- if (userSetting === "swc" || userSetting === "oxc" || userSetting === false || typeof userSetting === "object" && userSetting !== null && (userSetting.transform === "swc" || userSetting.transform === "oxc")) {
92
- return null;
93
- }
94
- if (userBabelConfig) {
95
- return getOptions(props, false, userBabelConfig);
96
- }
97
- return null;
71
+ props = {
72
+ ...props,
73
+ id: (0, import_vite.normalizePath)(props.id.split("?")[0])
74
+ };
75
+ const isProjectFile = !props.id.includes("node_modules");
76
+ const userBabelConfig = isProjectFile && props.projectRoot ? findUserBabelConfig(props.projectRoot) : null;
77
+ if (props.userSetting === "babel") {
78
+ return getOptions(props, true, userBabelConfig);
79
+ }
80
+ if (typeof props.userSetting === "undefined" || typeof props.userSetting === "object" && props.userSetting.transform === "babel") {
81
+ if (props.userSetting?.excludeDefaultPlugins) {
82
+ return {
83
+ ...props.userSetting,
84
+ ...userBabelConfig ? {
85
+ configFile: userBabelConfig,
86
+ babelrc: true
87
+ } : {}
88
+ };
89
+ }
90
+ return getOptions(props, false, userBabelConfig);
91
+ }
92
+ const userSetting = props.userSetting;
93
+ if (userSetting === "swc" || userSetting === "oxc" || userSetting === false || typeof userSetting === "object" && userSetting !== null && (userSetting.transform === "swc" || userSetting.transform === "oxc")) {
94
+ return null;
95
+ }
96
+ if (userBabelConfig) {
97
+ return getOptions(props, false, userBabelConfig);
98
+ }
99
+ return null;
98
100
  }
99
101
  const getOptions = (props, force = false, userBabelConfig = null) => {
100
- let plugins = [];
101
- if (force || shouldBabelGenerators(props)) {
102
- plugins = getBasePlugins(props);
103
- }
104
- const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") &&
105
- // if reanimated gets wrapped in transform it causes circular dep issues
106
- !/node_modules/.test(props.id) &&
107
- // only needed for createElement calls, so be a bit conservative
108
- props.code.includes("createElement");
109
- if (enableNativewind) {
110
- if (!props.id.includes("node_modules")) {
111
- plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
112
- }
113
- }
114
- if (enableNativewind || shouldBabelReanimated(props)) {
115
- try {
116
- const workletsPlugin = (0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot);
117
- (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
118
- plugins.push(workletsPlugin);
119
- } catch {}
120
- }
121
- if (shouldBabelReactCompiler(props)) {
122
- (0, import_constants.debug)?.(`Using babel react compiler on file`);
123
- plugins.push(getBabelReactCompilerPlugin(props));
124
- }
125
- if (plugins.length || userBabelConfig) {
126
- return {
127
- plugins,
128
- ...(userBabelConfig ? {
129
- configFile: userBabelConfig,
130
- babelrc: true
131
- } : {})
132
- };
133
- }
134
- return null;
102
+ let plugins = [];
103
+ if (force || shouldBabelGenerators(props)) {
104
+ plugins = getBasePlugins(props);
105
+ }
106
+ const enableNativewind = import_configure.configuration.enableNativewind && (props.environment === "ios" || props.environment === "android") && !/node_modules/.test(props.id) && props.code.includes("createElement");
107
+ if (enableNativewind) {
108
+ if (!props.id.includes("node_modules")) {
109
+ plugins.push((0, import_utils.resolvePath)("react-native-css-interop/dist/babel-plugin.js"));
110
+ }
111
+ }
112
+ if (enableNativewind || shouldBabelReanimated(props)) {
113
+ try {
114
+ const workletsPlugin = (0, import_utils.resolvePath)("react-native-worklets/plugin", props.projectRoot);
115
+ (0, import_constants.debug)?.(`Using babel worklets on file ${props.id}`);
116
+ plugins.push(workletsPlugin);
117
+ } catch {}
118
+ }
119
+ if (shouldBabelReactCompiler(props)) {
120
+ (0, import_constants.debug)?.(`Using babel react compiler on file`);
121
+ plugins.push(getBabelReactCompilerPlugin(props));
122
+ }
123
+ if (plugins.length || userBabelConfig) {
124
+ return {
125
+ plugins,
126
+ ...userBabelConfig ? {
127
+ configFile: userBabelConfig,
128
+ babelrc: true
129
+ } : {}
130
+ };
131
+ }
132
+ return null;
135
133
  };
136
134
  async function transformOxcReactCompiler(id, code, optionsOrTarget = "19", sourceMap = false) {
137
- const {
138
- transform
139
- } = await import("oxc-transform-react");
140
- const compilerOptions = typeof optionsOrTarget === "string" ? {
141
- target: optionsOrTarget
142
- } : optionsOrTarget || {};
143
- const target = compilerOptions.target ?? "19";
144
- const result = await transform(id, code, {
145
- jsx: "preserve",
146
- sourcemap: sourceMap,
147
- reactCompiler: {
148
- target,
149
- ...compilerOptions,
150
- environment: {
151
- enableCustomTypeDefinitionForReanimated: true,
152
- ...compilerOptions.environment
153
- }
154
- }
155
- });
156
- if (result.fatal) {
157
- throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map(e => e.message ?? String(e)).join(", ")}`);
158
- }
159
- if (result.errors?.length) {
160
- (0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map(e => e.message ?? String(e)).join(", ")}`);
161
- }
162
- return {
163
- code: result.code,
164
- map: sourceMap ? result.map : void 0
165
- };
135
+ const { transform } = await import("oxc-transform-react");
136
+ const compilerOptions = typeof optionsOrTarget === "string" ? { target: optionsOrTarget } : optionsOrTarget || {};
137
+ const target = compilerOptions.target ?? "19";
138
+ const result = await transform(id, code, {
139
+ jsx: "preserve",
140
+ sourcemap: sourceMap,
141
+ reactCompiler: {
142
+ target,
143
+ ...compilerOptions,
144
+ environment: {
145
+ enableCustomTypeDefinitionForReanimated: true,
146
+ ...compilerOptions.environment
147
+ }
148
+ }
149
+ });
150
+ if (result.fatal) {
151
+ throw new Error(`[vxrn:compiler] oxc react compiler failed on ${id}: ${(result.errors ?? []).map((e) => e.message ?? String(e)).join(", ")}`);
152
+ }
153
+ if (result.errors?.length) {
154
+ (0, import_constants.debug)?.(`[compiler/bailout] ${id}: ${result.errors.map((e) => e.message ?? String(e)).join(", ")}`);
155
+ }
156
+ return {
157
+ code: result.code,
158
+ map: sourceMap ? result.map : void 0
159
+ };
166
160
  }
167
161
  async function transformBabel(id, code, options) {
168
- const [{
169
- default: babelCore
170
- }, {
171
- default: hermesParserPlugin
172
- }] = await Promise.all([import("@babel/core"), import("babel-plugin-syntax-hermes-parser")]);
173
- const extension = (0, import_node_path.extname)(id);
174
- const isTSX = extension === ".tsx";
175
- const isTS = isTSX || extension === ".ts";
176
- const babelOptions = {
177
- filename: id,
178
- compact: false,
179
- babelrc: options.babelrc ?? false,
180
- configFile: options.configFile ?? false,
181
- sourceMaps: false,
182
- minified: false,
183
- ...options,
184
- presets: [isTS ? ["@babel/preset-typescript", {
185
- isTSX,
186
- allExtensions: isTSX
187
- }] : "", ...(options.presets || [])].filter(Boolean),
188
- // non-TS files use React Native's Flow dialect. RN's own component specs are
189
- // Flow `.js` (`import type`, `codegenNativeComponent<T>(…)`, `(expr: Type)` casts).
190
- // enable Hermes Flow parsing + stripping, mirroring the TypeScript preset above
191
- // (`@react-native/babel-preset` uses the same parser for JS). without it babel
192
- // can't parse current RN Flow syntax such as `call<T>(...) as HostComponent<T>`, so
193
- // plugins like
194
- // @react-native/babel-plugin-codegen silently fail on RN specs and the runtime
195
- // "Codegen didn't run" warning fires. TS path is byte-identical (empty slice).
196
- plugins: [...(isTS ? [] : [[hermesParserPlugin, {
197
- parseLangTypes: "flow",
198
- reactRuntimeTarget: "19"
199
- }]]), ...(options.plugins || []), ...(isTS ? [] : ["@babel/plugin-transform-flow-strip-types"])]
200
- };
201
- return await new Promise((res, rej) => {
202
- babelCore.transform(code, babelOptions, (err, result) => {
203
- if (!result || err) {
204
- return rej(err || new Error(`[vxrn:compiler] babel returned no result for ${id}`));
205
- }
206
- res(result);
207
- });
208
- });
162
+ const [{ default: babelCore }, { default: hermesParserPlugin }] = await Promise.all([import("@babel/core"), import("babel-plugin-syntax-hermes-parser")]);
163
+ const extension = (0, import_node_path.extname)(id);
164
+ const isTSX = extension === ".tsx";
165
+ const isTS = isTSX || extension === ".ts";
166
+ const babelOptions = {
167
+ filename: id,
168
+ compact: false,
169
+ babelrc: options.babelrc ?? false,
170
+ configFile: options.configFile ?? false,
171
+ sourceMaps: false,
172
+ minified: false,
173
+ ...options,
174
+ caller: {
175
+ name: "vxrn",
176
+ supportsStaticESM: true,
177
+ supportsDynamicImport: true
178
+ },
179
+ presets: [isTS ? ["@babel/preset-typescript", {
180
+ isTSX,
181
+ allExtensions: isTSX
182
+ }] : "", ...options.presets || []].filter(Boolean),
183
+ plugins: [
184
+ ...isTS ? [] : [[hermesParserPlugin, {
185
+ parseLangTypes: "flow",
186
+ reactRuntimeTarget: "19"
187
+ }], "babel-plugin-transform-flow-enums"],
188
+ ...options.plugins || [],
189
+ ...isTS ? [] : ["@babel/plugin-transform-flow-strip-types"]
190
+ ]
191
+ };
192
+ return await new Promise((res, rej) => {
193
+ babelCore.transform(code, babelOptions, (err, result) => {
194
+ if (!result || err) {
195
+ return rej(err || new Error(`[vxrn:compiler] babel returned no result for ${id}`));
196
+ }
197
+ res(result);
198
+ });
199
+ });
209
200
  }
210
- const getBasePlugins = ({
211
- development
212
- }) => [["@babel/plugin-transform-destructuring"], ["@babel/plugin-transform-react-jsx", {
213
- development
214
- }], ["@babel/plugin-transform-async-generator-functions"], ["@babel/plugin-transform-async-to-generator"], ["@babel/plugin-transform-runtime", {
215
- helpers: true,
216
- // NOTE THIS WAS SPELLED WRONG BEFOER THIS COMMIT MAYBE IT WAS UNINTENTIONALLY WORKING
217
- regenerator: false
218
- }]];
219
- const shouldBabelReactCompiler = props => {
220
- if (props.environment === "ssr") {
221
- return false;
222
- }
223
- if (!import_configure.configuration.enableCompiler) {
224
- return false;
225
- }
226
- const {
227
- enableCompiler
228
- } = import_configure.configuration;
229
- if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
230
- const isNative = props.environment === "ios" || props.environment === "android";
231
- const filter = isNative ? enableCompiler.native : enableCompiler.web;
232
- if (!filter) return false;
233
- return applyCompilerFilter(filter, props);
234
- }
235
- if (typeof enableCompiler === "function") {
236
- return enableCompiler(props.id, props.environment);
237
- }
238
- if (enableCompiler instanceof RegExp) {
239
- return enableCompiler.test(props.id);
240
- }
241
- if (Array.isArray(enableCompiler)) {
242
- if (!enableCompiler.includes(props.environment)) {
243
- return false;
244
- }
245
- }
246
- return applyDefaultFilters(props);
201
+ async function stripFlowTypes(id, code, sourceMaps = true) {
202
+ const result = await transformBabel(id, code, { sourceMaps });
203
+ return {
204
+ code: result.code,
205
+ map: result.map
206
+ };
207
+ }
208
+ const getBasePlugins = ({ development }) => [
209
+ ["@babel/plugin-transform-destructuring"],
210
+ ["@babel/plugin-transform-react-jsx", { development }],
211
+ ["@babel/plugin-transform-async-generator-functions"],
212
+ ["@babel/plugin-transform-async-to-generator"],
213
+ ["@babel/plugin-transform-runtime", {
214
+ helpers: true,
215
+ regenerator: false
216
+ }]
217
+ ];
218
+ const shouldBabelReactCompiler = (props) => {
219
+ if (props.environment === "ssr") {
220
+ return false;
221
+ }
222
+ if (!import_configure.configuration.enableCompiler) {
223
+ return false;
224
+ }
225
+ const { enableCompiler } = import_configure.configuration;
226
+ if (typeof enableCompiler === "object" && !Array.isArray(enableCompiler) && !(enableCompiler instanceof RegExp)) {
227
+ const isNative = props.environment === "ios" || props.environment === "android";
228
+ const filter = isNative ? enableCompiler.native : enableCompiler.web;
229
+ if (!filter) return false;
230
+ return applyCompilerFilter(filter, props);
231
+ }
232
+ if (typeof enableCompiler === "function") {
233
+ return enableCompiler(props.id, props.environment);
234
+ }
235
+ if (enableCompiler instanceof RegExp) {
236
+ return enableCompiler.test(props.id);
237
+ }
238
+ if (Array.isArray(enableCompiler)) {
239
+ if (!enableCompiler.includes(props.environment)) {
240
+ return false;
241
+ }
242
+ }
243
+ return applyDefaultFilters(props);
247
244
  };
248
245
  function applyCompilerFilter(filter, props) {
249
- if (typeof filter === "function") {
250
- return filter(props.id, props.environment);
251
- }
252
- if (filter instanceof RegExp) {
253
- return filter.test(props.id);
254
- }
255
- if (filter === true) {
256
- return applyDefaultFilters(props);
257
- }
258
- return false;
246
+ if (typeof filter === "function") {
247
+ return filter(props.id, props.environment);
248
+ }
249
+ if (filter instanceof RegExp) {
250
+ return filter.test(props.id);
251
+ }
252
+ if (filter === true) {
253
+ return applyDefaultFilters(props);
254
+ }
255
+ return false;
259
256
  }
260
257
  function applyDefaultFilters(props) {
261
- if (!/(\.tsx?)$/.test(props.id)) return false;
262
- if (props.id.includes("node_modules")) return false;
263
- if (props.id.includes("+api.")) return false;
264
- if (props.code.startsWith("// disable-compiler")) return false;
265
- return true;
258
+ if (!/(\.tsx?)$/.test(props.id)) return false;
259
+ if (props.id.includes("node_modules")) return false;
260
+ if (props.id.includes("+api.")) return false;
261
+ if (props.code.startsWith("// disable-compiler")) return false;
262
+ return true;
266
263
  }
267
- const getBabelReactCompilerPlugin = props => {
268
- const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
269
- return ["babel-plugin-react-compiler", {
270
- target
271
- }];
264
+ const getBabelReactCompilerPlugin = (props) => {
265
+ const target = props.reactForRNVersion === "18" && (props.environment === "ios" || props.environment === "android") ? "18" : "19";
266
+ return ["babel-plugin-react-compiler", { target }];
272
267
  };
273
- function shouldBabelGenerators({
274
- code
275
- }) {
276
- if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
277
- return import_constants.asyncGeneratorRegex.test(code);
278
- }
268
+ function shouldBabelGenerators({ code }) {
269
+ if (process.env.VXRN_USE_BABEL_FOR_GENERATORS) {
270
+ return import_constants.asyncGeneratorRegex.test(code);
271
+ }
279
272
  }
280
- const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = ["worklet", "useAnimatedGestureHandler", "useAnimatedScrollHandler", "useFrameCallback", "useAnimatedStyle", "useAnimatedProps", "createAnimatedPropAdapter", "useDerivedValue", "useAnimatedReaction", "useWorkletCallback", "withTiming", "withSpring", "withDecay", "withRepeat", "runOnUI", "executeOnUIRuntimeSync"];
273
+ const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
274
+ "worklet",
275
+ "useAnimatedGestureHandler",
276
+ "useAnimatedScrollHandler",
277
+ "useFrameCallback",
278
+ "useAnimatedStyle",
279
+ "useAnimatedProps",
280
+ "createAnimatedPropAdapter",
281
+ "useDerivedValue",
282
+ "useAnimatedReaction",
283
+ "useWorkletCallback",
284
+ "withTiming",
285
+ "withSpring",
286
+ "withDecay",
287
+ "withRepeat",
288
+ "runOnUI",
289
+ "executeOnUIRuntimeSync"
290
+ ];
281
291
  const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join("|"));
282
292
  const REANIMATED_IGNORED_PATHS = [
283
- // Prebuilt/vendored react-native that shouldn't be transformed
284
- "react-native-prebuilt", "node_modules/.vxrn/react-native",
285
- // Known false positives - they mention worklet keywords in comments/strings but don't use them
286
- "node_modules/react/", "node_modules/react-dom/", "node_modules/react-native/", "node_modules/react-native-web/"];
293
+ "react-native-prebuilt",
294
+ "node_modules/.vxrn/react-native",
295
+ "node_modules/react/",
296
+ "node_modules/react-dom/",
297
+ "node_modules/react-native/",
298
+ "node_modules/react-native-web/"
299
+ ];
287
300
  const REANIMATED_IGNORED_PATHS_REGEX = new RegExp(REANIMATED_IGNORED_PATHS.join("|"));
288
- function shouldBabelReanimated({
289
- code,
290
- id
291
- }) {
292
- if (!import_configure.configuration.enableReanimated) {
293
- return false;
294
- }
295
- if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
296
- return false;
297
- }
298
- if (REANIMATED_REGEX.test(code)) {
299
- const location = id.includes("node_modules") ? "node_modules" : "user-code";
300
- (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
301
- return true;
302
- }
303
- return false;
304
- }
301
+ function shouldBabelReanimated({ code, id }) {
302
+ if (!import_configure.configuration.enableReanimated) {
303
+ return false;
304
+ }
305
+ if (REANIMATED_IGNORED_PATHS_REGEX.test(id)) {
306
+ return false;
307
+ }
308
+ if (REANIMATED_REGEX.test(code)) {
309
+ const location = id.includes("node_modules") ? "node_modules" : "user-code";
310
+ (0, import_constants.debug)?.(` \u{1FA84} [reanimated/${location}] ${(0, import_node_path.relative)(process.cwd(), id)}`);
311
+ return true;
312
+ }
313
+ return false;
314
+ }